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

Custom Batch Script

Votes:

0

I created a custom batch script for monitoring a specific service on a webserver. It looks like this:

@echo off

sc \\pjlm-s02 query "PAFMAlerting" | find "RUNNING"
if "%ERRORLEVEL%"=="0" (
    echo Service PAFMAlerting is running
    Exit 0
) else (
    echo Service is NOT running
    Exit 2
)

If I run this on any machine on the domain it recognizes the service running, but when I add this custom Sensor it always gives me Service is NOT running.

Any ideas why it would do this?

batch prtg sensor service

Created on Nov 27, 2015 9:46:23 PM

Last change on Nov 30, 2015 8:26:05 AM by  Torsten Lindner [Paessler Support]



Best Answer

Accepted Answer

Votes:

0

Yes I am. I switched the account the PRTG service runs under. I actually figured it out, it was the formatting. It now looks like this:

@echo off

sc \\pjlm-s02 query "PAFMAlerting" | find "RUNNING"
if "%ERRORLEVEL%"=="0" (
    exit 0
) else (
    echo 100:Service is Not Running
    exit 2
)

The problem was that the service under ERRORLEVEL==0 would spit out a line of text before getting to exit 0 and that was conflicting with the PRTG formatting. Essentially the query returns a line of text prior to getting to the exit statement.

Created on Nov 30, 2015 3:40:15 PM

Last change on Dec 2, 2015 9:40:08 AM by  Torsten Lindner [Paessler Support]



3 Replies

Votes:

0

Are you using an administrative user in the credentials of PRTG and did you set the security context of the sensor to Use Windows credentials of parent device?

Created on Nov 30, 2015 8:51:24 AM by  Stephan Linke [Paessler Support]



Accepted Answer

Votes:

0

Yes I am. I switched the account the PRTG service runs under. I actually figured it out, it was the formatting. It now looks like this:

@echo off

sc \\pjlm-s02 query "PAFMAlerting" | find "RUNNING"
if "%ERRORLEVEL%"=="0" (
    exit 0
) else (
    echo 100:Service is Not Running
    exit 2
)

The problem was that the service under ERRORLEVEL==0 would spit out a line of text before getting to exit 0 and that was conflicting with the PRTG formatting. Essentially the query returns a line of text prior to getting to the exit statement.

Created on Nov 30, 2015 3:40:15 PM

Last change on Dec 2, 2015 9:40:08 AM by  Torsten Lindner [Paessler Support]



Votes:

0

Nice work, thanks for sharing!

Created on Dec 1, 2015 8:10:09 AM by  Stephan Linke [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.