Groovy web console

subscribe to the feed Subscribe
to this
site

test

Published 5 months ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import java.util.List;
import java.util.Date;
import com.hp.opr.api.scripting.Action;
import com.hp.opr.api.scripting.Event;
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 com.hp.opr.api.ws.model.event.ci.OprSourceCiHints;
import com.hp.opr.api.ws.model.event.OprSourceInfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

class Modify_halEsAlertInquiryTrap_Date {

 private static Log s_log = LogFactory.getLog("com.hp.opr.epi.Modify_halEsAlertInquiryTrap_Date");
 def init() {
 }
 def destroy() {
 }

 def process (List<Event> events) {
  events.each { event ->modifyEvent(event) }
 }
 def modifyEvent(Event event) {
  try {
   def timeReceived = event.getTimeReceived()()
   def customDate
   def dateReceived = timeReceived =~ /((.*?)\s)/
   if(dateReceived.find()) {
    customDate = dateReceived[0][0].toString()
    event.addCustomAttribute("customDate",customDate)
   }
   
   } catch (Exception e) {
   s_log.error("Modify_halEsAlertInquiryTrap_Date : Exception encountered: ", e)
  }
 }
}