master
md 212 lines 9.44 KB
Rendered Raw
1 # Health API Calls
2
3 ## Health Read API
4
5 ### Enabled Alerts
6
7 Netdata enables alerts on demand, i.e. when the chart they should be linked to starts collecting data. So, although many
8 more alerts are configured, only the useful ones are enabled.
9
10 To get the list of all enabled alerts, open your browser and navigate to `http://NODE:19999/api/v1/alarms?all`,
11 replacing `NODE` with the IP address or hostname for your Agent dashboard.
12
13 ### Raised Alerts
14
15 This API call will return the alerts currently in WARNING or CRITICAL state.
16
17 `http://NODE:19999/api/v1/alarms`
18
19 ### Event Log
20
21 The size of the alert log is configured in `netdata.conf`. There are 2 settings: the event history kept in the DB (in seconds), and the in memory size of the alert log.
22
23 ```
24 [health]
25 in memory max health log entries = 1000
26 health log retention = 5d
27 ```
28
29 The API call retrieves all entries of the alert log:
30
31 `http://NODE:19999/api/v1/alarm_log`
32
33 ### Alert Log Incremental Updates
34
35 `http://NODE:19999/api/v1/alarm_log?after=UNIQUEID`
36
37 The above returns all the events in the alert log that occurred after UNIQUEID (you poll it once without `after=`, remember the last UNIQUEID of the returned set, which you give back to get incrementally the next events).
38
39 ### Alert badges
40
41 The following will return an SVG badge of the alert named `NAME`, attached to the chart named `CHART`.
42
43 `http://NODE:19999/api/v1/badge.svg?alarm=NAME&chart=CHART`
44
45 ## Health Management API
46
47 Netdata v1.12 and beyond provides a command API to control health checks and notifications at runtime. The feature is especially useful for maintenance periods, during which you receive meaningless alerts.
48 From Netdata v1.16.0 and beyond, the configuration controlled via the API commands is [persisted across Netdata restarts](#persistence).
49
50 Specifically, the API allows you to:
51
52 - Disable health checks completely. Alert conditions will not be evaluated at all and no entries will be added to the alert log.
53 - Silence alert notifications. Alert conditions will be evaluated, the alerts will appear in the log and the Netdata UI will show the alerts as active, but no notifications will be sent.
54 - Disable or Silence specific alerts that match selectors on alert/template name, chart, context, and host.
55
56 The API is available by default, but it is protected by an `api authorization token` that is stored in the file you will see in the following entry of `http://NODE:19999/netdata.conf`:
57
58 ```
59 [registry]
60 # netdata management api key file = /var/lib/netdata/netdata.api.key
61 ```
62
63 You can access the API via GET requests, by adding the bearer token to an `Authorization` http header, like this:
64
65 ```
66 curl "http://NODE:19999/api/v1/manage/health?cmd=RESET" -H "X-Auth-Token: Mytoken"
67 ```
68
69 By default access to the health management API is only allowed from `localhost`. Accessing the API from anything else will return a 403 error with the message `You are not allowed to access this resource.`. You can change permissions by editing the `allow management from` variable in `netdata.conf` within the [web] section. See [web server access lists](/src/web/server/README.md#access-lists) for more information.
70
71 The command `RESET` just returns Netdata to the default operation, with all health checks and notifications enabled.
72 If you've configured and entered your token correctly, you should see the plain text response `All health checks and notifications are enabled`.
73
74 ### Disable or silence all alerts
75
76 If all you need is temporarily disable all health checks, then you issue the following before your maintenance period starts:
77
78 ```sh
79 curl "http://NODE:19999/api/v1/manage/health?cmd=DISABLE%20ALL" -H "X-Auth-Token: Mytoken"
80 ```
81
82 The effect of disabling health checks is that the alert criteria are not evaluated at all and nothing is written in the alert log.
83 If you want the health checks to be running but to not receive any notifications during your maintenance period, you can instead use this:
84
85 ```sh
86 curl "http://NODE:19999/api/v1/manage/health?cmd=SILENCE%20ALL" -H "X-Auth-Token: Mytoken"
87 ```
88
89 Alerts may then still be raised and logged in Netdata, so you'll be able to see them via the UI.
90
91 Regardless of the option you choose, at the end of your maintenance period you revert to the normal state via the RESET command.
92
93 ```sh
94 curl "http://NODE:19999/api/v1/manage/health?cmd=RESET" -H "X-Auth-Token: Mytoken"
95 ```
96
97 ### Disable or silence specific alerts
98
99 If you do not wish to disable/silence all alerts, then the `DISABLE ALL` and `SILENCE ALL` commands can't be used.
100 Instead, the following commands expect that one or more alert selectors will be added, so that only alerts that match the selectors are disabled or silenced.
101
102 - `DISABLE` : Set the mode to disable health checks.
103 - `SILENCE` : Set the mode to silence notifications.
104
105 You will normally put one of these commands in the same request with your first alert selector, but it's possible to issue them separately as well.
106 You will get a warning in the response, if a selector was added without a SILENCE/DISABLE command, or vice versa.
107
108 Each request can specify a single alert `selector`, with one or more `selection criteria`.
109 A single alert will match a `selector` if all selection criteria match the alert.
110 You can add as many selectors as you like.
111 In essence, the rule is: IF (alert matches all the criteria in selector1 OR all the criteria in selector2 OR ...) THEN apply the DISABLE or SILENCE command.
112
113 To clear all selectors and reset the mode to default, use the `RESET` command.
114
115 The following example silences notifications for all the alerts with context=load:
116
117 ```
118 curl "http://NODE:19999/api/v1/manage/health?cmd=SILENCE&context=load" -H "X-Auth-Token: Mytoken"
119 ```
120
121 #### Selection criteria
122
123 The `selection criteria` are key/value pairs, in the format `key : value`, where value is a Netdata [simple pattern](/src/libnetdata/simple_pattern/README.md). This means that you can create very powerful selectors (you will rarely need more than one or two).
124
125 The accepted keys for the `selection criteria` are the following:
126
127 - `alarm` : The expression provided will match both `alarm` and `template` names.
128 - `chart` : Chart ids/names, as shown on the dashboard. These will match the `on` entry of a configured `alarm`.
129 - `context` : Chart context, as shown on the dashboard. These will match the `on` entry of a configured `template`.
130 - `hosts` : The hostnames that will need to match.
131
132 You can add any of the selection criteria you need on the request, to ensure that only the alerts you are interested in are matched and disabled/silenced. e.g. there is no reason to add `hosts: *`, if you want the criteria to be applied to alerts for all hosts.
133
134 Example 1: Disable all health checks for context = `random`
135
136 ```
137 http://NODE:19999/api/v1/manage/health?cmd=DISABLE&context=random
138 ```
139
140 Example 2: Silence all alerts and templates with name starting with `out_of` on host `myhost`
141
142 ```
143 http://NODE:19999/api/v1/manage/health?cmd=SILENCE&alarm=out_of*&hosts=myhost
144 ```
145
146 ### List silencers
147
148 The command `LIST` was added in Netdata v1.16.0 and returns a JSON with the current status of the silencers.
149
150 ```
151 curl "http://NODE:19999/api/v1/manage/health?cmd=LIST" -H "X-Auth-Token: Mytoken"
152 ```
153
154 As an example, the following response shows that we have two silencers configured, one for an alert called `samplealert` and one for alerts with context `random` on host `myhost`
155
156 ```
157 json
158 {
159 "all": false,
160 "type": "SILENCE",
161 "silencers": [
162 {
163 "alarm": "samplealert"
164 },
165 {
166 "context": "random",
167 "hosts": "myhost"
168 }
169 ]
170 }
171 ```
172
173 The response below shows that we have disabled all health checks.
174
175 ```
176 json
177 {
178 "all": true,
179 "type": "DISABLE",
180 "silencers": []
181 }
182 ```
183
184 ### Responses
185
186 - "Auth Error" : Token authentication failed
187 - "All alarm notifications are silenced" : Successful response to cmd=SILENCE ALL
188 - "All health checks are disabled" : Successful response to cmd=DISABLE ALL
189 - "All health checks and notifications are enabled" : Successful response to cmd=RESET
190 - "Health checks disabled for alarms matching the selectors" : Added to the response for a cmd=DISABLE
191 - "Alarm notifications silenced for alarms matching the selectors" : Added to the response for a cmd=SILENCE
192 - "Alarm selector added" : Added to the response when a new selector is added
193 - "Invalid key. Ignoring it." : Wrong name of a parameter. Added to the response and ignored.
194 - "WARNING: Added alarm selector to silence/disable alarms without a SILENCE or DISABLE command." : Added to the response if a selector is added without a selector-specific command.
195 - "WARNING: SILENCE or DISABLE command is ineffective without defining any alarm selectors." : Added to the response if a selector-specific command is issued without a selector.
196
197 ### Persistence
198
199 From Netdata v1.16.0 and beyond, the silencers configuration is persisted to disk and loaded when Netdata starts.
200 The JSON string returned by the [LIST command](#list-silencers) is automatically saved to the `silencers file`, every time a command alters the silencers configuration.
201 The file's location is configurable in `netdata.conf`. The default is shown below:
202
203 ```
204 [health]
205 # silencers file = /var/lib/netdata/health.silencers.json
206 ```
207
208 ### Further reading
209
210 The test script under [tests/health_mgmtapi](/tests/health_mgmtapi/README.md) contains a series of tests that you can either run or read through to understand the various calls and responses better.
211
212