Sidebar
0 votes
67 views
by michael-h-5027 (14.8k points)
How can we modify all error emails from all channels?

1 Answer

0 votes

In the "System Configuration" under the "Advanced Settings" There is a checkbox for "Error Management Alert Handler Script".

This script will change how all error emails are handled.

Here is an example of a sample script:

function createModifiedErrorBody (emailOrigin, alertEmail, newError) {

   var parameterMap = qie.newParameterMap();

   newError = StringUtils.replace(newError, '\r\n', '\r');

   newError = StringUtils.replace(newError, '\r', '<br/>');

   parameterMap.put('newError', newError);

   parameterMap.put('zone', java.lang.String(emailOrigin.zoneName));

   parameterMap.put('channel', java.lang.String(emailOrigin.channelName));

   parameterMap.put('messageId', java.lang.String(emailOrigin.sourceId));

   parameterMap.put('errorCount', java.lang.String(emailOrigin.errorCount));

   parameterMap.put('threadName', java.lang.String(emailOrigin.threadName));

   parameterMap.put('date', qie.formatDate('EEE, d MMM yyyy HH:mm:ss z', alertEmail.date));

   return qie.evaluateTemplate(qie.getVariable('errorTemplate'), parameterMap, 'xml');  

}

//todo - implement alert email handling here

//qie.sendEmail('sampleFakeZZZ@NotRealEmailZZZ.com', 'testing', 'zone: ' + emailOrigin.zoneName + ' channel: ' + emailOrigin.channelName + ' body: ' + alertEmail.htmlBody + 'excetpion: ' + exceptionMessage);

if (StringUtils.equalsIgnoreCase(emailOrigin.zoneName, 'Default') && StringUtils.equalsIgnoreCase(emailOrigin.channelName, 'Error Channel1')) {

   try{

      if (StringUtils.startsWithIgnoreCase(exceptionMessage, 'ack error:')) {

         exceptionMessage = StringUtils.trim(StringUtils.substringAfter(exceptionMessage, 'ack Error:'));

      }

      var errorHl7 = qie.parseHL7String(exceptionMessage);

      errorHl7.removeFirstNode('ERR');  

      sendOriginalEmail = false;

      var emailBody = createModifiedErrorBody (emailOrigin, alertEmail, errorHl7.getNode('/'));

      qie.sendEmail(alertEmail.to, alertEmail.subject, emailBody);

      // var emailAttachments = qie.newEmailAttachmentMap();

      // qie.addEmailAttachment(emailAttachments, 'bodyHtml', alertEmail.htmlBody);

      // qie.sendEmail('sampleFakeZZZ@NotRealEmailZZZ.com', 'new error', errorHl7, emailAttachments);

   } catch (e) {

      qie.sendEmail('sampleFakeZZZ@NotRealEmailZZZ.com', 'error', e);

   }

} else {

   sendOriginalEmail = true;

}

//To send the original email after this script executes set sendOriginalEmail to true:

//To discard the original email set it to false:

// sendOriginalEmail = false;

//qie.sendEmail('sampleFakeZZZ@NotRealEmailZZZ.com', 'testing', 'this is a test');

//NOTE: If this script throws an exception the original email will be sent and a new

//      email will be created and sent to administrators with the script exception.

by michael-h-5027 (14.8k points)
...