5.12. Alarms

Alarms bind alerting rules, entities, and notification plans into a logical unit. Alarms are responsible for determining a state (OK, WARNING or CRITICAL) based on the result of a check, and executing a notification plan whenever that state changes. You create alerting rules by using the alarm domain-specific language (DSL). For information about using the DSL, see Appendix A. For alarm examples by check, see Alarm examples.

[Note]Note

The criteria is optional. If you don't provide this attribute, the state of your alarm depends entirely on the success or failure of the check. Omitting the criteria attribute is a convenient shortcut for setting a simple alarm with a notification plan. For example, if you set a PING check on a server, an alert is triggered only if no pings are returned, whereas adding criteria would enable the alarm to trigger based on metrics such as if the ping round trip time went past a certain threshold.

Concept: Alarm and alert, in Monitoring key terms and concepts

Requirements: An entity , check, notification, and notification plan

Next step: View alarm notification history

Table 5.15. Attributes
NameDescriptionValidation
check_id The ID of the check to alert on.
  • Immutable

  • String

notification_plan_id The id of the notification plan to execute when the state changes.
  • Valid Notification Plan

  • Non-empty string

criteria The alarm DSL for describing alerting conditions and their output states.
  • Optional

  • String between 1 and 16384 characters long

  • Valid Alarm

disabled Disable processing and alerts on this alarm
  • Optional

  • Boolean

label A friendly label for an alarm.
  • Optional

  • String between 1 and 255 characters long

metadata Arbitrary key/value pairs.
  • Optional

  • Hash [String,String between 1 and 255 characters long:String,String between 1 and 255 characters long]

  • Array or object with number of items between 0 and 256

Use the alarms API operations to create, view, and manage alarm resources

MethodURIDescription
POST/entities/{entityId}/alarms

Creates a new alarm for the specified entity.

POST/entities/{entityId}/test-alarm

Test an alarm before putting it in production.

GET/entities/{entityId}/alarms​{?id}

List the alarms on the specified entityId. Use /alarms?id=alarmOneId&id=alarmTwoId to filter the results to only include information on the specified alarms.

GET/entities/{entityId}/alarms/{alarmId}

Get information for a single alarm.

PUT/entities/{entityId}/alarms/{alarmId}

Updates the specified alarm with the properties submitted with the request.

DELETE/entities/{entityId}/alarms/{alarmId}

Delete an alarm from your account.

 5.12.1. Create an alarm

 
MethodURIDescription
POST/entities/{entityId}/alarms

Creates a new alarm for the specified entity.

Create a new alarm by using a valid set of attributes from the alarms attributestable.

For more information, see Alarm language.

This table shows the possible response codes for this operation:

Response CodeNameDescription
201Accepted

The location header contains a link to the newly created alarm.

400Bad request

The system received an invalid value in a request.

401Unauthorized

The system received a request from a user that is not authenticated.

403Forbidden

The system received a request that the user is not authorized to make.

500Internal Server Error

An unexpected condition was encountered.

503Service Unavailable

The system is experiencing heavy load or another system failure.

 5.12.1.1. Request

This table shows the header parameters for the create an alarm request:

NameTypeDescription

X-Auth-Token

​String

(Required)

A valid authentication token with administrative access. For details, see Retrieving an authentication token

 

Example 5.44. Create alarm: JSON request

{
    "check_id": "chAAAA",
    "criteria": "if (metric[\"duration\"] >= 2) { return new AlarmStatus(OK); } return new AlarmStatus(CRITICAL);",
    "notification_plan_id": "npAAAAA"
}

 5.12.2. Test an alarm

 
MethodURIDescription
POST/entities/{entityId}/test-alarm

Test an alarm before putting it in production.

The test_alarm endpoint is used to post alarm criteria and alarm data to test whether the alarm criteria is valid and to show how the alarm state is evaluated. You cannot specify an existing alarm ID with this endpoint; instead, you provide the alarm's criteria within the request. The test_alarm response not only provides the final evaluated state, but also includes all state transitions noticed during the calculation.

