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. We will use Bash, the standard Linux shell.
We will create a plugin that checks that the storage path specified in '
/etc/op5-backup/main.conf' exists, to make sure that
op5-backup is configured properly for local operation.
To create a more complex plugin
Create the script and edit it:
# cd /opt/plugins/custom
# touch check_op5backup
# chmod 755 check_op5backup
Open up the script with your favorite text editor and type in the following code:
# Create a function to print the storage path
grep ^storagepath /etc/op5-backup/main.conf |tail -1 |sed 's/^[^"]*"//g' | sed 's/"$//g'
# Put the storage path in an environmental variable
# Test if the storagepath exists and is a directory
if [[ ! -d "$STORAGEPATH" ]]; then
# Print a warning message for the web gui
echo op5-backup is not properly configured for local operation
# Exit with status Warning (exit code 1)
# If the script reaches this point then the test passed
# Print an OK message
echo $STORAGEPATH exists
# Exit with status OK
The above uses 'grep', the global regular expression printer, and 'sed', the stream editor:
? 'grep' was originally just a feature of an older Unix text editor, 'ex'. If you worked with DOS in the 3.x era, you may have used its sibling, 'edlin'. Unlike edlin, ex is still around. Unix and Linux admins still use its visual mode ('vi') several times a day.
? 'sed' was designed to deal with streams of text. It's complex enough to be studied as a scripting language of its own. Combine it with 'awk', a formatting language developed by some of the same team that invented C, and you can do amazing things in milliseconds that would take hours with a mouse.
Add a check_command like this using the OP5 Monitor configuration interface:
- Enter the service configuration for your monitor server, and add a service with
check_op5backup as the check_command
- Save configuration.
This chapter has only scratched on the surface of how to write your own plugins. To read more about plugin development, take a look at the guidelines from the Monitoring Plugins Development Team.