AlertFox is part of the Ipswitch family of tools and services. Learn More »

How to Alert on a Group of Sensors

by / Thursday, 10 April 2014 / Published in Uncategorized

Have you ever wanted to be able to receive an alert if one or more sensors are failing simultaneously?

For example, let’s say you have three sensors monitoring some aspect of your site, and each sensor is configured to run in its own region. These sensors will already alert you if there is a problem in any one region, but what you really want to do is send an alert to an escalation email address if the sensors are failing in all regions at the same time, since this would indicate a much more severe problem.

Here’s a rather simple way to create a new group sensor that will monitor the other sensors.

  1. Create a new iMacros sensor and give it an appropriate name

  2. Paste the following code into the macro editor:

1 SET AFID AF9999999
2 SET apiKey XXXX
3
4 SET groupName "Group Name"
5
6 SET sensorID1 11111
7 SET sensorID2 22222
8 SET sensorID3 33333
9
10 ' Get the most recent status for each sensor
11 URL GOTO=https://my.alertfox.com/api/whatsup/{{AFID}}/{{apiKey}}/{{sensorID1}}
12 TAG POS=1 TYPE=HTML ATTR=* EXTRACT=TXT
13 SET sensorStatus1 {{!EXTRACT}}
14 SET !EXTRACT NULL
15
16 URL GOTO=https://my.alertfox.com/api/whatsup/{{AFID}}/{{apiKey}}/{{sensorID2}}
17 TAG POS=1 TYPE=HTML ATTR=* EXTRACT=TXT
18 SET sensorStatus2 {{!EXTRACT}}
19 SET !EXTRACT NULL
20
21 URL GOTO=https://my.alertfox.com/api/whatsup/{{AFID}}/{{apiKey}}/{{sensorID3}}
22 TAG POS=1 TYPE=HTML ATTR=* EXTRACT=TXT
23 SET sensorStatus3 {{!EXTRACT}}
24 SET !EXTRACT NULL
25
26 ' Force an error to generate an alert if all the sensors have failed
27 SET alert EVAL("if (\"{{sensorStatus1}}\" != \"OK\" && \"{{sensorStatus2}}\" != \"OK\" && \"{{sensorStatus3}}\" != \"OK\") MacroError(\"Sensor group {{groupName}} has failed\");")
  1. Change the AFID in line 1 to your AlertFox Account ID (as displayed on your AlertFox home page)

  2. Change the apiKey value in line 2 to your AlertFox API key (as described here).

  3. Assign an appropriate group name in line 4 (this could be the same name you gave to this sensor in step 1). This name will be displayed in the alert email.

  4. Change each of the sensor IDs to the actual sensor IDs that you want to monitor. The sensor ID is visible in the URL that displays in your browser status bar whenever you hover over a sensor name on the Overview or Sensors pages.

  5. Configure the rest of the sensor settings:

    1. Set the sensor interval to be the same as the sensors you are monitoring.

    2. Leave the default values for zone and browser.

    3. Set an alert contact and configure the other notification settings.

  6. Test and save the new sensor.

What this macro code is doing is using the AlertFox Integration API to check the status of each of the sensors, and then the logic embedded in the EVAL command in line 27 evaluates the statuses and raises an error if they are not all OK.

Of course you can monitor more (or less) than three sensors this way by copying and pasting the relevant lines, assigning the sensor IDs, and changing the logic in the EVAL command accordingly.

Group sensors do not count toward the iMacros sensor limit of your AlertFox plan. So if you need additional sensors in order to implement group sensors in your account, please contact support and we will increase your limit.

One Response to “How to Alert on a Group of Sensors”

  1. […] How to Alert on a Group of Sensors […]

Leave a Reply

TOP