203
Chapter 15: Advanced Configuration
15.1.3 Example script - Power cycling on pattern match
IfforexamplewehadanRPC(PDU)connectedtoport1onaConsoleServerandalsohavesometelecommunicationsdevice
connectedtoport2andwhichispoweredbytheRPCoutlet3.Nowassumethetelecomdevicetransmitsacharacterstream
"EMERGENCY"outonitsserialconsoleporteverytimethatitencounterssomespecicerror,andtheonlywaytoxthiserror
is to power cycle the telecom device.
Therststepistosetupapattern-matchalertonport2tocheckforthepattern"EMERGENCY".
Nextweneedtocreateacustomscripttodealwiththisalert:
# cd /
# mkdir /etc/config/scripts (ifthedirectorydoesnotalreadyexist)
# cp /etc/scripts/portmanager-pattern-alert /etc/config/scripts/portmanager-pattern-alert
Note:Makesuretoremovetheifstatement(whichchecksforacustomscript)fromthenewscript,inordertopreventan
infinite loop.
The pmpower utility is used to send power commands to RPC device in order to power cycle our telecom device:
# pmpower -l port01 -o 3 cycle (TheRPCisonserialport1.ThetelecomdeviceispoweredbyRPCoutlet3)
We can now append this command to our custom script. This will guarantee that our telecom device will be power cycled every
timetheconsolereadsthe"EMERGENCY"characterstreamonport2.
15.1.4 Example script - Multiple email notifications on each alert
Ifyoudesiretosendmorethanoneemailwhenanalerttriggers,youhavetocreateareplacementscriptusingthemethod
described above and add the appropriate lines to your new script.
Currently,thereisascript/etc/scripts/alert-email whichgetsrunfromwithinallthealertscripts(e.g.portmanager-user-alert or
environmental-alert).Thealert-emailscriptisresponsibleforsendingtheemail.Thelinewhichinvokestheemailscriptlooks
as follows:
/bin/sh /etc/scripts/alert-email $suffix &
Ifyouwishtosendanotheremailtoasingleaddressorthesameemailtomanyrecipients,editthecustomscript
appropriately.Youcanfollowtheexamplesinanyofthesevenalertscriptslistedabove.Inparticularlet’sconsiderthe
portmanager-user-alertscript.Ifyouneedtosendthesamealertemailtomorethanoneemailaddress,ndthelinesinthe
scriptresponsibleforinvokingthealert-emailscript,thenaddthefollowinglinesbelowtheexistinglines:
export TOADDR="emailaddress@domain.com"
/bin/sh /etc/scripts/alert-email $suffix &
ThesetwolinesassignanewemailaddresstoTOADDRandinvokethealert-emailscriptinthebackground.