op5 Monitor is shipped with many plugins that cover most monitoring needs. But what to do if one of your corporate applications can not be monitored straight out of the box?Often you can find a plugin at www.nagiosexchange.org, and since op5 Monitor and Nagios uses the same plugin format you can often simply download a plugin, put it in /opt/plugins/custom/ and start using it.However, if you can not find a suitable plugin anywhere you might have to write your own plugin. Since the plugin interface is very straight-forward, anyone with a fair amount of UNIX scripting experience can do this.The reason for placing your own plugins in /opt/plugins/custom is because then it will not be touched by any upgrade from op5.Be for you can start develop you own plugins you need to make sure you have ssh access or terminal access to your op5 server the possibility to transfer files to your op5 Monitor server any kind of editor, vim and jed are installed by default on your op5 Monitor server.
Microsoft windows users may use PuTTY for terminal access via SSH and WinSCP for file transfers via SFTP (SSH).Macintosh or UNIX/Linux users may use the commands ssh or scp from a local terminal window.TCP OK - 0.043 second response time on port 80|time=0.042824s;0.000000;0.000000;0.000000;10.000000In the Example 1 on page 83 we first execute check_tcp to test that port 80/tcp on 193.201.96.136 responds, which it does, hence the exit code of 0.Then we check port 143/tcp on the same host and that port is not open, hence the result is Critical - exit code 2.
The performance data is not mandatory but you need it if you want your plugin to be able to produce graphs for you in op5 Monitor.The Status output is the text describing the result in readable words. The plugin must print the status output to stdout when your plugin is executed.This text can be anything, including HTML, you like to use to describe the status situation for your plugin.The performance data is data displaying the result in numbers. The plugin must print the status output to stdout when your plugin is executed. It is also used to produce performance graphs in op5 Monitor.
The label can contain any characters. If space is included quotes are needed. The plugin was able to check the service, but it appeared to be above some "warning" threshold or did not appear to be working properly
![]()
c - A continuous counter like bytes transmitted on an interface. warn, crit, min, max
![]()
Can all be null and trailing unfilled semicolons can be dropped.
Example 2 The Example 2 on page 85 shows a performance data output from a plugin with two values separated with one space in the output.The return code is the one that op5 Monitor uses to determine what state the services is in. It may be one of the following:All above 0 is to be known as problem states.
Table 2
The plugin was able to check the service, but it appeared to be above some "warning" threshold or did not appear to be working properly The plugin detected that either the service was not running or it was above some "critical" threshold Something unknown happened during the check. Things like invalid command line arguments or low-level failures internal to the plugin shall not be reported as Unknown state.In this section we will create a very simple plugin. We will write it as a bash script in a ssh connection to the op5 Monitor server.This plugin will not actually be very useful but we will use it to describe the steps needed when you starts to add other more useful plugins.
1
2 Open up the script with your favorite text editor and type in the following example plugin:
#!/bin/sh
echo 'WARNING: Hello world!'
exit 1
5 echo $? prints the return code of the last executed command.
1
2
3 In this section we will create a more complex and useful plugin compared to the one we created in Adding your first plugin to op5 Monitor on page 87. We will stick to bash, because of the simplicityWe will create a plugin that checks that the storage path specified in /etc/op5backup.conf exists, to make sure that op5backup.sh is configured properly for local operation.
1 Create the script and editing it:
cd /opt/plugins/custom
touch check_op5backup
chmod 755 check_op5backup
2 Open up the script with your favorite text editor and type in the following code:
#!/bin/bash
# Create a function to print the storage path
storagepath() {
grep ^storagepath /etc/op5backup.conf |
tail -1 |
sed 's/^[^"]*"//g' | sed 's/"$//g'
}
# Put the storage path in an environmental variable
STORAGEPATH=`storagepath`
# Test if the storagepath exists and is a directory
if [[ ! -d "$STORAGEPATH" ]]; then
# Print a warning message for the web gui
echo op5backup.sh is not properly configured for local operation
# Exit with status Warning (exit code 1)
exit 1
fi
# If the script reaches this point then the test passed
# Print an OK message
echo $STORAGEPATH exists
# Exit with status OK
exit 0
3 Add a check_command like this using the op5 Monitor web gui:
command_name: check_op5backup
command_line: $USER1/custom/check_op5backup
4 Enter the service configuration for your monitor server, and add a service with check_op5backup as the check_command.