Prometheus Alerts API

Create rules

POST /v2/alerts/prom/rules/

    

Request format:

{
   "rules": [
       {
           "alert": "Test Alert",
           "expr": "up == 1",
           "for": "1m",
           "labels": <key-value>,
           "annotations": <key-value>
       }
   ]
}

     

Parameters:

  • rules
    [REQUIRED]
    List of the rules objects to create.
  • alert
    [REQUIRED]
    The name of the alert.
  • expr
    [REQUIRED]
    The expression by which the alert triggers.
  • for
    The time range for which the expression should be triggered before the alert is sent.
  • labels
    The labels clause allows specifying a set of additional labels to be attached to the alert.
  • annotations
    The annotations clause specifies a set of informational labels that can be used to store longer additional information such as alert descriptions or runbook links. The annotation values can be templated.
    Label and annotation values can be templated using console templates. The $labels variable holds the label key/value pairs of an alert instance. The configured external labels can be accessed via the $externalLabels variable. The $value variable holds the evaluated value of an alert instance.

  

Curl example:

curl --location --request POST 'https://YOUR-API-KEY@api.hostedgraphite.com/v2/alerts/prom/rules/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "rules": [
        {
            "alert": "Test Alert",
            "expr": "up == 1",
            "for": "10m",
            "labels": {
                "service": "prom"
            },
            "annotations": {
                "description": "instance: {{ $labels.instance }}"
            }
        }
    ]
}'

      

Status Codes:

  • 200 - OK
  • 422 - You are trying to upload invalid rules or the same rules already exist.
   

Upload rules

POST /v2/alerts/prom/config/rules/

Curl example:

curl -X POST 'https://YOUR-API-KEY@api.hostedgraphite.com/v2/alerts/prom/config/rules/' --form 'rules=@{filename including path}'

  

You can also see how to configure rules file by the following rules configuration link.

Note:
WARNING: The alerts rule file you upload will DELETE all existing Prometheus alerts in your account, and INSTALL all the alerts in the uploaded alerts rule files. Please ensure that this is what you want. This API endpoint cannot be used to upload additional rules to existing Prometheus alerts, please use the UI for that.

Status Codes:

  • 200 - OK
  • 400 - Something wrong with the rules file.
     

Upload alertmanager configs

POST /v2/alerts/prom/config/alertmanager/

Curl example:

curl -X POST 'https://YOUR-API-KEY@api.hostedgraphite.com/v2/alerts/prom/config/alertmanager/' --form 'alertmanager=@{filename including path}'

  

You can also see how to configure alertmanager file by the following alertmanager configuration link.

Note:
WARNING: The alertmanager configuration file you upload will DELETE existing alertmanager configuration in your account, and INSTALL the configuration in the uploaded alertmanager configuration file. Please ensure that this is what you want.

Status Codes:

  • 200 - OK
  • 400 - Something wrong with the alertmanager file.
     

Obtain notification channels info

GET /v2/alerts/prom/notifications/ - Returns a list of notification channels for Prometheus alerts.

    

Curl example:

curl -X GET "https://YOUR-API-KEY@api.hostedgraphite.com/v2/alerts/prom/notifications/"

    

Response format:

HTTP/1.1 200
Content-Type: application/json

[{
    "destination": "email@example.com",
    "type": "email",
    "description": "Email me"
},
{
    "destination": "https://hooks.slack.com/services/example",
    "type": "slack",
    "description": "Alert slack"
}]

  

Status Codes:

  • 200 - OK

 

Obtain alerts info

GET /v2/alerts/prom/alerts/ - Returns a list of all active alerts.

   

Curl example:

curl -X GET "https://YOUR-API-KEY@api.hostedgraphite.com/v2/alerts/prom/alerts/"

    

Response format:

HTTP/1.1 200
Content-Type: application/json

[{
    "state": "Alert status",
    "labels": {"<Key-value pairs of labels>"},
    "annotations": {"<Key-value pairs of annotations>"},
    "value": "2.98e+00",
    "activeAt": "2020-07-22T11:44:49.564128025Z"
}]

   

Status Codes:

  • 200 - OK
    

Obtain rules info

GET /v2/alerts/prom/rules/ - Returns list of alerting rules.

    

Curl example:

curl -X GET "https://YOUR-API-KEY@api.hostedgraphite.com/v2/alerts/prom/rules/"

  

Alert response format:

HTTP/1.1 200
Content-Type: application/json

{
"groups": [
    {
        "name": "example",
        "rules": [
            {
                "alerts": ["<List of triggered alerts with this rule>"],
                "name": "Name of the alert",
                "labels": { "<Key-value pairs of labels>" },
                "evaluationTime": 0.004250918,
                "lastEvaluation": "2020-07-22T11:39:49.564325153Z",
                "state": "Alert rule status 'inactive/firing'",
                "health": "ok",
                "duration": 0,
                "query": "Alert expression",
                "lastError": "",
                "type": "alerting",
                "annotations": {"<Key-value pairs of annotations>"}
            }
        ],
        "interval": 60,
        "evaluationTime": 0.012137449,
        "file": "rules.yaml",
        "lastEvaluation": "2020-07-22T11:39:49.564312072Z"
    }
]}

  

Status Codes:

  • 200 - OK