Extend the Opsview Agent
Warning
This documentation is archived and will no longer be updated. We recommend that new and existing customers deploying new monitoring solutions use the ITRS Infrastructure Agent instead.
Overview Copied
Opsview can monitor different types of hosts, such as networking devices and servers. It offers a package for many servers that can be installed to improve monitoring and provide insights on what is internally happening to the server instead of just running checks from outside the host against the services that the host provides.
The Opsview Agent is preconfigured with Host Templates, but it can be extended to provide more functionalities.
Stock Opsview Agent Copied
The stock Opsview Agent installs all files under /usr/local/nagios
(this may change to /opt/opsview/agent
in the future) with all files owned by the user nagios
and group nagios
.
Six directories may be created in this area:
bin
— location of the nrpe daemon binary; when running, the daemon listens for connections from the Orchestrator or Collector Nodes, runs the plugin, and returns the result.etc
— location of the main configuration filenrpe.cfg
.lib
— optional directory containing supplementary files for the daemon.libexec
— location of plugins the daemon calls to do the actual work.perl
— supplementary library files used by Perl based plugins.var
— directory used by some plugins to store persistent data.
The file etc/nrpe.cfg
contains all the configuration that the nrpe daemon needs to run, such as which port to listen on, which IP addresses are allowed to contact it, which checks are available to run, and how long it must run before the daemon times out and stops them. This file should not be changed as it is overwritten every time the agent package is upgraded.
Add a new check Copied
In this example, a check called check_test
is used on a monitored host, which will return an OK
status along with the message Check ran okay
.
To start, log in to the Opsview Orchestrator or Collector Node. Assuming that 192.168.15.218 is the monitored host where we will create the check, run the command:
$ /usr/local/nagios/libexec/check_nrpe -H 192.168.15.218 -c check_test
NRPE: Command 'check_test' not defined
This means that the agent on the monitored host is responding to request, and the check name is not yet configured.
To create the plugin, log in to the monitored host as root and create the file /usr/local/nagios/libexec/check_test.pl
containing the following:
#!/bin/bash
echo "Check ran okay"
exit 0
For more information about writing checks, see Monitoring Plugins Development Guidelines.
Make this script executable by running:
# chmod +x check_test.pl
And then run the following to test that the check is working:
# /usr/local/nagios/libexec/check_test.pl
Check ran okay
# echo $?
0
At this point, you can configure the agent to associate the command check_test
with the plugin being executed, check_test.pl
.
To do this, an additional configuration file is created within the directory /usr/local/nagios/etc/nrpe_local/
. It is safe to create this directory if it does not already exist. Any files in this directory with the suffix .cfg
will be read after nrpe.cfg
.
Warning
Do not make changes tonrpe.cfg
as they will be lost when the agent is upgraded.
Create a file /usr/local/nagios/etc/nrpe_local/local.cfg
with the following line:
command[check_test]=/usr/local/nagios/libexec/check_test.pl $ARG1$
The $ARG1$
is important as this takes any arguments provided by Opsview and passes them directly to the plugin being called. Without this, the arguments configured in Opsview will be ignored.
Subsequently, the agent can be restarted.
# /etc/init.d/opsview-agent restart
Note
This depends on your host. For example,service opsview-agent restart
might be more appropriate.
At this point, you can now re-run the test on the Opsview Orchestrator or Collector Node and prove that the new plugin works as expected.
$ /usr/local/nagios/libexec/check_nrpe -H 192.168.15.218 -c check_test
Check ran okay
$ echo $?
0
Change the settings Copied
The local.cfg
file may also be used to reconfigure the agent. For example, the default timeout for the agent running a plugin is 60 seconds; for some plugins, this may not be long enough. To increase the timeout to 2 minutes, you can add the following command and restart the agent:
command_timeout=120
Warning
Changing some of these settings may prevent the daemon from starting or running correctly.