Created
January 7, 2016 14:48
-
-
Save andresvia/8f032f0f0a8650867b4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import requests | |
import os | |
auth = '' | |
def login(): | |
global auth | |
r = requests.post(os.getenv('ZABBIX_URL') + '/api_jsonrpc.php', json = { | |
'jsonrpc': '2.0', 'method': 'user.login', 'id': '0', 'params': { | |
'user': os.getenv('ZABBIX_USER'), 'password': os.getenv('ZABBIX_PASSWORD') | |
} | |
}) | |
auth = r.json()['result'] | |
def zabbix_do(method, params = {}): | |
global auth | |
r = requests.post(os.getenv('ZABBIX_URL') + '/api_jsonrpc.php', json = { | |
'jsonrpc': '2.0', 'method': method, 'id': '0', 'params': params, 'auth': auth | |
}) | |
return r.json()['result'] | |
login() | |
graphs = zabbix_do('graph.get') | |
for graph in graphs: | |
r = requests.get(os.getenv('ZABBIX_URL') + '/chart2.php', {'graphid': graph['graphid']}, cookies = {'zbx_sessionid':auth}) | |
f = open(graph['graphid'] + '.png', 'wb') | |
f.write(r.content) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment