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

Monitoring multiple services using one powershell script

Votes:

0

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

powershell prtg services

Created on Nov 28, 2016 5:10:04 PM

Last change on Nov 29, 2016 8:28:49 AM by  Luciano Lingnau [Paessler]



3 Replies

Votes:

0

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:

  • A PRTG sensor cannot have more than 50 channels.
  • You can add new channels to an existing Exe/Script Advanced sensor, but to have the sensor work reliably, any existing channel should get data with each sensor scan.
  • You cannot delete existing channels on a sensor, only a complete sensor can be deleted.

Created on Nov 29, 2016 9:15:29 PM by  Arne Seifert [Paessler Support]



Votes:

0

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?

Created on Dec 7, 2016 8:48:16 PM

Last change on Dec 8, 2016 12:06:10 PM by  Arne Seifert [Paessler Support]



Votes:

0

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.)

Created on Dec 8, 2016 12:07:28 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.