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

How can i execue the custom-script on the Host

Votes:

0

Hello,

i have created an custom powershell-script with xml-Output. The script checks some Windows-Services and show it in seperate channels in the Sensor. My Problem is, i don't know, how i must change my script, to execute the Script on the device, where i set-up the sensor. The script monitors actually the Services of the Probe-Server. Here is my script:

<#
===================================================================================
Paessler PRTG Sensor to check Windows Services
===================================================================================
Autor:        My
Script:       Services.ps1
Version:      1.0
Date:         10.08.2020
Scriptpath:   C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML
Scripttype:   EXE/Script Advanced
#>
param(
    [string]$ComputerName = "%host",
    [string]$Domain = "%windowsdomain",
    [string]$Username = "%windowsuser",
    [string]$Password = "%windowspassword",
    #Servicenames:
    [string]$ServiceName1 = "netlogon",
    [string]$ServiceName2 = "AppXSvc",
    [string]$ServiceName3 = "Dhcp"
)



$xmlOutput = '<?xml version="1.0" encoding="UTF-8" ?><prtg>'

if ((Get-Service -Name $ServiceName1).Status -eq 'Running'){$Count ="1"}
elseif

((Get-Service -Name $ServiceName1).Status -eq 'Stopped'){$Count ="2"}

elseif

((Get-Service -Name $ServiceName1).Status -eq 'Pause-Pending'){$Count ="3"}

elseif

((Get-Service -Name $ServiceName1).Status -eq 'Paused'){$Count ="4"}


 $xmlOutput = $xmlOutput + "<result>
        <channel>Anmeldedienst</channel>
        <value>$Count</value>
        <valuelookup>Windows_Services</valuelookup>
    </result>"

if ((Get-Service -Name $ServiceName2).Status -eq 'Running'){$Count ="1"}
elseif

((Get-Service -Name $ServiceName2).Status -eq 'Stopped'){$Count ="2"}

elseif

((Get-Service -Name $ServiceName2).Status -eq 'Pause-Pending'){$Count ="3"}

elseif

((Get-Service -Name $ServiceName2).Status -eq 'Paused'){$Count ="4"}

    $xmlOutput = $xmlOutput + "<result>
        <channel>AppX-Bereitstellungsdienst</channel>
        <value>$Count</value>
        <valuelookup>Windows_Services</valuelookup>
    </result>"
 if ((Get-Service -Name $ServiceName3).Status -eq 'Running'){$Count ="1"}
elseif

((Get-Service -Name $ServiceName3).Status -eq 'Stopped'){$Count ="2"}

elseif

((Get-Service -Name $ServiceName3).Status -eq 'Pause-Pending'){$Count ="3"}

elseif

((Get-Service -Name $ServiceName3).Status -eq 'Paused'){$Count ="4"}

    $xmlOutput = $xmlOutput + "<result>
        <channel>DHCP</channel>
        <value>$Count</value>
        <valuelookup>Windows_Services</valuelookup>
    </result>"  



$xmlOutput = $xmlOutput + "</prtg>"
$xmlOutput

custom-sensor powershell xml

Created on Aug 11, 2020 11:32:46 AM



1 Reply

Votes:

0

Hello,

that is correct, the script itself runs on the probe computer. You can read into remote powershell if the script should operate on a different target.

If that turns out to be too complicated, you can do it the other way:

  • On the target, use the Windows Scheduler to run a script locally
  • In that script, use HTTP POST (like with invoke-webrequest) to push an XML, or JSON to an HTTP Push Data Advanced sensor.

An example to push a static JSON:

$postParams = '{"prtg": {"text": "This sensor is added to 127.0.0.1", "result": [{"LimitMode": 1, "Value": 87, "LimitMinError": 10, "LimitErrorMsg": "Percentage too high", "Channel": "Percentage", "LimitMaxError": 90, "Unit": "Percent"}, {"Channel": "Response Time", "Unit": "TimeResponse", "Value": 4711}]}}'
Invoke-WebRequest -Uri http://10.49.1.2:5050/MyToken -Method POST -ContentType application/json -Body $postParams 

For XML, please adjust the ContentType parameter.

Created on Aug 12, 2020 12:46:04 PM by  Arne Seifert [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.