Class: Proxy::Monitoring::Icinga2::Icinga2InitialImporter
- Inherits:
-
Object
- Object
- Proxy::Monitoring::Icinga2::Icinga2InitialImporter
- Includes:
- Log
- Defined in:
- lib/smart_proxy_monitoring_icinga2/icinga2_initial_importer.rb
Instance Method Summary collapse
- #import_downtimes ⇒ Object
- #import_hosts ⇒ Object
- #import_services ⇒ Object
-
#initialize(queue) ⇒ Icinga2InitialImporter
constructor
A new instance of Icinga2InitialImporter.
- #monitor ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(queue) ⇒ Icinga2InitialImporter
Returns a new instance of Icinga2InitialImporter.
9 10 11 |
# File 'lib/smart_proxy_monitoring_icinga2/icinga2_initial_importer.rb', line 9 def initialize(queue) @queue = queue.queue end |
Instance Method Details
#import_downtimes ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/smart_proxy_monitoring_icinga2/icinga2_initial_importer.rb', line 66 def import_downtimes results = Icinga2Client.get('/objects/downtimes?attrs=host_name&attrs=service_name&attrs=trigger_time') results = JSON.parse(results) results['results'].each do |result| next unless result['attrs']['trigger_time'] != 0 parsed = { host: result['attrs']['host_name'], service: result['attrs']['service_name'], downtime: true, initial: true, type: '_parsed' } @queue.push(parsed) end end |
#import_hosts ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/smart_proxy_monitoring_icinga2/icinga2_initial_importer.rb', line 33 def import_hosts results = Icinga2Client.get('/objects/hosts?attrs=name&attrs=last_check_result&attrs=acknowledgement') results = JSON.parse(results) results['results'].each do |result| parsed = { host: result['attrs']['name'], result: result['attrs']['last_check_result']['state'], timestamp: result['attrs']['last_check_result']['schedule_end'], acknowledged: (result['attrs']['acknowledgement'] != 0), initial: true, type: '_parsed' } @queue.push(parsed) end end |
#import_services ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/smart_proxy_monitoring_icinga2/icinga2_initial_importer.rb', line 49 def import_services results = Icinga2Client.get('/objects/services?attrs=name&attrs=last_check_result&attrs=acknowledgement&attrs=host_name') results = JSON.parse(results) results['results'].each do |result| parsed = { host: result['attrs']['host_name'], service: result['attrs']['name'], result: result['attrs']['last_check_result']['state'], timestamp: result['attrs']['last_check_result']['schedule_end'], acknowledged: (result['attrs']['acknowledgement'] != 0), initial: true, type: '_parsed' } @queue.push(parsed) end end |
#monitor ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/smart_proxy_monitoring_icinga2/icinga2_initial_importer.rb', line 13 def monitor logger.debug 'Starting initial icinga import.' around_action('Initial Host Import') do import_hosts end around_action('Initial Services Import') do import_services end around_action('Initial Downtimes Import') do import_downtimes end logger.info 'Finished initial icinga import.' rescue Exception => e logger.error "Error during initial import: #{e.message}\n#{e.backtrace}" end |
#start ⇒ Object
82 83 84 85 86 |
# File 'lib/smart_proxy_monitoring_icinga2/icinga2_initial_importer.rb', line 82 def start @thread = Thread.new { monitor } @thread.abort_on_exception = true @thread end |
#stop ⇒ Object
88 89 90 |
# File 'lib/smart_proxy_monitoring_icinga2/icinga2_initial_importer.rb', line 88 def stop @thread.terminate unless @thread.nil? end |