Nagios Glitzerlampe
Nagios Glitzerlampe
I have a nagios-system running in my network. i wanted to see if my network is ok, without checking the nagios console or reading my mail. So i hacked together a little ruby script to visualize my network status using a "Glitzerlampe" (similar to a lava-lamp but little metal pieces instead of funny bubbles)
All it does is fetching the nagios status page and parsing it for critical services. status is stored to a simple textfile so it only switches the lamp on/off if the status has changed since the last check.
my script controls the lamp using a Gembird SIS-PM sispmctl but it should be very easy to use something like X10 instead
Sourcecode
#!/usr/bin/ruby
require 'net/http'
def fetchstatus()
res = nil
Net::HTTP.start('nagiosserverhostname', 80) {|http|
req = Net::HTTP::Get.new('/nagios/cgi-bin/status.cgi?host=all')
req.basic_auth 'nagiosadmin', 'youtpasswordhere'
res = http.request( req )
}
body = res.body
if /statusCRITICAL/ =~ body then
status = 'on'
else
status = 'off'
end
return status
end
filename = '/path/to/status.glz'
status = fetchstatus()
if status == 'on' then
sleep 10
status = fetchstatus()
end
f = open( filename )
if f.read() != status then
f2 = open( filename, 'w')
f2.write( status )
f2.flush
f2.close
exec "sudo /usr/local/bin/sispmctl -o 2" if status == 'on'
exec "sudo /usr/local/bin/sispmctl -f 2" if status == 'off'
end
f.close