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

Problem with custom Sensor

Votes:

0

Hi there,

I`m trying to use an Advanced Custom Sensor, to get the open Snapshots in a VMWare Environment.

Therefor I use the Script from the following thread --> https://www.paessler.com/knowledgebase/en/topic/29313-vmware-snapshots.

I tried both ways, to get the Values:

1. Use the Script as written and filled out the Parameters on PRTG

2. Wrote down the variable parameters (Server, User etc.) directly into the Script

When I run the script via Powershell, I get some values back, but if I try to get the Sensor Values via PRTG I get the Message:

"Error reading response: Invalid XML (missing /prtg)"

In the log file, I can read the following:

Die Datei "C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\Sn apshots.ps1" kann nicht geladen werden, da die Ausführung von Skripts auf diese m System deaktiviert ist. Weitere Informationen erhalten Sie mit "get-help abou t_signing".

I don`t know, why it is not working. I already did the followig:

1. Set-ExecutionPolicy RemoteSigned (negative)

2. Installed the newest .NET Framework (4.5.1) (negative)

3. Created the Script again, on the machine where it is executed (to solve problem with signing) (negative)

4. Set-ExecutionPolicy temporarely to "Unrestricted" to look if it works (negative)

5. Opened the Powershell first and then tried to get sensor working over PRTG (negative)

Anymore Ideas?

Thanks in advance,

Fox

custom-script-exe custom-sensor invalid-xml snapshots vmware

Created on Jan 31, 2014 9:03:25 AM

Last change on Mar 19, 2015 3:51:18 PM by  Martina Wittmann [Paessler Support]



Best Answer

Accepted Answer

Votes:

1

There are a few more things that I thought of, please make sure that the remote signed is set up for the 32-bit version of Powershell since this is the one that is used by PRTG.

https://www.paessler.com/knowledgebase/en/topic/20443-powershell-32bit-or-64bit-and-execution-policy

If that doesn't help, please check that the credentials you are using have access to the vcenter server that you are querying.

Also, just to confirm, you have VMware Infrastructure (VI) Toolkit for Windows v 1.5 installed on the PRTG machine that is running this PS script correct?

The last thing to check is to make sure that the account that is running the script can access the script. If it's the service account, try running the command from powershell with the service account credentials.

Created on Feb 7, 2014 2:51:07 PM by  Greg Campion [Paessler Support]



12 Replies

Votes:

0

Have you tried specifying credentials to run the sensor? In the sensor settings you can define the security context to be the windows credentials of the parent device which can help depending on the script. If that doesn't help, could you send over the script as well as the result in Powershell to [email protected]?

Created on Jan 31, 2014 1:33:48 PM by  Greg Campion [Paessler Support]



Votes:

0

Hi Greg,

first of all, thanks for your help ;)

I already had the settings "Use Windows credentials of parent device " active, but I switched to "Use security context of probe service" and back to the Windows credentials and now I got the following (for both script -> Data in parameters field and data directly in the script):

"Dem Client fehlt ein erforderliches Recht. (0x522)" .... strange

I seem to remember, that the first time I tried to activate the remote signing for scripts, I`ve received a hint, that another setting would overwrite the remote signing. Is that possible?

The Script is the same as described in my first comment:

#---------------------------------------------------------------------------------------------
# Get the number of VM snapshots on ESX host or vCenter
#
# This script requires the installation of the VMware Infrastructure (VI) Toolkit for Windows.
# 
# Args[0]:Server
# Args[1]:Protocol (HTTP/HTTPS)
# Args[2]:User
# Args[3]:Password
# Args[4]:Location (VI container(s), e.g. folders, datacenters, clusters). 
#		  Enclose in ' ' if location name contains spaces.
# Args[5]:VM power state (PoweredOn, PoweredOff, * for all)
#
# Example 1: Snapshot count for single DRS cluster, only powered-on VMs
# 10.23.112.235 https Administrator pass01 'My DRS Cluster' 'PoweredOn'
#
# Example 2: multiple datacenters, all VMs
# 10.23.112.235 https Administrator pass01 'My Data Center 1','My Data Center 2' '*'
# 
#---------------------------------------------------------------------------------------------


Add-PSSnapin VMWare.VIMAutomation.core >$Null

$global:textvar = ""

$server=Connect-VIServer -Server $Args[0] -Protocol $Args[1] -User $Args[2] -Password $Args[3]>$Null
$powerstate = [string]$Args[5]
$snapshot_count = 0

Get-VM -Location $Args[4] -Server $server | Get-Snapshot | `
ForEach-Object {
	$snapshot_count = $snapshot_count+1
}


