need to trigger alert if same event is greater than 3 in an hour

hydu9535
Tera Contributor

Hi All

 

we need to check the events if the event count is greater than 3 in an hour only than it should trigger an alert 

4 REPLIES 4

Mohith Devatte
Tera Sage
Tera Sage

Hello @hydu9535 ,

Where should you trigger this alert  and what is the scenario ? 

we are doing it in event management where we have created rules

Chavan AP
Kilo Sage

try this with little modification on BR:

 

 

(function executeRule(current, previous /* , g */) {
  var now = new GlideDateTime();
  var oneHourAgo = new GlideDateTime();
  oneHourAgo.addHours(-1);
  
  // Define the event name to filter
  var eventNameToFilter = 'MyEventName';

  // Query to get the count of events with the specified event name within the last hour
  var eventCount = new GlideAggregate('sysevent');
  eventCount.addAggregate('COUNT');
  eventCount.addQuery('sys_created_on', '>', oneHourAgo);
  eventCount.addQuery('name', eventNameToFilter); // Add the event name filter
  eventCount.query();

  var count = 0;
  if (eventCount.next()) {
    count = parseInt(eventCount.getAggregate('COUNT'), 10);
  }

  if (count > 3) {
    // Trigger an alert (you can replace this with your actual alert mechanism)
    gs.addInfoMessage('ALERT: Event count is greater than 3 for event name ' + eventNameToFilter + ' in the last hour!');
  }
})(current, previous);

 

Glad I could help! If this solved your issue, please mark it as Helpful and Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****

sorry it was on a event management- em_event table we get all the events and from there we need to write a event rule , i need to add the condition if the event occurs more than 3 in an hour then i need to trigger the alert