Bug fix release
Discovery failed on Hyper-V hosts with exactly one VM (#54)
On a host running a single VM, VM discovery never ran and no VM hosts were created in Zabbix. The discovery item failed with:
Cannot find the "data" array in the received JSON object
Host-level data was collected normally, which made this awkward to diagnose. Migrating a second VM onto the host made discovery spring to life — and moving it away broke it again.
Cause. The monitoring script serialized its results with $data | ConvertTo-Json. Piping an array into ConvertTo-Json makes PowerShell unroll the pipeline, so the cmdlet receives the elements one at a time instead of the array. With two or more VMs it still emits a JSON array; with exactly one VM it emits a bare object, which Zabbix LLD cannot consume.
| VMs on host | before | after |
|---|---|---|
| 0 | (no output at all) | []
|
| 1 | {"{#VM.NAME}":"vm1"}
| [{"{#VM.NAME}":"vm1"}]
|
| 2 or more | [{...},{...}]
| unchanged |
Hosts with zero VMs were affected too — the item returned an empty value rather than an empty array.
Fix. All discovery functions now serialize with ConvertTo-Json -InputObject, which does not unroll the pipeline. The same problem was present in the embedded {#VM.NETWORK.INFO}, {#VM.DISK.INFO}, {#VM.DVD.INFO}, {#VM.INTEGRATION.INFO}, {#VM.CHECKPOINT.INFO} and {#HOST.VIRTUAL.SWITCHES} payloads, which produced an object instead of an array for any VM with a single nic or disk, and is corrected there as well.
Thanks to @bannbino for the report and for pinpointing the missing square bracket.
Upgrading
Deploy the updated hyper-v-monitoring2.ps1 to your Hyper-V hosts. This is a script-side fix — re-importing the templates alone will not resolve it. If your hosts run the script under AllSigned/RemoteSigned, re-sign it after copying (see ZabbixAgentScriptSigner.ps1 or the AD CS instructions in the README).
Importing the templates from this release is optional; the only change is the vendor version bump to 2.0.5.
Also in this release
Developers.md: removed the stale notes about the xml/json counter cache and theRebuildCachecommand, which only existed in the v1 script, and documented how v2 actually handles localized counters