Kaseya Community

Monitor for Old Files in Queue Folder

  • I'm looking for a way to throw an alert upon aging files in a queue folder.

    I know I can use an Agent Procedure to send a batch file that writes to a log and then use log parser to watch for the condition to alert on, but that doesn't seem like a very elegant solution.


    Anybody out there have any better ideas on how to skin this cat?

     

    Much thanks,

    Chris C.

  • Forfiles is the easiest way I can think of accomplishing this. Something like this:

    forfiles /P "C:\SomeFolder" /M *.log /D -30 /C "cmd /c dir /b @path >> C:\LogFile.txt"

    This command will look for files with .log extension that are older than 30 days and output to a log file. From there, you can alert if the file contains... anything. You can even have forfiles delete the stuff if you prefer that.

  • SMason

    Forfiles is the easiest way I can think of accomplishing this. Something like this:

     

    forfiles /P "C:\SomeFolder" /M *.log /D -30 /C "cmd /c dir /b @path >> C:\LogFile.txt"

    This command will look for files with .log extension that are older than 30 days and output to a log file. From there, you can alert if the file contains... anything. You can even have forfiles delete the stuff if you prefer that.

     

    Thanks @SMason, I saw a files cleanup script in the samples folder that does almost that exact thing.   It would work perfectly except one thing...... I need it to look for files that are X minutes old, not days.  I tried altering that syntax to use /D -0.5 or /D 0.1, but it requires an integer value, not decimal. 

    If I can find a good Win32 port of the linux "find" command, then that would work great.  But the only one I can find out there that doesn't run in Cygwin has a busted downloads page right now.  

    I'm starting to think my answer here may come in the form of a vbs file...

    Any VBS wizzes out there that can throw me a line or two to find all files >= 10 minutes old?

     

    Thanks,

    Chris C.

     

     

  • This might work then: halfloaded.com/.../vbscript-delete-all-files-older-than-one-hour

    Note: that example will delete files older than one hour (over 59 minutes old). You probably want to switch the delete to a print or something to get a log file.

  • SMason

    This might work then: halfloaded.com/.../vbscript-delete-all-files-older-than-one-hour

    Note: that example will delete files older than one hour (over 59 minutes old). You probably want to switch the delete to a print or something to get a log file.

     

    Rock on @SMason.  This is exactly what I was looking for on the Agent side of this objective.  

    Now I need to figure out what mechanism to use to trigger an alarm. 

    I could output my values to a log and use the Log Parser, or output to the Event Viewer and watch for the messages there, but I would much rather have the Agent Procedure directly trigger the Alarm.

     

    Anybody know how to make an Agent Procedure directly trigger an Alarm????

     

    Thanks Guys!

    Chris C.....

  • If all you care about is whether or not there are any old files detected at all, then just use that vbscript to output the old file names to a txt file, and then in your procedure, use the Get Variable command and get the size that txt file. If there are no files it should be empty, and if anything was detected it should have some sort of contents. So then just do an IF statement that checks the size of that file, and if it's greater than 0, send an alert.

  • kcears

    If all you care about is whether or not there are any old files detected at all, then just use that vbscript to output the old file names to a txt file, and then in your procedure, use the Get Variable command and get the size that txt file. If there are no files it should be empty, and if anything was detected it should have some sort of contents. So then just do an IF statement that checks the size of that file, and if it's greater than 0, send an alert.

    That's exactly what I'm trying to do, but I don't see a step type in the Agent Procedures to send an alert or trigger an alarm.   I suppose I could have it send a raw e-mail, but I'd much prefer it to trigger an alarm so that the built-in notification system handles it.   

    Am I missing something?

    Thanks,
    Chris C.

  • If you want an actual alert you'll need to use a command like eventcreate in the IF - Then section of the procedure to create an event ID in the event logs on the agent the old files are detected on. You then create an event monitoring set for that event ID and apply it to all of your agents that you're running that procedure on. I'm pretty sure that's the cleanest way to do it, inside the procedure itself I believe you're limited to just sending e-mails.

  • kcears

    If you want an actual alert you'll need to use a command like eventcreate in the IF - Then section of the procedure to create an event ID in the event logs on the agent the old files are detected on. You then create an event monitoring set for that event ID and apply it to all of your agents that you're running that procedure on. I'm pretty sure that's the cleanest way to do it, inside the procedure itself I believe you're limited to just sending e-mails.

    When you say event monitoring, are you referring to the Windows Application Log?   If so, I already have the VBS file configured to create such an event on its own, as I figured this would be the cleanest way to handle it. 

     

    I was just hoping there was a hidden Step type that would natively trigger an alarm of some type.   Oh well!

     

    Thanks,
    Chris C.

  • Thanks for this - I have a script the does the opposite, checks if a queue folder to ensure the latest file is NOT older than x days, but this is a much more elegant solution that what I was doing.  Does it work for windows XP and server 2003?