Hi,
I'm a newbie on PRTG and I'm trying to create a custom sensor that will monitor multiple Windows services on a remote server using one powershell script. The "test_service" is dynamically created by web-service which may have multiple instance (for example: "test_service", "test_service01", "test_service02"...)
Below is a simple PS script that will tell me the status of the "test_service" services.
-------SAMPLE SCRIPT-----------
$SvrName = 'rmt_host' get-service -computername $SvrName -displayname "*test_service*" | Foreach { if ($_.status -eq "stopped") {Write-Host $_ 'Service Not Running'} else {Write-Host $_ 'Service Running';Exit '1000'} }
------------------
At this point, I'm not sure how to proceed making this work in PRTG and hopefully someone can assist me or guide me to any documentations.
Thanks in advance.
Armin
Article Comments
Thank you. I was able to add a new sensor and made some changes on the script to generate a simple output.
Param( [string]$SvrName = 'localhost' ) Clear-Host $SvrName = 'localhost' get-service -computername $SvrName -displayname "*Cch.Taxcan*" | Foreach { if ((Get-Service $_.Name).Status -eq "Running") { } else { Write-Host "<prtg>" Write-Host "<result>" Write-Host "<channel>Error Found</channel>" Write-Host "<value>" $_.Name " is not running </value>" Write-Host "</result>" Write-Host "</prtg>" } }
However, I cannot get to display an error on the sensor. Can you please guide me as to I'm missing?
Dec, 2016 - Permalink
Dear rmin75,
the structure to display an error is
<prtg> <error>1</error> <text>Your error message</text> </prtg>
(You cannot send channel data and an error status at the same time.)
Dec, 2016 - Permalink
Dear rmin75
You can output an XML which puts earch service into one channel. Please find the relevant documentation via Setup / PRTG API, tab "Custom Sensors", section "Advanced script and HTTP data sensors".
However, several limitations apply:
Nov, 2016 - Permalink