-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.rst
160 lines (115 loc) · 4.72 KB
/
README.rst
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
xibbaz: backwards zabbix
========================
Home page: https://github.com/erik-stephens/xibbaz
.. image:: https://img.shields.io/pypi/v/xibbaz.svg
:target: https://pypi.python.org/pypi/xibbaz
.. image:: https://api.travis-ci.org/erik-stephens/xibbaz.png?branch=master,develop
:target: http://travis-ci.org/erik-stephens/xibbaz
Goals
-----
- Be self-documenting. Should not have to flip between the Zabbix API
docs and a python REPL.
- Be discoverable. Should not have to be familiar with the Zabbix API
to get started. Relationships between Zabbix objects should be easy
and natural to discover. Want to avoid being a thin wrapper around
the JSON api like this::
params = dict(...)
group = api.response('hostgroup.get', params)
hosts = api.response('host.get', groupids=group['result'][0]['groupid'])
in favor of something like this::
group = api.group('Maintenance')
host = api.host('needs-work.com')
group.add_hosts(host)
for host in group.hosts.values():
print('{} is in maintenance'.format(host))
- Be notebook friendly. Zabbix is great at collecting data and triggering
alerts, but makes it difficult to navigate the data. Coupled with the likes of
IPython Notebook & Pandas, it should be easy to analyze and visualize the
data. Notebooks can be shared, serve as dashboards, generate reports, etc.
- Minimize server load and improve latency with aggressive caching of objects.
- Be idiomatic (mostly about packaging). This was initially a non-goal but it's
better to spend a little bit of effort to be a good citizen. If this becomes a
drag, then will become a non-goal.
Non-Goals
---------
- Minimal lines of code. There is a lot of boiler-plate and copy-pasta from
zabbix documentation. That is ok. For the fewest lines of code, please refer
to curl, wget, httpie, et al.
- Completeness. The implemented portions of the zabbix api reflect the need to
satisfy known use cases in the real world.
- DRY-ness (Don't Repeat Yourself). There are plenty of opportunities to factor
out common bits.
How to REPL
-----------
An example of how to bootstrap in interactive session::
$ cat ixibbaz.py
import xibbaz
import keyring
import os
api = xibbaz.Api('https://zabbix.yours')
username = os.environ.get('ZABBIX_USER', os.environ.get('USER'))
api.login(username, keyring.get_password('zabbix-api', username))
api.groups?
from xibbaz import objects
objects.Group?
$ python3 -m IPython -i ixibbaz.py
Scripts
-------
Authentication
--------------
Environment variables are used for your zabbix api credentials:
- ZABBIX_API: the base url for your zabbix server's api
- ZABBIX_USER: defaults to `USER` from environment
- ZABBIX_PASS: defaults to using keyring('zabbix-api', ZABBIX_USER)
group
-----
Add hosts to a group::
ZABBIX_API=https://zabbix PYTHONPATH=.:.pip python3 -m xibbaz.main group add 'On-Demand Maintenance' needs-some-work.com
cli
---
There is a `cli` script to help support one-liners & simple shell scripts.
Contrary to the "dont' be a thin api wrapper" goal, this script is basically
that with some integrated `jq` support for systems without good json support.
There are two flavors of the docker image, with or without `--jq` support which
requires build dependencies.
Some examples:
- Look up a group and its linked hosts by name::
ZABBIX_API=https://zabbix PYTHONPATH=.:.pip python3 -m xibbaz.main cli group get filter:name:'On-Demand Maintenance'
[
{
"groupid": "42",
"name": "On-Demand Maintenance",
"internal": 0,
"flags": 0,
"hosts": [
{...}
]
}
]
- Enumerate hosts in a group::
make build
docker run --env-file .env --rm xibbaz:jq cli --jq 'first | .hosts | map({hostid, name})' group get filter:name:'On-Demand Maintenance'
[
{
"hostid": "11878",
"name": "needs-some-work.com"
}
]
triggers
--------
Reports trigger status for a host (see `--help` for details). Example::
ZABBIX_API=https://zabbix PYTHONPATH=.:.pip python3 -m xibbaz.main triggers -v -p warn some-host
problem high some-host Zabbix agent on some-host is unreachable for 5 minutes
ok average some-host some-host is unavailable by ICMP
ok average some-host SSH service is down on some-host
TODO
----
- ACK's for a trigger so an operator can quickly see history & remediations.
- Noisy triggers
- Noisy hosts
About the Name
--------------
- Disambiguation from other python zabbix projects.
- This was the only cool name left.
- An homage to our favorite zabbix forum user.
- Zabbix makes heads hurt and eyes bleed. Backwards might be more intuitive.