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 exists 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
Multiple Email Example
If you desire to send more than one email when an alert triggers, you have to create a replacement alert script and add the appropriate lines to your new script.
Currently, there is a script /etc/scripts/alert-email which gets run from within all the alert scripts (e.g. portmanager-user-alert orenvironmental-alert). The alert-email script is responsible for sending the email. So if you wished to send multiple email notifications for a user alert event you first would create a custom alert script :
# cd /
# mkdir /etc/config/scripts (if the directory does not already exist)
# cp /etc/scripts/portmanager-user-alert /etc/config/scripts/portmanager-user-alert
Note: Make sure to remove the if statement (which checks for a custom script) from the new alert script in order to prevent an infinite loop!
The line in the new alert script which invokes the email script looks as follows:
/bin/sh /etc/scripts/alert-email $suffix &
If you wish to send another email to a single address, or the same email to many recipients, edit the custom script appropriately. So you need to send the same alert email to more than one email address, find the lines in the script responsible for invoking the alert-email script, then add the following lines below the existing lines:
export TOADDR="emailaddress@domain.com"
/bin/sh /etc/scripts/alert-email $suffix &
These two lines assign a new email address to TOADDR and invokes the alert-email script in the background.
For more general information on custom scripts refer faq 255.
Note: With firmware v2.8 and later you can configure to send multiple emails from the GUI refer faq 306.
Comments
0 comments
Article is closed for comments.