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 folder for new files

Votes:

0

Hi,

I want notifications only when in a folder arrives a new file, how it is possible?

I have used the folder sensor but I only know to put notifications when the folder changes, I mean I receive notifications in every change, I only want notifications when the folder receives a new file.

It is possible?

Thanks!

folder-sensor prtg sensor

Created on Oct 24, 2018 9:36:34 AM



5 Replies

Votes:

0

This would be possible if you keep some kind of list behind it with a custom script - there might even be some other way(s) to accomplish this...

Can you let us know some of the background - what is really happening there and why this is important and so on - sometimes it helps to understand the reason, why and what you want to do as well as the big picture to find the best solution.

Regards

Florian Rossmark

www.it-admins.com

Created on Oct 24, 2018 2:14:06 PM



Votes:

0

I only want to receive a mail when a file arrives in a shared folder. Only that. I don't want to know if there are changes in that directory.

Thanks for your answer! :)

Created on Oct 24, 2018 2:36:57 PM



Votes:

0

Hmm... try this:

Dim strPath

If WScript.Arguments.Count = 1 Then
	strPath = WScript.Arguments.Item(0)
Else
	Wscript.Echo "Usage: cscript GenericLogSensor.vbs ""C:\path"""
	Wscript.Quit
End If

Dim strReturn
strReturn = -99 'default return value = -99 would mean the script didn't find anything - value in minutes

Dim objFS
Set objFS = CreateObject("Scripting.FileSystemObject")
	If objFS.FolderExists(strPath) Then
		Dim objFolder
		Set objFolder = objFS.GetFolder(strPath)
			For Each objFile in objFolder.Files			
				wscript.echo DateDiff("n",objFile.DateCreated,Now())
				If DateDiff("n",objFile.DateCreated,Now()) <= strReturn Then
					strReturn = DateDiff("n",objFile.DateCreated,Now()) 'this will find the newest file...
				End If
			Next			
		Set objFolder = Nothing
	End If
Set objFS = Nothing 


WScript.echo "<prtg>"
	WScript.echo "<result>"
	WScript.echo "<channel>Newest file age in minutes</channel><value>" & strReturn & "</value>"
	WScript.echo "</result>"
WScript.echo "</prtg>"

The script is an advanced EXE/XML sensor and needs to be placed in the directory:

C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML

It is a VBS script script - so the extension is .VBS - e.g. NewestFile.vbs

You can test it on a command prompt like this:

CSCRIPT NewestFile.vbs "c:\testfolder"

As you can see - it expects a PATH parameter - use text-quotes for the path as well.. even in PRTG when you set the parameters...

Return values:

  • it returns a TIME in MINUTES or -99
  • -99 means that the script had an issue in general
  • 0 means the newest file found was created within 0 minutes
  • 1 or 2 or 3 or 4 ...... 999999 means the file was created N minutes ago

So - what do you do with this?

  • You create an EXE Advanced sensor pointing it to the directory as parameter
  • you edit the sensor channel "Newest file age in minutes" and set limits
    • upper limit: 6 minutes
  • you schedule the sensor to run every 5 minutes

What will happen:

  • every 5 minutes the sensor will execute
  • if there is a file that is newer then 6 minutes it will raise an error
    • this includes -99 what means there was a generic Error
    • this includes 0 what means within the past 1 minute
    • this accounts for the slack between the sensor execution of every 5 minutes
    • this will set the sensor back to NORMAL after the second or third run - meaning after 10 minutes, 15 minutes - assuming you run it every 5 minutes ...

The 5 minutes and 6 minutes is just an example - there is a slack / the execution time is not exactly every 5 minutes, so you need to account for that, that's why I suggested 6 minutes or newer as lower error limit - the NOTIFICATION needs to be adjust as well accordingly - you probably just want ERROR notifications...

Note: This will not fire for every new file - for this you would need a real file-system monitoring solution that works with AUDITING - but it at least will raise an error state of the sensor if a file (or multiple) have been created...

Hope this helps you - the script could be adjusted more and report more advanced information in theory - but I think this should cover your request already...

Regards

Florian Rossmark

www.it-admins.com

Created on Oct 24, 2018 4:00:44 PM



Votes:

0

Hi! thanks for your answer Florian!
I did it exactly like you posted but I think it isn't monitoring the folder. Do u know if this script could be work in a shared folder? I have put the path: "
10.x.x.x\project$\..." is it ok?
I think the problem can be there, but maybe is in other place... The sensor never fall, I put the limit parameters also.

Any idea?

Thanks again!

Created on Oct 25, 2018 9:29:33 AM

Last change on Oct 25, 2018 10:03:03 AM by  Luciano Lingnau [Paessler]



Votes:

0

Hi,

If it all the path would be more like "
ip_or_hostname\share\folder
" - now it depends - make sure the PRTG Probe account or the credentials that are used on that server have permissions to that share path - likely the probe.

Would actually suggest to logon to the PRTG server with those credentials and test it.

Further would I try and execute the script on the CMD / command prompt as suggested - via CSCRIPT - to see how it behaves and if it works...

What results do you see from the probe? There must be a numeric result.

Regards

Florian

Created on Oct 25, 2018 4:10:58 PM

Last change on Oct 26, 2018 8:56:06 AM by  Luciano Lingnau [Paessler]




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.