Mirth: Monitor and Send Alerts every X hours

Hi;

This is a very quick post as I want to link the code to someone asking a question on LinkedIn.

Any one who has dealt with Mirth alerts knows that you can get flooded by messages when there is a problem.

I wrote this channel to alert us every 3 hours if a problem occurred in a fairly important channel.

You can see in this code how I use the ChannelUtil class to collect data.

You can also use this class to control the channel and connectors.  Here’s the documentation.

Here’s the code that is in a javascript writer destination.


var olissr = '91d05f9d-6020-4ecc-b9fb-5301c77a1e0f'; //this is the target channel

var cstate = ChannelUtil.getChannelState(olissr).toString(); //declares the channel as a channel util object

//get the stats

var cQ = ChannelUtil.getQueuedCount(olissr);
var cE = ChannelUtil.getErrorCount(olissr);
var cS = ChannelUtil.getSentCount(olissr);

//get the previous stats from the globalChannelMap for comparison purposes.
var tq = globalChannelMap.get('tq');
var te = globalChannelMap.get('te');
var ts = globalChannelMap.get('ts');
var lt = globalChannelMap.get('curtime');
var ltms = globalChannelMap.get('timelastmsgsent');
var ltas = globalChannelMap.get('activitylastalert');
var ltaserror = globalChannelMap.get('errorlastalert');
var curtime = java.util.Calendar.getInstance().getTimeInMillis();
//puts the variables into the channelMap in case they're needed by the mailer.

channelMap.put('cQ',cQ);
channelMap.put('tq',tq);
channelMap.put('ds',ds);
channelMap.put('e',cE);
channelMap.put('s',cS);
channelMap.put('lastime',lt);
var timediff = curtime - lt;

channelMap.put('tdiff',timediff);

globalChannelMap.put('tq',cQ);
globalChannelMap.put('te',cE);
globalChannelMap.put('ts',cS);
globalChannelMap.put('curtime',curtime);

//error

var errordiff = cE - te;
if (errordiff > 0) {

var leralert = ((curtime - ltaserror)/1000)/60;

if (leralert > 15) {

channelMap.put('SendAlert','yes');
channelMap.put('AlertSubject','Errors on OLIS-SR Channel!');

var body = "There are errors on the OLIS-SR Channel!\nErrorCount: " + te + "\nDifference in error count since last check: " + errordiff + "\n";
channelMap.put('AlertBody',body);
globalChannelMap.put('errorlastalert',curtime);
return;
}

}
//inactivity

ics = parseInt(cS);
its = parseInt(ts);

var ds = cS - ts;

if (ds != 0) {

ltms = curtime;
globalChannelMap.put('timelastmsgsent',curtime);

} else {
var timelag = ((curtime - ltms)/1000) / 60;

channelMap.put('timelaginmin',timelag);
channelMap.put('alertlag',alertlag);
if (timelag > 60) {
var alertlag = ((curtime - ltas)/1000) / 60;

if (alertlag > 120) {

channelMap.put('timelag',timelag);

channelMap.put('SendAlert','yes');
channelMap.put('AlertSubject','Inactivity on OLIS-SR Channel!');
channelMap.put('AlertBody','There has been no activity on the OLIS-SR Channel for ' + timelag + ' minutes!');

globalChannelMap.put('activitylastalert',curtime);
return;
}

}
}

Advertisements

One thought on “Mirth: Monitor and Send Alerts every X hours

  1. Pingback: Mirth: Monitor and Send Alerts every X hours | Dinesh Ram Kali.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s