web stats
Queued Message Alerts - Mirth Community

Go Back   Mirth Community > Mirth Connect > General Discussion

Reply
 
Thread Tools Display Modes
  #1  
Old 08-10-2010, 06:05 AM
cward cward is offline
 
Join Date: Feb 2008
Posts: 84
cward is an unknown quantity at this point
Default Queued Message Alerts

I have worked on a function (that will run in the postprocessor) that will page person on call when queued messages from any deployed channel reaches a set number. It will also stop/start a certain interface when x number of queued messages reach a certain number. The function needs to be a context of channel. You will need to set 2 channel maps one for the channel name and one for the channelid. Then you will need to set a var that has your alert values. I have some extra commands commented out that can be used for future reference. If you see any changes that can make this function better please let me know.

Thanks,
Chad

function MirthAlertsFunction(channelID, channelName, alertValues)
{
// Create an instance of the channelStatusController object
var channelStatusController = Packages.com.webreach.mirth.server.controllers.Cha nnelStatusController.getInstance();

// Commands that go with ChannelStatusController
// Start the channel responsible for processing the tables just created
//channelStatusController.startChannel( channelID );

// Stop
//channelStatusController.stopChannel( channelId );

// Pause
//channelStatusController.pauseChannel( channelID );

// Resume
//channelStatusController.resumeChannel( channelID );


// Create an instance of the ChannelStatisticsController object

// getStatistics
var channelStatisticsController = Packages.com.webreach.mirth.server.controllers.Cha nnelStatisticsController.getInstance();

// Commands that go with ChannelStatisticsController

// Get channel Statistics
var stats = channelStatisticsController.getStatistics( channelID );


// Create Subject and Body
var smtpSubject = channelName + " has an issue"
var smtpBody = channelName + " has been stopped because it has " + stats.queued + " messages Queued";


// Split alertValues to get the text values
// QueuedValue,smtpto,smtpcc,smtpfrom
var alertValues = alertValues.split('^');


if (stats.queued > alertValues[0])
{
if(stats.alerted == '0')
{
// send message
var smtpConn = SMTPConnectionFactory.createSMTPConnection();
smtpConn.send(alertValues[1], alertValues[2], alertValues[3], smtpSubject, smtpBody);

// So we do not get multiple pages will will increment the Alerted stats by 1
channelStatisticsController.incrementAlertedCount( channelID );
}
} else {
if ((stats.queued == alertValues[0] / 2 && stats.queued != '0'))
{
// Stop Interface
channelStatusController.stopChannel( channelID );

// Start Interface
channelStatusController.startChannel( channelID );

} else {
if (stats.queued < alertValues[0] && stats.alerted >= '1')
{
channelStatisticsController.clearStatistics( channelID, false, false, false, false, false, true);
}
}
}
return;
}
Reply With Quote
  #2  
Old 01-03-2011, 06:36 AM
steveman steveman is offline
Mirth Newb
 
Join Date: Apr 2009
Posts: 21
steveman is on a distinguished road
Default

Thanks! I've being looking for something like this and am glad you posted it.
Reply With Quote
  #3  
Old 02-09-2011, 12:14 PM
cward cward is offline
 
Join Date: Feb 2008
Posts: 84
cward is an unknown quantity at this point
Default Updated code

Please let me know what you think of the new code.
Attached Files
File Type: xml Mirth Alerts 1.xml (12.2 KB, 389 views)
Reply With Quote
  #4  
Old 03-16-2011, 02:25 PM
kmickeletto kmickeletto is offline
Mirth Newb
 
Join Date: Jul 2010
Posts: 24
kmickeletto is on a distinguished road
Default

Hi Chad,

This looks really nice. What all do i need to update in this? Just email address? I am anxious to tinker around with this tomorrow.

Ken

Last edited by kmickeletto; 03-16-2011 at 02:28 PM.
Reply With Quote
  #5  
Old 03-16-2011, 02:34 PM
cward cward is offline
 
Join Date: Feb 2008
Posts: 84
cward is an unknown quantity at this point
Default

You will need to update var AddName, AlertAdmin

Then you will need to update the case statements with The name of you channel in the switch statements. The default is a catch all, the other case statements are for any special channels you may have. You can add more case statements(for additional channels) as needed. Let me know how it works for you. Feel free to email me if you run into any problems.

Thanks,
Chad
Reply With Quote
  #6  
