Are event messages available in scripts?
-
Hello,
I would like to forward on events as they are received using the HttpBuilder similar to this topic https://forum.infiniteautomation.com/topic/3169/send-alarm-notification-to-mobile-phone
The difference is that I would like to send on all events as they are received. Is there a way to make an incoming event message available to a scripting source (possibly the text sent in an Event email)?
If possible, what would be the scripts context reference used to trigger the script?
Thank you.
-
Hi Wingnut2.0,
There is no event handler for "all" events, although that feature was implemented on a branch and not yet picked up.
For now, I would advise polling with a script for events, using a script on a cron. It's not as responsive as being event driven (although you could poll with the script arbitrarily quickly), doing something like what occurs in this thread, but probably for a time period less than a day and more like a minute: https://forum.infiniteautomation.com/topic/3147/email-last-day-s-events
In that script the eventList is a com.serotonin.m2m2.rt.event.EventInstance and have a method
.getMessageString()
that will return the translated message. https://github.com/infiniteautomation/ma-core-public/blob/main/Core/src/com/serotonin/m2m2/rt/event/EventInstance.java -
Thank you Phillip, this was very helpful.
I was not able to get this running on 3.6.0-beta.6 (not a huge deal), but no problems with 3.5.6. -
Certainly!
Do you mean that you tried it on the beta and it didn't work or you're saying that you're not using the beta and it still works? It should work for lots of older versions and still in future versions, as the post about the events email is a year and a half old at least.
-
I tried it on 3.6.0-beta.6 and received the following error -
java.lang.RuntimeException: java.lang.ClassNotFoundException: com.serotonin.m2m2.Common.getTranslations
I had an instance of 3.5.6 open and tried it there as well. It worked without error.
-
In 3.6 security was added to scripts to ensure that only a script with superadmin permissions could invoke Java code. That's probably what you're seeing.