What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Falha no sensor de monitoramento replicação Hyper-V

Votes:

0

I found a script and added it as an exe/advanced sensor as directed, however the sensor returns the following error:

XML: The returned XML does not match the expected schemas. (code: PE233) -- JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)

Below is the script

Import-Module Hyper-V
 
$VMReplication = Get-VMReplication | select Name,Health,State

if (($VMReplication).count -lt 1) {
  Write-Host 1, ": No data returned from Get-VMReplication! Either no VMs are replicating, or have not elevated!" 
  Exit 4
}

$ErrMessage = " "
$Errors = 0
$Warning = 0
$Critical = 0
foreach ($Name in $VMReplication) {
  if ($Name.Health -Contains "Normal" -and $Name.State -Contains "Replicating") {
    $stat = 0
  }
  elseif ($Name.Health = "Warning") {
    $stat = 1
    $Warning = $Warning + 1
  }
  elseif ($Name.Health = "Critical") {
    $stat = 1
    $Critical = $Critical + 1
  }

  if ($stat -gt 0) {
    $VM = $Name.Name
    $Health = $Name.Health
    $Status = $Name.State
    $ErrMessage = $ErrMessage, $VM, " " , $Health , " (", $Status, ") "
    $Errors = $Errors + 1
  }
}

If ($Errors -eq 0) {
  Write-Host 0, ":OK", "Replication is working fine for", ($VMReplication).count, "of", (Get-VM).count, "VMs"
  Exit 0
}
else {
  Write-Host $Errors, ":", $ErrMessage
  Exit 2
}

prtg script sensor

Created on Sep 19, 2021 1:37:00 PM

Last change on Sep 20, 2021 6:52:46 AM by  Felix Wiesneth [Paessler Support]



11 Replies

Votes:

0

Hello,

Thank you for your message.

According to the output of the script, I invite you to use an EXE/Script sensor instead of the EXE/Script Advanced as the latter indeed expect to receive a JSON whereas the sensor returns the following output "value:message".

You can also replace the end of the script with the following instead of using many strings:

if ($Errors -eq 0) {
  Write-Host "0:OK Replication is working fine for $(($VMReplication).count) of $((Get-VM).count) VMs"
  Exit 0
}
else {
  Write-Host "$($Errors):$ErrMessage"
  Exit 2
}

If you have questions, let us know.

Regards.

Created on Sep 20, 2021 7:46:26 AM by  Florian Lesage [Paessler Support]

Last change on Sep 20, 2021 7:46:40 AM by  Florian Lesage [Paessler Support]



Votes:

0

Ao realizar as ações recomendadas, deu a seguinte mensagem:

Erro do conteúdo:

The specified module 'Hyper-V' was not loaded because no valid module file was found in any module directory. At C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXE\replication_sensor.ps1:1 char:1 + Import-Module Hyper-V + ~~~~~~~~~~~~ (código: PE024)

Created on Sep 20, 2021 12:22:29 PM

Last change on Sep 20, 2021 1:27:37 PM by  Felix Wiesneth [Paessler Support]



Votes:

0

Hello,

Thank you for the update.

According to the message you get, the Hyper-V module is not installed and as a consequence the script can't import it. Therefore, I invite you to open a PowerShell console (32bit) on the PRTG server and then make sure that the module is installed there.

To check if the PowerShell console opened is in 32bit you can use "[System.Environment]::Is64BitProcess" which should return the value "False".

Regards.

Created on Sep 21, 2021 5:38:12 AM by  Florian Lesage [Paessler Support]



Votes:

0

Olá!

Muito obrigado! Deu certo. Porém uma pergunta, no meu ambiente na mesma rede existe vários servidores com hyper-v replicando vms, porém na rede o probe está instalado somente em uma máquina, para selecionar outros servidores necessitaria instalar em cada servidor o probe? Ou nesse mesmo script tem como selecionar qual vm buscar? Poderia me informar qual parametro inserir no script, por gentileza?

Grato!

Created on Sep 22, 2021 1:34:06 PM



Votes:

0

Hello,

Thank you very much for the update. Glad to hear that it works now!

Regarding your question, you do not have to install a remote probe on each server to monitor the VM replication there. Instead, you can modify the script to execute the code remotely by using the cmdlet Invoke-Command. This will allow you to create EXE sensors for each of your machines.

Note that to execute the code remotely you will need to pass the Windows credentials as well as address (IP/DNS) defined in the devices settings in PRTG. To do so, you can use the placeholders %host, %windowsuser and %windowspassword as follows:

"%host" "%windowsuser" "%windowspassword"

You also need to add the following lines at the beginning of the script to get these parameters:

Param (
    [string]$host= "",
    [string]$winuser = "",
    [string]$winpass= ""
)

