Announcement

Collapse
No announcement yet.

File count with Mirth ??

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • File count with Mirth ??

    I want to set up a alerting system to receive an email when the number of files in a folder exceeds a certain threshold. (This way I could monitor if receiving destinations process files normally, as some receiving applications fail rather frequentely!)

    I thought Mirth could be helpful to "simply" count files in a folder and send an email if count is too high. Unfortunately, I could find nothing helpful so far.

    Any ideas about this out there?

    Thanks for any help.
    JJ Mouris
    FFE Luxembourg
    IT-Department

  • #2
    This would actually be pretty easy to do with a little bit of Java/JavaScript code. Within any JavaScript context (transformer, JS Reader/Writer, Pre-/Post-processor script, etc.), use the Java File class to point to your folder. You could then use File's listFiles() method to get a list of all of the files within that folder. That returns an array, so you could just use the length property of the array to determine the number of files in the folder. Then, if that count is greater than your threshold, you can programatically trigger an alert by calling alerts.sendMessage(). Then set up an alert for your channel to be triggered on the ERROR-302 (Custom Transformer) alert error code (this is the code that is raised when calling alerts.sendMessage()). Et voila!

    Your code might look something like this:

    var folder = Packages.java.util.File("/myfolder");
    var numFiles = folder.listFiles().length;
    if (numFiles > myMaxThreshold)
    {
    alerts.sendMessage("File count has reached maximum!");
    }

    Comment


    • #3
      Since the time I posted this question, we had come to a solution using exactly this listFile.lenth() function.

      Works perfect for us.
      JJ Mouris
      FFE Luxembourg
      IT-Department

      Comment


      • #4
        I couldn't get this to work with Packages.java.util.File so I used Packages.java.io.File. I set up a MonitoringChannel with Javascript Reader as source & destination of channel writer with none as destination channel and the below code:

        ///Script to validate that their arent to many files in the pickup directory
        importPackage(java.io);
        importClass(java.io.File);
        var folder = new Packages.java.io.File("/myfolder");
        var numFiles = folder.listFiles().length;
        var myMaxThreshold = 5;
        if (numFiles > myMaxThreshold)
        {
        alerts.sendAlert('File count has reached maximum!');
        }

        Comment

        Working...
        X