Skip to content

Instantly share code, notes, and snippets.

@andresvia
Created January 7, 2016 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andresvia/8f032f0f0a8650867b4b to your computer and use it in GitHub Desktop.
Save andresvia/8f032f0f0a8650867b4b to your computer and use it in GitHub Desktop.
#!/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