I would like to use meta-scans when adding custom EXE/Script sensors via auto-discovery. Is there an option to include such scans with device templates?
This article applies to PRTG Network Monitor 19 or later
Using the meta-scan functionality for EXE/Script Advanced sensors
To apply this meta-scan functionality, you can write a custom sensor using an executable file that returns a list in XML format. Your sensor can then use the data from the XML ouput to create one sensor for each entry in this list. The data from the XML output will be added to the respective sensor.
What do you need?
There are a few things you have to provide to add your custom EXE/Script Advanced sensor with a meta-scan.
- You need your custom sensor in executable file format, for example, mysensor.exe (you can also use another supported executable file, for example, PS1 or BAT).
- You need a parameter that triggers the meta-scan, for example, -metascan
- When you run mysensor.exe –metascan, it has to write XML output to the console in the following format:
<prtg> <item> <name>Sensor name</name> <exefile>myfile.exe</exefile> <params>-run 1</params> </item> <item> <name>Sensor name 2</name> <exefile>myfile.exe</exefile> <params>-run 2</params> </item> [...] </prtg>
- You need a device template that adds your sensor using the meta-scan. The template has to look like this:
<?xml version="1.0" encoding="UTF-8"?> <devicetemplate id="customexexml" name="my custom exe xml" priority="1"> <check id="ping" meta="ping"/> <create id="<my meta id>" kind="exexml" meta="customexexmlscan" requires="ping"> <metadata> <exefile> mysensor.exe </exefile> <exeparams> -metascan </exeparams> </metadata> <createdata/> </create> </devicetemplate>
- Replace <my meta id> with a unique ID.
- mysensor.exe is your custom sensor that returns XML that is used to create the actual sensors.
- If the meta-scan needs credentials, you can use the same placeholders for <exeparams> that you can use in the parameters field in the EXE/Script Advanced sensor settings.
- You can use the same executable file with different parameters or even different executable files for the meta-scan and the sensor itself.
You can now run an auto-discovery using this template (my custom exe xml in this example). This will automatically add the sensors according to the XML output. In this example, the added sensors Sensor name and Sensor name 2 will execute myfile.exe with the parameters -run 1 and -run 2.