Skip to content

Instantly share code, notes, and snippets.

@dlecocq
Created November 19, 2012 20:14
Show Gist options
  • Save dlecocq/4113589 to your computer and use it in GitHub Desktop.
Save dlecocq/4113589 to your computer and use it in GitHub Desktop.
Zabbix Metric Creation
#! /usr/bin/env python
import zabbix_api
# Connect, auth
client = zabbix_api.ZabbixAPI('http://bigzabbix.seomoz.org')
client.login('your', 'credentials')
assert client.test_login(), 'Failed to log in'
# Try to find our Template
templates = client.template.get({
'output': 'extend',
'filter': {
'name': 'Freshscape Queues'
},
})
assert templates, 'Failed to find templates'
# Try to find our host
hosts = client.host.get({
'output': 'extend',
'filter': {
'name': 'Testing'
}
})
assert hosts, 'Failed to find hosts'
host = hosts[0]
# And now we'll try to add some metrics to it
template = templates[0]
def make_metrics(mappping):
'''Take a mapping of key -> {
'name': ...,
'units': ...,
'description': ...,
...
'''
for key, options in mapping.items():
options.update({
'key_': key,
'type': '2', # Trapper type
'value_type': '0', # Numerical float
'hostid': template['templateid'],
'interfaceid': 0
})
try:
client.item.create(options)
except:
print '%s already exists' % key
# Describe some of our metrics
metrics = [{
'name': 'foo.avg',
'units': 'seconds',
'description': 'Some metric'
}, {
'name': 'bar.max',
'units': 'jobs',
'description': 'Some other metric'
}]
# Make our metrics now
make_metrics(metrics)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment