File count with Mirth ??

02-04-2010, 01:03 PM

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.

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!

Comment

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:

We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, personalize advertising, and to analyze site activity. We may share certain information about our users with our advertising and analytics partners. For additional details, refer to our Privacy Policy.

By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.