We write our plugin for nagios
In my daily work I use nagios very actively . It seems to me that this is a very powerful system for monitoring servers. You can monitor server load, availability of different servers, etc., etc.
There are so many plugins for nagios. A large collection of plugins is located at nagiosplugins.org . You can find the right one for yourself, put and enjoy life. But what to do if not a single plugin suits your functionality? Never mind. Let's write your own. It is very simple.
So, let's begin.
The first thing we need to know to write the simplest plugin is how nagios works at a basic level.
He parses his config, finds the command to launch a plugin there and launches it. For example, php -f checkServer.php. checkServer.php does some of its job of checking the server and returns a status message and a shutdown code in response.
Nagios understands 4 shutdown codes
A status message is any information that is output by a script to standard output.
And so the script itself is the simplest plugin for nagios (in php). that’s all - we connect in nagios and it will check whether the file exists or not. Of course, you can organize any test of the business logic of your project, up to automatic testing through phpunit.
There are so many plugins for nagios. A large collection of plugins is located at nagiosplugins.org . You can find the right one for yourself, put and enjoy life. But what to do if not a single plugin suits your functionality? Never mind. Let's write your own. It is very simple.
So, let's begin.
The first thing we need to know to write the simplest plugin is how nagios works at a basic level.
He parses his config, finds the command to launch a plugin there and launches it. For example, php -f checkServer.php. checkServer.php does some of its job of checking the server and returns a status message and a shutdown code in response.
Nagios understands 4 shutdown codes
- 0 - Everything is OK.
- 1 - Warning
- 2 - Critical error
- 3 - Something unknown happened
A status message is any information that is output by a script to standard output.
And so the script itself is the simplest plugin for nagios (in php). that’s all - we connect in nagios and it will check whether the file exists or not. Of course, you can organize any test of the business logic of your project, up to automatic testing through phpunit.
define( "STATUS_OK", 0 );
define( "STATUS_WARNING", 1 );
define( "STATUS_CRITICAL", 2 );
define( "STATUS_UNKNOWN", 3 );
$checkFilePath = 'file';
if(file_exists($checkFilePath))
{
echo 'File exists. Everything is ok';
exit(STATUS_OK);
}
echo 'File does not exists';
exit(STATUS_CRITICAL);