Chapter 15: Advanced Configuration

For power and alarm sensor alerts (power load, and battery charge alerts): /etc/scripts/environmental-alert

For an interface failover alert: /etc/scripts/interface-failover-alert

All of 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. 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 (if the directory does not already exist)

#cp /etc/scripts/portmanager-pattern-alert /etc/config/scripts/portmanager-pattern-alert

The next step will be to edit the new script file. First, open the file /etc/config/scripts/portmanager-pattern-alertusing vi (or any other editor), and remove the lines that check for a custom script (the code from above). This will prevent the new custom script from repeatedly calling itself. After these lines have been removed, edit the file, or add any additional scripting to the file.

!         

For example, we have an RPC (PDU) connected to port 1 on a console server and also have some telecommunications device connected to port 2 (which is powered by the RPC outlet 3). Now assume the telecom device transmits a character stream "EMERGENCY" out on its serial console port every time that it encounters some specific error, and the only way to fix this error is to power cycle the telecom device.

The first step is to setup a pattern-match alert on port 2 to check for the pattern "EMERGENCY".

Next we need to create a custom script to deal with this alert:

#cd /

#mkdir /etc/config/scripts (if the directory does not already exist)

#cp /etc/scripts/portmanager-pattern-alert /etc/config/scripts/portmanager-pattern-alert

NOTE: Make sure to remove the if statement (which checks for a custom script) from the new script, in order to prevent an infinite loop.

The pmpower utility is used to send power commands to an RPC device in order to power cycle our telecom device:

#pmpower -l port01 -o 3 cycle (The RPC is on serial port 1. The telecom device is powered by RPC outlet 3)

We can now append this command to our custom script. This will guarantee that our telecom device will be power cycled every time the console reads the "EMERGENCY" character stream on port 2.

!          

If you want to send more than one email when an alert triggers, you have to create a replacement script using the method described above and add the appropriate lines to your new script.

Currently, there is a script /etc/scripts/alert-emailthat runs from within all the alert scripts (for example, portmanager-user-alert or environmental- alert). The alert-email script sends the email. The line that invokes the email script is as follows:

/bin/sh /etc/scripts/alert-email $suffix &

If you want to send another email to a single address or the same email to many recipients, edit the custom script appropriately. You can follow the examples in any of the seven alert scripts listed above. In particular, consider the portmanager-user-alertscript. If you need to send the same alert

724-746-5500 blackbox.com

137

Page 137
Image 137
Black Box 1101, Secure Device Servers, 1102 Advanced Configuration, !