-
Notifications
You must be signed in to change notification settings - Fork 0
/
addItem.py
46 lines (38 loc) · 1.34 KB
/
addItem.py
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
#!/usr/bin/env python
import os
from pyzabbix import ZabbixAPI, ZabbixAPIException
import sys
# The hostname at which the Zabbix web interface is available
# Replace with url to interface. Keep the quotes.
ZABBIX_SERVER = 'Zabbix Web Interface URL'
zapi = ZabbixAPI(ZABBIX_SERVER)
# Login to the Zabbix API
#replace username and password with the appropriate data. Keep the quotes around the data.
zapi.login('username', 'password')
#display hosts
command="./zhostfinder.py -A"
os.system(command)
#find a host
desire=raw_input("Please enter the name of the host to add the item to:")
host_name = desire
hosts = zapi.host.get(filter={"host": host_name}, selectInterfaces=["interfaceid"])
if hosts:
host_id = hosts[0]["hostid"]
print("Found host id {0}".format(host_id))
#vm.memory.size[buffers] should be replaced to change the check being performed
try:
item = zapi.item.create(
hostid=host_id,
name='Check VM memory size buffers',
key_='vm.memory.size[buffers]',
type=0,
value_type=3,
interfaceid=hosts[0]["interfaces"][0]["interfaceid"],
delay=30
)
except ZabbixAPIException as e:
print(e)
sys.exit()
print("Added item with itemid {0} to host: {1}".format(item["itemids"][0], host_name))
else:
print("No hosts found")