Then, to use the cmdlet Invoke-Command you need to create a credential object with the values of $winuser and $winpass. I invite you to have a look at the following article for further information: https://adamtheautomator.com/powershell-get-credential/#Create_a_Credential_without_a_Prompt

$credential = New-Object System.Management.Automation.PSCredential ($winuser, $winpass)

Finally, execute the code expected to run on the machine within a scriptblock as follows:

Invoke-Command -ComputerName $host -Credential $credential -ScriptBlock {
# Your code here (will be executed on the target device)
}

Please, note that we do not provide official support for it. Therefore, if there is modifications required according to your environment, I won't be able to provide support for it.

Created on Sep 23, 2021 10:40:04 AM by  Florian Lesage [Paessler Support]

Last change on Sep 23, 2021 10:40:51 AM by  Florian Lesage [Paessler Support]



Votes:

0

Boa noite!

Muito obrigado pelo retorno, me perdoe o abuso, compreendo que que não dão suporte oficial nessa parte, mas realmente estou encontrando dificuldades e acabou não dando certo o procedimento, poderia por gentileza me exemplificar como ficaria as orientações no script? Poderia me passar um modelo no script, de como ficaria?

Import-Module Hyper-V
 
$VMReplication = Get-VMReplication | select Name,Health,State

if (($VMReplication).count -lt 1) {
  Write-Host 1, ": No data returned from Get-VMReplication! Either no VMs are replicating, or have not elevated!" 
  Exit 4
}

$ErrMessage = " "
$Errors = 0
$Warning = 0
$Critical = 0
foreach ($Name in $VMReplication) {
  if ($Name.Health -Contains "Normal" -and $Name.State -Contains "Replicating") {
    $stat = 0
  }
  elseif ($Name.Health = "Warning") {
    $stat = 1
    $Warning = $Warning + 1
  }
  elseif ($Name.Health = "Critical") {
    $stat = 1
    $Critical = $Critical + 1
  }

  if ($stat -gt 0) {
    $VM = $Name.Name
    $Health = $Name.Health
    $Status = $Name.State
    $ErrMessage = $ErrMessage, $VM, " " , $Health , " (", $Status, ") "
    $Errors = $Errors + 1
  }
}

If ($Errors -eq 0) {
  Write-Host 0, ":OK", "Replication is working fine for", ($VMReplication).count, "of", (Get-VM).count, "VMs"
  Exit 0
}
else {
  Write-Host $Errors, ":", $ErrMessage
  Exit 2
}

Grato!

Created on Sep 23, 2021 10:06:22 PM

Last change on Sep 24, 2021 6:09:26 AM by  Florian Lesage [Paessler Support]



Votes:

0

Hi,

Here is the script slightly modified, of course it requires to be tested and probably modified to work properly:

Param (
    [string]$host= "",
    [string]$winuser = "",
    [string]$winpass= ""
)

$credential = New-Object System.Management.Automation.PSCredential ($winuser, $winpass)

$VMReplication = Invoke-Command -ComputerName $host -Credential $credential -ScriptBlock {
    Import-Module Hyper-V
    Get-VMReplication | select Name,Health,State
}

if (($VMReplication).count -lt 1) {
  Write-Host 1, ": No data returned from Get-VMReplication! Either no VMs are replicating, or have not elevated!" 
  Exit 4
}

$ErrMessage = " "
$Errors = 0
$Warning = 0
$Critical = 0
foreach ($Name in $VMReplication) {
  if ($Name.Health -Contains "Normal" -and $Name.State -Contains "Replicating") {
    $stat = 0
  }
  elseif ($Name.Health = "Warning") {
    $stat = 1
    $Warning = $Warning + 1
  }
  elseif ($Name.Health = "Critical") {
    $stat = 1
    $Critical = $Critical + 1
  }

  if ($stat -gt 0) {
    $VM = $Name.Name
    $Health = $Name.Health
    $Status = $Name.State
    $ErrMessage = $ErrMessage, $VM, " " , $Health , " (", $Status, ") "
    $Errors = $Errors + 1
  }
}

If ($Errors -eq 0) {
  Write-Host 0, ":OK", "Replication is working fine for", ($VMReplication).count, "of", (Get-VM).count, "VMs"
  Exit 0
}
else {
  Write-Host $Errors, ":", $ErrMessage
  Exit 2
}

Created on Sep 24, 2021 6:19:53 AM by  Florian Lesage [Paessler Support]



Votes:

0

Bom dia!

Obrigado!

Porém está dando o seguinte erro:

