skip to main content
Plugins : Ccreating a more complex plugin
   
Creating a more complex plugin
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 112. We will stick to bash, because of the simplicity.
We 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.
To create a more complex plugin
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.
5 Save configuration.