How to monitor Hyper-V Replica Health with the custom advanced Sensor in Paessler PRTG

With this VBS Script you can Monitor Hyper-V Replica Health with the custom Advanced XML Sensor in Paessler PRTG.
https://prtg.paessler.com/api.htm?tabid=7
Replace server.domain.local with IP or DNS Name of your Hyper-V Server.
The PRTG Service Account needs to have Admin rights on Hyper-V Host (SYSTEM uses AD Computer Account to access remote Servers).
Save the VBS in “C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML” Folder.
Create a Custom EXE/Script Advanced Sensor and select the Script.

locstrServer = "server.domain.local"
locstrText = ""
locstrStatus = ""
set objWshShell = CreateObject("WScript.Shell")
wscript.echo "<?xml version=""1.0"" encoding=""Windows-1252"" ?>"
wscript.echo "<prtg>"
locstrCommand = "cmd /c powershell.exe Invoke-Command -ComputerName " & locstrServer & " -ScriptBlock { Get-VMReplication ^| where Health -eq 'Normal' ^| measure-object }"
Set locobjExec = objWshShell.Exec(locstrCommand)
Do While Not locobjExec.StdOut.AtEndOfStream
 locstrReadline = trim(locobjExec.StdOut.ReadLine())
 locstrReadline = replace(locstrReadline, " ", "")
 if left(lcase(locstrReadline), len("count:")) = "count:" then 
  wscript.echo "<result>"
  wscript.echo "<channel>Health Normal Count</channel>"
  locintcount = cint(replace(lcase(locstrReadline), "count:", ""))  
  wscript.echo "<value>" & locintcount & "</value>"
  wscript.echo "<unit>Count</unit>"  
  wscript.echo "</result>"
 end if
Loop
locstrCommand = "cmd /c powershell.exe Invoke-Command -ComputerName " & locstrServer & " -ScriptBlock { Get-VMReplication ^| where Health -eq 'Warning' ^| measure-object }"
Set locobjExec = objWshShell.Exec(locstrCommand)
Do While Not locobjExec.StdOut.AtEndOfStream
 locstrReadline = trim(locobjExec.StdOut.ReadLine())
 locstrReadline = replace(locstrReadline, " ", "")
 if left(lcase(locstrReadline), len("count:")) = "count:" then 
  wscript.echo "<result>"
  wscript.echo "<LimitMaxWarning>0</LimitMaxWarning>"
  wscript.echo "<LimitMode>1</LimitMode>"
  wscript.echo "<channel>Health Warning Count</channel>"
  locintcount = cint(replace(lcase(locstrReadline), "count:", ""))
  wscript.echo "<LimitWarningMsg>Hyper-V Replica(s) Health Warning!</LimitWarningMsg>"
  wscript.echo "<value>" & locintcount & "</value>"
  wscript.echo "<unit>Count</unit>"
  wscript.echo "</result>"
 end if
Loop
locstrCommand = "cmd /c powershell.exe Invoke-Command -ComputerName " & locstrServer & " -ScriptBlock { Get-VMReplication ^| where Health -eq 'Critical' ^| measure-object }"
Set locobjExec = objWshShell.Exec(locstrCommand)
Do While Not locobjExec.StdOut.AtEndOfStream
 locstrReadline = trim(locobjExec.StdOut.ReadLine())
 locstrReadline = replace(locstrReadline, " ", "")
 if left(lcase(locstrReadline), len("count:")) = "count:" then 
  wscript.echo "<result>"
  wscript.echo "<LimitMaxError>0</LimitMaxError>"
  wscript.echo "<LimitMode>1</LimitMode>"  
  wscript.echo "<channel>Health Critical Count</channel>"
  locintcount = cint(replace(lcase(locstrReadline), "count:", ""))  
  wscript.echo "<LimitErrorMsg>Hyper-V Replica(s) Health Critical!</LimitErrorMsg>"
  wscript.echo "<value>" & locintcount & "</value>"
  wscript.echo "<unit>Count</unit>"  
  wscript.echo "</result>"
 end if
Loop
if locstrStatus <> "" then wscript.echo locstrStatus
if locstrText <> "" then wscript.echo locstrText
wscript.echo "</prtg>"
Advertisements

7 thoughts on “How to monitor Hyper-V Replica Health with the custom advanced Sensor in Paessler PRTG

    1. EGamp Post author

      Use Taskmanager or Procexp https://technet.microsoft.com/en-us/sysinternals/bb896653.aspx to find the Account running the Script.
      Add this Account to the Administrators Group on the Hyper-V Host.
      On my PRTG it runs as “NT AUTHORITY\SYSTEM”. In this case add the PRTG Server Active Directory Domain Account (DOMAIN\[PRTGSERVERNAME]$) to the Administrators Group on the Hyper-V Host.
      Also check the Firewall and Powershell Remoting settings on Hyper-V Host.

      Reply
  1. Giuseppe

    Hello
    i got the following error
    XML: The returned xml does not match the expected schema. (code: PE233) —
    JSON: The returned json does not match the expected structure (Invalid JSON.). (code: PE231)
    PRTG server version is the last.
    thanks

    Reply
  2. jaime austria

    i’m getting an “invalid pointer operation” error when using this script. do i need to enable ps remoting?

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s