Resposta não formada corretamente: "(Param ( [string]$host= "", [string]$winuser = ", [string]$winpass= "" ) $credential = New-Object System.Management.Automation.PSCredential ($winuser, $winpass) $VMReplication = Invoke-Command -ComputerName $host -Credential $credential -ScriptBlock { Import-Module Hyper-V Get-VMReplication | select Name,Health,State } if (($VMReplication).count -lt 1) { Write-Host 1, ": No data returned from Get-VMReplication! Either no VMs are replicating, or have not elevated!" Exit 4 } $ErrMessage = " " $Errors = 0 $Warning = 0 $Critical = 0 foreach ($Name in $VMReplication) { if ($Name.Health -Contains "Normal" -and $Name.State -Contains "Replicating") { $stat = 0 } elseif ($Name.Health = "Warning") { $stat = 1 $Warning = $Warning + 1 } elseif ($Name.Health = "Critical") { $stat = 1 $Critical = $Critical + 1 } if ($stat -gt 0) { $VM = $Name.Name $Health = $Name.Health $Status = $Name.State $ErrMessage = $ErrMessage, $VM, " " , $Health , " (", $Status, ") " $Errors = $Errors + 1 } } If ($Errors -eq 0) { Write-Host 0, ":OK", "Replication is working fine for", ($VMReplication).count, "of", (Get-VM).count, "VMs" Exit 0 } else { Write-Host $Errors, ":", $ErrMessage Exit 2 } )" (código: PE132)

Na parte aonde insiro os dados do servidor, inseri desta forma:

Param (
    [string]$host= "nome do servidor",
    [string]$winuser = "login do usuário",
    [string]$winpass= "senha"
)

É desta forma mesmo?

Grato!

Created on Sep 24, 2021 12:06:55 PM

Last change on Sep 24, 2021 12:16:10 PM by  Florian Lesage [Paessler Support]



Votes:

0

Hello,

The values passed to the parameters are correct however you do not have to write them in the script. Regarding that matter, please make sure to remove them before publishing your post. We might not see them and therefore they would be visible to everyone.

In the script I provided, you do not have to write the credentials in the script. I invite you to use to add the following placeholders in the Parameter field of the EXE sensor:

"%host" "%windowsuser" "%windowspassword"

EXE settings

Then, before using the script with the sensor I invite you to make sure that it works properly and return a value following the format below:

value:message

If it doesn't, then there is an issue something that you need to troubleshoot. To avoid any issue with the module Hyper-V, make sure that it is installed on each server you would like to monitor with that script.

I have modified the script to return the value -1 as well as the error encountered in the sensor message field:

Param (
    [string]$host= "",
    [string]$winuser = "",
    [string]$winpass= ""
)

$credential = New-Object System.Management.Automation.PSCredential ($winuser, $winpass)

try{

$VMReplication = Invoke-Command -ComputerName $host -Credential $credential -ScriptBlock {
    Import-Module Hyper-V
    Get-VMReplication | select Name,Health,State
}

if (($VMReplication).count -lt 1) {
  Write-Host "1:No data returned from Get-VMReplication! Either no VMs are replicating, or have not elevated!" 
  Exit 4
}

$ErrMessage = " "
$Errors = 0
$Warning = 0
$Critical = 0
foreach ($Name in $VMReplication) {
  if ($Name.Health -Contains "Normal" -and $Name.State -Contains "Replicating") {
    $stat = 0
  }
  elseif ($Name.Health = "Warning") {
    $stat = 1
    $Warning = $Warning + 1
  }
  elseif ($Name.Health = "Critical") {
    $stat = 1
    $Critical = $Critical + 1
  }

  if ($stat -gt 0) {
    $VM = $Name.Name
    $Health = $Name.Health
    $Status = $Name.State
    $ErrMessage = $ErrMessage, $VM, " " , $Health , " (", $Status, ") "
    $Errors = $Errors + 1
  }
}

If ($Errors -eq 0) {
  Write-Host 0, ":OK", "Replication is working fine for", ($VMReplication).count, "of", (Get-VM).count, "VMs"
  Exit 0
}
else {
  Write-Host $Errors, ":", $ErrMessage
  Exit 2
}
}catch {
    Write-Host "-1:$($_.exception.message) At line $($_.InvocationInfo.ScriptLineNumber)"
}

Regards.

Created on Sep 24, 2021 12:31:17 PM by  Florian Lesage [Paessler Support]

Last change on Sep 28, 2021 10:17:06 AM by  Florian Lesage [Paessler Support]



Votes:

0

Boa tarde!

Em um dos servidores hyper-v está dando esse erro ao adicionar o sensor:

Erro do conteúdo: No data returned from Get-VMReplication! Either no VMs are replicating, or have not elevated! (código: PE024)

Grato

Created on Sep 27, 2021 6:04:44 PM



Votes:

0

Hello,

I'm afraid that I can't provide further support here, the script returns this error message when $VMReplication is null.

if (($VMReplication).count -lt 1) {
  Write-Host "1:No data returned from Get-VMReplication! Either no VMs are replicating, or have not elevated!" 
  Exit 4
}

Therefore, I can only invite you to execute the cmdlets in the script block manually on the target server and check if that's the case.

Regards.

Created on Sep 28, 2021 10:20:11 AM by  Florian Lesage [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.