Now more and more companies choose to use open source software Zabbix to do server business monitoring, its high-grid user management is a bright spot, so you can call its interface to apply rights management to a lot of places, such as Fortress machine permissions. The following is a simple script written in Python, by defining the group name can be grouped under the server information.
#coding =utf-8__author__ = ' perling ' from urllib import urlencodeimport Urllib2import jsondef post (post_data): api_url = '/HTTP monitor.zabbix.com/api_jsonrpc.php ' #api url req = urllib2. Request (Api_url,json.dumps (Post_data)) req.add_header ("Content-type", "Application /json ") resp = urllib2.urlopen (req) re = Json.loads (Resp.read ()) return redef get_sessionid (): login_post_data = {"Jsonrpc": "2.0", "Method": "User.login ", &nbsP; " Params ": {" User ": " admin ", "Password": "pass" }, "id": "1", } re = post (Login_post_data) if re.has_key ("Result"): return re["Result"] else: &nbsP; return re exit (1, "Login_error") def Hostget (): hostget_post_json = { "Jsonrpc": "2.0", "Method" : "Hostgroup.get", "params": { "Output": "Extend", "Filter": { "Name": [ "zabbix Servers ", # #要获取主机列表的分组名称 ] }, "selecthosts": [' HostID ', ' host ', }, "auth": get_sessionid (), "id": 1 } return post (Hostget_post_json) Print hostget ( )
The selecthosts field is the information display option that defines the host below the selected group, including the contents below
| Property
Type |
Description |
HostID |
String |
(readonly) ID of the host. |
Host (required) |
String |
Technical name of the host. |
Available |
Integer |
(readonly) Availability of Zabbix agent.
Possible values are: 0- (default) unknown; 1-available; 2-unavailable. |
Disable_until |
Timestamp |
(readonly) The next polling time of an unavailable Zabbix agent. |
Error |
String |
(readonly) The Error text if Zabbix agent is unavailable. |
Errors_from |
Timestamp |
(readonly) time when Zabbix agent became unavailable. |
Flags |
Integer |
(readonly) Origin of the host.
Possible values: 0-a Plain host; 4-a discovered host. |
Ipmi_authtype |
Integer |
IPMI authentication algorithm.
Possible values are: -1- (default) default; 0-none; 1-MD2; 2-md5 4-straight; 5-oem; 6-rmcp+. |
Ipmi_available |
Integer |
(readonly) Availability of the IPMI agent.
Possible values are: 0- (default) unknown; 1-available; 2-unavailable. |
Ipmi_disable_until |
Timestamp |
(readonly) The next polling time of an unavailable IPMI agent. |
Ipmi_error |
String |
(readonly) Error text If IPMI agent is unavailable. |
Ipmi_errors_from |
Timestamp |
(readonly) time when the IPMI agent became unavailable. |
Ipmi_password |
String |
IPMI password. |
Ipmi_privilege |
Integer |
IPMI privilege level.
Possible values are: 1-callback; 2- (default) user; 3-operator; 4-admin; 5-oem. |
Ipmi_username |
String |
IPMI username. |
Jmx_available |
Integer |
(readonly) Availability of JMX agent.
Possible values are: 0- (default) unknown; 1-available; 2-unavailable. |
Jmx_disable_until |
Timestamp |
(readonly) The next polling time of an unavailable JMX agent. |
Jmx_error |
String |
(readonly) The Error text if JMX agent is unavailable. |
Jmx_errors_from |
Timestamp |
(readonly) time when JMX agent became unavailable. |
Maintenance_from |
Timestamp |
(readonly) Starting time of the effective maintenance. |
Maintenance_status |
Integer |
(readonly) Effective maintenance status.
Possible values are: 0- (default) no maintenance; 1-maintenance in effect. |
Maintenance_type |
Integer |
(readonly) Effective maintenance type.
Possible values are: 0- (default) maintenance with data collection; 1-maintenance without data collection. |
Maintenanceid |
String |
(readonly) ID of the maintenance that's currently in effect on the host. |
Name |
String |
Visible name of the host.
Default: Property host value. |
Proxy_hostid |
String |
ID of the proxy is used to monitor the host. |
Snmp_available |
Integer |
(readonly) Availability of the SNMP agent.
Possible values are: 0- (default) unknown; 1-available; 2-unavailable. |
Snmp_disable_until |
Timestamp |
(readonly) The next polling time of an unavailable SNMP agent. |
Snmp_error |
String |
(readonly) The Error text if SNMP agent is unavailable. |
Snmp_errors_from |
Timestamp |
(readonly) time when the SNMP agent became unavailable. |
Status |
Integer |
Status and function of the host.
Possible values are: 0- (default) monitored host; 1-unmonitored host. |
This article is from the "perling" blog, make sure to keep this source http://zhaolin.blog.51cto.com/9397923/1713188
Use the Zabbix API to get a list of servers under each group and more information