function get-snaps{
    $vms = get-vm | sort name
    $vmsnaps = @()
    foreach($vm in $vms){
    	$snap = Get-Snapshot $vm
    	if($snap){
		  $vmsnaps += $vm
		  $snapshots = Get-Snapshot $vm
		  foreach ($snapshot in $snapshots){
          $global:textvar += $vm 
		  $global:textvar += "("
          $global:textvar += $snapshot.name
		  $global:textvar += "," 
		  $global:textvar += ([math]::Round($snapshot.sizemb/1024,2))
		  $global:textvar += ")"
		  $global:textvar += " - "

		}
    	}
    }
}
 
get-snaps


$x=[string]$snapshot_count+":"+$global:textvar

#write-host "$snapshot_count"

if($snapshot_count -ne 0){

write-host "<prtg>"
write-host "<error>"
write-host "1"
write-host "</error>"
write-host "<text>"
write-host $global:textvar
write-host "</text>"
write-host "</prtg>"


}

if($snapshot_count -eq 0){

write-host "<prtg>"
write-host "<result>"
write-host "<channel>Snapshots running</channel>"
write-host "<value>"
write-host $snapshot_count
write-host "</value>"
write-host "<LimitMaxError>0</LimitMaxError>"
write-host "<LimitMode>1</LimitMode>"
write-host "</result>"
write-host "</prtg>"


}

Result in Powershell

WARNUNG: There were one or more problems with the server certificate:

* The X509 chain could not be built up to the root certificate.

* The certificate's CN name does not match the passed value.

<prtg>
<error>
1
</error>
<text>
Servername1.tld(_datarecovery_,0) - Servername2.tld(_datarecovery_,0) - Servername3.tld(_datarecovery_,0) -
</text>
</prtg>

Thanks in advance for your help,

Fox

Created on Feb 4, 2014 6:52:23 AM



Votes:

0

Just to get a clearer idea of what is causing the error, can you write the EXE to disk and post it here?

Created on Feb 5, 2014 2:15:06 PM by  Greg Campion [Paessler Support]



Votes:

0

You mean the Log?!

Created on Feb 5, 2014 3:02:10 PM



Votes:

0

Yes, are you still getting the same failure as before in the log when you select the option "Write EXE result to disk"?

"Die Datei "C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\Sn apshots.ps1" kann nicht geladen werden, da die Ausführung von Skripts auf diese m System deaktiviert ist. Weitere Informationen erhalten Sie mit "get-help abou t_signing"."

If so, what server do you have this sensor running on? Have you checked the Execution Policy on the server the script is being run on with the Get-Execution Policy command? Can you try setting this to unrestricted?

Created on Feb 6, 2014 10:33:03 AM by  Greg Campion [Paessler Support]



Votes:

0

Hi Creg,

thanks for your help!

"Write EXE result to disk" an "Write EXE result to disk in case of error" don`t bring up any logs anymore in the LOG-Folder (C:\ProgramData\Paessler\PRTG Network Monitor\Logs (Sensors))...

As for the Execution Policy, do you read my Comments?!?! I already tried that, as you can read in my first post. It doesn`t work.

The Server, the script is running on, is the same which runs the Probe and VCenter Server.

Anymore ideas?

Regards, Fox

Created on Feb 6, 2014 11:36:12 AM



Votes:

0

So the setup is that you have a remote probe running on a server that is also running vcenter and you have put the sensor in PRTG on that probe to run correct? Are you using the IP of the server or the localhost for the IP in the parameters? Also, please try running the script from below to see if that works.

#---------------------------------------------------------------------------------------------
# Get the number of VM snapshots on ESX host or vCenter
#
# This script requires the installation of the VMware Infrastructure (VI) Toolkit for Windows.
# 
# Args[0]:Server
# Args[1]:Protocol (HTTP/HTTPS)
# Args[2]:User
# Args[3]:Password
# Args[4]:Location (VI container(s), e.g. folders, datacenters, clusters). 
#		  Enclose in ' ' if location name contains spaces.
# Args[5]:VM power state (PoweredOn, PoweredOff, * for all)
#
# Example 1: Snapshot count for single DRS cluster, only powered-on VMs
# 10.23.112.235 https Administrator pass01 'My DRS Cluster' 'PoweredOn'
#
# Example 2: multiple datacenters, all VMs
# 10.23.112.235 https Administrator pass01 'My Data Center 1','My Data Center 2' '*'
# 
#---------------------------------------------------------------------------------------------


