Class: Proxy::Monitoring::Icinga2::Provider
- Includes:
- Log, Util
- Defined in:
- lib/smart_proxy_monitoring_icinga2/monitoring_icinga2_main.rb
Direct Known Subclasses
Constant Summary collapse
- ICINGA_HOST_ATTRS =
%w[display_name address address6 templates].freeze
- ICINGA_ATTR_MAPPING =
{ 'ip' => 'address', 'ip6' => 'address6', }.freeze
Instance Method Summary collapse
- #create_host(host, attributes) ⇒ Object
- #query_host(host) ⇒ Object
- #remove_downtime_host(host, author, comment) ⇒ Object
- #remove_host(host) ⇒ Object
- #set_downtime_host(host, author, comment, start_time, end_time, all_services: nil) ⇒ Object
- #update_host(host, attributes) ⇒ Object
Instance Method Details
#create_host(host, attributes) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/smart_proxy_monitoring_icinga2/monitoring_icinga2_main.rb', line 24 def create_host(host, attributes) request_url = "/objects/hosts/#{host}" result = with_errorhandling("Create #{host}") do Icinga2Client.put(request_url, host_data(attributes).to_json) end result.to_json end |
#query_host(host) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/smart_proxy_monitoring_icinga2/monitoring_icinga2_main.rb', line 15 def query_host(host) request_url = "/objects/hosts/#{host}?attrs=vars&attrs=address&attrs=address6&attrs=templates" result = with_errorhandling("Query #{host}") do Icinga2Client.get(request_url) end host_attributes(host, result['results'][0]['attrs']) end |
#remove_downtime_host(host, author, comment) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/smart_proxy_monitoring_icinga2/monitoring_icinga2_main.rb', line 51 def remove_downtime_host(host, , comment) request_url = "/actions/remove-downtime" data = { type: 'Host', filter: "host.name==\"#{host}\"", author: , comment: comment, } result = with_errorhandling("Remove downtime from #{host}") do Icinga2Client.post(request_url, data.to_json) end result.to_json end |
#remove_host(host) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/smart_proxy_monitoring_icinga2/monitoring_icinga2_main.rb', line 42 def remove_host(host) request_url = "/objects/hosts/#{host}?cascade=1" result = with_errorhandling("Remove #{host}") do Icinga2Client.delete(request_url) end result.to_json end |
#set_downtime_host(host, author, comment, start_time, end_time, all_services: nil) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/smart_proxy_monitoring_icinga2/monitoring_icinga2_main.rb', line 66 def set_downtime_host(host, , comment, start_time, end_time, all_services: nil, **) request_url = "/actions/schedule-downtime" data = { 'type' => 'Host', 'filter' => "host.name==\"#{host}\"", 'author' => , 'comment' => comment, 'start_time' => start_time, 'end_time' => end_time, 'duration' => 1000, } data['all_services'] = all_services unless all_services.nil? result = with_errorhandling("Set downtime on #{host}") do Icinga2Client.post(request_url, data.to_json) end result.to_json end |
#update_host(host, attributes) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/smart_proxy_monitoring_icinga2/monitoring_icinga2_main.rb', line 33 def update_host(host, attributes) request_url = "/objects/hosts/#{host}" result = with_errorhandling("Update #{host}") do Icinga2Client.post(request_url, host_data(attributes).to_json) end result.to_json end |