|
ret
=
self
.zb.item.get(
*
*
data)
return
ret
def
history_get(
self
, itemid, i ,limit
=
10
):
data
=
{
"output"
:
"extend"
,
"history"
: i,
"itemids"
: [itemid],
"limit"
: limit
}
ret
=
self
.zb.history.get(
*
*
data)
return
ret
def
add_zabbix_host(
self
,hostname
=
"test_zabbix"
,ip
=
"192.168.10.100"
,groupid
=
"2"
):
data
=
{
"host"
: hostname,
"interfaces"
: [
{
"type"
:
1
,
"main"
:
1
,
"useip"
:
1
,
"ip"
: ip,
"dns"
: "",
"port"
:
"10050"
}
],
"groups"
: [
{
"groupid"
: groupid
}
]
}
ret
=
self
.zb.host.create(data)
return
ret
def
get_template(
self
):
datalist
=
[]
datadict
=
{}
data
=
{
"output"
:[
"templateid"
,
"name"
]
}
ret
=
self
.zb.template.get(data)
for
i
in
ret:
datadict[i[
'name'
]]
=
i[
'templateid'
]
datalist.append(datadict)
return
datalist
def
link_template(
self
, hostid
=
10156
, templateids
=
10001
):
data
=
{
"hostid"
:hostid,
"templates"
:templateids
}
ret
=
self
.zb.host.update(data)
return
ret
def
create_maintenance(
self
,name
=
"test"
,hostids
=
10156
,time
=
2
):
data
=
{
"name"
: name,
"active_since"
:
1458142800
,
"active_till"
:
1489678800
,
"hostids"
: [
hostids
],
"timeperiods"
: [
{
"timeperiod_type"
:
0
,
"period"
:
3600
}
]
}
ret
=
self
.zb.maintenance.create(data)
self
.host_status(
10130
,
1
)
return
ret
def
get_maintenance(
self
):
data
=
{
"output"
:
"extend"
,
"selectGroups"
:
"extend"
,
"selectTimeperiods"
:
"extend"
}
ret
=
self
.zb.maintenance.get(data)
return
ret
def
del_maintenance(
self
,maintenanceids):
return
self
.zb.maintenance.delete(maintenanceids)
def
host_status(
self
, hostid, status):
data
=
{
"hostid"
:hostid,
"status"
:status
}
return
self
.zb.host.update(data)
def
host_del(
self
,hostids
=
10155
):
return
self
.zb.host.delete(hostids)
if
__name__
=
=
"__main__"
:
zabbix_server
=
Zabbix()
print
zabbix_server.del_maintenance(
15
)
|