New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


EXEXML Sensor specify computername with parameter

Votes:

0

Your Vote:

Up

Down

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 by  Ferron (0) 1

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



3 Replies

Accepted Answer

Votes:

0

Your Vote:

Up

Down

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 Support]



Votes:

1

Your Vote:

Up

Down

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 by  Curtis Kayfish (70) 2 1



Votes:

0

Your Vote:

Up

Down

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

Created on Apr 4, 2016 6:38:17 AM by  Ferron (0) 1



Please log in or register to enter your reply.


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.