Old 04-02-2012, 07:27 AM
kt7277 kt7277 is offline
OBX.2 Kenobi
 
Join Date: Apr 2008
Location: Conway, AR
Posts: 60
kt7277
Default Needs From email address

Chad,
Thanks for the Alert code, works for me!
I tried it using version 2.2 and found that my email function was looking for a qualified From email address i.e. "Mirth@yourdomain.com".
Thanks again,
Kevin
Reply With Quote
  #7  
Old 06-22-2012, 08:48 AM
lueckep lueckep is offline
OBX.2 Kenobi
 
Join Date: Jul 2011
Posts: 73
lueckep is on a distinguished road
Default

I also wanted to say thank you for posting this channel - I'm going to use a variation of it.

I found that as is, it doesn't play nice with the standard Mirth alerts. It checks and modifies each channel's 'alerted' statistic but if you have other Mirth alerts running at the same time then they step on each others toes and you can miss sending these 'messages are queued' emails (if the alerted statistic was already > 0 from another Mirth alert) and you can send a bunch of extra 'the queue is clear now' emails (anytime the queue is < 10 but the alerted stat is > 0 from another Mirth alert).

I got around this by updating the script to use a global channel map rather than the standard 'alerted' channel statistic.
Reply With Quote
  #8  
Old 08-28-2012, 02:32 PM
sbdrummond sbdrummond is offline
What's HL7?
 
Join Date: Aug 2012
Posts: 2
sbdrummond is on a distinguished road
Default Queue messaged alerts - Mirth 2.2

Hello, I have taken this example and created an alert as below : It fails to actually Alert at all, and displays this error in the server log : Any help much appreciated! Does it have anything to do with the new version since this post is older? Or, I supposed I am missing something very obvious given that I am a newbie!


