Whenever an alert is triggered in the console server, specific scripts are called. Each of these scripts first check to see whether you have created a custom script to run instead of running the default. These scripts reside in /etc/scripts/. The default script that runs for each applicable alert:
- For a connection alert (when a user connects or disconnects from a serial 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 a 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 of these scripts do a check to see whether you have created a custom script to run instead. Below is an extract from the file/etc/scripts/portmanager-pattern-alert) showing the code that does this check:
# 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
As this code shows there are two alternative scripts that can be run instead of the default one.
This code first checks whether the file "/etc/config/scripts/pattern-alert.${ALERT_PORTNAME}" exists. The variable${ALERT_PORTNAME} must be replaced with "port01" or "port13" or whichever serial port the alert should run for.
If this port specific file cannot be found, the script then checks whether the file "/etc/config/scripts/portmanager-pattern-alert" exists. If either of these files exist, the script calls the exec command on the first file that it finds and runs that custom script file instead of the default.
The custom script file can be created from scratch or can be based on the default i.e. 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
Then you can edit this new script file:
- Firstly, open the file /etc/config/scripts/portmanager-pattern-alert using vi (or any other editor) and remove the lines that check for a custom script (i.e. the code from above). This will prevent the new custom script from repeatedly calling itself
- Then you can edit the file or add any additional scripting to the file
Power cycle on alert example
Let's assume we have an RPC(PDU) connected to port 1 on a CM4116. Assume we also have some telecommunications device connected to port 2 on the CM4116 and that this device is powered by outlet 3 on the RPC.
Say the telecom device transmits a character stream "EMERGENCY" on its serial console port everytime 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 set up a pattern-match alert on serial port 2 to check for the pattern "EMERGENCY" by clicking Add Alertsin the Alerts&Logging:Alerts menu. This alert can also be configured to send a email notifying of the device error message etc.
Next we need to create our 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 Opengear command line utility used to send power commands to RPC devices is called pmpower. In order to power cycle our telecom device, we need to execute the pmpower command:
# 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 everytime the CM4116 reads the "EMERGENCY" character stream on port 2, a notification email is sent and the telecom device will be power cycled.
For more general information on custom scripts refer faq 255.
pmpower command
The pmpower command is a high level Opengear tool for manipulating remote preconfigured power devices connected to the console server via a serial or network connection. pmpower controls the power devices directly itself or through the embedded open source PowerMan or Network UPS Tools:
pmpower [-?h] [-l device | -r host] [-o outlet] [-u username] [-p password] action
-?/-h This help message
-l The serial port to use
-o The outlet on the power target to apply to
-r The remote host address for the power target
-u Override the configured username
-p Override the configured password
on This action switches the specified device or outlet(s) on
off This action switches the specified device or outlet(s) off
cycle This action switches the specified device or outlet(s) off and on again
status This action retrieves the current status of the device or outlet
Comments
0 comments
Article is closed for comments.