Event Analytics – And Slight More Complex Email Notifications

Last month I posted about how to create basic email alerts fired from Event Base Alerts (https://potatoit.kiwi/2016/11/06/basic-email-alerts-event-based-alerts/)

Which is nice and lightweight and all contained within the M3BE. However it is pretty limited with only three different filters that you can define. As I mentioned in the previous post, you can user e-Collaborate or ION – of-course I missed Event Analytics as another option – it has a drools engine for us to define rules and then ‘do stuff’ 🙂

This post is about the ‘do stuff’ being send an email to a couple of people.

But first things, in order to make this work we need to drop a .jar file in to the lib directory of Event Analytics – with that in mind and with the direction that Infor are going, I’m cautious of this approach even though in the M3 Core Admin guide we have this little extract:

In a multi-tenanted world, I can’t see us being able to drop our own .jars in and I can already hear the ‘OFFS’ from the Infor Labs team handling Cloudsuite Single Tenants.

But this is a stop-gap for IFL until we can take advantage of the notifications via ION.

We will drop the mail-1.4.7.jar in to the libs directory which exposes fairly standard Java mail functions.

We then need to restart Event Analytics.

Now we go to the management pages of Event Analytics

I’ve created a session called “SACTest”

We click on the rules in SACTest so we can create new rules

Here we can see that I’ve already got two rules that I’ve been testing. PurchaseOrderNotifyTest and CustomerOrderNotifyStatus66. Under the subscriptions we can see that we are subscribing to M3, OOHEAD and MPHEAD for update operations only.

Clicking on Edit for one of the rules allows us to edit the existing rule within the web-browser/LCM. We can of-course create a new rule and then upload a .drl file or edit the file directly.

Creating a new rule provides a base template, or you can use the Infor Eclipse plugin called Smart Rules which I found useful to create a template file which I then edited manually.

Drools is pretty self descriptive, so I’ll only cover the key points

Provides our filtering, we are looking for a supplier (SUNO) of either CHINA or GOLDENF that is at status 75.

Then we initialise our message object with our mail relay settings, a from and to address, set the subject before finally sending.

Taking a closer look at the subject, we are populating it with the Purchase Order Number (PUNO), supplier (SUNO) and the status (PUST).

And we get a message like this (though obviously at status 75, not 15 :-))

At the end of the M3 Core Administration guide, there is quite a bit of useful information on Event Analytics and there is plenty of information about the drools language on the net.

Anyway, here’s the rule in all its gory glory…

package com.lawson.eventhub.analytics.drools;

import com.lawson.eventhub.EventOperation;
import com.lawson.eventhub.EventPriority;
import com.lawson.eventhub.analytics.drools.model.Event;
import com.lawson.eventhub.analytics.drools.model.HubEvent;
import com.lawson.eventhub.analytics.drools.model.Time;
import com.lawson.eventhub.analytics.drools.model.Start;
import com.lawson.eventhub.analytics.drools.model.Stop;

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

declare HubEvent
@typesafe(false)
end

rule "annotations (MPHEAD to PurchaseOrderNotify)"
@subscription(M3:MPHEAD:U)
@publisher(EventAnalytics:PurchaseOrderNotify:S)
@revision(5)

then
end

rule "Send Email on Status 15 (MPHEAD to PurchaseOrderNotify)"
no-loop
when
event : HubEvent(
publisher == "M3",
documentName == "MPHEAD",
(
operation == EventOperation.UPDATE
) &&
((elementValues.SUNO == "CHINA" || elementValues.SUNO == "GOLDENF") && elementValues.PUST == "75")
)

then

Properties props = new Properties();
props.put("mail.smtp.host", "mail.yourdomainhere");
props.put("mail.smtp.port", "25");

Session session = Session.getInstance(props);

try {

Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("tst_m3_EventAnalytics@yourdomain.here"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("your@emailaddress.here"));
message.setSubject("**TST** Purchase Order " + event.getElementValue("PUNO") + " for " + event.getElementValue("SUNO") + " status at " + event.getElementValue("PUST"));
message.setText("");

Transport.send(message);

} catch (MessagingException e) {
System.out.println(e);
}
end

This entry was posted in M3 / MoveX. Bookmark the permalink.

8 Responses to Event Analytics – And Slight More Complex Email Notifications

  1. Ahmed Taha says:

    Can we get information from another DB table while sending the email, for example to get the item description from MITMAS while sending the item information from MPDHED which doesn’t contain the description

    • potatoit says:

      I’m sure you can, but it will be a lot more involved and Event Analytics isn’t really the right place to do that. You would be better off using MeC/IeC.

      Cheers,
      Scott

  2. sanyukta2017 says:

    Hey,
    It is possible to set rule on non M3 tables in EventAnalytics? I want an event to trigger when update operation performed on the table. Is it possible to set rule for this non M3 table?

    Thanking in anticipation.

    Sanyukta

    • potatoit says:

      Hi Sanyukta,

      I wouldn’t think so. M3 is a publisher, it sends the events to event hub which distributes them to the subscribers. If there are tables external to M3, the M3BE isn’t going to know about them so the event won’t be generated.

      You could investigate database triggers with whichever database you are using.

      Cheers,
      Scott

  3. sanyukta2017 says:

    Hey Scott,

    Great article !

    Just a generic question – can we schedule the restart of event analytics ?

    We are facing a problem where event analytics stops working and works only after restarting it.

    Your thoughts and advice would be helpful. Thank you,
    Sanyukta

    • potatoit says:

      Hi Sanyukta,

      thank you.

      Yes, Event Analytics can be restarted using a scheduled task. The options you have depends on which version of the grid you are running.

      In the later versions of the grid which came with 13.2 and higher you can use REST interfaces to restart grid applications or you can use the new command line interface tool. Pre this there is an older command line tool you can use.

      If you take a look at the Infor ION Grid Administration Guide for your version of the grid and look for a section called “Managing the Grid” it has instructions.

      However, what I would strongly recommend is looking in to what is causing Event Analytics to stop – the first thing that springs to mind is, is there enough heap space allocated to Event Analytics and Event Hub? Otherwise, I’d be logging an issue with Infor.

      Cheers,
      Scott

      • sanyukta2017 says:

        Hey Scott,
        Thank you so much for the reply. It was indeed helpful. I would surely check on heap space, guess you are absolutely right with your suggestion.
        We are also planning on logging a case with Infor if it doesn’t get resolved.

        Best Wishes,
        Sanyukta

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