Comments (23)
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
from python-alerta-client.
If you use an API key associated with a customer then the customer attribute will be filled in.
from python-alerta-client.
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
from python-alerta-client.
can you run the command with --debug
and paste the output here? thanks.
from python-alerta-client.
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:/#
from python-alerta-client.
btw. the heartbeats page in the GUI is not showing a Customer column
from python-alerta-client.
what does alerta keys
show?
from python-alerta-client.
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 [email protected] 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 [email protected] admin - read-write 2018/06/29 16:05:14 2017/06/29 16:05:40 1
from python-alerta-client.
You are using API key ZvM...
to generate the heartbeats but there is no customer associated with that API Key.
from python-alerta-client.
the heartbeats are created with etZp1bweLSMCqhGsLDG3OWp3xUHfln0y-y92LbJS but the cron job is running with a key without customer
from python-alerta-client.
if I create a key with customer for the cron job it should work ?
from python-alerta-client.
will try
from python-alerta-client.
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 [email protected] 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 [email protected] admin - read-write 2018/06/29 16:05:14 2017/06/29 16:05:40 1
M0KCNiBzfJvbH89aU3LZT1c6cH-eCHNyktj4HkNu [email protected] 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:/#
from python-alerta-client.
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"
}
from python-alerta-client.
Ok. I'll see if I can reproduce.
from python-alerta-client.
I have an API key with an associated customer ...
$ alerta keys
API KEY USER DESCRIPTION CUSTOMER RO / RW EXPIRES LAST USED COUNT
uypX2VXBuCWGd4wkDPGpXPheK4Ea-bcvUwxazvLc [email protected] 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
from python-alerta-client.
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.
from python-alerta-client.
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)
`
from python-alerta-client.
You're right. I'll fix. Thanks for raising the issue.
from python-alerta-client.
Ok. I'll take a look. Thanks.
from python-alerta-client.
my update to shell.py was not ok, this should be.
shell.py.zip
from python-alerta-client.
Fixed by #60 , alerta/alerta#361 and alerta/angular-alerta-webui#79.
from python-alerta-client.
@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.
from python-alerta-client.
Related Issues (20)
- Configurable timeout for alerts created from heartbeats
- Get config request ignores "SSL verify" setting
- severity used to close stale heartbeat alerts is hardcoded to 'normal' HOT 2
- Handle when config cannot be loaded from server
- Error when creating new users HOT 1
- output=silent (crontab mode) HOT 7
- Alerts on heartbeat are not triggered HOT 6
- Add generating heartbeat alerts to python SDK HOT 1
- Wheel name and python package name are different HOT 4
- `alerta heartbeats --alert` broken HOT 4
- TypeError: Object of type 'function' is not JSON serializable from CLI when running heartbeat alert HOT 1
- TypeError: Object of type 'function' is not JSON serializable from CLI when running heartbeat alert HOT 2
- SDK passing page size as "None" if not set
- alerta delete not removing all alerts HOT 1
- TypeError: 'User' object is not subscriptable
- Cron job for stale or slow heartbeats do not accept arguments specified in the documentation HOT 1
- Set alarm status in send_alarm HOT 3
- Add Python3 typing
- Alerta doesn't return all alert with get_alerts
- Unable to handshake between alerta server and Web UI HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-alerta-client.