Event Filter "Time Created" options "older than" not available

  • KM03652907
  • 18-Jun-2020
  • 18-Jun-2020

Summary

This script will close incoming events that were created more than 60 minutes before OBM received them. Time is adjustable. Event Filter lifecycle Time Created "older than" options no longer available beginning with OBM 2019.05.

Question

Since OBM 2019.05 the "event forwarding rule" lifecycle filter option 'time created' selection "older than" is no longer available. 

Our customer uses this filter option to close events that were created more than an hour ago but just received instead of forwarding to Service Now.

 

Answer

We can use the following Groovy script to perform the same actions that event forwarding did prior to 2019.05.

This script will close incoming events that were created more than 60 minutes before OBM received them.

Event Filter lifecycle Time Created "older than" options no longer available beginning with OBM 2019.05.

Add the following script to  "event processing" -> "event processing customizations"

No need to select a filter for this script.

Add in the script section - timing is in milliseconds per the comment below and can be adjusted:


import java.util.List;
import com.hp.opr.api.scripting.Event;
import java.util.Date;
import com.hp.opr.api.scripting.Action;
import com.hp.opr.api.scripting.EventActionFlag;
import com.hp.opr.api.scripting.LifecycleState;
import com.hp.opr.api.scripting.MatchInfo;
import com.hp.opr.api.scripting.NodeInfo;
import com.hp.opr.api.scripting.PolicyType;
import com.hp.opr.api.scripting.Priority;
import com.hp.opr.api.scripting.ResolutionHints;
import com.hp.opr.api.scripting.Severity;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory
class GroovyScriptSkeleton
{
private static Log s_log = LogFactory.getLog("com.hp.opr.epi.testold")
def init()
{
}
def destroy()
{
}
def process(List<Event> events)
{
try
{
long now = (new Date()).getTime()
events.each {
event ->
if (now - event.getTimeCreated().getTime() > 60 * 60 * 1000)
{// 60 min as milliseconds
event.setState(LifecycleState.CLOSED);
}
if(Thread.interrupted())
throw new InterruptedException()
}
}
catch(InterruptedException e)
{
Return
}
}
}