To test an alarm, you need to provide one or more observations. An observation consists of a set of metrics from a single data center, such as DFW, LON, and IAD. A group of observations consist of a set of metrics from more than one data center.

Cloud Monitoring passes the observation(s) that you provide to the event processors, and then captures and returns an array of all state changes in the same order that they were evaluated. The state returned by the test alarm depends both upon the criteria and the metrics provided for the test alarm. For example, if you have a criteria that returns "CRITICAL" if a certain metric is above a threshold and "OK" otherwise, you should expect to receive a "CRITICAL" response if you provide a metric with a value above that threshold and an "OK" response if you provide a metric with a value below that threshold.

When you test an alarm, you provide a list of check data, which you can retrieve from a test check operation.

[Note]Note

A consecutiveCount of 1 is always used for these calls. If another value is set in your criteria it is overridden.

This table shows the possible response codes for this operation:

Response CodeNameDescription
200OK

The request completed.

400Bad request

The system received an invalid value in a request.

401Unauthorized

The system received a request from a user that is not authenticated.

403Forbidden

The system received a request that the user is not authorized to make.

500Internal Server Error

An unexpected condition was encountered.

503Service Unavailable

The system is experiencing heavy load or another system failure.

 5.12.2.1. Request

This table shows the header parameters for the test an alarm request:

NameTypeDescription

X-Auth-Token

​String

(Required)

A valid authentication token with administrative access. For details, see Retrieving an authentication token

 

Example 5.45. Test alarms criteria

:set consecutiveCount=1
    if (metric["busy_workers"] > 2) {
      return new AlarmStatus(WARNING);
    }
    if (metric["busy_workers"] > 3) {
      return new AlarmStatus(CRITICAL);
    }
    return new AlarmStatus(OK);

 

Example 5.46. Test alarm: JSON request

{
    "criteria": "if (metric[\"code\"] == \"404\") { return new AlarmStatus(CRITICAL, \"not found\"); } return new AlarmStatus(OK);",
    "check_data": [
        {
            "timestamp": 1319222001982,
            "monitoring_zone_id": "mzxJ4L2IU",
            "available": true,
            "status": "code=200,rt=0.257s,bytes=0",
            "metrics": {
                "bytes": {
                    "type": "i",
                    "data": "0"
                },
                "tt_firstbyte": {
                    "type": "I",
                    "data": "257"
                },
                "tt_connect": {
                    "type": "I",
                    "data": "128"
                },
                "code": {
                    "type": "s",
                    "data": "200"
                },
                "duration": {
                    "type": "I",
                    "data": "257"
                }
            }
        }
    ]
}

 5.12.2.2. Response

 

Example 5.47. Test alarm: JSON response

[
    {
        "timestamp": 1319224500831,
        "state": "OK",
        "status": "Matched default return statement"
    }
]

 

Example 5.48. Test alarm, multi-state: JSON response

[
    {
        "state": "OK",
        "status": "Ping responds as expected.",
        "timestamp": "1417732774575"
    },
    {
        "state": "WARNING",
        "status": "blah.",
        "timestamp": "1417732795200"
    },
    {
        "state": "CRITICAL",
        "status": "cnt=6,avail=0,min=-nan,max=-nan,avg=-nan",
        "timestamp": "1417732795216"
    }
]

 5.12.3. List alarms

 
MethodURIDescription
GET/entities/{entityId}/alarms​{?id}

List the alarms on the specified entityId. Use /alarms?id=alarmOneId&id=alarmTwoId to filter the results to only include information on the specified alarms.

This operation can be paginated. For information, see Paginated collections.

This table shows the possible response codes for this operation:

Response CodeNameDescription
200OK

The request completed.

401Unauthorized

The system received a request from a user that is not authenticated.

403Forbidden

The system received a request that the user is not authorized to make.

500Internal Server Error

An unexpected condition was encountered.

