Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"alerta heartbeats --alert" is not adding customer field to alerts that are generated #57

Closed
wimfabri opened this issue Jun 29, 2017 · 23 comments
Assignees
Labels
bug Something isn't working

Comments

@wimfabri
Copy link

"alerta heartbeats --alert" should add customer from heartbeat to alert

@satterly
Copy link
Member

If you use an API key associated with a customer then the customer attribute will be filled in.

@wimfabri
Copy link
Author

when creating an alert the customer attribute is indeed filled in, but when using "alerta heartbeats --alert" to create alerts for timed-out heartbeats these alerts do not have the customer attribute

I am using alerta/docker-alerta

@satterly
Copy link
Member

can you run the command with --debug and paste the output here? thanks.

@wimfabri
Copy link
Author

wimfabri commented Jun 29, 2017

root@c2a86c1e055a:/# alerta --debug heartbeats --alert
2017-06-29 14:52:14,990 - alertaclient.shell - DEBUG - Alerta cli version: 4.8.8
2017-06-29 14:52:14,992 - urllib3.connectionpool - DEBUG - Starting new HTTP connection (1): localhost
2017-06-29 14:52:14,996 - urllib3.connectionpool - DEBUG - http://localhost:80 "GET /api/heartbeats HTTP/1.1" 200 468
2017-06-29 14:52:14,997 - alertaclient.api - DEBUG - Request Headers: {'Authorization': 'Key ZvMlaoHtGm677kWchwGri8fISAd0iZbevuLGJ2NU', 'Connection': 'keep-alive', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.18.1'}
2017-06-29 14:52:14,997 - alertaclient.api - DEBUG - Response Headers: {'Content-Length': '468', 'Vary': 'Origin', 'Server': 'nginx/1.10.0 (Ubuntu)', 'Connection': 'keep-alive', 'Date': 'Thu, 29 Jun 2017 14:52:14 GMT', 'Access-Control-Allow-Origin': 'http://explorer.alerta.io', 'Content-Type': 'application/json'}
2017-06-29 14:52:14,997 - alertaclient.api - DEBUG - Response Body: {
  "heartbeats": [
    {
      "createTime": "2017-06-29T14:21:13.543Z", 
      "customer": null, 
      "href": "http://localhost/api/heartbeat/b659bab4-0234-4aa7-acb6-077c1f02f5df", 
      "id": "b659bab4-0234-4aa7-acb6-077c1f02f5df", 
      "origin": "Cabot", 
      "receiveTime": "2017-06-29T14:21:13.558Z", 
      "tags": [], 
      "timeout": 120, 
      "type": "Heartbeat"
    }
  ], 
  "status": "ok", 
  "time": "2017-06-29T14:52:14.995Z", 
  "total": 1
}

ORIGIN                       TAGS                       CREATED              LATENCY TIMEOUT SINCE             STATUS 
Cabot                                                   2017/06/29 15:21:13     15ms    120s 0:31:01           stale  
2017-06-29 14:52:15,034 - urllib3.connectionpool - DEBUG - http://localhost:80 "POST /api/alert HTTP/1.1" 201 1144
2017-06-29 14:52:15,036 - alertaclient.api - DEBUG - Request Headers: {'Content-Length': '521', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.18.1', 'Connection': 'keep-alive', 'Content-Type': 'application/json', 'Authorization': 'Key ZvMlaoHtGm677kWchwGri8fISAd0iZbevuLGJ2NU'}
2017-06-29 14:52:15,036 - alertaclient.api - DEBUG - Request Body: {"status": "unknown", "origin": "alerta/c2a86c1e055a", "resource": "Cabot", "severity": "major", "correlate": ["HeartbeatFail", "HeartbeatSlow", "HeartbeatOK"], "tags": [], "text": "Heartbeat not received in 120 seconds", "createTime": "2017-06-29T14:52:15.014Z", "value": "0:31:01", "event": "HeartbeatFail", "environment": "Production", "customer": null, "service": ["Alerta"], "rawData": "", "timeout": 86400, "attributes": {}, "group": "System", "type": "heartbeatAlert", "id": "ba5d3da9-bc50-40ca-ba62-ee2f3aa98679"}
2017-06-29 14:52:15,036 - alertaclient.api - DEBUG - Response Headers: {'Content-Length': '1144', 'Vary': 'Origin', 'Server': 'nginx/1.10.0 (Ubuntu)', 'Connection': 'keep-alive', 'Location': 'http://localhost/api/alert/334fdfdb-7a44-4a4b-9638-a2e2a8253f3f', 'Date': 'Thu, 29 Jun 2017 14:52:15 GMT', 'Access-Control-Allow-Origin': 'http://explorer.alerta.io', 'Content-Type': 'application/json'}
2017-06-29 14:52:15,036 - alertaclient.api - DEBUG - Response Body: {
  "alert": {
    "attributes": {
      "ip": "::1"
    }, 
    "correlate": [
      "HeartbeatFail", 
      "HeartbeatSlow", 
      "HeartbeatOK"
    ], 
    "createTime": "2017-06-29T14:24:01.220Z", 
    "customer": null, 
    "duplicateCount": 29, 
    "environment": "Production", 
    "event": "HeartbeatFail", 
    "group": "System", 
    "history": [], 
    "href": "http://localhost/api/alert/334fdfdb-7a44-4a4b-9638-a2e2a8253f3f", 
    "id": "334fdfdb-7a44-4a4b-9638-a2e2a8253f3f", 
    "lastReceiveId": "616848b6-9664-46eb-aa07-5cd5309a2815", 
    "lastReceiveTime": "2017-06-29T14:52:15.026Z", 
    "origin": "alerta/4a148bf6a49d", 
    "previousSeverity": "normal", 
    "rawData": "", 
    "receiveTime": "2017-06-29T14:24:01.228Z", 
    "repeat": true, 
    "resource": "Cabot", 
    "service": [
      "Alerta"
    ], 
    "severity": "major", 
    "status": "open", 
    "tags": [], 
    "text": "Heartbeat not received in 120 seconds", 
    "timeout": 86400, 
    "trendIndication": "moreSevere", 
    "type": "heartbeatAlert", 
    "value": "0:31:01"
  }, 
  "id": "334fdfdb-7a44-4a4b-9638-a2e2a8253f3f", 
  "status": "ok"
}

334fdfdb-7a44-4a4b-9638-a2e2a8253f3f (29 duplicates)
root@c2a86c1e055a:/# 

@wimfabri
Copy link
Author

btw. the heartbeats page in the GUI is not showing a Customer column

@satterly
Copy link
Member

what does alerta keys show?

@wimfabri
Copy link
Author

wimfabri commented Jun 29, 2017

in the container nothing, with a key I created without customer:

17:05 $ alerta keys
API KEY                                  USER                     DESCRIPTION          CUSTOMER         RO / RW    EXPIRES             LAST USED           COUNT
vBC2r/T/jAMTvvaE79ZOFKN0z3E6Wtex/bcaYOcS internal                 cron jobs            -                read-write 2018/06/27 11:32:48 2017/06/27 11:44:01  12.0
R5NiWJsiSTH3MvEY/nUc8LoqZlzgORykP8wpYFzf internal                 cron jobs            -                read-write 2018/06/29 13:08:37 2017/06/29 13:47:01 155.0
etZp1bweLSMCqhGsLDG3OWp3xUHfln0y-y92LbJS wim.fabri@xenit.eu       Cabot                Xenit            read-write 2018/06/29 13:09:14 2017/06/29 15:21:13   438
ap0Ask/7YWqyZoEmCO6CI02+0DcuaqyZ9Rj3fBiA internal                 cron jobs            -                read-write 2018/06/29 13:47:48 2017/06/29 13:48:02   6.0
yG5Era3zDHASaH5EkwZG20lKQIIJDsl9RU2b2qVP internal                 cron jobs            -                read-write 2018/06/29 13:48:48 2017/06/29 14:05:01  34.0
nmSd9m+GQ215I4vc1/WLZExz7RmkdhysKKl/zag9 internal                 cron jobs            -                read-write 2018/06/29 14:05:38 2017/06/29 14:10:01  10.0
vXM+wHuGyi3tECurGHPt0S5jM/G8b7SltmNO+E7H internal                 cron jobs            -                read-write 2018/06/29 14:10:18 2017/06/29 14:17:02  14.0
9TH0Vrv90qhZLkFZhYFvOhF65rVUgzFwAm3CkAy8 internal                 cron jobs            -                read-write 2018/06/29 14:17:34 2017/06/29 15:05:02  96.0
ZvMlaoHtGm677kWchwGri8fISAd0iZbevuLGJ2NU internal                 cron jobs            -                read-write 2018/06/29 15:05:44 2017/06/29 16:05:01 123.0
W9EO9-QJBhs-n1c0oRz0AB6JsadNXR2aza2dqBaG wim.fabri@xenit.eu       admin                -                read-write 2018/06/29 16:05:14 2017/06/29 16:05:40     1

@satterly
Copy link
Member

You are using API key ZvM... to generate the heartbeats but there is no customer associated with that API Key.

@wimfabri
Copy link
Author

the heartbeats are created with etZp1bweLSMCqhGsLDG3OWp3xUHfln0y-y92LbJS but the cron job is running with a key without customer

@wimfabri
Copy link
Author

if I create a key with customer for the cron job it should work ?

@wimfabri
Copy link
Author

will try

@wimfabri
Copy link
Author

wimfabri commented Jun 29, 2017

the new key lists the keys but doesn't find the heartbeat:

root@44386aa56d28:/# alerta keys                      
API KEY                                  USER                     DESCRIPTION          CUSTOMER         RO / RW    EXPIRES             LAST USED           COUNT
vBC2r/T/jAMTvvaE79ZOFKN0z3E6Wtex/bcaYOcS internal                 cron jobs            -                read-write 2018/06/27 11:32:48 2017/06/27 11:44:01  12.0
R5NiWJsiSTH3MvEY/nUc8LoqZlzgORykP8wpYFzf internal                 cron jobs            -                read-write 2018/06/29 13:08:37 2017/06/29 13:47:01 155.0
etZp1bweLSMCqhGsLDG3OWp3xUHfln0y-y92LbJS wim.fabri@xenit.eu       Cabot                Xenit            read-write 2018/06/29 13:09:14 2017/06/29 15:21:13   438
ap0Ask/7YWqyZoEmCO6CI02+0DcuaqyZ9Rj3fBiA internal                 cron jobs            -                read-write 2018/06/29 13:47:48 2017/06/29 13:48:02   6.0
yG5Era3zDHASaH5EkwZG20lKQIIJDsl9RU2b2qVP internal                 cron jobs            -                read-write 2018/06/29 13:48:48 2017/06/29 14:05:01  34.0
nmSd9m+GQ215I4vc1/WLZExz7RmkdhysKKl/zag9 internal                 cron jobs            -                read-write 2018/06/29 14:05:38 2017/06/29 14:10:01  10.0
vXM+wHuGyi3tECurGHPt0S5jM/G8b7SltmNO+E7H internal                 cron jobs            -                read-write 2018/06/29 14:10:18 2017/06/29 14:17:02  14.0
9TH0Vrv90qhZLkFZhYFvOhF65rVUgzFwAm3CkAy8 internal                 cron jobs            -                read-write 2018/06/29 14:17:34 2017/06/29 15:05:02  96.0
ZvMlaoHtGm677kWchwGri8fISAd0iZbevuLGJ2NU internal                 cron jobs            -                read-write 2018/06/29 15:05:44 2017/06/29 16:17:01 148.0
W9EO9-QJBhs-n1c0oRz0AB6JsadNXR2aza2dqBaG wim.fabri@xenit.eu       admin                -                read-write 2018/06/29 16:05:14 2017/06/29 16:05:40     1
M0KCNiBzfJvbH89aU3LZT1c6cH-eCHNyktj4HkNu wim.fabri@xenit.eu       cron                 xenit            read-write 2018/06/29 16:13:05 2017/06/29 16:24:58     1
NSa4AzBnHtFRzGs5Z5qxuer7bo0SOVHcNRo3ng63 internal                 cron jobs            -                read-write 2018/06/29 16:17:17 2017/06/29 16:24:02  17.0
root@44386aa56d28:/# alerta --debug heartbeats --alert
2017-06-29 15:25:09,029 - alertaclient.shell - DEBUG - Alerta cli version: 4.8.8
2017-06-29 15:25:09,030 - urllib3.connectionpool - DEBUG - Starting new HTTP connection (1): localhost
2017-06-29 15:25:09,034 - urllib3.connectionpool - DEBUG - http://localhost:80 "GET /api/heartbeats HTTP/1.1" 200 123
2017-06-29 15:25:09,035 - alertaclient.api - DEBUG - Request Headers: {'Authorization': 'Key M0KCNiBzfJvbH89aU3LZT1c6cH-eCHNyktj4HkNu', 'Connection': 'keep-alive', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.18.1'}
2017-06-29 15:25:09,035 - alertaclient.api - DEBUG - Response Headers: {'Content-Length': '123', 'Vary': 'Origin', 'Server': 'nginx/1.10.0 (Ubuntu)', 'Connection': 'keep-alive', 'Date': 'Thu, 29 Jun 2017 15:25:09 GMT', 'Access-Control-Allow-Origin': 'http://explorer.alerta.io', 'Content-Type': 'application/json'}
2017-06-29 15:25:09,035 - alertaclient.api - DEBUG - Response Body: {
  "heartbeats": [], 
  "message": "not found", 
  "status": "ok", 
  "time": "2017-06-29T15:25:09.033Z", 
  "total": 0
}

ORIGIN                       TAGS                       CREATED              LATENCY TIMEOUT SINCE             STATUS 
root@44386aa56d28:/# 

@wimfabri
Copy link
Author

wimfabri commented Jun 29, 2017

the heartbeats are created without customer although I use a key with customer:

17:31 $ ./cabot2alerta.py -c http://test:8083 -a http://localhost/api -k etZp1bweLSMCqhGsLDG3OWp3xUHfln0y-y92LbJS -l debug
INFO:root:Namespace(alerta='http://localhost/api', cabot='http://test:8083', environment='Production', interval=60, key='etZp1bweLSMCqhGsLDG3OWp3xUHfln0y-y92LbJS', loglevel='debug', origin='Cabot', password='admin', timeout=120, user='admin')
DEBUG:root:sending heartbeat to http://localhost/api
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): localhost
DEBUG:requests.packages.urllib3.connectionpool:"POST /api/heartbeat HTTP/1.1" 201 432
DEBUG:alertaclient.api:Request Headers: {'Content-Length': '174', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.10.0', 'Connection': 'keep-alive', 'Content-Type': 'application/json', 'Authorization': 'Key etZp1bweLSMCqhGsLDG3OWp3xUHfln0y-y92LbJS'}
DEBUG:alertaclient.api:Request Body: {"origin": "Cabot", "customer": null, "tags": [], "createTime": "2017-06-29T15:32:52.954Z", "timeout": 120, "type": "Heartbeat", "id": "8c7e8c91-3dd4-4728-99eb-a7dc27275ef3"}
DEBUG:alertaclient.api:Response Headers: {'Content-Length': '432', 'Vary': 'Origin', 'Server': 'nginx/1.10.0 (Ubuntu)', 'Connection': 'keep-alive', 'Location': 'http://localhost/api/heartbeat/6afdf2e3-0964-4380-a1c1-8fff25ba783d', 'Date': 'Thu, 29 Jun 2017 15:32:52 GMT', 'Access-Control-Allow-Origin': 'http://explorer.alerta.io', 'Content-Type': 'application/json'}
DEBUG:alertaclient.api:Response Body: {
  "heartbeat": {
    "createTime": "2017-06-29T15:32:52.954Z", 
    "customer": null, 
    "href": "http://localhost/api/heartbeat/6afdf2e3-0964-4380-a1c1-8fff25ba783d", 
    "id": "6afdf2e3-0964-4380-a1c1-8fff25ba783d", 
    "origin": "Cabot", 
    "receiveTime": "2017-06-29T15:32:52.964Z", 
    "tags": [], 
    "timeout": 120, 
    "type": "Heartbeat"
  }, 
  "id": "6afdf2e3-0964-4380-a1c1-8fff25ba783d", 
  "status": "ok"
}

@satterly
Copy link
Member

Ok. I'll see if I can reproduce.

@satterly
Copy link
Member

I have an API key with an associated customer ...

$ alerta keys
API KEY                                  USER                     DESCRIPTION          CUSTOMER         RO / RW    EXPIRES             LAST USED           COUNT
uypX2VXBuCWGd4wkDPGpXPheK4Ea-bcvUwxazvLc user@bar.com             user bar             Bar              read-write 2018/06/07 11:53:17 2017/06/29 21:52:21     8

If I send a heartbeat using this API key the customer will be sent as "null" but I'll get a customer auto-assigned and sent back in the payload...

$ alerta --debug heartbeat --tag london
2017-06-29 21:52:05,550 - alertaclient.shell - DEBUG - Alerta cli version: 4.8.7
2017-06-29 21:52:05,585 - requests.packages.urllib3.connectionpool - DEBUG - Starting new HTTP connection (1): localhost
2017-06-29 21:52:05,593 - requests.packages.urllib3.connectionpool - DEBUG - http://localhost:8081 "POST /heartbeat HTTP/1.1" 201 469
2017-06-29 21:52:05,593 - alertaclient.api - DEBUG - Request Headers: {'Content-Length': '197', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.13.0', 'Connection': 'keep-alive', 'Content-Type': 'application/json', 'Authorization': 'Key uypX2VXBuCWGd4wkDPGpXPheK4Ea-bcvUwxazvLc'}
2017-06-29 21:52:05,594 - alertaclient.api - DEBUG - Request Body: {"origin": "alerta/fdaa33ca.home", "customer": null, "tags": ["london"], "createTime": "2017-06-29T20:52:05.550Z", "timeout": 300, "type": "Heartbeat", "id": "902d6362-f1f2-4eba-a897-f3829210e08f"}
2017-06-29 21:52:05,594 - alertaclient.api - DEBUG - Response Headers: {'Content-Length': '469', 'Vary': 'Origin', 'Server': 'Werkzeug/0.11.11 Python/2.7.12', 'Location': 'http://localhost:8081/heartbeat/da040d1f-24ed-466e-825c-4b0f32119081', 'Date': 'Thu, 29 Jun 2017 20:52:05 GMT', 'Access-Control-Allow-Origin': 'http://localhost:4200', 'Content-Type': 'application/json'}
2017-06-29 21:52:05,620 - alertaclient.api - DEBUG - Response Body: {
  "heartbeat": {
    "createTime": "2017-06-29T20:52:05.550Z",
    "customer": "Bar",
    "href": "http://localhost:8081/heartbeat/da040d1f-24ed-466e-825c-4b0f32119081",
    "id": "da040d1f-24ed-466e-825c-4b0f32119081",
    "origin": "alerta/fdaa33ca.home",
    "receiveTime": "2017-06-29T20:52:05.589Z",
    "tags": [
      "london"
    ],
    "timeout": 300,
    "type": "Heartbeat"
  },
  "id": "da040d1f-24ed-466e-825c-4b0f32119081",
  "status": "ok"
}

da040d1f-24ed-466e-825c-4b0f32119081

I can use the same API key to check for heartbeats associated with that customer ...

$ alerta heartbeats
ORIGIN                       TAGS                       CREATED              LATENCY TIMEOUT SINCE             STATUS
alerta/fdaa33ca.home         london                     2017/06/29 21:52:05     39ms    300s 0:00:04           ok

@satterly
Copy link
Member

Note that if I use an "admin" API Key I can see heartbeats for all customers, including those without a customer defined.

$ alerta --profile admin heartbeats
ORIGIN                       TAGS                       CREATED              LATENCY TIMEOUT SINCE             STATUS
alerta/fdaa33ca.home                                    2017/06/29 22:02:11     25ms    300s 0:01:13           ok
test/admin                   newyork                    2017/06/29 22:01:51     36ms    300s 0:01:34           ok

But I have just noticed that heartbeats with the same origin are overwritten if they come from different customers.

@wimfabri
Copy link
Author

the problem is that the customer attrib is not set when the api key is created by an admin
from app/views/py:
`def create_heartbeat():

try:
    heartbeat = Heartbeat.parse_heartbeat(request.data)
except ValueError as e:
    return jsonify(status="error", message=str(e)), 400

if g.get('role', None) != 'admin':
    heartbeat.customer = g.get('customer', None)

`

@satterly
Copy link
Member

You're right. I'll fix. Thanks for raising the issue.

@wimfabri
Copy link
Author

I also updated alertaclient/shell.py to add the customer attrib from the heartbeat to the alert that is created. This makes it possible to create heartbeat alerts for all customers at once.
shell.py.zip

@satterly
Copy link
Member

Ok. I'll take a look. Thanks.

@wimfabri
Copy link
Author

my update to shell.py was not ok, this should be.
shell.py.zip

@satterly
Copy link
Member

Fixed by #60 , alerta/alerta#361 and alerta/angular-alerta-webui#79.

@satterly
Copy link
Member

satterly commented Jun 30, 2017

@wimfabri Thanks for the shell.py file. I used your suggestions except for hardcoding the customer when generating the stale heartbeat alerts. Customer assignment can only be done at the server based on the API key otherwise there could be issues with users overwriting each others alerts, accidentally or not. Passing a customer value in the alert sent to the server is ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants