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

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

Looking for some advice, sfc scan via PRTG with bat file

Votes:

0

Your Vote:

Up

Down

I'm looking to create a sensor that will (on a schedule) run against the device to scan it and report back if there are SFC errors found I have created the following, but its not working. I have not really writing something like this for PRTG, but there is a use case for it due to newer Windows Server OS. Basically its a validate scan only, and if it finds "errors" the sensor would be red, if none are found its green.

@echo off

IF NOT EXIST C:\temp MKDIR C:\temp
set temp-txt=C:\temp\sfc.txt

sfc.exe /verifyonly>>%temp-txt%
findstr /m "found integrity violations" %temp-txt% >Nul
if %errorlevel%==1 (
set errorlevel=0
)
if %errorlevel%==0 (
set errorlevel=1
)
del %temp-txt%

echo ^<?xml version="1.0" encoding="Windows-1252" ?^>

echo ^<prtg^>

echo    ^<result^>
echo        ^<channel^>SFC Result^</channel^>
echo        ^<value^>%errorlevel%^</value^>
echo        ^<LimitErrorMsg^>Repair OS Health^</LimitErrorMsg^>
echo    ^</result^>


echo ^</prtg^>

cmd-commands exe-script-advanced-sensor windows

Created on Feb 19, 2022 12:02:36 AM by  TMotto (5) 1

Last change on Feb 21, 2022 3:04:18 PM by  Felix Wiesneth [Paessler Support]



3 Replies

Votes:

0

Your Vote:

Up

Down

Hello,

Thank you for your message.

Please note that we can't provide official support for customizations, only giving indications which could help. Therefore, I hope the community might also help you here.

Regarding what you would like to achieve, I would first pinpoint an issue regarding the command used (sfc /verifyonly). The latter takes quite some time to return data and therefore the sensor will be blocked for that time. Consequently, this might lead to mutex being blocked and open requests on the probe. Therefore, I recommend to use an interval of 24/48 hours here.

The script also execute the code on a single system (on the probe server). To check remote systems, you would need to use PowerShell to use the cmdlet Invoke-Command for example, and provide the address of the target device from the sensor Settings tab.

Finally, you have defined the error message in the script, nevertheless there is no limit defined for it. Therefore, I invite you to do so in PRTG, by open the settings of the corresponding channel (via the gear icon or by clicking on it).

Regards.

Created on Feb 24, 2022 6:42:25 AM by  Florian Lesage [Paessler Support]

Last change on Feb 24, 2022 6:44:06 AM by  Florian Lesage [Paessler Support]



Votes:

0

Your Vote:

Up

Down

That would explain why I'm not seeing what I expected, I have honestly never written a custom sensor. This is truly my first attempt. I am hoping someone in the community can help me with it. I do agree it is something that only needs to run as a sensors like once a week or so.

Created on Feb 24, 2022 3:20:04 PM by  TMotto (5) 1



Votes:

0

Your Vote:

Up

Down

After verification, the script you provided properly return data to PRTG (from the probe server), nevertheless I invite you to make sure that the value returned are correct according to the result of the command sfc /verifyonly.

To use it, I invite you to copy the .bat file in the EXEXML folder located under "C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\". Then, create an EXE/Script Advanced with the setting "Timeout (Sec)" defined to 300 (5 minutes) at least, to avoid timeout issue due to the command sfc /verify. Increase this setting if needed.

Finally, under Setup > System Administration > Monitoring | Scanning intervals add a new interval (ex: 5d for 5 days) and configure the latter in the sensor Settings tab.

Afterwards, execute a manual scan of the sensor for the script to be executed and generate data. Note that it will take some time until data are displayed in PRTG.

Created on Feb 25, 2022 6:40:19 AM by  Florian Lesage [Paessler Support]



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.