Customizing subject and body of the emails sent out by EMC Smarts Mail Notification Adapter
search cancel

Customizing subject and body of the emails sent out by EMC Smarts Mail Notification Adapter

book

Article ID: 322911

calendar_today

Updated On:

Products

VMware

Issue/Introduction

Symptoms:


Customizing subject and body of the emails sent out by EMC Smarts Mail Notification Adapter.
Add or change fields used by "sm_notify mail" to meet custom requirements.



Environment

VMware Smart Assurance - SMARTS

Resolution

Customization of notification adapters is covered in great detail by sa_notification_adapter.pdf located in <BASEDIR>/SAM/smarts/doc/pdf directory.  Below is a summary and an example of customizing sm_notify mail. In order to customize the format of emails sent out by "sm_notiy mail" adapter, 2 files need to be modified.  Use sm_edit to modify these files so modifications are saved under local directory structure.

<BASEDIR>/SAM/smarts/local/rules/notifier/mail/mail-filter.asl and <BASEDIR>/SAM/smarts/local/rules/notifier/mail/mail-custom.asl

Modify OMIT_CLEAR_EVENTS function in mail_filter.asl file. The default function allows the mail notifier to skip "CLEAR" notifications and not send out an email once a notification has cleared. The modified function below does the same but is also allows execution of custom code that has changes or customizations to the format of the emails sent out by the notifier. Lines 51-55 contains the code the set currentEvent->sentByCustom to TRUE. By setting currentEvent->sentByCustom, we are telling the notifier to read in customizations in mail-custom.asl.

 OMIT_CLEAR_EVENTS()
    42  do {
    43      if (currentEvent->icType == "CLEAR" ""
    44          currentEvent->icType == "NL_CLEAR")
    45      {
    46          // Discard Clear events
    47          currentEvent->filterMe = TRUE;
    48          print(time()."currentEvent->filterMe is ".currentEvent->filterMe);
    49      } else if (currentEvent->icType == "NOTIFY" ""
    50                 currentEvent->icType == "NL_NOTIFY")
    51      {
    52          // Customize and forward Notify events
    53          currentEvent->sentByCustom = TRUE;
    54          print(time()."currentEvent->sentByCustom is ".currentEvent->sent ByCustom);
    55      }
    56  }

After modifying mail-filter.asl, changes need to be made to mail-custom.asl. Line 53 means changes to the "subject" line of the email specified below will be used only if currentEvent->sentByCustom is set to TRUE. This is done in mail-filter.asl above. By default, subject of an email sent out by email notifier contains "Instance Name" and event name. In the code below, we are also adding currentEvent->icDisplayType, currentEvent->icFirstNotifiedAt. Note we also call time() function on the FirstNotifiedAt value as it is notified in EPOC time by default.

    53      (currentEvent->sentByCustom)
    54  } do {
    55
    56      /*
    57       * This is how the adapter constructs the default message.
    58       * Edit to suit your tastes.
    59       */
    60     
    61      subject = currentEvent->icDisplayType." ".
    62                time(currentEvent->icFirstNotifiedAt)." ".
    63                currentEvent->icInstanceDisplayName." ".

Lines 51-77 add additional fields to the body of the email in the same manner it was done for the subject.

    51       * Only send here if sentByCustom is TRUE.
    52       */
    53      (currentEvent->sentByCustom)
    54  } do {
    55
    56      /*
    57       * This is how the adapter constructs the default message.
    58       * Edit to suit your tastes.
    59       */
    60      subject = currentEvent->icDisplayType." ".
    61                time(currentEvent->icFirstNotifiedAt)." ".
    62                currentEvent->icInstanceDisplayName." ".
    63                currentEvent->icEventDisplayName;
    64      body = ("InCharge Server: " . serverName . "\n  ".
    65              "Display Type: ".currentEvent->icDisplayType . " \n" .
    66              "Display Name: ".currentEvent->icClassDisplayName . " \n" .
    67              "Instance Display Name: ".currentEvent->icInstanceDisplayName . "\n ".
    68              "First Notified: ".time(currentEvent->icFirstNotifiedAt) . "\n ".
    69              "Last Notified: ".time(currentEvent->icLastNotifiedAt) . "\n
 ". 70              "Last Changed: ".time(currentEvent->icLastChangedAt) . "\n ".
    71              "Count: ".currentEvent->icOccurrenceCount . "\n ".
    72              "Description: ".currentEvent->icEventDescription . "\n ".
    73              "Event: ".currentEvent->icEvent . "\n ".
    74              "Display Name: ".currentEvent->icEventDisplayName ."\n".
    75              ".(" . string(currentEvent->icCertainty) . "%)\n  " .
    76              "Description: ".currentEvent->icEventDescription . "\n");
    77
    78      mailer->sendmail(sender, recipients, subject, body) ? LOG, STOP;
    79  }