alerta统一命令行工具和sdk
alerta的Python项目详细描述
Alerta命令行工具
Alerta监控系统的统一命令行工具、终端GUI和python SDK
相关项目可以在Alerta Org Repo上找到,地址是https://github.com/alerta/
python 2.7支持为eol
从6.0版开始,仅支持Python3.5+。版本5.2是 最后一个支持Python2.7和此版本的功能增强在 2018年8月31日。只有关键的错误修复才会被移植到5.2版。
安装
要安装alerta cli工具,请运行::
$ pip install alerta
配置
选项可以在配置文件中设置为环境变量或在命令行上设置。 配置文件可用于在不同的配置设置之间轻松切换。
Option | Config File | Environment Variable | Optional Argument | Default |
---|---|---|---|---|
file | n/a | ^{ | n/a | ^{ |
profile | profile | ^{ | ^{ | None |
endpoint | endpoint | ^{ | ^{ | ^{ |
key | key | ^{ | n/a | None |
timezone | timezone | n/a | n/a | Europe/London |
SSL verify | sslverify | ^{ | n/a | verify SSL certificates |
timeout | timeout | n/a | n/a | 5s TCP connection timeout |
output | output | n/a | ^{ | simple |
color | color | ^{ | ^{ | color on |
debug | debug | ^{ | ^{ | no debug |
示例
配置文件~/.alerta.conf
:
[DEFAULT]
timezone = Australia/Sydney
# output = psql
profile = production
[profile production]
endpoint = https://api.alerta.io
key = demo-key
[profile development]
endpoint = https://localhost:8443
sslverify = off
timeout = 10.0
debug = yes
环境变量
默认情况下,将环境变量设置为使用生产配置设置:
$ export ALERTA_CONF_FILE=~/.alerta.conf
$ export ALERTA_DEFAULT_PROFILE=production
$ alerta query
以及在需要时切换到开发配置设置,请使用--profile
选项:
$ alerta --profile development query
用法
$ alerta
Usage: alerta [OPTIONS] COMMAND [ARGS]...
Alerta client unified command-line tool.
Options:
--config-file <FILE> Configuration file.
--profile <PROFILE> Configuration profile.
--endpoint-url <URL> API endpoint URL.
--output-format <FORMAT> Output format. eg. simple, grid, psql, presto, rst
--color / --no-color Color-coded output based on severity.
--debug Debug mode.
--help Show this message and exit.
Commands:
ack Acknowledge alerts
blackout Suppress alerts
blackouts List alert suppressions
close Close alerts
customer Add customer lookup
customers List customer lookups
delete Delete alerts
heartbeat Send a heartbeat
heartbeats List heartbeats
help Show this help
history Show alert history
key Create API key
keys List API keys
login Login with user credentials
logout Clear login credentials
perm Add role-permission lookup
perms List role-permission lookups
query Search for alerts
raw Show alert raw data
revoke Revoke API key
send Send an alert
status Display status and metrics
tag Tag alerts
token Display current auth token
unack Un-acknowledge alerts
untag Untag alerts
update Update alert attributes
uptime Display server uptime
user Update user
users List users
version Display version info
whoami Display current logged in user
python sdk
alerta client python包也可以用作python SDK
示例
>>> from alertaclient.api import Client
>>> client = Client(key='NGLxwf3f4-8LlYN4qLjVEagUPsysn0kb9fAkAs1l')
>>> client.send_alert(environment='Production', service=['Web', 'Application'], resource='web01', event='HttpServerError', value='501', text='Web server unavailable.')
Alert(id='42254ef8-7258-4300-aaec-a9ad7d3a84ff', environment='Production', resource='web01', event='HttpServerError', severity='normal', status='closed', customer=None)
>>> [a.id for a in client.search([('resource','~we.*01'), ('environment!', 'Development')])]
['42254ef8-7258-4300-aaec-a9ad7d3a84ff']
>>> client.heartbeat().serialize()['status']
'ok'
许可证
Alerta monitoring system and console
Copyright 2012-2019 Nick Satterly
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.