need to trigger alert if same event is greater than 3 in an hour
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2023 02:29 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2023 02:33 AM
Hello @hydu9535 ,
Where should you trigger this alert and what is the scenario ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2023 02:59 AM
we are doing it in event management where we have created rules
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2023 02:42 AM - edited 08-14-2023 02:43 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2023 03:00 AM
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