📜 ⬆️ ⬇️

We write your plugin for nagios

In my daily work I use nagios very actively. As it seems to me, this is a very powerful system for monitoring servers. You can monitor server load, availability of different servers, etc., etc.

For nagios there are so many plugins. A large collection of plugins is available at nagiosplugins.org . You can find a suitable for yourself, set and enjoy life. But what to do if no plugin suits you in terms of functionality? Never mind. We will write your own. It is very simple.

So, let's begin.
')
The first thing we need to know for writing a simple plugin is how Nagios works at a basic level.

It parses its config, finds a command to start any plug-in there and launches it. For example, php -f checkServer.php. checkServer.php does some of its job of checking the server and responds with a status message and exit code.

Nagyos understands 4 exit codes

The status message is any information that is displayed by the script on the standard output.

And so the script of the simplest nagios plugin (in php).

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);


that's all - plug in nagios and it will check whether the file exists or not. Of course, you can organize any verification of the business logic of your project, up to automatic testing via phpunit.

Source: https://habr.com/ru/post/61430/


All Articles