503Service Unavailable

The system is experiencing heavy load or another system failure.

 5.12.3.1. Request

This table shows the header parameters for the list alarms request:

NameTypeDescription

X-Auth-Token

​String

(Required)

A valid authentication token with administrative access. For details, see Retrieving an authentication token

This operation does not accept a request body.

 5.12.3.2. Response

 

Example 5.49. List alarms: JSON response

{
    "values": [
        {
            "id": "alAAAA",
            "check_id": "chAAAA",
            "entity_id": "enZZZZA",
            "criteria": "if (metric[\"duration\"] >= 2) { return new AlarmStatus(OK); } return new AlarmStatus(CRITICAL);"
        }
    ],
    "metadata": {
        "count": 1,
        "limit": 50,
        "marker": null,
        "next_marker": null,
        "next_href": null
    }
}

 5.12.4. Get alarm by ID

 
MethodURIDescription
GET/entities/{entityId}/alarms/{alarmId}

Get information for a single alarm.

This table shows the possible response codes for this operation:

Response CodeNameDescription
200OK

The request completed.

401Unauthorized

The system received a request from a user that is not authenticated.

403Forbidden

The system received a request that the user is not authorized to make.

500Internal Server Error

An unexpected condition was encountered.

503Service Unavailable

The system is experiencing heavy load or another system failure.

 5.12.4.1. Request

This table shows the header parameters for the get alarm by id request:

NameTypeDescription

X-Auth-Token

​String

(Required)

A valid authentication token with administrative access. For details, see Retrieving an authentication token

This operation does not accept a request body.

 5.12.4.2. Response

 

Example 5.50. Get alarms by ID: JSON response

{
    "id": "alAAAA",
    "check_id": "chAAAA",
    "entity_id": "enZZZZA",
    "criteria": "if (metric[\"duration\"] >= 2) { return new AlarmStatus(OK); } return new AlarmStatus(CRITICAL);"
}

 5.12.5. Update alarm by ID

 
MethodURIDescription
PUT/entities/{entityId}/alarms/{alarmId}

Updates the specified alarm with the properties submitted with the request.

Update an alarm by using a valid set of attributes from the alarms attributes table.

This table shows the possible response codes for this operation:

Response CodeNameDescription
204No Content

The server has fulfilled the request. Does not return a response body.

400Bad request

The system received an invalid value in a request.

401Unauthorized

The system received a request from a user that is not authenticated.

403Forbidden

The system received a request that the user is not authorized to make.

404Not Found

The URL, entity, or account requested is not found in the system.

500Internal Server Error

An unexpected condition was encountered.

503Service Unavailable

The system is experiencing heavy load or another system failure.

 5.12.5.1. Request

This table shows the header parameters for the update alarm by id request:

NameTypeDescription

X-Auth-Token

​String

(Required)

A valid authentication token with administrative access. For details, see Retrieving an authentication token

 

Example 5.51. Update alarm by ID: JSON request

{
    "criteria": "if (metric[\"average\"] < 100) { return new AlarmStatus(OK); } return new AlarmStatus(WARNING);"
}

 5.12.6. Delete alarm by ID

 
MethodURIDescription
DELETE/entities/{entityId}/alarms/{alarmId}

Delete an alarm from your account.

This table shows the possible response codes for this operation:

Response CodeNameDescription
200OK

The request completed.

401Unauthorized

The system received a request from a user that is not authenticated.

403Forbidden

The system received a request that the user is not authorized to make.

404Not Found

The URL, entity, or account requested is not found in the system.

500Internal Server Error

An unexpected condition was encountered.

503Service Unavailable

The system is experiencing heavy load or another system failure.

 5.12.6.1. Request

This table shows the header parameters for the delete alarm by id request:

NameTypeDescription

X-Auth-Token

​String

(Required)

A valid authentication token with administrative access. For details, see Retrieving an authentication token

This operation does not accept a request body.



Contents Search
loading table of contents...