summaryrefslogtreecommitdiffstats
path: root/health/notifications/alerta/README.md
blob: bbed23bacea4e83f9fa381be08bd3b7a29bc9960 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# alerta.io notifications

The alerta monitoring system is a tool used to consolidate and de-duplicate alerts from multiple sources for quick ‘at-a-glance’ visualisation. With just one system you can monitor alerts from many other monitoring tools on a single screen.

![](http://docs.alerta.io/en/latest/_images/alerta-screen-shot-3.png)

When receiving alerts from multiple sources you can quickly become overwhelmed. With Alerta any alert with the same environment and resource is considered a duplicate if it has the same severity. If it has a different severity it is correlated so that you only see the most recent one. Awesome.

main site http://www.alerta.io

We can send Netadata alarms to Alerta so yo can see in one place alerts coming from many Netdata hosts or also from a multihost Netadata configuration.\
The big advantage over other notifications method is that you have in a main view all active alarms with only las state, but you can also search history.

## Setting up an Alerta server with Ubuntu 16.04

Here we will set a basic Alerta server to test it with Netdata alerts.\
More advanced configurations are out os scope of this tutorial.

source: http://alerta.readthedocs.io/en/latest/gettingstarted/tutorial-1-deploy-alerta.html

I recommend to set up the server in a separated server, VM or container.\
If you have other Nginx or Apache server in your organization, I recommend to proxy to this new server.

Set us as root for easiest working
```
sudo su
cd
```

Install Mongodb https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
```
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.6.list
apt-get update
apt-get install -y mongodb-org
systemctl enable mongod
systemctl start mongod
systemctl status mongod
```

Install Nginx and Alerta uwsgi
```
apt-get install -y python-pip python-dev nginx
pip install alerta-server uwsgi
```

Install web console
```
cd /var/www/html
mkdir alerta
cd alerta
wget -q -O - https://github.com/alerta/angular-alerta-webui/tarball/master | tar zxf -
mv alerta*/app/* .
cd
```
## Services configuration

Create a wsgi python file
```
nano /var/www/wsgi.py
```
fill with
```
from alerta import app
```
Create uWsgi configuration file
```
nano /etc/uwsgi.ini
```
fill with
```
[uwsgi]
chdir = /var/www
mount = /alerta/api=wsgi.py
callable = app
manage-script-name = true

master = true
processes = 5
logger = syslog:alertad

socket = /tmp/uwsgi.sock
chmod-socket = 664
uid = www-data
gid = www-data
vacuum = true

die-on-term = true
```
Create a systemd configuration file
```
nano /etc/systemd/system/uwsgi.service
```
fill with
```
[Unit]
Description=uWSGI service

[Service]
ExecStart=/usr/local/bin/uwsgi --ini /etc/uwsgi.ini

[Install]
WantedBy=multi-user.target
```
enable service
```
systemctl start uwsgi
systemctl status uwsgi
systemctl enable uwsgi
```
Configure nginx to serve Alerta as a uWsgi application on /alerta/api
```
nano /etc/nginx/sites-enabled/default
```
fill with
```
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        location /alerta/api { try_files $uri @alerta/api; }
        location @alerta/api {
            include uwsgi_params;
            uwsgi_pass unix:/tmp/uwsgi.sock;
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        location / {
            root /var/www/html;
        }
}
```
restart nginx
```
service nginx restart
```
## Config web console
```
nano /var/www/html/config.js
```
fill with
```
'use strict';

angular.module('config', [])
  .constant('config', {
    'endpoint'    : "/alerta/api",
    'provider'    : "basic",
    'colors'      : {},
    'severity'    : {},
    'audio'       : {}
  });
```

## Config Alerta server

source: http://alerta.readthedocs.io/en/latest/configuration.html

Create a random string to use as SECRET_KEY
```
cat /dev/urandom | tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= | head -c 32 && echo
```
will output something like
```
0pv8Bw7VKfW6avDAz_TqzYPme_fYV%7g
```
Edit alertad.conf
```
nano /etc/alertad.conf
```
fill with (take care about all single quotes)
```
BASE_URL='/alerta/api'
AUTH_REQUIRED=True
SECRET_KEY='0pv8Bw7VKfW6avDAz_TqzYPme_fYV%7g'
ADMIN_USERS=['<here put you email for future login>']
```

restart
```
systemctl restart uwsgi
```

* go to console to http://yourserver/alerta/
* go to Login -> Create an account
* use your email for login so and administrative account will be created

## create an API KEY

You need an API KEY to send messages from any source.\
To create an API KEY go to Configuration -> Api Keys\
Then create a API KEY with write permisions.

## configure Netdata to send alarms to Alerta

On your system run:

```
/etc/netdata/edit-config health_alarm_notify.conf
```

and set

```
# enable/disable sending alerta notifications
SEND_ALERTA="YES"

# here set your alerta server API url
# this is the API url you defined when installed Alerta server, 
# it is the same for all users. Do not include last slash.
ALERTA_WEBHOOK_URL="http://yourserver/alerta/api"

# Login with an administrative user to you Alerta server and create an API KEY
# with write permissions.
ALERTA_API_KEY="you last created API KEY"

# you can define environments in /etc/alertad.conf option ALLOWED_ENVIRONMENTS
# standard environments are Production and Development
# if a role's recipients are not configured, a notification will be send to
# this Environment (empty = do not send a notification for unconfigured roles):
DEFAULT_RECIPIENT_ALERTA="Production"
```

## Test alarms

We can test alarms with standard
```
sudo su -s /bin/bash netdata
/opt/netdata/netdata-plugins/plugins.d/alarm-notify.sh test
exit
```
But the problem is that Netdata will send 3 alarms, and because last alarm is "CLEAR" you will not se them in main Alerta page, you need to select to see "closed" alarma in top-right lookup.

A little change in alarm-notify.sh that let us test each state one by one will be useful.