Hi all,
You will find a python script named zbxwmi in attachment. The purpose of this script is to simplify agentless WMI monitoring of Windows machines from a Zabbix server or proxy. Here is the usage :
zbxwmi must be installed on a server or proxy and depends on wmic (can be installed from rpmforge or compiled from source, http://dev.zenoss.org/svn/tags/wmi-1.3.14/), and zabbix_sender.
It supports four actions :
- get : query a specific WMI item and returns the value. It can be used as an external check for a few item checks.
The item must be configured like this :

- discover : query WMI for a list of items and displays a JSON-formatted object for use with Low-Level Discovery. It helps to automatically create WMI checks with LLD, as WMI can sometimes return a lot of items (ex: processes).
The "Name" key name is converted to the {#WMI.NAME} macro, which can be used in item prototypes. Configure it like this :

- bulk : query WMI for a list of items and sends them to the server using zabbix_sender. It's a bulk insert, which is way more effective than single checks.
It sends this to the server :
The WMI item checks must be configured as "Zabbix trapper" to accept these inserts.
- both : this action combines discover and bulk. It displays a JSON-formatted object for use with LLD and bulk sends the matching values to the server with zabbix_sender in a single command. It allows to automatically create all items and to update them efficiently using zabbix_sender. This is the default action.
So you need to configure a discovery item like this :

And item prototypes like this :

Zabbix will then do the job, create all the necessary item checks automatically, and update them using bulk checks at the interval specified in the discovery item screen.
This script was tested with python 2.7 and it is provided as-is. Don't forget to use a secure Windows account to query your hosts (a domain admin will work but it's not recommended). You can add the credentials into the script if you don't want to display them into the Zabbix frontend.
Let me know if you find this script useful.
/dav3860
You will find a python script named zbxwmi in attachment. The purpose of this script is to simplify agentless WMI monitoring of Windows machines from a Zabbix server or proxy. Here is the usage :
Code:
Usage:
zbxwmi [-a action] [-z <server>] -h <host> -k <key> -i <items> -c <class> [-f <filter>] [-D <domain>] [-U <username>] [-P<password] [-d] [-o <logfile>] [-w <wmic>] [-s <zabbix_sender>]
zbxwmi -a get -h <host> -i <item> -c <class> [-f <filter>] [-D <domain>] [-U <username>] [-P<password] [-d] [-o <logfile>] [-w <wmic>]
zbxwmi --help
zbxwmi --version
Options:
-a, --action <action> The action to take. Possible values : get, bulk, discover, both
[default: both]
-h, --host <host> The host to query
-z, --zabbix-server <server> The Zabbix server or proxy
[default: localhost]
-v, --version Display version and exit
-k <key>, --key <key> The key to use as an index for Zabbix LLD discovery
-i <items>, --items <items> The list of items to query for
-c <class>, --class <class> The class to use in the query
-f <filter>, --filter <filter> An optional filter to the query
-D <domain>, --domain <domain> The domain to use for authentication
-U <username>, --username <username> The username to use for authentication
-P <password>, --password <password> The password to use for authentication
-d, --debug Debug mode, be more verbose
-o <logfile>, --output <logfile> The log file to use
-w <wmic>, --wmic <wmic> The path to the wmic binary
[default: /usr/bin/wmic]
-s <zabbix_sender>, --zabbix-sender <zabbix_sender> The path to the zabbix_sender binary
[default: /usr/bin/zabbix_sender]
It supports four actions :
- get : query a specific WMI item and returns the value. It can be used as an external check for a few item checks.
Code:
ZABBIX externalscripts # ./zbxwmi -a get -h myserver.domain.local -i "AvailableBytes" -c "Win32_PerfRawData_PerfOS_Memory" 4988350464

- discover : query WMI for a list of items and displays a JSON-formatted object for use with Low-Level Discovery. It helps to automatically create WMI checks with LLD, as WMI can sometimes return a lot of items (ex: processes).
Code:
ZABBIX externalscripts # ./zbxwmi -a discover -h myserver.domain.local -k "Name" -i "Name,Size,FreeSpace" -c "Win32_LogicalDisk" -f "MediaType = 12"
{
"data": [
{
"{#WMI.NAME}": "C:"
},
{
"{#WMI.NAME}": "D:"
},
{
"{#WMI.NAME}": "E:"
},
{
"{#WMI.NAME}": "F:"
}
]
}

- bulk : query WMI for a list of items and sends them to the server using zabbix_sender. It's a bulk insert, which is way more effective than single checks.
Code:
ZABBIX externalscripts # ./zbxwmi -a bulk -h myserver.domain.local -k "Name" -i "Name,Size,FreeSpace" -c "Win32_LogicalDisk" -f "MediaType = 12"
Code:
myserver.domain.local FreeSpace[C:] 10070560768 myserver.domain.local Size[C:] 42842714112 myserver.domain.local DeviceID[C:] C: myserver.domain.local FreeSpace[D:] 17642258432 myserver.domain.local Size[D:] 107371032576 myserver.domain.local DeviceID[D:] D: myserver.domain.local FreeSpace[E:] 32522383360 myserver.domain.local Size[E:] 42946523136 myserver.domain.local DeviceID[E:] E: myserver.domain.local FreeSpace[F:] 181060218880 myserver.domain.local Size[F:] 268432306176 myserver.domain.local DeviceID[F:] F:
- both : this action combines discover and bulk. It displays a JSON-formatted object for use with LLD and bulk sends the matching values to the server with zabbix_sender in a single command. It allows to automatically create all items and to update them efficiently using zabbix_sender. This is the default action.
Code:
ZABBIX externalscripts # ./zbxwmi -a both -h myserver.domain.local -k "Name" -i "Name,Size,FreeSpace" -c "Win32_LogicalDisk" -f "MediaType = 12"
{
"data": [
{
"{#WMI.NAME}": "C:"
},
{
"{#WMI.NAME}": "D:"
},
{
"{#WMI.NAME}": "E:"
},
{
"{#WMI.NAME}": "F:"
}
]
}

And item prototypes like this :

Zabbix will then do the job, create all the necessary item checks automatically, and update them using bulk checks at the interval specified in the discovery item screen.
This script was tested with python 2.7 and it is provided as-is. Don't forget to use a secure Windows account to query your hosts (a domain admin will work but it's not recommended). You can add the credentials into the script if you don't want to display them into the Zabbix frontend.
Let me know if you find this script useful.
/dav3860

. could you pls to give me little time to help me ,and give me some advise about this question,many thanks!!!
Comment