Last active
February 12, 2016 19:23
-
-
Save markhorrocks/3a75ec56640acd6f15ed to your computer and use it in GitHub Desktop.
A Nagios ruby NRPE plugin to check, list and graph all volumes for an Ubuntu server.
This file contains 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 | |
# you may need to use /usr/bin/ruby | |
def largest_hash_key(hash) | |
hash.max_by{|k,v| v} | |
end | |
filesystem = %x(df -h) | |
perfdata = filesystem.split("\n") | |
.grep(/\A\/dev/) | |
.map(&:split) | |
.map{ |e| "'%s'=%s" % [ e[-1], e[-2] ] } | |
.join(" ") | |
volumes = Hash[perfdata.split(" ").map {|str| str.split("=")}] | |
volumes = volumes.map{ |k, v| [k, v.to_i] } | |
full_disk = largest_hash_key(volumes) | |
pc_full = full_disk[1] | |
message = "#{perfdata} | #{perfdata}" | |
if pc_full > 94 | |
puts "DISK CRITICAL - #{message}" | |
exit 2 | |
elsif pc_full > 89 | |
puts "DISK WARNING - #{message}" | |
exit 1 | |
else | |
puts "DISK OK - #{message}" | |
exit 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make the file check_disk_usage.rb executable with chmod +x and upload it to /usr/lib/nagios/plugins.
Add the following line to nrpe.cfg
command[check_disk_usage]=/usr/lib/nagios/plugins/check_disk_usage.rb
Add the service in services.cfg:
define service {
hostgroup_name check_disk_usage
service_description check_disk_usage
check_command check_nrpe_1arg!check_disk_usage
use generic-service,graphed-service
notification_interval 5
}
Add the hostgroup in hostgroups.cfg (or hosts.cfg if you don't use hostgroups)
define hostgroup {
hostgroup_name check_disk_usage
alias check_disk_usage
members server1,server2,server3
}
Test with
nagios@nagios-server:/home/me$ /usr/lib/nagios/plugins/check_nrpe -H client-server -c check_disk_usage
DISK OK - '/'=37% '/tmp'=1% '/srv'=63% '/backups'=80% | '/'=37% '/tmp'=1% '/srv'=63% '/backups'=80%