-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_active_monitors.rb
33 lines (32 loc) · 1023 Bytes
/
get_active_monitors.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 2016
# Written By Kerrington Wells
require 'open3'
hostname = `hostname -f`
def save_health_count(hostname)
cmd = 'curl -l https://dash.ihg.com/api/ipsoft/hostDowntimeUptime.php?hosts=' + hostname + '\\&action=downtime\\&duration=100'
cmd = cmd.gsub("\n","")
puts cmd
stdout, stdeerr, status = Open3.capture3(cmd)
output = stdout
puts output
if output.include? 'rrors' or output.include? 'Undefined variable:' or output.include? 'Trying to get property of non-object'
puts 'THIS NODE IS WAS NOT DOWNTIMED'
else
puts 'HOST HAS BEEN DOWNTIMED.'
end
cmd = 'curl -l https://dash.ihg.com/api/ipsoft/hostStatus.php?hosts=' + hostname + '.ihg'
cmd = cmd.gsub("\n","")
stdout, stdeerr, status = Open3.capture3(cmd)
output = stdout
output = output.split(/,/)
total = 0
output.each do |x|
if x.include? "OK"
x = x.gsub! /"OK":/, ''
total += x.to_i
end
end
File.open('/var/log/node_health', 'w') { |file| file.write(total) }
total
end
save_health_count(hostname)