zbxwmi icon indicating copy to clipboard operation
zbxwmi copied to clipboard

New type option not working with multiple values

Open lekzz opened this issue 4 years ago • 2 comments

The new type option doesn't seem to work multiple values.

from README:

Get memory load:

zbxwmi["-action","-json","-type","n,n,n","-fields","AvailableBytes,CommitLimit,CommittedBytes","Win32_PerfRawData_PerfOS_Memory",{HOST.HOST}]

Actual result:

$ sudo /etc/zabbix/externalscripts/zbxwmi -action json -fields AvailableBytes,CommitLimit,CommittedBytes Win32_PerfRawData_PerfOS_Memory -type n,n,n -cred /etc/zabbix/wmi.pw SERVER
An error occured: can only concatenate str (not "NoneType") to str

old script

$ sudo /etc/zabbix/externalscripts/zbxwmi.old -action json -fields AvailableBytes,CommitLimit,CommittedBytes Win32_PerfRawData_PerfOS_Memory -cred /etc/zabbix/wmi.pw SERVER
[{"AvailableBytes": "11361402880", "CommitLimit": "19728936960", "CommittedBytes": "6544306176", "Name": "None"}]

Also tried with n,n,n,s as the old script reports an extra name value, same error. And with s,s,s,s, which results in a slightly different error "An error occured: can only concatenate str (not "int") to str"

lekzz avatar Dec 01 '20 15:12 lekzz

Not sure you fixed..., I was just having the same issue. You can use the key (-k) option to map the fields

/usr/lib/zabbix/externalscripts/zbxwmi -k "AvailableBytes,AvailableKBytes" -a json -type n,n -fields "AvailableBytes,AvailableKBytes" "Win32_PerfFormattedData_PerfOS_Memory" -cred /etc/zabbix/wmi.pw SERVER

output is: [{"AvailableBytes": 1109749760, "AvailableKBytes": 1083740}]

nicolagatta avatar Feb 04 '21 16:02 nicolagatta

Using -k seems to work indeed. I guess i was wrong with the bug description and it's really about the "json" action sometimes requiring -k, but not always.

Example of single value failing without -k:

sudo /etc/zabbix/externalscripts/zbxwmi -action get -fields PagesPersec Win32_PerfFormattedData_PerfOS_Memory -t n -cred /etc/zabbix/wmi.pw SERVER
3

sudo /etc/zabbix/externalscripts/zbxwmi -action both -fields PagesPersec Win32_PerfFormattedData_PerfOS_Memory -t n -cred /etc/zabbix/wmi.pw SERVER
{ "data": [ {"{#WMI.PAGESPERSEC}": 0} ] }

sudo /etc/zabbix/externalscripts/zbxwmi -action json -fields PagesPersec Win32_PerfFormattedData_PerfOS_Memory -t n -cred /etc/zabbix/wmi.pw SERVER
An error occured: can only concatenate str (not "NoneType") to str

sudo /etc/zabbix/externalscripts/zbxwmi -action json -k PagesPersec -fields PagesPersec Win32_PerfFormattedData_PerfOS_Memory -t n -cred /etc/zabbix/wmi.pw SERVER
[{"PagesPersec": 0}]

Example of single value working without -k:

sudo /etc/zabbix/externalscripts/zbxwmi -action json -item "6" -fields PercentProcessorTime Win32_PerfFormattedData_PerfOS_Processor -t n -cred /etc/zabbix/wmi.pw SERVER
[{"Name": "6", "PercentProcessorTime": 5}]

It seems unclear what the -k key option really is for. If it has to be the same as -fields it seems redundant. In the README other examples use "-k DeviceID" however removing it from those examples results in the exact same output?

lekzz avatar May 28 '21 12:05 lekzz