Tripp Lite B0930042E4U Owners Manual for B093- B097- and B098-Series Console S - Page 236

Sample Script - Power Cycling on Pattern Match, 1.4 Sample Script - Multiple Email Notifications

Page 236 highlights

15. Advanced Configuration This code shows there are two alternative scripts that can be run instead of the default script. 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. If this file cannot be found, the script 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 file/script instead. For example, you can copy the /etc/scripts/portmanager-pattern-alert script file to /etc/config/scripts/portmanagerpattern-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 is to edit the new script file. 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 (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. 15.1.3 Sample Script - Power Cycling on Pattern Match For example, if an RPC (PDU) is connected to port 1 on a console server and some telecommunications device connected to port 2, which is powered by the RPC outlet 3. Assuming the telecom device transmits a character stream "EMERGENCY" out on its serial console port every time that it encounters some specific error, 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 port 2 to check for the pattern "EMERGENCY". Next, we need to create a custom script for 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: To prevent an infinite loop, make sure to remove the if statement (which checks for a custom script) from the new script. The pmpower utility is used to send power commands to an RPC device in order to power cycle the telecom device: # pmpower -l port01 -o 3 cycle (The RPC is on serial port 1. The telecom device is powered by RPC outlet 3) Now append this command to our custom script. This will guarantee the telecom device will be power cycled every time the console reads the "EMERGENCY" character stream on port 2. 15.1.4 Sample Script - Multiple Email Notifications on Each Alert If you desire 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-email that runs from within all the alert scripts (e.g., portmanager-user-alert or environmental-alert). The alert-email script is responsible for sending the email. The line that invokes the email script appears 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. You can follow the examples in any of the seven alert scripts listed above. In particular, consider the portmanager-user-alert script. If 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="[email protected]" /bin/sh /etc/scripts/alert-email $suffix & These two lines assign a new email address to TOADDR and invoke the alert-email script in the background. 236

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288

236
15. Advanced Configuration
This code shows there are two alternative scripts that can be run instead of the default script. 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. If this file cannot be found, the script 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 file/script instead.
For 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 is to edit the new script file. 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 (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.
15.1.3 Sample Script - Power Cycling on Pattern Match
For example, if an RPC (PDU) is connected to port 1 on a console server and some telecommunications device connected to
port 2, which is powered by the RPC outlet 3. Assuming the telecom device transmits a character stream “EMERGENCY” out
on its serial console port every time that it encounters some specific error, 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 port 2 to check for the pattern “EMERGENCY”.
Next, we need to create a custom script for 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:
To prevent an infinite loop, make sure to remove the if statement (which checks for a custom script) from the new script.
The
pmpower
utility is used to send power commands to an RPC device in order to power cycle the telecom device:
# pmpower -l port01 -o 3 cycle (The RPC is on serial port 1. The telecom device is powered by RPC outlet 3)
Now append this command to our custom script. This will guarantee the telecom device will be power cycled every time the
console reads the “EMERGENCY” character stream on port 2.
15.1.4 Sample Script - Multiple Email Notifications on Each Alert
If you desire 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-email
that runs from within all the alert scripts (e.g.,
portmanager-user-alert
or
environmental-alert
). The alert-email script is responsible for sending the email. The line that invokes the email script
appears 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. You can follow the examples in any of the seven alert scripts listed above. In particular, consider the
portmanager-user-alert
script. If 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=”[email protected]
/bin/sh /etc/scripts/alert-email $suffix &
These two lines assign a new email address to TOADDR and invoke the alert-email script in the background.