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

EXEXML Sensor specify computername with parameter

Votes:

0

Hi,

I've created the following script:

Write-Host "<prtg>"
param([string]$ComputerName)


$value= Get-WmiObject -Query  "SELECT * FROM Win32_Processor" -ComputerName $ComputerName

		$LoadPercentage = $value.LoadPercentage
		Write-Host "<result>"
    	Write-Host "<channel>Processor Percentage</channel>"
    	Write-Host "<value>$LoadPercentage</value>"
    	Write-Host "<float>1</float>"
    	Write-Host "<showTable>1</showTable>"
    	Write-Host "<showChart>1</showChart>"
    	Write-Host "<unit>Go</unit>"
    	Write-Host "<mode>Absolute</mode>"
    	Write-Host "<warning>0</warning>"
    	Write-Host "</result>"

$value2= Get-WmiObject -Query  "SELECT * FROM Win32_OperatingSystem" -ComputerName $ComputerName
		
		$FreePhysicalMemory = $value2.FreePhysicalMemory/1024
		Write-Host "<result>"
    	Write-Host "<channel>Beschikbaar Geheugen MB</channel>"
    	Write-Host "<value>$FreePhysicalMemory</value>"
    	Write-Host "<float>1</float>"
    	Write-Host "<showTable>1</showTable>"
    	Write-Host "<showChart>1</showChart>"
    	Write-Host "<unit>Go</unit>"
    	Write-Host "<mode>Absolute</mode>"
    	Write-Host "<warning>0</warning>"
    	Write-Host "</result>"
		
	

$MemoryUsed = ($value2.FreePhysicalMemory/$value2.TotalVisibleMemorySize) * 100
$PercentMemoryUsed = "{0:N2}" -f $MemoryUsed
$PercentMemoryUsed = $PercentMemoryUsed -replace ("," , ".")

		Write-Host "<result>"
    	Write-Host "<channel>Beschikbaar Geheugen %</channel>"
    	Write-Host "<value>$PercentMemoryUsed</value>"
    	Write-Host "<float>1</float>"
    	Write-Host "<showTable>1</showTable>"
    	Write-Host "<showChart>1</showChart>"
    	Write-Host "<unit>Go</unit>"
    	Write-Host "<mode>Absolute</mode>"
    	Write-Host "<warning>0</warning>"
    	Write-Host "</result>"
	

Write-Host "</prtg>"

When I manually specify the $ComputerName variable everything works fine. But I want to set the computername with the parameter field from the sensor. I've looked everywhere, but I can't find a working example.

I hope someone has an answer for me.

exexml parameters wmi

Created on Mar 31, 2016 11:35:11 AM

Last change on Apr 1, 2016 6:37:28 AM by  Luciano Lingnau [Paessler]



3 Replies

Accepted Answer

Votes:

0

Two steps are required, the first is "reading" the parameter in powershell, which you are already doing:

param(
    [string]$host = "defaulthost"
)


(script continues...)

Then, in PRTG configure the Parameters section of the sensor's settings, for instance to "pass" the IPv4 Address/DNS Name from the parent device where the sensor was deployed enter %host in the parameters field. For more details on the available parameters see the Command line Parameters from the Setup > PRTG API > Custom Sensors page.

The same process may be used to forward credentials and other parameters as well.

There's a similar example in this tutorial.

Created on Apr 1, 2016 6:45:26 AM by  Luciano Lingnau [Paessler]



Votes:

1

param() must be the first non-comment line in the file. Place it before Write-Host "<prtg>"

Its good practice to always test your scripts manually before calling them from PRTG

Created on Apr 1, 2016 7:22:55 PM



Votes:

0

Both replies where very helpfull! Thank you for your help!

Created on Apr 4, 2016 6:38:17 AM




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.