# Alarm rules

The alarm catalogue: the rules an alarm can be based on, with their defaults.

Its operations need the scope `alarms.view`.

**Endpoints**

- `GET/v1/alarm-rules`

## List the alarm rule catalogue

GET/v1/alarm-rules

Lists the rules an alarm can be based on, for one `entity_type`, with each rule’s slug, unit, comparison and default thresholds. Pass the slug as `rule_slug` when creating an alarm. `domain_type`, `protocol`, `engines` and `os` narrow the list to the rules a resource of that sub-type supports; without them every sub-type’s rules are listed, so read the catalogue with the resource’s sub-type before creating an alarm. `is_default` is true for a rule a new resource of the type gets by default when its server or profile has no alarm templates; it is false for every volume, port and unit rule, whose alarms are created by the agent’s reports. Pages by `page` and `per_page` (`limit` is the same as `per_page`); every page carries `current_page`, `per_page`, `last_page` and `total`.

Needs the scope `alarms.view`.

### Query parameters

- `entity_type` (string, required): The type of resource whose catalogue is read; required. The same nine values `GET /v1/alarms` takes. Values:`domain``service``server``log_source``custom_metric``database_instance``server_port``server_system_service``server_volume`(an open set: new values may be added)
- `domain_type` (string or null): For `entity_type=domain`, narrows the catalogue to the rules a domain of this type supports: `apex`, `wildcard` or `subdomain`. Left out, every domain type’s rules are listed. Values:`apex``wildcard``subdomain`(an open set: new values may be added)
- `protocol` (string or null): For `entity_type=service`, narrows the catalogue to the rules a service of this protocol supports. Left out, every protocol’s rules are listed. Values:`http``https``tcp``udp``smtp`(an open set: new values may be added)
- `engines` (array of strings or null): For `entity_type=database_instance`, the database’s engines: narrows the catalogue to the rules those engines support. A list: repeat the parameter (`engines=mysql&engines=mariadb`) or send one value (`engines=mysql`); `engines[]=mysql` is accepted too. Values:`mysql``mariadb``postgresql`(an open set: new values may be added)
- `os` (string or null): For a server’s rules and its volumes’, units’ and ports’: `linux` or `windows`, narrows the catalogue to the rules a server of that operating system supports. Left out, both operating systems’ rules are listed. Values:`linux``windows`(an open set: new values may be added)
- `limit` (integer or null): The same as `per_page`, kept for existing clients.
- `include_total` (string or null): Ignored: `total` is always present. Values:`true``false``1``0`(an open set: new values may be added)
- `per_page` (integer or null): The page size, from 1 to 100.
- `page` (integer or null): The page to read, from 1; 1 when omitted. A page past the last answers no rows.

### Returns

`200 OK`:

The rules of the entity type.

Each item of the page:

- `rule_slug` (string): The rule’s slug: pass it as `rule_slug` to create an alarm.
- `name` (string): The rule’s name.
- `description` (string or null): The rule’s description; null when it has none.
- `entity_type` (string): The type of resource the rule is for.
- `alarm_type` (string or null): `boolean` or `threshold`.
- `classification` (string): The rule’s classification: one of `operations`, `security`, `monitoring`.
- `unit` (string or null): The unit of the thresholds; null when the rule has none.
- `comparison_operator` (string): How a reading is compared with the thresholds by default.
- `warning_threshold` (number or null): The default warning threshold; null when the rule has none.
- `critical_threshold` (number or null): The default critical threshold; null when the rule has none.
- `warning_consecutive_failures_count` (integer): The default number of consecutive evaluations before a warning.
- `critical_consecutive_failures_count` (integer): The default number of consecutive evaluations before a critical.
- `consecutive_configurable` (boolean): Whether an alarm on this rule may set its own consecutive counts.
- `supported_aggregations` (array of strings): The aggregations an alarm on this rule may use; empty when the rule takes none.
- `supports_window` (boolean): Whether an alarm on this rule may set a window.
- `self_resolving` (boolean): Whether an alarm on this rule clears itself when the condition ends (it sends no resolve notification).
- `notify_on_acknowledge` (boolean): Whether an alarm on this rule notifies when acknowledged, by default.
- `notify_on_resolve` (boolean): Whether an alarm on this rule notifies when resolved, by default.
- `applies_to_os` (string): The operating system a server must run for this rule to apply: `linux`, `windows`, or `any` for both and for every rule that is not a server’s.
- `is_default` (boolean): Whether a new resource of this type gets an alarm on this rule by default, when its server or profile has no alarm templates. False for every volume, port and unit rule.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**GET /v1/alarm-rules**

curl:

```bash
curl -G https://rest.watchtower15.com/v1/alarm-rules \
  -H "Authorization: Bearer $WT15_API_KEY" \
  -d entity_type=domain
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

foreach ($wt15->alarmRules->list(['entity_type' => 'domain'])->autoPaging() as $item) { echo $item->ruleSlug, "\n"; }
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

for await (const item of wt15.alarmRules.list({ entity_type: 'domain' })) {
  console.log(item.rule_slug);
}
```

Python:

```python
client = Client.from_environment()

for item in client.alarm_rules.list(entity_type='domain'):
    print(item.rule_slug)
```

**Response (200 OK)**

```json
{
  "data": [
    {
      "rule_slug": "example",
      "name": "example",
      "description": "example",
      "entity_type": "example",
      "alarm_type": "example",
      "classification": "example",
      "unit": "example",
      "comparison_operator": "example",
      "warning_threshold": 0,
      "critical_threshold": 0,
      "warning_consecutive_failures_count": 1,
      "critical_consecutive_failures_count": 1,
      "consecutive_configurable": true,
      "supported_aggregations": [
        "example"
      ],
      "supports_window": true,
      "self_resolving": true,
      "notify_on_acknowledge": true,
      "notify_on_resolve": true,
      "applies_to_os": "example",
      "is_default": true
    }
  ],
  "current_page": 1,
  "per_page": 1,
  "last_page": 1,
  "total": 1
}
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the alarms.view scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid (`invalid_request`; `errors` names the parameters).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

Source: https://developer.watchtower15.com/api/reference/alarm-rules/
