|
|
Examples of Custom Checks
As outlined in faq414-Custom-Script-Checks the Auto-Response facility can be set to run custom scripts with nominated arguments, whose return values are used to trigger particular actions. Below are some examples of custom script checks.
Monitoring web sites and applications
The Auto-Response facility provides a number of checks that can be used to monitor if a website or web application is responding, running and delivering meaningful information:
- Test the web server is available and responding to a Ping Check
- Check the web server aplication is running by using Custom Check to either:
- Execute a script to telnet to the server and check Port 80 (HTTP) and/or Port 443 (HTTPS) are open, or
- Execute a /bin/curl script with Argument 1: -o, Argument 2: /dev/null and Argument 3: web server/application address
- Monitor website content on a targeted page on the site to check that it is serving up expected text.
- Create script to access web address and check pattern match:
#!/bin/bash
ADDR=$1
STRING=$2
if [ -z "$ADDR" -o -z "$STRING" ]
then
echo "Usage: checker address pattern";
exit 1;
fi
curl $ADDR 2>/dev/null | grep "$STRING"
RESULT=$?
if [ $RESULT -ne 0 ]
then
echo "Pattern: $STRING not found";
fi
exit $RESULT
Save as /etc/config/scripts/web-check
- Then create the Custom Check:
Script Executable = /etc/config/scripts/web-check
Argument 1: web server/application address
Argument 2: grep pattern to search for
Successful Return Code: 0
An Auto-Response is triggered if the response from the script is not "0" which indicates the web site/application did return the expected text
Verify your Exchange server is accepting connections
- Configure the Custom Check to run netcat monitor if smtp server is up (i.e. port 25 is open)
Script executable: /bin/nc
Argument 1: -w
Argument 2: 5
Argument 3: -z
Argument 4: Server address (eg. mail.opengear.com)
Argument 5: 25 (port 25 is smtp)
Successful return code: 0
- Alternately you can create a telnet script executable that tests incoming connection.
Create script test_smtp.sh:
#!/bin/bash
logger "Checking smtp server"
status=1
(
echo "quit"
) | telnet $1 25 | grep Connected > /dev/null 2>&1 if [ "$?" -ne "1" ]; then logger "PORT CONNECTED"
status=0;
else #Connection failure
logger "CONNECTION FAILED"
fi
exit $status
Then create the Custom Check:
Script Executable = ...../test_smtp.sh
Argument 1: server address ( eg. mail.opengear.com)
Other Custom Checks
SNMP
Custom scripts are able to query SNMP MIBs on managed devices using the snmpwalk application (which is able to retrieve a subtree of any arbitrary MIB). So you can build custom actions based on SNMP queries.
Note: For general info on monitoring, auto-response (and alert config pre V3.5.1) refer faq409-Auto-Response-Alerts
|