284
1.877.877.2269
BLACKBOX.COM
NEED HELP?
LEAVE THE TECH TO US
LIVE 24/7
TECHNICAL
SUPPORT
1.877.877.2269
CHAPTER 16: ADVANCED CONFIGURATION
16.1.2 RUNNING CUSTOM SCRIPTS WHEN ALERTS ARE TRIGGERED
Whenever an alert gets triggered, specific scripts get called. These scripts all reside in /etc/scripts/. Below is a list of the default
scripts that get run for each applicable alert.
For a connection alert (when a user connects or disconnects from a port or network host):
/etc/scripts/portmanager-user-alert (for port connections).
/etc/scripts/sdt-user-alert (for host connections).
For a signal alert (when a signal on a port changes state):
/etc/scripts/portmanager-signal-alert
For a pattern match alert (when a specific regular expression is found in the serial ports character stream):
/etc/scripts/portmanager-pattern-alert
For a UPS status alert (when the UPS power status changes between on line, on battery, and low battery):
/etc/scripts/ups-status-alert
For an environmental, power and alarm sensor alerts (temperature, humidity, power load and battery charge alerts):
/etc/scripts/environmental-alert
For an interface failover alert:
/etc/scripts/interface-failover-alert
All these scripts do a check to see whether you have created a custom script to run instead. The code that does this check is shown
below (an extract from the file /etc/scripts/portmanager-pattern-alert):
# If there’s a user-configured script, run it instead
scripts[0]="/etc/config/scripts/pattern-alert.${ALERT_PORTNAME}"
scripts[1]="/etc/config/scripts/portmanager-pattern-alert"
for (( i=0 ; i < ${#scripts[@]} ; i++ )); do
if [ -f "${scripts[$i]}" ]; then
exec /bin/sh "${scripts[$i]}"
fi
done
This code shows that there are two alternative scripts that can be run instead of the default one. This code first checks whether a file
— /etc/config/scripts/pattern-alert.${ALERT_PORTNAME} — exists.
NOTE: The variable ${ALERT_PORTNAME} must be replaced with port01 or port13 or whichever port the alert should run for.
If this file cannot be found, the script checks whether the file /etc/config/scripts/portmanager-pattern-alert exists.
If either of these files exists, the script calls the exec command on the first file that it finds and runs that custom file/script instead.
As an example, you can copy the /etc/scripts/portmanager-pattern-alert script file to /etc/config/scripts/portmanager-pattern-alert:
# cd /
# mkdir /etc/config/scripts
NOTE: This command assumes the directory created does not already exist.
# cp /etc/scripts/portmanager-pattern-alert \
/etc/config/scripts/portmanager-pattern-alert