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!
Article Comments
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! :)
Oct, 2018 - Permalink
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
Oct, 2018 - Permalink
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!
Oct, 2018 - Permalink
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
Oct, 2018 - Permalink
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
Oct, 2018 - Permalink