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^>

Article Comments

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.


Feb, 2022 - Permalink

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.


Feb, 2022 - Permalink

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.


Feb, 2022 - Permalink