Created
May 15, 2015 00:58
-
-
Save jamiecook/63f08c1ad9c439f7daa2 to your computer and use it in GitHub Desktop.
check_temperature.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'date' | |
warn,crit=30.0,35.0 | |
while a = ARGV.shift | |
if a == "-w" | |
warn = ARGV.shift.to_f | |
elsif a == "-c" | |
crit = ARGV.shift.to_f | |
end | |
end | |
temp = `tail -1 /var/log/temperature.log | awk '{ print $2 }'`.strip.to_f | |
reading_time_stamp = `tail -1 /var/log/temperature.log | awk '{ print $1 }'`.strip.gsub(/[\[\]]/, '') | |
reading_time_stamp = DateTime.strptime(reading_time_stamp, "%Y:%m:%d:%H:%M:%S") | |
age_of_reading = (DateTime.now - reading_time_stamp).to_f * 24 * 60 # in minutes | |
puts "#{temp}|banner-temp=#{temp}" | |
# nagios states: ok, warning, critical, unknown (0-3) | |
exit 1 if temp > warn || age_of_reading > 5 | |
exit 2 if temp > crit || age_of_reading > 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment