Hi,
I recently started using prtg. I now run into a problem. I would like a number of sensors / triggers that read a log file. There is text in the log file. For example, how full a hard disk is in%. if it is above 90% it must give a warning.
I have now used the Logfilereader. But this does return the text but only triggers on 1 and 2. but not on the text.
do you have a solution for this problem.
Tim,
Article Comments
Florian,
Thanks for your reply. The standard sensors does not work because it is an outdated system. I can only get this log file with telnet.
This is how the log looks like:
=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2018.08.14 07:14:03 =~=~=~=~=~=~=~=~=~=~=~= 220 X300 TELNET server, service ready X300> user *** 331 User name okay, need password X300> pass *** 230 User logged in, proceed X300> #GETSTATS Capacity: 128.04GB Used: 0.00 % Write Protected: 0.00 % First File: N/A Last File: N/A #END X300> QUIT
Tim
Aug, 2018 - Permalink
Hi Tim,
Just create a custom script - I did that already for you, see below - took just 10 minutes...
'Execute: 'Argument 0 = File-Path 'LegacyDiskSizeSensor.vbs "C:\path\file.txt" - alternative with UNC path: "\\server\share\path\file.txt" Dim strPath If WScript.Arguments.Count = 1 Then strPath = WScript.Arguments.Item(0) Else Wscript.Echo "Usage: cscript LegacyDiskSizeSensor.vbs ""C:\path\file.txt""" Wscript.Quit End If Dim strCapacity, strUsed Dim objFile Set objFile = CreateObject("Scripting.FileSystemObject").OpenTextFile(strPath,1) Dim strLine Do While Not objFile.AtEndOfStream strLine = Trim(objFile.ReadLine()) If LCase(Left(strLine,Len("Capacity:"))) = LCase("Capacity:") Then strCapacity = Trim(Replace(Replace(strLine, "Capacity:", "", 1, -1, 1), "GB", "", 1, -1, 1)) ElseIf LCase(Left(strLine,Len("Used:"))) = LCase("Used:") Then strUsed = Trim(Replace(Replace(strLine, "Used:", "", 1, -1, 1), "%", "", 1, -1, 1)) End If Loop objFile.Close Set objFile = Nothing Dim strCalculatedFree strCalculatedFree = -1 'default is -1 - this would indicate the calculation wasn't possilble due to non numeric values If IsNumeric(strCapacity) And IsNumeric(strUsed) Then If strUsed <= 0 Then 'avoiding multiplaction with 0 strCalculatedFree = strCapacity Else strCalculatedFree = strCapacity * (strUsed / 100) End If End If WScript.echo "<prtg>" WScript.echo "<result>" WScript.echo "<channel>Capacity</channel><value>" & strCapacity & "</value>" WScript.echo "</result>" WScript.echo "<result>" WScript.echo "<channel>Used</channel><value>" & strUsed & "</value>" WScript.echo "</result>" WScript.echo "<result>" WScript.echo "<channel>Calculated free</channel><value>" & strCalculatedFree & "</value>" WScript.echo "</result>" WScript.echo "</prtg>"
This will expect one parameter - the path and name of the file you want to read - put them in "" (text-marks) to avoid issues.
Add the script to your Advanced EXE folder in PRTG and create an Advanced EXE sensor. Add the path/name of the file as a parameter.
You will currently get 3x values / channels back:
- Capacity - numeric - in GB (I assume they are all GB - respective, the script does)
- Used - numeric - in percent
- Calculated Free - numeric - in GB - or what ever the Capacity channel would represent
Hope this helps you - some response will be appreciated to know if it worked for you :-)
Regards
Florian Rossmark
Aug, 2018 - Permalink
Hi Florian,
Thank you very much for this script and the effort you have taken. Only I still run into an error message.
Sensor use EXE/Script Sensor Answer not properly formatted: "(<prtg> <result> <channel>Capacity</channel><value>128.04</value> </result> <result> <channel>Used</channel><value>46.94</value> </result> <result> <channel>Calculated free</channel><value>601019,76</value> </result> </prtg> )" (code: PE132)
what am I doing wrong?
Tim
Aug, 2018 - Permalink
Your calculated result has a comma while your other results have a period. It now depends even on PRTG how this will be interpreted, respective on your operating system settings.
This is a bit dependent on the language of your operating system and your numeric settings. In order to avoid that at all, I adjusted the script a bit so it removes those decimal places and only gives you whole numbers back.
In other words - instead of 128.28 you will see 128 / instead of 128,28 you will see 128. This should be still sufficient for your task, cause I doubt that those decimal places in your case really would make a huge difference.
You as well could adjust the script to replace a period with a comma or comma with a period - depending on what would work in your case.
'Execute: 'Argument 0 = File-Path 'LegacyDiskSizeSensor.vbs "C:\path\file.txt" - alternative with UNC path: "\\server\share\path\file.txt" Dim strPath If WScript.Arguments.Count = 1 Then strPath = WScript.Arguments.Item(0) Else Wscript.Echo "Usage: cscript LegacyDiskSizeSensor.vbs ""C:\path\file.txt""" Wscript.Quit End If Dim strCapacity, strUsed Dim objFile Set objFile = CreateObject("Scripting.FileSystemObject").OpenTextFile(strPath,1) Dim strLine Do While Not objFile.AtEndOfStream strLine = Trim(objFile.ReadLine()) If LCase(Left(strLine,Len("Capacity:"))) = LCase("Capacity:") Then strCapacity = Trim(Replace(Replace(strLine, "Capacity:", "", 1, -1, 1), "GB", "", 1, -1, 1)) ElseIf LCase(Left(strLine,Len("Used:"))) = LCase("Used:") Then strUsed = Trim(Replace(Replace(strLine, "Used:", "", 1, -1, 1), "%", "", 1, -1, 1)) End If Loop objFile.Close Set objFile = Nothing If Instr(1, strCapacity, ".", 1) Then strCapacity = Left(strCapacity,Instr(1, strCapacity, ".", 1)-1) End If If Instr(1, strCapacity, ",", 1) Then strCapacity = Left(strCapacity,Instr(1, strCapacity, ",", 1)-1) End If If Instr(1, strUsed, ".", 1) Then strUsed = Left(strUsed,Instr(1, strUsed, ".", 1)-1) End If If Instr(1, strUsed, ",", 1) Then strUsed = Left(strUsed,Instr(1, strUsed, ",", 1)-1) End If Dim strCalculatedFree strCalculatedFree = -1 'default is -1 - this would indicate the calculation wasn't possilble due to non numeric values If IsNumeric(strCapacity) And IsNumeric(strUsed) Then If strUsed <= 0 Then 'avoiding multiplaction with 0 strCalculatedFree = strCapacity Else strCalculatedFree = strCapacity * (strUsed / 100) End If strCalculatedFree = Round(strCalculatedFree,0) End If WScript.echo "<prtg>" WScript.echo "<result>" WScript.echo "<channel>Capacity</channel><value>" & strCapacity & "</value>" WScript.echo "</result>" WScript.echo "<result>" WScript.echo "<channel>Used</channel><value>" & strUsed & "</value>" WScript.echo "</result>" WScript.echo "<result>" WScript.echo "<channel>Calculated free</channel><value>" & strCalculatedFree & "</value>" WScript.echo "</result>" WScript.echo "</prtg>"
Let me know if this solved the issue - I sure hope it did :-)
Florian Rossmark
Aug, 2018 - Permalink
Hi Florian,
again thank you very much. but now get a slightly different error message.
Sensor Schijf Gebruik Answer not properly formatted: "(C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXE\SchijfGebruik.vbs(67, 1) Compilatiefout Microsoft VBScript: Instructie wordt verwacht )" (code: PE132)
System info:
Windows 7 pro 64 Bit
Tim
Aug, 2018 - Permalink
Translating this, it says instruction expected.
To move forward, this is what I have and proofed it works in a CMD as well as in PRTG just fine:
The script posted above and a simple text-file having the following content
=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2018.08.14 07:14:03 =~=~=~=~=~=~=~=~=~=~=~= 220 X300 TELNET server, service ready X300> user *** 331 User name okay, need password X300> pass *** 230 User logged in, proceed X300> #GETSTATS Capacity: 128.04GB Used: 0.00 % Write Protected: 0.00 % First File: N/A Last File: N/A #END X300> QUIT
The file name and path is provided as a parameter in "" (test-marks) - cause the script expects only one parameter and any spaces etc. would interfere here.
Could you test the whole script in a CMD prompt to see if it works on your system at all? I have it working just fine on my end. In a CMD prompt as well as a sensor in PRTG.
PS: in order to test this in a CMD prompt - please execute the script per
CSCRIPT Scriptname.vbs "pathtofile"
Put the CSCRIPT first - this bypasses that the script is executed per WSCRIPT
Difference between CSCRIPT in a CMD and WSCRIPT: Note: WSCRIPT will be used by default for any executed .VBS script - if you don't specify WSCRIPT will executing a .VBS it will still be used.
WSCRIPT will show you dialog-boxes while CSCRIPT will move the whole WSCRIPT.ECHO to the CMD - this is a huge difference and will help you while avoiding getting to many dialog-boxes while testing around...
Keep us posted!
Florian Rossmark
Aug, 2018 - Permalink
This is the result of the CMD.
C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXE>CSCRIPT SchijfGeb ruikV2.vbs "C:\PRTGKitty\Logs\10.135.137.205.log" Microsoft (R) Windows Script Host versie 5.8 Copyright (C) Microsoft Corporation 1996-2001. Alle rechten voorbehouden. <prtg> <result> <channel>Capacity</channel><value>128</value> </result> <result> <channel>Used</channel><value>54</value> </result> <result> <channel>Calculated free</channel><value>69</value> </result> </prtg>
Aug, 2018 - Permalink
Hi Tim,
Thank you for posting this. The results are correct and it look all good. The issue you have, the script is in the wrong folder and the sensor is an EXE sensor, instead of an Advanced EXE.
Please put the script in to the directory
C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML
and use a
EXE/Script Advanced
Sensor to execute it.
This should resolve your issues.
Keep us updated :-)
Florian Rossmark
Aug, 2018 - Permalink
Florian,
Awesome! it seems to work. Thank you very much for your help and time. I can continue with this!
thanks again
Tim
Aug, 2018 - Permalink
Florian
I still have a question. I started working with the script to make another sensor with it.
The senor must show how many days have been recorded.
Days Recording: 0.00
if there is in the log 5.17 I only see 0 in the sensor. Only if there are 5, 5 will be displayed.
Tim
Aug, 2018 - Permalink
Hi Tim,
Your issue remains the period vs. the comma. Imperial vs. metric if you want so...
What you want to do is adjust the script so it replaces the period (.) with a comma (,).
Look at the adjusted script below, this should help you
'Execute: 'Argument 0 = File-Path 'LegacyDiskSizeSensor.vbs "C:\path\file.txt" - alternative with UNC path: "\\server\share\path\file.txt" Dim strPath If WScript.Arguments.Count = 1 Then strPath = WScript.Arguments.Item(0) Else Wscript.Echo "Usage: cscript LegacyDiskSizeSensor.vbs ""C:\path\file.txt""" Wscript.Quit End If Dim strCapacity, strUsed Dim objFile Set objFile = CreateObject("Scripting.FileSystemObject").OpenTextFile(strPath,1) Dim strLine Do While Not objFile.AtEndOfStream strLine = Trim(objFile.ReadLine()) If LCase(Left(strLine,Len("Capacity:"))) = LCase("Capacity:") Then strCapacity = Trim(Replace(Replace(strLine, "Capacity:", "", 1, -1, 1), "GB", "", 1, -1, 1)) ElseIf LCase(Left(strLine,Len("Used:"))) = LCase("Used:") Then strUsed = Trim(Replace(Replace(strLine, "Used:", "", 1, -1, 1), "%", "", 1, -1, 1)) End If Loop objFile.Close Set objFile = Nothing strCapacity = Trim(Replace(strCapacity, ".", ",", 1, -1, 1)) strUsed = Trim(Replace(strUsed, ".", ",", 1, -1, 1)) Dim strCalculatedFree strCalculatedFree = -1 'default is -1 - this would indicate the calculation wasn't possilble due to non numeric values If IsNumeric(strCapacity) And IsNumeric(strUsed) Then If strUsed <= 0 Then 'avoiding multiplaction with 0 strCalculatedFree = strCapacity Else strCalculatedFree = strCapacity * (strUsed / 100) End If strCalculatedFree = Round(strCalculatedFree,0) End If WScript.echo "<prtg>" WScript.echo "<result>" WScript.echo "<channel>Capacity</channel><value>" & strCapacity & "</value>" WScript.echo "</result>" WScript.echo "<result>" WScript.echo "<channel>Used</channel><value>" & strUsed & "</value>" WScript.echo "</result>" WScript.echo "<result>" WScript.echo "<channel>Calculated free</channel><value>" & strCalculatedFree & "</value>" WScript.echo "</result>" WScript.echo "</prtg>"
What I changed is the blog starting at line 30 (I highly recommend using Notepad++ to edit those scripts, it has a pretty good syntax highlighting feature).
If Instr(1, strCapacity, ".", 1) Then strCapacity = Left(strCapacity,Instr(1, strCapacity, ".", 1)-1) End If If Instr(1, strCapacity, ",", 1) Then strCapacity = Left(strCapacity,Instr(1, strCapacity, ",", 1)-1) End If If Instr(1, strUsed, ".", 1) Then strUsed = Left(strUsed,Instr(1, strUsed, ".", 1)-1) End If If Instr(1, strUsed, ",", 1) Then strUsed = Left(strUsed,Instr(1, strUsed, ",", 1)-1) End If
was replaced with
strCapacity = Trim(Replace(strCapacity, ".", ",", 1, -1, 1)) strUsed = Trim(Replace(strUsed, ".", ",", 1, -1, 1))
This will actually replace the period with a comma - so that it matches the number settings of your local system. This is a pretty common issue. I grew up in Germany with a comma on my number block and had to adjust while living in the USA to the period. The advantage over here is that I can type e.g. IP addresses way quicker and a lot of coding on the US keyboard is easier due to less key strokes needed - in any case - those are the quirks of IT, lol.
Hope this helps you :-)
Florian Rossmark
Aug, 2018 - Permalink
Florian,
what am I doing wrong. I am really a noob in scripting. When I run this script with CMD. I get the right value.
C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML>CSCRIPT dagen. vbs "C:\PRTGKitty\Logs\10.133.216.40.log" Microsoft (R) Windows Script Host versie 5.8 Copyright (C) Microsoft Corporation 1996-2001. Alle rechten voorbehouden. <prtg> <result> <channel>Dagen</channel><value>1,1</value> </result> </prtg>}}} But when I do this with a sensor, I only get to see 0. {{{ Kanaal ID Laatste Waarde Minimale Maximale Instellingen Dagen 2 0 dagen 0 dagen 1 dagen Uitvaltijd -4
This is the script I changed
'Execute: 'Argument 0 = File-Path 'LegacyDiskSizeSensor.vbs "C:\path\file.txt" - alternative with UNC path: "\\server\share\path\file.txt" Dim strPath If WScript.Arguments.Count = 1 Then strPath = WScript.Arguments.Item(0) Else Wscript.Echo "Usage: cscript LegacyDiskSizeSensor.vbs ""C:\path\file.txt""" Wscript.Quit End If Dim strDagen Dim objFile Set objFile = CreateObject("Scripting.FileSystemObject").OpenTextFile(strPath,1) Dim strLine Do While Not objFile.AtEndOfStream strLine = Trim(objFile.ReadLine()) If LCase(Left(strLine,Len("Days Recording:"))) = LCase("Days Recording:") Then strDagen = Trim(Replace(Replace(strLine, "Days Recording:", "", 1, -1, 1), "dagen", "", 1, -1, 1)) End If Loop objFile.Close Set objFile = Nothing strDagen = Trim(Replace(strDagen, ".", ",", 1, -1, 1)) WScript.echo "<prtg>" WScript.echo "<result>" WScript.echo "<channel>Dagen</channel><value>" & strDagen & "</value>" WScript.echo "</result>" WScript.echo "</prtg>"
Thanks a lot
Tim (the Netherlands ;)
Aug, 2018 - Permalink
Hi Tim,
After Dim strDagen put a line that sets a default value - like strDagen = -1 - this would then later be overwritten with the right value from the file, assuming there was one found - otherwise the default value would be true and you would know that the value wasn't found in the file.
There is a Do While to Loop - loop - in this loop the next line from the file is read and then checked if there is a specific value in the line. Once you found this line and because you only check for one item, you could put a Exit Do before the End If - meaning only the first appearance you your Days Recording: will be obeyed and the script will stop processing the file afterwards.
Now - you say you only see 0 in PRTG - this raises questions like how did you define the channel - like a count value, etc... your issue might be there... you did not yet set a default value, what makes me wonder about the 0 you see.
It could be the line to replace the "." period with the "," comma might be unnecessary - you could try what happens if you leave the period instead - right now I am not sure about all your system settings and how PRTG would react there - it's at least worth a try.
In any case - please activate the WRITE results to disk and check those files - if you see a value like 1,1 then check the channel settings (value type count, percent, etc..) and try a period instead of a comma (two tests - change one setting at a time). If you see 0 in the output logs - then you need to check the file you are looking in to... or adjust your script.
Don't forget to disable the write results to disk afterwards, it would partly have an impact on the system performance.
There are some really helpful information in the KB of PRTG in regards to channel value types - this might be very helpful.
Your script and results look good to me so far..
Hope this helps you
Florian Rossmark (USA/Germany) www.it-admins.com
Aug, 2018 - Permalink
Florian,
It is unbelievable but prtg log shows the correct data.
<prtg>
<result>
<channel>Dagen</channel><value>0,16</value>
</result>
</prtg>
So it seems to be the institutions. But I have adjusted a number of things but unfortunately no improvement.
Tim
Aug, 2018 - Permalink
Hi Tim,
The comma or period (, or .) is something I am not certain about - I can't fully simulate this here.
Assuming this is all good - I would try to adjust the unit settings in the channel...
This link references Advanced EXE sensors: https://www.paessler.com/manuals/prtg/exe_script_advanced_sensor Here is a reference to Units in custom sensors: https://www.paessler.com/manuals/prtg/custom_sensors#advanced_sensors
I understand that you calculate this in days. Now - this could be re-calculated as well in to hours... to get a better value - but it as well depends on what you really need / want to see:
strDagen = Round((strDagen * 24),0)
(place this after the replace line / or instead)
The above is just an example - assuming you multiply the days value with 24 hours you and round it to 0 decimal places you might get a value that PRTG easily can interpret - probably as Count or TimeHours
You sure reached a point where it comes down to the interpretation of the data by PRTG.
Aug, 2018 - Permalink
Hi Tim,
There as various questions about this:
Regards
Florian Rossmark
www.it-admins.com
Aug, 2018 - Permalink