|
1 | 1 | # PyZabbix #
|
2 | 2 |
|
3 |
| -**PyZabbix** is a Python module for working with the [Zabbix API](https://www.zabbix.com/documentation/2.0/manual/appendix/api/api). |
| 3 | +**PyZabbix** is a Python module for working with the [Zabbix API](https://www.zabbix.com/documentation/3.0/manual/api/reference). |
4 | 4 |
|
5 | 5 | [](https://travis-ci.org/lukecyca/pyzabbix)
|
6 | 6 | [](https://pypi.python.org/pypi/pyzabbix/)
|
7 | 7 | [](https://pypi.python.org/pypi/pyzabbix/)
|
8 | 8 |
|
9 |
| -## Documentation |
| 9 | +## Requirements |
| 10 | +* Tested against Zabbix 1.8 through 3.0 |
10 | 11 |
|
11 |
| -See https://wiki.github.com/lukecyca/pyzabbix/ |
| 12 | +## Documentation ## |
| 13 | +### Getting Started |
| 14 | + |
| 15 | +Install PyZabbix using pip: |
| 16 | + |
| 17 | +```bash |
| 18 | +$ pip install pyzabbix |
| 19 | +``` |
| 20 | + |
| 21 | +You can now import and use pyzabbix like so: |
| 22 | + |
| 23 | +```python |
| 24 | +from pyzabbix import ZabbixAPI |
| 25 | + |
| 26 | +zapi = ZabbixAPI("http://zabbixserver.example.com") |
| 27 | +zapi.login("zabbix user", "zabbix pass") |
| 28 | +print "Connected to Zabbix API Version %s" % zapi.api_version() |
| 29 | + |
| 30 | +for h in zapi.host.get(output="extend"): |
| 31 | + print h['hostid'] |
| 32 | +``` |
| 33 | + |
| 34 | +Refer to the [Zabbix API Documentation](https://www.zabbix.com/documentation/3.0/manual/api/reference) and the [PyZabbix Examples](https://github.com/lukecyca/pyzabbix/tree/master/examples) for more information. |
| 35 | + |
| 36 | +### Customizing the HTTP request |
| 37 | +PyZabbix uses the [requests](http://www.python-requests.org/en/latest/) library for http. You can customize the request parameters by configuring the [requests Session](http://docs.python-requests.org/en/latest/user/advanced/#session-objects) object used by PyZabbix. |
| 38 | + |
| 39 | +This is useful for: |
| 40 | +* Customizing headers |
| 41 | +* Enabling HTTP authentication |
| 42 | +* Enabling Keep-Alive |
| 43 | +* Disabling SSL certificate verification |
| 44 | + |
| 45 | +```python |
| 46 | +from pyzabbix import ZabbixAPI |
| 47 | + |
| 48 | +zapi = ZabbixAPI("http://zabbixserver.example.com") |
| 49 | + |
| 50 | +# Enable HTTP auth |
| 51 | +zapi.session.auth = ("http user", "http password") |
| 52 | + |
| 53 | +# Disable SSL certificate verification |
| 54 | +zapi.session.verify = False |
| 55 | + |
| 56 | +# Specify a timeout (in seconds) |
| 57 | +zapi.timeout = 5.1 |
| 58 | + |
| 59 | +# Login (in case of HTTP Auth, only the username is needed, the password, if passed, will be ignored) |
| 60 | +zapi.login("http user", "http password") |
| 61 | +``` |
| 62 | + |
| 63 | +### Enabling debug logging |
| 64 | +If you need to debug some issue with the Zabbix API, you can enable the output of logging, pyzabbix already uses the default python logging facility but by default, it logs to "Null", you can change this behavior on your program, here's an example: |
| 65 | +```python |
| 66 | +import sys |
| 67 | +import logging |
| 68 | +from pyzabbix import ZabbixAPI |
| 69 | + |
| 70 | +stream = logging.StreamHandler(sys.stdout) |
| 71 | +stream.setLevel(logging.DEBUG) |
| 72 | +log = logging.getLogger('pyzabbix') |
| 73 | +log.addHandler(stream) |
| 74 | +log.setLevel(logging.DEBUG) |
| 75 | + |
| 76 | + |
| 77 | +zapi = ZabbixAPI("http://zabbixserver.example.com") |
| 78 | +zapi.login('admin','password') |
| 79 | +``` |
| 80 | +The expected output is as following: |
| 81 | + |
| 82 | +``` |
| 83 | +Sending: { |
| 84 | + "params": { |
| 85 | + "password": "password", |
| 86 | + "user": "admin" |
| 87 | + }, |
| 88 | + "jsonrpc": "2.0", |
| 89 | + "method": "user.login", |
| 90 | + "id": 2 |
| 91 | +} |
| 92 | +Response Code: 200 |
| 93 | +Response Body: { |
| 94 | + "jsonrpc": "2.0", |
| 95 | + "result": ".................", |
| 96 | + "id": 2 |
| 97 | +} |
| 98 | +>>> |
| 99 | +``` |
| 100 | + |
| 101 | +Further info on [PyZabbix Wiki](https://wiki.github.com/lukecyca/pyzabbix/) |
12 | 102 |
|
13 | 103 | ## License ##
|
14 | 104 | LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
|
|
0 commit comments