The following script allows you to monitor multiple file sizes in one PRTG sensor. It expects you to determine the amount of files in the first parameter and add the correct amount of files as additional parameters.
E.g. – three files:
1 | 3 "c:\pagefile.sys" "c:\boot.ini" "c:\windows\win.ini" |
It of course wouldn’t mage much sense to monitor the example files, but that’s how you would give the parameters to this advanced exe/script sensor in PRTG. To test it, I recommend to use it via CSCRIPT in a DOS / CMD command window:
1 | cscript CheckMultipleFileSizes.vbs 3 "c:\pagefile.sys" "c:\boot.ini" "c:\windows\win.ini" |
PRTG will see the file-name as channel name and the resulting file-size in byte per file you set up. Please be aware that you can’t just add additional channels later on – you could place dummy-files in the parameters to bypass this if ever needed.
Here is the VBS file that you need to place in to your PRTG installations advanced exe sensors directory:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | 'Execute: 'Argument 0 = amount of files 'Argument 1 to x = file-path in "" 'CheckMultipleFileSizes.vbs 2 "C:\path\file" "\\server\share\path\file" Dim iFiles Dim strPaths Dim cnt If WScript.Arguments.Count > 1 Then iFiles = WScript.Arguments.Item(0) For cnt = 1 To iFiles If Len(strPaths) > 0 Then strPaths = strPaths & "|&|" End If strPaths = strPaths & WScript.Arguments.Item(cnt) Next Else Wscript.Echo "Usage: cscript CheckMultipleFileSizes.vbs 2 ""C:\path\file"" ""\\server\share\path\file""" Wscript.Quit End If Dim fs Dim objFile Dim strPathTemp WScript.echo "<prtg>" Set fs = CreateObject("Scripting.FileSystemObject") strPathTemp = Split(strPaths,"|&|") For cnt = 0 To UBound(strPathTemp) If fs.FileExists(strPathTemp(cnt)) Then Set objFile = fs.GetFile(strPathTemp(cnt)) WScript.echo "<result>" WScript.echo "<channel>" & objFile.Name & "</channel><value>" & objFile.Size & "</value>" WScript.echo "</result>" End If Next Set fs = Nothing WScript.echo "</prtg>" |
This was as well posted in this PRTG article.