Class: Proxy::Monitoring::Icinga2::Icinga2InitialImporter
- Inherits:
-
Object
- Object
- Proxy::Monitoring::Icinga2::Icinga2InitialImporter
show all
- Includes:
- Log, TasksCommon
- Defined in:
- lib/smart_proxy_monitoring_icinga2/icinga2_initial_importer.rb
Instance Method Summary
collapse
#action, #activated?, #start
Constructor Details
Returns a new instance of Icinga2InitialImporter.
10
11
12
|
# File 'lib/smart_proxy_monitoring_icinga2/icinga2_initial_importer.rb', line 10
def initialize(queue)
@queue = queue.queue
end
|
Instance Method Details
#do_start ⇒ Object
85
86
87
88
89
|
# File 'lib/smart_proxy_monitoring_icinga2/icinga2_initial_importer.rb', line 85
def do_start
@thread = Thread.new { monitor }
@thread.abort_on_exception = true
@thread
end
|
#import_downtimes ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/smart_proxy_monitoring_icinga2/icinga2_initial_importer.rb', line 69
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/smart_proxy_monitoring_icinga2/icinga2_initial_importer.rb', line 34
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|
next if result['attrs']['last_check_result'] == nil
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/smart_proxy_monitoring_icinga2/icinga2_initial_importer.rb', line 51
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|
next if result['attrs']['last_check_result'] == nil
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
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/smart_proxy_monitoring_icinga2/icinga2_initial_importer.rb', line 14
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
|
#stop ⇒ Object
91
92
93
|
# File 'lib/smart_proxy_monitoring_icinga2/icinga2_initial_importer.rb', line 91
def stop
@thread.terminate unless @thread.nil?
end
|