Our FTP server automatically creates a new log file each day. I'd like to use the "File Content Sensor" (https://www.paessler.com/manuals/prtg/file_content_sensor.htm) to check the newest file each day. I tried to use the (*) wildcard in my sensor for d$\directory\to\log\files\* but does not seem to work and keeps failing.
Any input would be greatly appreciated.
Thank you.
Article Comments
Thank you for the reply. However, in the documentation it states "Enter the full path to the file this sensor will monitor. For example, enter C:\Windows\file.txt . You may use the star symbol (* ) as a wildcard here."
So is this not true, or when do you plan to have this implemented?
Feb, 2013 - Permalink
This is simply a fault in the documentation, I'm afraid. I apologize for confusion caused, we will correct this of course in the manual.
Feb, 2013 - Permalink
So it seems that it's a bit counter intuitive that the log file monitor can only monitor ONE log file at a time, yet a new log file is generated every day for PRTG (as an example Logs (Web Server)). That means it will never be possible to use PRTG it self to monitor its own log files (as an example - we want to monitor logins and logouts of PRTG).
Does that make sense?
It seems that either the log files for PRTG should be changed to allow them to be monitored without having to change the file name every day, or the monitor should be adjusted / upgraded / changed.
It's a bit silly that PRTG can't even be used to monitor it self in this type of situation.
May, 2013 - Permalink
Noted, I will bring this up in the next developers meeting and let you know what comes of it here. Thank you for your input on this.
May, 2013 - Permalink
Soooooooo... four years later this is a long developers meeting. I guess I can't complain about my 4-8 hour meetings lol.
Jab aside, I have the same issue. An option to use wildcards AND scan the latest file that the wildcard matches would be handy... Otherwise this is a kind of useless sensor ATM.
Thanks,
May, 2017 - Permalink
Hello, I understand your point, we did not add a result of that meeting here. Thing is, we have seen very very few requests for a wildcard feature for the File Sensors in PRTG. That lead us to give other projects / features a much higher priority. We do have it on the wish list still, with no ETA set though.
Please use the Custom Exe Sensors as workarounds.
May, 2017 - Permalink
add me to this request... The file monitor has no real use monitoring log files if you cant either monitor every file in a directory, or monitor using a wild card like Security_Log_*.txt so that it could cover daily log files, Security_Log_12302017.txt
Dec, 2017 - Permalink
Oh, sorry, I just noticed I was the last person requesting this already... Im looking for a solution yet again.. How would i use a custom exe sensor to look for "Authentication Failed" within 10 text files?
Dec, 2017 - Permalink
Hi there. I've got the same Problem. Need a filesensor to monitor the content of a file like "error", "warning" etc. with rolling names like error-timestamp.log (example: error-20180322.log)
Is there still no solution using wildcards on filenames I want to monitor. After searching your KB I cannot understand your statement:
"Thing is, we have seen very very few requests for a wildcard feature for the File Sensors in PRTG"
There are a lot of Questions exactly asking for this.
Solution in KB Article https://helpdesk.paessler.com/en/support/solutions/articles/76000063510-can-i-use-placeholders-in-file-names-to-monitor-log-files only checks for filesize or newer files with wildcards, so it is useless for the problem users have in this post.
Would be great to force your developers fixing this problem and hand over a solution or new filesensor to the users needs.
Thanks an advance and regards
Mar, 2018 - Permalink
I also have the need for this functionality in PRTG. Most applications write daily log files, instead of one rolling log file, due to filesize efficiency.
So. + 1 for this request.
Jul, 2018 - Permalink
Note from Paessler TechSupport: While the File Content Sensor cannot work with wildcards in the moment, the following script should help and achieve this. Please bear in mind, it comes without official support from us, and using it will be at your own risk.
This would be possible with custom scripts - you could create a VBScript and search for the newest file in the directory etc... then open the file as a text-stream and inspect the content and processing it.
Did similar stuff several times myself, either because PRTG did not have a default sensor or I did but I wanted to have the data processed and presented differently.
There are various script examples in the knowledge base here and around the web on how this can be accomplished... In the end if often depends on specific needs so it is "hard" to come up with a generic script... if at all it would be dependent on parameters like path, wildcard filename, search phrase 1 and probably 2 as arguments, then processing this - searching the directory for the file-pattern, using the newest file (modified date) and processing it while searching for the phrases provided. If found, it would just give you a positive response or not found a negative response.
I personally would like it more advanced and specific to the needs - like how many times did the phrase come up - and if the log provides more information - I would even process and provide this.
Understanding that not everyone can write scripts, I thought I provide the below example script that might hopefully help out a bit:
'Execute: 'Argument 0 = File-Path 'Argument 1 = File-Pattern 'Argument 2 = File-Extension 'Argument 3 = Search Phrase 'GenericLogSensor.vbs "C:\path\file.txt" "file*" ".log" "error" 'Returns -1 file not found / 0 keyword not found / 1 keyword was found Dim strPath, strFilePattern, strFileExtension, strSearchPattern If WScript.Arguments.Count = 4 Then strPath = WScript.Arguments.Item(0) strFilePattern = WScript.Arguments.Item(1) strFileExtension = WScript.Arguments.Item(2) strSearchPattern = WScript.Arguments.Item(3) Else Wscript.Echo "Usage: cscript GenericLogSensor.vbs ""C:\path\file.txt"" ""file*"" "".log"" ""error""" Wscript.Quit End If If Left(strFileExtension, 1) <> "." Then strFileExtension = "." & strFileExtension End If If Right(strFilePattern, 1) <> "*" Then strFilePattern = strFilePattern & "*" End If Dim strFound strFound = -1 'default return value Dim objFS Set objFS = CreateObject("Scripting.FileSystemObject") If objFS.FolderExists(strPath) Then Dim objFolder Set objFolder = objFS.GetFolder(strPath) Dim objRE Set objRE = New RegExp objRE.IgnoreCase = True objRE.Pattern = strFilePattern Dim objFile, objNewestFile Dim datFileDate datFileDate = DateAdd("yyyy",-1000,Date()) For Each objFile in objFolder.Files If LCase(Right(objFile.Name, Len(strFileExtension))) = LCase(strFileExtension) Then If objRE.Test(objFile.Name) Then If DateDiff("s",datFileDate,objFile.DateLastModified) > 0 Then datFileDate = objFile.DateLastModified Set objNewestFile = objFile End If End If End If Next Dim strFoundFileName On Error Resume Next 'make it easy to understand and modify - not the perfect way to handle this strFoundFileName = objNewestFile.Name On Error GoTo 0 If Len(strFoundFileName) > 0 Then 'this now means we found a file strFound = 0 Dim strLine Dim objTS Set objTS = objNewestFile.OpenAsTextStream(1, -0) Do While Not objTS.AtEndOfStream strLine = objTS.ReadLine() If InStr(1, strLine, strSearchPattern, 1) Then strFound = 1 Exit Do End If Loop objTS.Close Set objTS = Nothing End If Set objNewestFile = Nothing Set objFolder = Nothing End If Set objFS = Nothing WScript.echo "<prtg>" WScript.echo "<result>" WScript.echo "<channel>" & strSearchPattern & "</channel><value>" & strFound & "</value>" WScript.echo "</result>" WScript.echo "</prtg>"
This is an Advanced EXE sensor script - please put it in the according folder in your PRTG installation.
The Parameters are:
- path
- expression to find the newest file (without the file-extension)
- file-extension
- keyword to find in the file
Results are:
- -1 = file not found
- 0 = keyword not found in file
- 1 = keyword found in file
Now you can modify the script a bit to your needs and process the found text in the file further - if you want to. Since the results are in XML you should be able to even expand this way further and give PRTG more data / channels you can monitor on. Adding additional arguments might allow you to search for various keywords as well...
Hope this helps some of you!
Regards
Florian Rossmark
Aug, 2018 - Permalink
Hello Florian Rossmark, After adding the vbs-Scipt to the PRTG Folder and generate a new Sensor, can you tell me how the parameters should look like? How do I have to configure in which log path and for which keywords the sensor should looking for? Thank you
Aug, 2020 - Permalink
Hi Marchagemann,
Have a look at the script header:
'Execute: 'Argument 0 = File-Path 'Argument 1 = File-Pattern 'Argument 2 = File-Extension 'Argument 3 = Search Phrase 'GenericLogSensor.vbs "C:\path\file.txt" "file*" ".log" "error" 'Returns -1 file not found / 0 keyword not found / 1 keyword was found
You can easily test the results with this line:
GenericLogSensor.vbs "C:\path\file.txt" "file*" ".log" "error"
Your arguments in PRTG would be like this:
"C:\path\file.txt" "file*" ".log" "error"
Seems like I did just one "mistake" - you don't need the file-name as the first parameter rather then the folder-path - that should do it, in combination with the file-name pattern and the extension. The script should work - I only just saw that I mentioned the parameters slightly wrong in the header...
"c:\folder\folder" "LogFileNamePattern*" ".log" "keyword"
Meaning:
- File-Path
- File-Name Pattern
- File Extension
- Keyword
Hope that helps.
Florian
Aug, 2020 - Permalink
Hello Florian ,
Thank you very much for this update.
we have issues with the script, we did all steps as described and we are still getting error.
could you please assist?
Thanks
Aug, 2022 - Permalink
Hello,
I'm sorry, the File Content Sensor cannot work with wildcards in the moment.
best regards.
Feb, 2013 - Permalink