Hello,
So I am attempting to use a Powershell script to pull in the Hyper V Replication Status.
Here is my Powershell Script and the line in my Zabbix Agent Config.
Now from my Zabbix Server I can run the "vm.replication.status" key and I get a list of all of the VMs on our Hypervisor Server and it looks like this.
So far so good. I am getting Replication State, Replicaton Mode, Replication Enabled and Health Status.
Now what I want is to create an auto discovery rule with 4x items that say
Replication State - VM Name
Replication Mode - VM Name
Replication Enabled - VM Name
Health Status - VM Name
But I am struggling to make it work. I breifly had it pulling in and I changed something and I was a little discracted and it stopped working.
Here is what I have so far.
Here is the discovery rule on my template in our test environment.


And here is the Item Prototype I made.

When I apply the template to the Hypervisor host I am getting the following error.
This is my first time writing a Discovery Rule from scratch and not modifying or going off of someone elses work so I am a little lost and I know I have messed up somewhere but I cant see where I messed up.
Can someone help me with this discovery rule.
So I am attempting to use a Powershell script to pull in the Hyper V Replication Status.
Here is my Powershell Script and the line in my Zabbix Agent Config.
HTML Code:
# Function to get Hyper-V VM replication status and output LLD JSON data
function Get-HyperVReplicationStatus {
$vms = Get-VM
$lldData = @()
foreach ($vm in $vms) {
$replication = Get-VMReplication -VMName $vm.VMName -ErrorAction SilentlyContinue
$vmData = @{
"{#VMNAME}" = $vm.VMName
"ReplicationEnabled" = if ($replication) { $true } else { $false }
"ReplicationMode" = if ($replication) { $replication.ReplicationMode } else { "Disabled" }
"ReplicationState" = if ($replication) { $replication.ReplicationState } else { "N/A" }
"HealthStatus" = if ($replication) { $replication.Health } else { "N/A" }
}
$lldData += $vmData
}
$lldJson = $lldData | ConvertTo-Json -Depth 100
Write-Output $lldJson
}
# Get Hyper-V VM replication status and output LLD JSON data
Get-HyperVReplicationStatus
HTML Code:
UserParameter=vm.replication.status[*],powershell -NoProfile -ExecutionPolicy Bypass -File "C:\Program Files\Zabbix Agent\scripts\Get-HyperVReplicationStatus.ps1" "$1"
HTML Code:
# zabbix_get -s <IP ADDRESS> -k vm.replication.status [ { "ReplicationState": "N/A", "ReplicationMode": "Disabled", "ReplicationEnabled": false, "HealthStatus": "N/A", "{#VMNAME}": "<REDACTED>" }, { "ReplicationState": 4, "ReplicationMode": 2, "ReplicationEnabled": true, "HealthStatus": 1, "{#VMNAME}": "<REDACTED>" }, { "ReplicationState": "N/A", "ReplicationMode": "Disabled", "ReplicationEnabled": false, "HealthStatus": "N/A", "{#VMNAME}": "<REDACTED>" }, { "ReplicationState": "N/A", "ReplicationMode": "Disabled", "ReplicationEnabled": false, "HealthStatus": "N/A", "{#VMNAME}": "<REDACTED>" }, { "ReplicationState": "N/A", "ReplicationMode": "Disabled", "ReplicationEnabled": false, "HealthStatus": "N/A", "{#VMNAME}": "<REDACTED>" }, { "ReplicationState": "N/A", "ReplicationMode": "Disabled", "ReplicationEnabled": false, "HealthStatus": "N/A", "{#VMNAME}": "<REDACTED>" }, { "ReplicationState": "N/A", "ReplicationMode": "Disabled", "ReplicationEnabled": false, "HealthStatus": "N/A", "{#VMNAME}": "<REDACTED>" }, { "ReplicationState": "N/A", "ReplicationMode": "Disabled", "ReplicationEnabled": false, "HealthStatus": "N/A", "{#VMNAME}": "<REDACTED>" }, { "ReplicationState": "N/A", "ReplicationMode": "Disabled", "ReplicationEnabled": false, "HealthStatus": "N/A", "{#VMNAME}": "<REDACTED>" }, { "ReplicationState": "N/A", "ReplicationMode": "Disabled", "ReplicationEnabled": false, "HealthStatus": "N/A", "{#VMNAME}": "<REDACTED>" }, { "ReplicationState": "N/A", "ReplicationMode": "Disabled", "ReplicationEnabled": false, "HealthStatus": "N/A", "{#VMNAME}": "<REDACTED>" } ]
Now what I want is to create an auto discovery rule with 4x items that say
Replication State - VM Name
Replication Mode - VM Name
Replication Enabled - VM Name
Health Status - VM Name
But I am struggling to make it work. I breifly had it pulling in and I changed something and I was a little discracted and it stopped working.
Here is what I have so far.
Here is the discovery rule on my template in our test environment.
And here is the Item Prototype I made.
When I apply the template to the Hypervisor host I am getting the following error.
This is my first time writing a Discovery Rule from scratch and not modifying or going off of someone elses work so I am a little lost and I know I have messed up somewhere but I cant see where I messed up.
Can someone help me with this discovery rule.
And it has always given me headaches..
Comment