Add-PSSnapin VMWare.VIMAutomation.core > $Null

$global:textvar = ""

$server=Connect-VIServer -Server $Args[0] -Protocol $Args[1] -User $Args[2] -Password $Args[3] > $Null
$powerstate = [string]$Args[5]
$snapshot_count = 0

Get-VM -Location $Args[4] -Server $server | Get-Snapshot | `
ForEach-Object {
	$snapshot_count = $snapshot_count+1
}


function get-snaps{
    $vms = get-vm | sort name
    $vmsnaps = @()
    foreach($vm in $vms){
    	$snap = Get-Snapshot $vm
    	if($snap){
		  $vmsnaps += $vm
		  $snapshots = Get-Snapshot $vm
		  foreach ($snapshot in $snapshots){
          $global:textvar += $vm 
		  $global:textvar += "("
          $global:textvar += $snapshot.name
		  $global:textvar += "," 
		  $global:textvar += ([math]::Round($snapshot.sizemb/1024,2))
		  $global:textvar += ")"
		  $global:textvar += " - "

		}
    	}
    }
}
 
get-snaps


$x=[string]$snapshot_count+":"+$global:textvar

#write-host "$snapshot_count"

if($snapshot_count -ne 0){

write-host "<prtg>"
write-host "<error>"
write-host "1"
write-host "</error>"
write-host "<text>"
write-host $global:textvar
write-host "</text>"
write-host "</prtg>"


}

if($snapshot_count -eq 0){

write-host "<prtg>"
write-host "<result>"
write-host "<channel>Snapshots running</channel>"
write-host "<value>"
write-host $snapshot_count
write-host "</value>"
write-host "<LimitMaxError>0</LimitMaxError>"
write-host "<LimitMode>1</LimitMode>"
write-host "</result>"
write-host "</prtg>"


}

Created on Feb 6, 2014 1:27:39 PM by  Greg Campion [Paessler Support]



Votes:

0

Hi Creg,

thanks that you keep on supporting me ;)

Unfortunately, I get the same Error with your new Version of the Script, but there is one thing I was able to find out.

If I run the PRTG Service with the "local system" User, I get the Error:

"Error reading response: Invalid XML (missing /prtg)"

If I run the PRTG Service with a special Service User (for example: svc.prtg) and Dom-Admin rights etc., I get the Error:

"Dem Client fehlt ein erforderliches Recht. (0x522)"

But I don`t now, where I have to delegate the rights to the service user, to get that sensor running.

Generally I`m not sure, which Error is better :) Should I use the "local system" or the "prtg service" user.

Regards, Fox

Created on Feb 7, 2014 1:44:53 PM



Accepted Answer

Votes:

1

There are a few more things that I thought of, please make sure that the remote signed is set up for the 32-bit version of Powershell since this is the one that is used by PRTG.

https://www.paessler.com/knowledgebase/en/topic/20443-powershell-32bit-or-64bit-and-execution-policy

If that doesn't help, please check that the credentials you are using have access to the vcenter server that you are querying.

Also, just to confirm, you have VMware Infrastructure (VI) Toolkit for Windows v 1.5 installed on the PRTG machine that is running this PS script correct?

The last thing to check is to make sure that the account that is running the script can access the script. If it's the service account, try running the command from powershell with the service account credentials.

Created on Feb 7, 2014 2:51:07 PM by  Greg Campion [Paessler Support]



Votes:

0

Hi Creg,

thank you very much, it seems that it`s working now :) What have I done:

1. "Set-ExecutionPolicy" to "Unrestricted" on both Powershells (32-Bit and 64-Bit) 2. "Set-ExecutionPolicy" back to "RemoteSigned" on both Powershells (32-Bit and 64-Bit) 3. Set back the Settings for "Security Context" to "Use security context of probe service"

And now it is working, hurray!

So again Craig, thank you very much for your help, I really appreciated!!!

A last question before I will let you go :)

Is there a possibility to show the result of the sensor (the XML output) in the "Channels" field. At the moment it is shown under "Last Message" and I can`t see the whole output, because the field is to small.

Regards from germany, Fox

Created on Feb 10, 2014 7:22:30 AM



Votes:

0

I'm afraid that the results in a channel wouldn't be beneficial since the fields for the channels are also limited to 2000 characters. You could try splitting this up into multiple fields but this wouldn't really be an attractive option...

Created on Feb 10, 2014 9:15:14 AM by  Greg Campion [Paessler Support]



Votes:

0

Ok, thanks.

Created on Feb 10, 2014 12:44:38 PM




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.