Atom feed of this document
 
 
 

 3.6. Create an Alarm

In this exercise, you set an alarm for the entity. Here's an example alarm that will send you a warning alert if the average PING response time is over 50ms. Remember that alarms always have a parent entity associated with them, so all URLs are contained underneath the entity URL. In this example, the entity ID is enn14Ch5mc, so we issue the following request to create the alarm and associate it with the entity:

 

Example 3.39. Create Alarm Request: cURL

curl -i -X POST \
--data-binary \
'{
  "check_id": "chyYWNw59I", 
  "notification_plan_id": "npkmLh5vVk", 
  "criteria": "if (metric[\"duration\"] < 50) { return OK } return WARNING"
}' \
-H 'X-Auth-Token: auth_token' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
'https://monitoring.api.rackspacecloud.com/v1.0/010101/entities/enn14Ch5mc/alarms'

 

Example 3.40. Create Alarm Response: cURL

HTTP/1.1 201 Created
X-Ratelimit-Remaining: 49947
X-Response-Id: .rh-ew99.h-dfw1-maas-prod-api1.r-Kti7H0py.c-39599.ts-1329418764114.v-b9d7626
Content-Length: 0
X-Lb: dfw1-maas-prod-api0
X-Ratelimit-Type: global
X-Ratelimit-Limit: 50000
Location: https://monitoring.api.rackspacecloud.com/v1.0/010101/entities/enn14Ch5mc/alarms/alIxnPKcZp
Date: Thu, 16 Feb 2012 18:59:24 GMT
X-Ratelimit-Window: 24 hours
Content-Type: text/plain

 

Example 3.41. Create Alarm Request: raxmon

raxmon-alarms-create --criteria="if (metric[\"average\"] < 50) { return new AlarmStatus(OK); } return new AlarmStatus(WARNING);" --check-id=chyYWNw59I --notification-plan=npkmLh5vVk --entity-id=enn14Ch5mc

 

Example 3.42. Create Alarm Response: raxmon

Resource created. ID: alIxnPKcZp

If the endpoint returns a response code is 201 and a Location: header containing the URL of the new alarm, the alarm was successfully created, otherwise the endpoint returns an error.

Since we're monitoring two items, both PING times and the HTTP response time, let's add a second alarm to go off when the web response time takes longer than 100ms. Here's an example of how you might specify the attributes for this alarm:

 

Example 3.43. Create an Alarm HTTP Request: cURL

curl -i -X POST \
--data-binary \
'{ "check_id" : "chTTslRf7v",
  "criteria" : "if (metric[\"code\"] regex \"^[23]..$\") { return OK } return WARNING",
  "notification_plan_id" : "npkmLh5vVk"
}' \
-H 'X-Auth-Token: your_auth_key' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
'https://monitoring.api.rackspacecloud.com/v1.0/010101/entities/enn14Ch5mc/alarms'

 

Example 3.44. Create an Alarm Response: cURL

HTTP/1.1 201 Created
X-Ratelimit-Remaining: 49946
X-Response-Id: .rh-E79I.h-ord1-maas-prod-api1.r-HDDENoUp.c-106.ts-1329419675047.v-a037e7a
Content-Length: 0
X-Lb: ord1-maas-prod-api0
X-Ratelimit-Type: global
X-Ratelimit-Limit: 50000
Location: https://monitoring.api.rackspacecloud.com/v1.0/010101/entities/enn14Ch5mc/alarms/alVwP6z00k
Date: Thu, 16 Feb 2012 19:14:34 GMT
X-Ratelimit-Window: 24 hours
Content-Type: text/plain

 

Example 3.45. Create an Alarm Request: raxmon

raxmon-alarms-create --criteria="if (metric[\"duration\"] < 100) { return OK } return WARNING" --check-id=chTTslRf7v  --notification-plan=npkmLh5vVk --entity-id=enn14Ch5mc

 

Example 3.46. Create an Alarm Response: raxmon

Resource created. ID: alVwP6z00k

Note that because alarms are shared between all of the checks on an entity, if you have multiple HTTP URLs, you will receive alerts if any of the checks are lagging.

You can list the available alarms as follows:

 

Example 3.47. List Alarms Request: cURL

curl -i -X GET \
-H 'X-Auth-Token: auth_token' \
-H 'Accept: application/json' \
'https://monitoring.api.rackspacecloud.com/v1.0/010101/entities/enn14Ch5mc/alarms'

 

Example 3.48. List Alarms Response: cURL

HTTP/1.1 200 OK
X-Ratelimit-Remaining: 49941
X-Response-Id: .rh-qRGT.h-ord1-maas-prod-api0.r-UH0HesoS.c-404.ts-1329420284585.v-a037e7a
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Lb: ord1-maas-prod-api0
X-Ratelimit-Type: global
X-Ratelimit-Limit: 50000
Date: Thu, 16 Feb 2012 19:24:44 GMT
X-Ratelimit-Window: 24 hours
Content-Type: application/json; charset=UTF-8

36e
{
    "values": [
        {
            "id": "alIxnPKcZp",
            "label": null,
            "check_type": "remote.ping",
            "check_id": null,
            "criteria": "if (metric[\"average\"] < 50) { return new AlarmStatus(OK); } return new AlarmStatus(WARNING);",
            "notification_plan_id": "npkmLh5vVk",
            "created_at": 1329418764882,
            "updated_at": 1329418764882
        },
        {
            "id": "alVwP6z00k",
            "label": null,
            "check_type": "remote.http",
            "check_id": null,
            "criteria": "if (metric[\"average\"] < 100) { return new AlarmStatus(OK); } return new AlarmStatus(WARNING);",
            "notification_plan_id": "npkmLh5vVk",
            "created_at": 1329419675727,
            "updated_at": 1329419675727
        }
    ],
    "metadata": {
        "count": 2,
        "limit": 100,
        "marker": null,
        "next_href": null
    }
}

 

Example 3.49. List Alarms Request: raxmon

raxmon-alarms-list --entity-id=enn14Ch5mc --details

 

Example 3.50. List Alarms Response: raxmon

{'criteria': u'if (metric["average"] < 50) { return new AlarmStatus(OK); } return new AlarmStatus(WARNING);',
 'driver': <rackspace_monitoring.drivers.rackspace.RackspaceMonitoringDriver object at 0x100649ad0>,
 'entity_id': u'enn14Ch5mc',
 'id': u'alIxnPKcZp',
 'notification_plan_id': u'npkmLh5vVk',
 'type': u'remote.ping'}
{'criteria': u'if (metric["average"] < 100) { return new AlarmStatus(OK); } return new AlarmStatus(WARNING);',
 'driver': <rackspace_monitoring.drivers.rackspace.RackspaceMonitoringDriver object at 0x100649ad0>,
 'entity_id': u'enn14Ch5mc',
 'id': u'alVwP6z00k',
 'notification_plan_id': u'npkmLh5vVk',
 'type': u'remote.http'}

Total: 2

The results show there are now two alarms for the entity.

NEXT UP: Make a modification to the entity.