What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Monitor multiple log files using the "File Content Sensor"

Votes:

0

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.

file-content log-files wildcard

Created on Feb 12, 2013 8:59:37 PM

Last change on Feb 13, 2013 4:21:49 PM by  Daniel Zobel [Product Manager]



Best Answer

Accepted Answer

Votes:

7

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

www.it-admins.com

Created on Aug 15, 2018 3:24:51 PM

Last change on Aug 16, 2018 9:41:20 AM by  Torsten Lindner [Paessler Support]



16 Replies

Votes:

0

Hello,

I'm sorry, the File Content Sensor cannot work with wildcards in the moment.

best regards.

Created on Feb 13, 2013 5:30:23 PM by  Torsten Lindner [Paessler Support]



Votes:

0

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?

Created on Feb 13, 2013 6:40:23 PM



Votes:

0

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.

Created on Feb 14, 2013 2:08:43 PM by  Torsten Lindner [Paessler Support]



Votes:

0

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.

Created on May 2, 2013 2:43:32 PM



Votes:

0

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.

Created on May 2, 2013 7:47:33 PM by  Greg Campion [Paessler Support]



Votes:

0

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,

Created on May 27, 2017 11:17:21 PM



Votes:

0

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.

Created on May 29, 2017 7:28:33 AM by  Torsten Lindner [Paessler Support]



Votes:

0

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

Created on Dec 30, 2017 11:35:30 PM



Votes:

0

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?

Created on Dec 30, 2017 11:37:24 PM



Votes:

1

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://kb.paessler.com/en/topic/67965-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

Created on Mar 22, 2018 12:29:43 PM



Votes:

0

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.

Created on Jul 25, 2018 9:12:13 AM



Votes:

0

+1 for this feature

Created on Aug 15, 2018 1:36:35 PM



Accepted Answer

Votes:

7

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

www.it-admins.com

Created on Aug 15, 2018 3:24:51 PM

Last change on Aug 16, 2018 9:41:20 AM by  Torsten Lindner [Paessler Support]



Votes:

0

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

Created on Aug 24, 2020 11:03:18 AM



Votes:

0

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

Created on Aug 25, 2020 3:39:52 PM



Votes:

0

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

Created on Aug 3, 2022 9:43:55 AM




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.