Nagios Plugins
We've got Nagios system monitoring running here at the office to check that our services such as:
- Web servers
- Email servers
- Internal servers (HDD space)
- SSH
- FT
are up and running and that we have not run out of disk space. This is working quite well inside but I wanted to roll it out further and to be able to check the disk space on our Cobalt RaQ's as well. But as luck would have it I was unable to compile the Nagios plugins on the RaQ's due to it requiring GLIBC2_2 or higher.
Now these machines are working fine and I really did not want to break anything. So off I went a googling but that came back with nothing. My next brilliant idea was to then develop my own plugin but in PHP so that it could be run on any server.
Thankfully that turned out to be fairly simple as PHP already has inbuilt functions to determine space available, free, etc. Not too much later and I had the following:
<?php
$fs = $argv[1];
$percentage_warn = $argv[2];
$space_total = round(disk_total_space($fs) / (1024*1024));
$space_free = round(disk_free_space($fs) / (1024*1024));
$space_used = round((disk_total_space($fs) - disk_free_space($fs)) / (1024*1024));
$space_used_percentage = round((disk_total_space($fs) -disk_free_space($fs)) / disk_total_space($fs) * 100);
$space_free_percentage = 100 - $space_used_percentage;
// Display in Nagios tradition
if ($space_free_percentage > $percentage_warn)
{
echo "DISK OK - free space: $fs $space_free MB (".$space_free_percentage."%);n";
exit(0);
}
else
{
echo "DISK WARNING - free space: $fs $space_free MB (".(100 - $space_used_percentage)."%);\n";
exit(1);
}
?>
We are now running that script via SSH and integrating that into Nagios (check_by_ssh). Voila!