[2012-08-28 14:26:41,252] ERROR (com.mirth.connect.connectors.js.JavaScriptMessage Receiver:145): org.mozilla.javascript.WrappedException: Wrapped org.apache.commons.mail.EmailException: Missing final '@domain' (bfc62f2e-d170-4507-83a9-8cce08baaa71#93)


[2012-08-28 14:27:37,571] FATAL (org.mule.impl.DefaultComponentExceptionStrategy:8 3): The Default Component Exception Strategy has been invoked but there is no current event on the context

[2012-08-28 14:27:17,410] FATAL (org.mule.impl.DefaultComponentExceptionStrategy:8 4): The error is: null
java.lang.NullPointerException
at com.mirth.connect.connectors.js.JavaScriptMessageR eceiver.poll(JavaScriptMessageReceiver.java:81)
at org.mule.providers.PollingMessageReceiver.run(Poll ingMessageReceiver.java:97)
at org.mule.impl.work.WorkerContext.run(WorkerContext .java:290)
at edu.emory.mathcs.backport.java.util.concurrent.Thr eadPoolExecutor.runWorker(ThreadPoolExecutor.java: 1061)
at edu.emory.mathcs.backport.java.util.concurrent.Thr eadPoolExecutor$Worker.run(ThreadPoolExecutor.java :575)
at java.lang.Thread.run(Unknown Source)


Channel source javascript :

// Here we will set up the values for the Alert Email/Pages
// Here we will set the flags for Ugrades or Downtime
var AlertFlagDowntime = "N";
var AlertFlagUpgrade = "N";

// Here we will set values for each user
var AddName = 'myemail@email.com';

// Value for Admin
var AlertAdmin = AddName;


// First thing we want to see if we need to send alerts based on the alert flags
if(AlertFlagUpgrade.toString() == "N" && AlertFlagDowntime.toString() == "N")
{

// Now we want to check to see if Hour is not 00 or 01. This is when most systems are doing there nightly backup and messages could be queued nightly during
// this process.
if(DateUtil.getCurrentDate('HH') >= '02')
{
// create an array of deployed channels
// Create an instance of the channelStatusController object
var channelStatusController = Packages.com.mirth.connect.server.controllers.Chan nelStatusController.getInstance();
var test = channelStatusController.getChannelStatusList();

// get stats of each channel in array
var dc = channelStatusController.getChannelStatusList().toS tring().split("],");

for (var i=0; i<dc.length; i++)
{
// Now we will get the channelID so we can get the stats.queud
var getchannellist = dc[i].toString().split("=");
var getchannelid = getchannellist[1].toString().split(",");
var channelid = getchannelid[0];

// Now we will get the stats for that channelid

// Create an instance of the ChannelStatisticsController object
// getStatistics
var channelStatisticsController = Packages.com.mirth.connect.server.controllers.Chan nelStatisticsController.getInstance();

// Commands that go with ChannelStatisticsController
// Get channel Statistics
var stats = channelStatisticsController.getStatistics( channelid );

// Now we will check to see if the the stats.queued is over 100
// If so we need to compare the channel Name to get some values to use for the alerts
if(stats.queued > 5)
{
// Now we need to get the Channel Name
var channelController = Packages.com.mirth.connect.server.controllers.Chan nelController.getInstance();
var CN = channelController.getDeployedChannelById(channelid ).getName();

// Now that we have the channel Name we need to see what criteria to use for the alert

// Now we will make a value to use as a switch variable
var CNValue = CN.toString();

switch (CNValue) {
case 'SORIAN':
// Now we will see if the stats.queued equals values to send page
if(stats.queued > '300' && stats.alerted == '0'){
// send issue message
var smtpConn = SMTPConnectionFactory.createSMTPConnection();
var smtpto = AlertAdmin;
var smtpsubject = CN + " has an issue"
var smtpbody = CN + " has " + stats.queued + " messages Queued";

var smtpConn = SMTPConnectionFactory.createSMTPConnection();
smtpConn.send(smtpto, '', 'Mirth', smtpsubject, smtpbody);

// So we do not get multiple pages will will increment the Alerted stats by 1
channelStatisticsController.incrementAlertedCount( channelid );
}


break;


default:
// Now we will see if the stats.queued equals values to send page
if(stats.queued > '100' && stats.alerted == '0'){
// send issue message
var smtpConn = SMTPConnectionFactory.createSMTPConnection();
var smtpto = AlertAdmin;
var smtpsubject = CN + " has an issue"
var smtpbody = CN + " has " + stats.queued + " messages Queued";

var smtpConn = SMTPConnectionFactory.createSMTPConnection();
smtpConn.send(smtpto, '', 'Mirth', smtpsubject, smtpbody);

// So we do not get multiple pages will will increment the Alerted stats by 1
channelStatisticsController.incrementAlertedCount( channelid );
}

break;
}
} else {
if (stats.queued < 10 && stats.alerted >= '1')
{
channelStatisticsController.clearStatistics( channelid, false, false, false, false, false, true);


// Now we need to get the Channel Name
var channelController = Packages.com.mirth.connect.server.controllers.Chan nelController.getInstance();
var CN = channelController.getDeployedChannelById(channelid ).getName();

// Now that we have the channel Name we need to see what criteria to use for the alert

// Now we will make a value to use as a switch variable
var CNValue = CN.toString();

switch (CNValue) {

case 'SORIAN':
// send Resolved message
var smtpConn = SMTPConnectionFactory.createSMTPConnection();
var smtpto = AlertAdmin + ", " + AlertConnectRX;
var smtpsubject = CN + " issue had been resolved"
var smtpbody = CN + " messages are processing now ";

var smtpConn = SMTPConnectionFactory.createSMTPConnection();
smtpConn.send(smtpto, '', 'Mirth', smtpsubject, smtpbody);
break;

default:
// send Resolved message
var smtpConn = SMTPConnectionFactory.createSMTPConnection();
var smtpto = AlertAdmin;
var smtpsubject = CN + " issue had been resolved"
var smtpbody = CN + " messages are processing now ";

var smtpConn = SMTPConnectionFactory.createSMTPConnection();
smtpConn.send(smtpto, '', 'Mirth', smtpsubject, smtpbody);
break;
}

}
}
}
}
}
Reply With Quote
  #9  
Old 08-29-2012, 07:54 AM
cward cward is offline
 
Join Date: Feb 2008
Posts: 84
cward is an unknown quantity at this point
Default

smtpConn.send(smtpto, '', 'Mirth', smtpsubject, smtpbody);

You now need to have something like:

smtpConn.send(smtpto, '', 'Mirth@yourdomain.org', smtpsubject, smtpbody);
Reply With Quote
  #10  
Old 08-29-2012, 08:08 AM
sbdrummond sbdrummond is offline
What's HL7?
 
Join Date: Aug 2012
Posts: 2
sbdrummond is on a distinguished road
Default Queue Message Alert

Chad,
That did it.

Thanks,
Scott
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 10:53 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation