alerta / python-alerta-client Goto Github PK
View Code? Open in Web Editor NEWUnified command-line tool and python SDK for alerta
Home Page: https://pypi.org/project/alerta/
License: Apache License 2.0
Unified command-line tool and python SDK for alerta
Home Page: https://pypi.org/project/alerta/
License: Apache License 2.0
pip install alerta for 4.8.1 doesnt install any files in python lib.
pip uninstall alerta
Uninstalling alerta-4.8.1:
/usr/local/lib/python2.7/dist-packages/alerta-4.8.1-py2.7.egg-info
/usr/local/lib/python2.7/dist-packages/alertaclient
Proceed (y/n)? ^COperation cancelled by user
Thanks for providing such a nice python client and taking care of it. I think it is quite uncommon to provide a python package via a wheel name differently. Would it be possible to change the wheel name in
Line 13 in cf1a193
alerta
to alertaclient
.This is a bit of a strange one. In Alerta CLI 5.1.0, I get silent exits (return code is 1) when running alerta send as a cron job (directly or as a subprocess). When I've downgraded to Alerta CLI 5.0.12, this problem goes away.
It appears to me that the cause is line 84 on https://github.com/alerta/python-alerta-client/blame/master/alertaclient/commands/cmd_send.py
I believe this bug has been introduced by #126
Looking at the code, I don't understand why you're calling sys.exit(1) instead of sys.exit(0), it looks like a normal exit to me, but I haven't dug deeper there. I think this may be a bug in itself, but this isn't what's causing my issue.
The main problem for me is that send_alert on line 92 becomes unreachable. When running as a cron job (and perhaps other cases), it must not think it's a TTY, assumes it's getting piped input, does nothing because it get's no input and then calls sys.exit, never reaching the bit that would process the traditional command line flags.
I'm not sure what the solution is, but I think sys.stdin.isatty() alone probably isn't enough to guarantee that something is being piped in. Nothing is being piped in in this case. Perhaps the logic could be changed to be based the presence of command line options like resource, because these don't need to be present if it's all in the payload.
Issue Summary
Running alerta heartbeats
is showing all heartbeat records ok. When running alerta heartbeats --alert
this exception is being thrown:
Traceback (most recent call last):
File "/usr/local/bin/alerta", line 8, in <module>
sys.exit(cli())
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/click/decorators.py", line 33, in new_func
return f(get_current_context().obj, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/alertaclient/commands/cmd_heartbeats.py", line 100, in cli
customer=b.customer
File "/usr/local/lib/python3.6/dist-packages/alertaclient/api.py", line 65, in send_alert
r = self.http.post('/alert', data)
File "/usr/local/lib/python3.6/dist-packages/alertaclient/api.py", line 519, in post
response = self.session.post(url, data=json.dumps(data, cls=CustomJsonEncoder),
File "/usr/lib/python3.6/json/__init__.py", line 238, in dumps
**kw).encode(obj)
File "/usr/lib/python3.6/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python3.6/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/usr/local/lib/python3.6/dist-packages/alertaclient/utils.py", line 18, in default
return json.JSONEncoder.default(self, o)
File "/usr/lib/python3.6/json/encoder.py", line 180, in default
o.__class__.__name__)
TypeError: Object of type 'function' is not JSON serializable
Environment
OS: Ubuntu 18.04 LTS
API version: 7.4.4
Deployment: Docker
For self-hosted: no WSGI, just the alerta/alerta_web container behind Apache proxy
Database: Postgres
Server config:
Auth enabled? Yes
Auth provider? GitLab
Customer views? Yes
{"actions":[],"alarm_model":{"colors":{"severity":{"cleared":"#00CC00","critical":"red","debug":"#9D006D","indeterminate":"lightblue","informational":"#00CC00","major":"orange","minor":"yellow","normal":"#00CC00","ok":"#00CC00","security":"blue","trace":"#7554BF","unknown":"silver","warning":"dodgerblue"},"text":"black"},"defaults":{"normal_severity":"normal","previous_severity":"indeterminate","status":"open"},"name":"Alerta 7.4.4","severity":{"cleared":7,"critical":1,"debug":8,"indeterminate":5,"informational":6,"major":2,"minor":3,"normal":7,"ok":7,"security":0,"trace":9,"unknown":10,"warning":4},"status":{"ack":"C","assign":"B","blackout":"E","closed":"F","expired":"G","open":"A","shelved":"D","unknown":"H"}},"audio":{"new":null},"auth_required":true,"aws_region":"us-east-1","azure_tenant":"common","client_id":"0e0d1f1df40e2cde0ca3989b654b102aaed761f9bf104cfef4e00bc65e059f58","cognito_domain":null,"colors":{"severity":{"cleared":"#00CC00","critical":"red","debug":"#9D006D","indeterminate":"lightblue","informational":"#00CC00","major":"orange","minor":"yellow","normal":"#00CC00","ok":"#00CC00","security":"blue","trace":"#7554BF","unknown":"silver","warning":"dodgerblue"},"text":"black"},"columns":["severity","status","lastReceiveTime","timeoutLeft","duplicateCount","customer","environment","service","resource","event","value"],"customer_views":true,"dates":{"longDate":"ddd D MMM, YYYY HH:mm:ss.SSS Z","mediumDate":"ddd D MMM HH:mm","shortTime":"HH:mm"},"debug":false,"email_verification":false,"endpoint":"https://alerta.lakedrops.com/api","filter":{"status":["open","ack"]},"github_url":"https://github.com","gitlab_url":"https://gitlab.lakedrops.com","indicators":{"queries":[{"query":[["environment","Production"]],"text":"Production"},{"query":[["environment","Development"]],"text":"Development"},{"query":{"q":"event:Heartbeat"},"text":"Heartbeats"},{"query":"group=Misc","text":"Misc."}],"severity":["critical","major","minor","warning","indeterminate","informational"]},"keycloak_realm":null,"keycloak_url":null,"oidc_auth_url":"https://gitlab.lakedrops.com/oauth/authorize","provider":"gitlab","refresh_interval":5000,"severity":{"cleared":7,"critical":1,"debug":8,"indeterminate":5,"informational":6,"major":2,"minor":3,"normal":7,"ok":7,"security":0,"trace":9,"unknown":10,"warning":4},"signup_enabled":false,"site_logo_url":"","sort_by":"lastReceiveTime","tracking_id":null}
To Reproduce
Steps to reproduce the behavior:
alerta heartbeats --alert
Additional context
docker-compose.yml
version: '2.1'
services:
web:
image: alerta/alerta-web
ports:
- "8091:8080"
depends_on:
- db
volumes:
- ./config/alertad.conf:/app/alertad.conf
- ./config/config.json:/web/config.json
environment:
- DATABASE_URL=postgres://postgres:postgres@db:5432/monitoring
- BASE_URL=https://alerta.lakedrops.com/api
restart: always
db:
image: postgres
volumes:
- ./pg-data:/var/lib/postgresql/data
environment:
POSTGRES_DB: monitoring
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
restart: always
config/alertad.conf
BASE_URL='https://alerta.lakedrops.com/api'
AUTH_REQUIRED=True
AUTH_PROVIDER='gitlab'
SECRET_KEY='XYZ'
ADMIN_USERS=['some entries']
CUSTOMER_VIEWS=True
# OAuth
GITLAB_URL='https://gitlab.lakedrops.com'
OAUTH2_CLIENT_ID='XYZ'
OAUTH2_CLIENT_SECRET='XYZ'
ALLOWED_GITLAB_GROUPS=['some strings']
# Plugins
PLUGINS=['reject','blackout','normalise','enhance']
ORIGIN_BLACKLIST=[]
ALLOWED_ENVIRONMENTS=['some strings']
config/config.json
{
"endpoint": "https://alerta.lakedrops.com/api",
"base_path": "/",
"provider": "gitlab",
"client_id": "XYZ",
"gitlab_url": "https://gitlab.lakedrops.com"
}
See #141 and alerta/alerta#480
noticed an issue while testing out heartbeats
sending heartbeats like this :
mydata = {
'origin': origin,
'timeout': 2000 * timeout_days,
'tags': tags
}
r = requests.post('httpfqdn/api/heartbeat', json=mydata, headers = myheaders)
I can see the heartbeat in the ui with timeout of 2000 seconds
however when I run alerta heartbeats --alert I'm getting json parse error for timeout
File "/usr/lib/python2.7/site-packages/alertaclient/commands/cmd_heartbeats.py", line 85, in cli
type='heartbeatAlert'
File "/usr/lib/python2.7/site-packages/alertaclient/api.py", line 69, in send_alert
alert = Alert.parse(r['alert']) if 'alert' in r else None
File "/usr/lib/python2.7/site-packages/alertaclient/models/alert.py", line 64, in parse
raise ValueError('timeout must be an integer')
ValueError: timeout must be an integer
its showing as 2000s in command line
Issue Summary
after last update got exception on alerta heartbeats --alert
Environment
OS: linux ubuntu 16.04
API version: 7.4.4
Deployment: self-hosted
For self-hosted, WSGI environment: nginx/uwsgi
Database: postgresql
Server config:
Auth enabled? Yes
Auth provider? Basic
Customer views? No
To Reproduce
Steps to reproduce the behavior:
Traceback (most recent call last):
File "/srv/projects/venv3/bin/alerta", line 11, in <module>
sys.exit(cli())
File "/srv/projects/venv3/lib/python3.5/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/srv/projects/venv3/lib/python3.5/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/srv/projects/venv3/lib/python3.5/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/srv/projects/venv3/lib/python3.5/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/srv/projects/venv3/lib/python3.5/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/srv/projects/venv3/lib/python3.5/site-packages/click/decorators.py", line 33, in new_func
return f(get_current_context().obj, *args, **kwargs)
File "/srv/projects/venv3/lib/python3.5/site-packages/alertaclient/commands/cmd_heartbeats.py", line 100, in cli
customer=b.customer
File "/srv/projects/venv3/lib/python3.5/site-packages/alertaclient/api.py", line 65, in send_alert
r = self.http.post('/alert', data)
File "/srv/projects/venv3/lib/python3.5/site-packages/alertaclient/api.py", line 519, in post
response = self.session.post(url, data=json.dumps(data, cls=CustomJsonEncoder),
File "/usr/lib/python3.5/json/__init__.py", line 237, in dumps
**kw).encode(obj)
File "/usr/lib/python3.5/json/encoder.py", line 198, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python3.5/json/encoder.py", line 256, in iterencode
return _iterencode(o, 0)
File "/srv/projects/venv3/lib/python3.5/site-packages/alertaclient/utils.py", line 18, in default
return json.JSONEncoder.default(self, o)
File "/usr/lib/python3.5/json/encoder.py", line 179, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <function origin at 0x7f5cba65ad90> is not JSON serializable
Expected behavior
Alerting heartbeats [####################################] 100%
Additional context
temporary workaround:
$ alerta --profile heroku version
2017-07-26 14:03:44,856 - alertaclient.shell - ERROR - 'status'
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/alertaclient/shell.py", line 1661, in main
AlertaShell().run()
File "/usr/local/lib/python2.7/site-packages/alertaclient/shell.py", line 1646, in run
args.func(args)
File "/usr/local/lib/python2.7/site-packages/alertaclient/shell.py", line 923, in version
response = self._status()
File "/usr/local/lib/python2.7/site-packages/alertaclient/shell.py", line 899, in _status
if response['status'] == "error":
KeyError: 'status'
Hi,
Is it possible to add an option to specify a timeout to the alerts sending API?
From what I've seen, the requests.session.post specifies no timeout,
which can cause the app to hang indefinitely.
Would be nice to have an option to pass a timeout parameter in ApiClient.send.
Generally, I think it's a good idea to have a timeout configured for each requests API.
Thanks.
Issue Summary
Running alerta heartbeats
is showing all heartbeat records ok. When running alerta heartbeats --alert
this exception is being thrown:
Traceback (most recent call last):
File "/usr/local/bin/alerta", line 8, in <module>
sys.exit(cli())
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/click/decorators.py", line 33, in new_func
return f(get_current_context().obj, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/alertaclient/commands/cmd_heartbeats.py", line 100, in cli
customer=b.customer
File "/usr/local/lib/python3.6/dist-packages/alertaclient/api.py", line 65, in send_alert
r = self.http.post('/alert', data)
File "/usr/local/lib/python3.6/dist-packages/alertaclient/api.py", line 519, in post
response = self.session.post(url, data=json.dumps(data, cls=CustomJsonEncoder),
File "/usr/lib/python3.6/json/__init__.py", line 238, in dumps
**kw).encode(obj)
File "/usr/lib/python3.6/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python3.6/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/usr/local/lib/python3.6/dist-packages/alertaclient/utils.py", line 18, in default
return json.JSONEncoder.default(self, o)
File "/usr/lib/python3.6/json/encoder.py", line 180, in default
o.__class__.__name__)
TypeError: Object of type 'function' is not JSON serializable
Environment
OS: Ubuntu 18.04 LTS
API version: 7.4.4
Deployment: Docker
For self-hosted: no WSGI, just the alerta/alerta_web container behind Apache proxy
Database: Postgres
Server config:
Auth enabled? Yes
Auth provider? GitLab
Customer views? Yes
{"actions":[],"alarm_model":{"colors":{"severity":{"cleared":"#00CC00","critical":"red","debug":"#9D006D","indeterminate":"lightblue","informational":"#00CC00","major":"orange","minor":"yellow","normal":"#00CC00","ok":"#00CC00","security":"blue","trace":"#7554BF","unknown":"silver","warning":"dodgerblue"},"text":"black"},"defaults":{"normal_severity":"normal","previous_severity":"indeterminate","status":"open"},"name":"Alerta 7.4.4","severity":{"cleared":7,"critical":1,"debug":8,"indeterminate":5,"informational":6,"major":2,"minor":3,"normal":7,"ok":7,"security":0,"trace":9,"unknown":10,"warning":4},"status":{"ack":"C","assign":"B","blackout":"E","closed":"F","expired":"G","open":"A","shelved":"D","unknown":"H"}},"audio":{"new":null},"auth_required":true,"aws_region":"us-east-1","azure_tenant":"common","client_id":"0e0d1f1df40e2cde0ca3989b654b102aaed761f9bf104cfef4e00bc65e059f58","cognito_domain":null,"colors":{"severity":{"cleared":"#00CC00","critical":"red","debug":"#9D006D","indeterminate":"lightblue","informational":"#00CC00","major":"orange","minor":"yellow","normal":"#00CC00","ok":"#00CC00","security":"blue","trace":"#7554BF","unknown":"silver","warning":"dodgerblue"},"text":"black"},"columns":["severity","status","lastReceiveTime","timeoutLeft","duplicateCount","customer","environment","service","resource","event","value"],"customer_views":true,"dates":{"longDate":"ddd D MMM, YYYY HH:mm:ss.SSS Z","mediumDate":"ddd D MMM HH:mm","shortTime":"HH:mm"},"debug":false,"email_verification":false,"endpoint":"https://alerta.lakedrops.com/api","filter":{"status":["open","ack"]},"github_url":"https://github.com","gitlab_url":"https://gitlab.lakedrops.com","indicators":{"queries":[{"query":[["environment","Production"]],"text":"Production"},{"query":[["environment","Development"]],"text":"Development"},{"query":{"q":"event:Heartbeat"},"text":"Heartbeats"},{"query":"group=Misc","text":"Misc."}],"severity":["critical","major","minor","warning","indeterminate","informational"]},"keycloak_realm":null,"keycloak_url":null,"oidc_auth_url":"https://gitlab.lakedrops.com/oauth/authorize","provider":"gitlab","refresh_interval":5000,"severity":{"cleared":7,"critical":1,"debug":8,"indeterminate":5,"informational":6,"major":2,"minor":3,"normal":7,"ok":7,"security":0,"trace":9,"unknown":10,"warning":4},"signup_enabled":false,"site_logo_url":"","sort_by":"lastReceiveTime","tracking_id":null}
To Reproduce
Steps to reproduce the behavior:
alerta heartbeats --alert
Additional context
docker-compose.yml
version: '2.1'
services:
web:
image: alerta/alerta-web
ports:
- "8091:8080"
depends_on:
- db
volumes:
- ./config/alertad.conf:/app/alertad.conf
- ./config/config.json:/web/config.json
environment:
- DATABASE_URL=postgres://postgres:postgres@db:5432/monitoring
- BASE_URL=https://alerta.lakedrops.com/api
restart: always
db:
image: postgres
volumes:
- ./pg-data:/var/lib/postgresql/data
environment:
POSTGRES_DB: monitoring
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
restart: always
config/alertad.conf
BASE_URL='https://alerta.lakedrops.com/api'
AUTH_REQUIRED=True
AUTH_PROVIDER='gitlab'
SECRET_KEY='XYZ'
ADMIN_USERS=['some entries']
CUSTOMER_VIEWS=True
# OAuth
GITLAB_URL='https://gitlab.lakedrops.com'
OAUTH2_CLIENT_ID='XYZ'
OAUTH2_CLIENT_SECRET='XYZ'
ALLOWED_GITLAB_GROUPS=['some strings']
# Plugins
PLUGINS=['reject','blackout','normalise','enhance']
ORIGIN_BLACKLIST=[]
ALLOWED_ENVIRONMENTS=['some strings']
config/config.json
{
"endpoint": "https://alerta.lakedrops.com/api",
"base_path": "/",
"provider": "gitlab",
"client_id": "XYZ",
"gitlab_url": "https://gitlab.lakedrops.com"
}
"alerta heartbeats --alert" should add customer from heartbeat to alert
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
In version:
~> alerta version
alerta 4.8.11
alerta client 5.0.3
requests 2.18.4
There seems to be a requirement for at least an empty ~/.netrc
file:
> alerta --profile vpc send -r web03 -e NodeDown -E Production -S Website -s major -t "Web server is down." -v ERROR
Traceback (most recent call last):
File "/usr/local/bin/alerta", line 11, in <module>
sys.exit(cli())
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1063, in invoke
Command.invoke(self, ctx)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/alertaclient/cli.py", line 65, in cli
token=get_token(endpoint),
File "/usr/local/lib/python2.7/dist-packages/alertaclient/auth.py", line 21, in get_token
info = netrc(NETRC_FILE)
File "/usr/lib/python2.7/netrc.py", line 34, in __init__
with open(file) as fp:
IOError: [Errno 2] No such file or directory: '/home/admin/.netrc'
When I add just an empty one it works fine:
> touch ~/.netrc
> alerta --profile vpc send -r web03 -e NodeDown -E Production -S Website -s major -t "Web server is down." -v ERROR
f542ebdb-0b05-4992-be0f-cb258d71fdfd (2 duplicates)
See #57
$ alerta --debug --profile me user --email [email protected]
Password:
send: b'POST /user HTTP/1.1\r\nHost: localhost:8080\r\nUser-Agent: python-requests/2.19.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-Type: application/json\r\nContent-Length: 151\r\nAuthorization: Key Xm6X2leGzaMOuUXUeB25AGVu-NVGbjcfyddyFnpd\r\n\r\n'
send: b'{"name": null, "email": "[email protected]", "password": "devops", "status": null, "roles": [], "attributes": {}, "text": null, "email_verified": false}'
reply: 'HTTP/1.0 500 INTERNAL SERVER ERROR\r\n'
header: Content-Type header: Content-Length header: Access-Control-Allow-Origin header: Vary header: Server header: Date
body: {
"code": 500,
"errors": [
"Traceback (most recent call last):\n File \"/Users/nsatterl/.virtualenvs/alerta/lib/python3.6/site-packages/flask/app.py\", line 1813, in full_dispatch_request\n rv = self.dispatch_request()\n File \"/Users/nsatterl/.virtualenvs/alerta/lib/python3.6/site-packages/flask/app.py\", line 1799, in dispatch_request\n return self.view_functions[rule.endpoint](**req.view_args)\n File \"/Users/nsatterl/.virtualenvs/alerta/lib/python3.6/site-packages/flask_cors/decorator.py\", line 128, in wrapped_function\n resp = make_response(f(*args, **kwargs))\n File \"/Users/nsatterl/Projects/alerta/alerta/auth/decorators.py\", line 49, in wrapped\n return f(*args, **kwargs)\n File \"/Users/nsatterl/Projects/alerta/alerta/utils/response.py\", line 19, in decorated\n return func(*args, **kwargs)\n File \"/Users/nsatterl/Projects/alerta/alerta/views/users.py\", line 42, in create_user\n user.send_confirmation()\n File \"/Users/nsatterl/Projects/alerta/alerta/models/user.py\", line 187, in send_confirmation\n utils.send_confirmation(self, token)\n File \"/Users/nsatterl/Projects/alerta/alerta/auth/utils.py\", line 90, in send_confirmation\n name=user.name, email=user.email, url=link(request.referrer, 'confirm', token)\n File \"/Users/nsatterl/Projects/alerta/alerta/auth/utils.py\", line 77, in link\n if base_url.endswith('/'):\nAttributeError: 'NoneType' object has no attribute 'endswith'\n"
],
"message": "'NoneType' object has no attribute 'endswith'",
"status": "error"
}
ERROR: 'NoneType' object has no attribute 'endswith'
Hi Satterly,
i am trying to get history of alerts between two dates (depends of last received time), however when i am printing alerts am not getting any date fields.
sample output:
Alert(id=u'51e3509b-eb9e-46b9-a1cc-c9105b5c9847', environment=u'prod', resource=u'some name', event=u'Down', severity=u'down', status=u'open', customer=None)
Alert(id=u'57adb144-dd4e-4095-8d10-672b74481741', environment=u'prod', resource=u'some name', event=u'Down', severity=u'down', status=u'open', customer=None)
Alert(id=u'9ac99071-dc0c-4e09-b027-89d7f21e81bf', environment=u'prod', resource=u'some name', event=u'down', severity=u'critical', status=u'open', customer=None)
It would be really great to have a configurable timeout for alerts created from failed heartbeats. Maybe it would be possible to add them to the tags field (just like "environment" or "group")?
This may effect other commands too. alerta query
works though.
$ alerta users
USER ID NAME LOGIN ROLE CREATE TIME PROVIDER TEXT
2017-09-25 13:17:41,743 - alertaclient.shell - ERROR - 'login'
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/alertaclient/shell.py", line 1484, in main
AlertaShell().run()
File "/usr/local/lib/python2.7/site-packages/alertaclient/shell.py", line 1469, in run
args.func(args)
File "/usr/local/lib/python2.7/site-packages/alertaclient/shell.py", line 598, in users
user['login'],
KeyError: 'login'
In Alerta CLI 5.2.0, I get an error in alerta.tabular
method.
Looking at the code (https://github.com/alerta/python-alerta-client/blob/master/alertaclient/models/alert.py#L156) I don't understand why there calling #'history': [h.serialize(timezone) for h in self.history]
instead of 'history': [h for h in self.history]
It would be great to handle more gracefully the error when config from Alerta API cannot be obtained by alerta
cli.
Such helpless trace can happen when ALERTA_ENDPOINT
URL is accessible URL but doesn't lead to Alerta API. (i.e. to Alert UI or just some other website), so there is no config in json to decode:
alerta status --debug
Traceback (most recent call last):
File "C:\temp\repos\python-alerta-client\venv\Scripts\alerta-script.py", line 11, in <module>
load_entry_point('alerta==6.5.0', 'console_scripts', 'alerta')()
File "C:\Users\wabbit\AppData\Roaming\Python\Python37\site-packages\click\core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "C:\Users\wabbit\AppData\Roaming\Python\Python37\site-packages\click\core.py", line 717, in main
rv = self.invoke(ctx)
File "C:\Users\wabbit\AppData\Roaming\Python\Python37\site-packages\click\core.py", line 1134, in invoke
Command.invoke(self, ctx)
File "C:\Users\wabbit\AppData\Roaming\Python\Python37\site-packages\click\core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\wabbit\AppData\Roaming\Python\Python37\site-packages\click\core.py", line 555, in invoke
return callback(*args, **kwargs)
File "C:\Users\wabbit\AppData\Roaming\Python\Python37\site-packages\click\decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "C:\temp\repos\python-alerta-client\venv\lib\site-packages\alerta-6.5.0-py3.7.egg\alertaclient\cli.py", line 54, in cli
config.get_remote_config(endpoint_url)
File "C:\temp\repos\python-alerta-client\venv\lib\site-packages\alerta-6.5.0-py3.7.egg\alertaclient\config.py", line 57, in get_remote_config
remote_config = r.json()
File "C:\Users\wabbit\AppData\Roaming\Python\Python37\site-packages\requests\models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Program Files\Python37\lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Program Files\Python37\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Program Files\Python37\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Hello, when using:
$ alerta version
alerta 4.8.11
alerta client 5.0.2
requests 2.18.4
and running:
$ /usr/local/bin/alerta heartbeat --origin host-vpc-1 --timeout 630
I get a warning:
ERROR: timeout must be an integer
However, if I look on the Alerta server the heartbeat shows up with a timeout of 630 seconds (which is non-standard so I assume being set properly by command).
(alertaclient) macbook:python-alerta-client nsatterl$ alerta user --name me --email [email protected] --password me
Traceback (most recent call last):
File "/Users/nsatterl/.virtualenvs/alertaclient/bin/alerta", line 11, in <module>
load_entry_point('alerta', 'console_scripts', 'alerta')()
File "/Users/nsatterl/.virtualenvs/alertaclient/lib/python3.6/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/Users/nsatterl/.virtualenvs/alertaclient/lib/python3.6/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/Users/nsatterl/.virtualenvs/alertaclient/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/nsatterl/.virtualenvs/alertaclient/lib/python3.6/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/nsatterl/.virtualenvs/alertaclient/lib/python3.6/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/Users/nsatterl/.virtualenvs/alertaclient/lib/python3.6/site-packages/click/decorators.py", line 27, in new_func
return f(get_current_context().obj, *args, **kwargs)
File "/Users/nsatterl/Projects/python-alerta-client/alertaclient/commands/cmd_user.py", line 56, in cli
raise AuthError
TypeError: __init__() missing 1 required positional argument: 'message'
When the customer contains an accented character I get following error:
[wim@localhost ~]$ alerta heartbeats --alert
ORIGIN CUSTOMER TAGS CREATED LATENCY TIMEOUT SINCE STATUS
2017-07-05 18:26:18,989 - alertaclient.shell - ERROR - 'ascii' codec can't encode character u'\xe8' in position 11: ordinal not in range(128)
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/alertaclient/shell.py", line 1605, in main
AlertaShell().run()
File "/usr/lib/python2.7/site-packages/alertaclient/shell.py", line 1593, in run
args.func(args)
File "/usr/lib/python2.7/site-packages/alertaclient/shell.py", line 510, in heartbeats
status()
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 11: ordinal not in range(128)
This is valid syntax:
alerta query --filter status=ack
And this is not:
alerta query status=closed
But you wouldn't know that from the alerta
help message.
i need to have html redirection for all the alerts in alerta, however i could not able to send html code to alerta.
#!/usr/bin/env python
from alertaclient.api import Client
client = Client(endpoint='http://10.45.124.64/api', key='ToAAVE6mbCACAeQcFYbyzsR4VvN2UEueKbr75A90')
a = """
<html>
<a href="where/you/want/the/link/to/go">text of the link</a>
</html>
"""
try:
alert = client.send_alert(
severity='critical',
environment='Production',
service=['s11p02b175'],
resource='10.11.12.175',
event=a,
value='Check_Disks',
text='CRIT bounce=1008Brfailsafe=0, queue=0',
)
print(alert)
except Exception as e:
print(e)
Hi,
Just have a question in terms of alert lifecycle: I noticed amount of closed alerts is going down during the day. What is the alert lifecycle? Is Alerta doing some sort of purge on daily basis?
thanks
$ alerta
2017-07-25 09:42:26,275 - alertaclient.shell - ERROR - 'Namespace' object has no attribute 'func'
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/alertaclient/shell.py", line 1601, in main
AlertaShell().run()
File "/usr/local/lib/python3.5/site-packages/alertaclient/shell.py", line 1574, in run
if args.func == cli.help:
AttributeError: 'Namespace' object has no attribute 'func'
Currently the customer is left off. See #57
Changing any user profile attribute changes the the "email verified" value back to False.
$ alerta --profile heroku query --ids a0e9a98e
a0e9a98e|2017/10/05 05:24:33|normal| 0|-|Development|Website |asdf |Misc |1337 |
|
severity | indeterminate -> normal
trend | noChange
status | ack
resource | asdf
group | Misc
event | 1337
value |
Traceback (most recent call last):
File "/Users/nsatterl/.virtualenvs/py2/bin/alerta", line 11, in <module>
load_entry_point('alerta', 'console_scripts', 'alerta')()
File "/Users/nsatterl/.virtualenvs/py2/lib/python2.7/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/Users/nsatterl/.virtualenvs/py2/lib/python2.7/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/Users/nsatterl/.virtualenvs/py2/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/nsatterl/.virtualenvs/py2/lib/python2.7/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/nsatterl/.virtualenvs/py2/lib/python2.7/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/Users/nsatterl/.virtualenvs/py2/lib/python2.7/site-packages/click/decorators.py", line 27, in new_func
return f(get_current_context().obj, *args, **kwargs)
File "/Users/nsatterl/Projects/python-alerta-client/alertaclient/commands/cmd_query.py", line 69, in cli
click.secho(' tags | {}'.format(' '.join(alert.tags)), fg=color['fg'])
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 14: ordinal not in range(128)
Scenario:
Following code needs to be updated:
https://github.com/alerta/python-alerta-client/blob/master/alertaclient/commands/cmd_heartbeats.py#L73-L86
Add an else condition needs to check if cleared already sent.
Just a quick question is there any workaround possible to get this client working on a windows machine (2012 R2), I am having some trouble with the curses module import in top.py which is not available on windows python (2.7.12), and I haven't really seen an obvious workaround.
Not sure from the docs if alerta is even officially supported on windows, but the server and web ui are working great. (If not that's fine I was just hoping to be able to use the mailer integration from the contrib project). It just that pull request like #18 suggest that people are running this on windows.
If non-ASCII characters are used in an alert then the output from the client can't be piped or redirected from stdout
without causing an exception. Eg. value = 41°C
gives ...
$ alerta query --details | grep value
2015-02-22 15:27:24,242 - alerta.shell - ERROR - 'ascii' codec can't encode character u'\xb0' in position 133: ordinal not in range(128)
Traceback (most recent call last):
File "build/bdist.macosx-10.9-x86_64/egg/alerta/shell.py", line 1004, in main
AlertaShell().run()
File "build/bdist.macosx-10.9-x86_64/egg/alerta/shell.py", line 996, in run
args.func(args)
File "build/bdist.macosx-10.9-x86_64/egg/alerta/shell.py", line 169, in query
a.value) + end_color)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 133: ordinal not in range(128)
We were successful in installation on VM or Server, when we try to create as docker container it's default connecting to Mongo. Please help us to connect to Postgres DB, find below error for your reference.
" Error: assertion src/mongo/client/dbclientinterface.h:231 at src/mongo/shell/mongo.js:148
exception: connect failed"
Describe the bug
Alerts on heartbeat are not created. They are set as expired but no alert is triggered.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A new alert displayed in the GUI.
Additional context
Ubuntu 18.04
Hello,
the funtion of set_status in alertaclient/api.py does not have timeout para, It result in the alert timeout become the default value. And that is not what I want to do.
So, I advice add timeout para in the funtion of set_status. just like that:
def set_status(self, id, status, text, timeout):
$ alerta --profile heroku users
Error: argument of type 'NoneType' is not iterable
$ alerta --profile heroku query
Error: '<' not supported between instances of 'str' and 'int'
I Fix modify api.py to avoid this:
2016-09-30 22:42:57,041 - alertaclient.shell - DEBUG - Alerta cli version: 4.8.2
2016-09-30 22:42:57,063 - requests.packages.urllib3.connectionpool - INFO - Starting new HTTPS | connection (1): alerta.ssss.com
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py:838: | InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is | strongly advised. See: https://urllib3.readthedocs.io/en/latest/security.html
InsecureRequestWarning)
Modify:
_get.request(...., verify=False)
_post.request(..., verify=False)
_put.request(..., verify=False)
_delete(..., verify=False)
Could you add options to verify certificate CA? Or ignore the Certificate verification.
Thanks in advance
Hi there,
Not sure what is happening here since I looked at the source code and the file seems to be here.
But somehow after installing alerta with pip the init.py is not present in the module directory, so it fails to load the module in python2.7 due to the trap import ( http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html )
Here is what I see:
$ mkvirtualenv pipissue
$ workon pipissue
$ pip install alerta
$ pip show alerta
You are using pip version 7.1.0, however version 8.1.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
---
Metadata-Version: 2.0
Name: alerta
Version: 4.7.5
Summary: Alerta unified command-line tool
Home-page: http://github.com/alerta/python-alerta-client
Author: Nick Satterly
Author-email: [email protected]
License: MIT
Location: /Users/juanito/Envs/pipissue/lib/python2.7/site-packages
Requires: argparse, pytz, requests
$ ls -la /Users/juanito/Envs/pipissue/lib/python2.7/site-packages/alerta/
total 392
drwxr-xr-x 12 juanito staff 408 7 Mar 14:05 .
drwxr-xr-x 22 juanito staff 748 7 Mar 14:05 ..
-rw-r--r-- 1 juanito staff 13310 7 Mar 14:05 alert.py
-rw-r--r-- 1 juanito staff 12962 7 Mar 14:05 alert.pyc
-rw-r--r-- 1 juanito staff 4968 7 Mar 14:05 api.py
-rw-r--r-- 1 juanito staff 10507 7 Mar 14:05 api.pyc
-rw-r--r-- 1 juanito staff 7725 7 Mar 14:05 heartbeat.py
-rw-r--r-- 1 juanito staff 9284 7 Mar 14:05 heartbeat.pyc
-rw-r--r-- 1 juanito staff 45921 7 Mar 14:05 shell.py
-rw-r--r-- 1 juanito staff 36688 7 Mar 14:05 shell.pyc
-rw-r--r-- 1 juanito staff 18557 7 Mar 14:05 top.py
-rw-r--r-- 1 juanito staff 17103 7 Mar 14:05 top.pyc
If download the file directly from the source, the file is there :
$ curl https://pypi.python.org/packages/source/a/alerta/alerta-4.7.5.tar.gz#md5=984431af033a4841ee703cf0b40a9621 2> /dev/null | tar -tzvf - | grep __init__
I am unsure what is happening here, but I guess there must be an easy fix.
$ alerta query
2016-10-31 22:49:13,484 - alertaclient.shell - ERROR - 400 Client Error: BAD REQUEST for url: http://localhost:8080/alerts?sort-by=lastReceiveTime
$ alerta --debug query
2016-10-31 22:49:18,921 - alertaclient.shell - DEBUG - Alerta cli version: 4.8.3
2016-10-31 22:49:18,929 - requests.packages.urllib3.connectionpool - INFO - Starting new HTTP connection (1): localhost
2016-10-31 22:49:18,932 - requests.packages.urllib3.connectionpool - DEBUG - "GET /alerts?sort-by=lastReceiveTime HTTP/1.1" 400 84
2016-10-31 22:49:18,933 - alertaclient.api - DEBUG - Request Headers: {'Authorization': 'Key ', 'Connection': 'keep-alive', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.11.1'}
2016-10-31 22:49:18,933 - alertaclient.api - DEBUG - Response Headers: {'Content-Length': '84', 'Vary': 'Origin', 'Server': 'Werkzeug/0.11.11 Python/2.7.12', 'Date': 'Mon, 31 Oct 2016 22:49:18 GMT', 'Access-Control-Allow-Origin': 'http://explorer.alerta.io', 'Content-Type': 'application/json'}
2016-10-31 22:49:18,941 - alertaclient.api - DEBUG - Response Body: {
"message": "'ImmutableMultiDict' objects are immutable",
"status": "error"
}
2016-10-31 22:49:18,942 - alertaclient.shell - ERROR - 400 Client Error: BAD REQUEST for url: http://localhost:8080/alerts?sort-by=lastReceiveTime
2016-10-31 22:49:18,942 - alertaclient.shell - WARNING - Exiting alerta client.
Is your feature request related to a problem? Please describe.
when using alerta-cli with crontab, extra-output send annoyed emails. It's possible to suppress output by > /dev/null
, but it is not good solution
Describe the solution you'd like
plz add --output=silent
for crontab :-)
Linuxtechie @linuxtechie 11:08
@satterly one more bug:
should use DEFAULT_NORMAL_SEVERITY
Hi,
Is there anyway to use MYSQL as a database for Alerta instead of default MongoDB?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.