web stats
Mirth Community - View Single Post - Mirth Tools: User defined functions
View Single Post
Old 04-17-2012, 03:26 PM
glenn71 glenn71 is offline
OBX.3 Kenobi
Join Date: Nov 2010
Location: Sydney Australia
Posts: 129
glenn71 is on a distinguished road

Function to Stop a channel if it reaches a particular error count. Also sends an alert message via another channel (this sends a sms via our monitoring system).

function stopOnErrorCount(cid, errorCount) {
	var channelStatisticsController = Packages.com.mirth.connect.server.controllers.ChannelStatisticsController.getInstance();
	var channelStatusController = Packages.com.mirth.connect.server.controllers.ChannelStatusController.getInstance();
	var stats = channelStatisticsController.getStatistics(cid);
	// var numOfQueued = stats.queued;
	var numOfErrors = stats.error;

	if(numOfErrors > errorCount )
		//Stop Me
		//Alert msg sent to _SVHALERT channel
		var channelController = Packages.com.mirth.connect.server.controllers.ChannelController.getInstance();
		var channelName = channelController.getDeployedChannelById(cid).getName();
		var alertmsg = 'mirth01 mirth_channel_status codeTemplate_stopOnErrorCount 0 ' +
					   'channel ' + channelName + ' stopped';
		router.routeMessage('_SVHALERT', alertmsg);

To use this in the Postprocessor:
// will stop the current channel when errorcount greater than 10.
stopOnErrorCount(channelId, 10);
Reply With Quote