Suppress alerts to not create incident during change scheduled period

ritesh1
Tera Contributor

There is one usecase I have been working on. There is an Alert Management Rule which will create an incident when an alert is created. Whenever a change request is created, and the current state of change request is in scheduled/implementation state, the alert generated within this period should not create incident as the CI would be in maintenance state. I am not allowed to change any alert management rules which is already configured. I have come up with a solution to this, but this is not working.

 

I have created an event registry:

ritesh1_0-1696622946721.png

 

After that I had created a business rule:

ritesh1_1-1696623014669.png

Withing advance, I have added this code(can be seen in picture also):

(function executeRule(current, previous /*null when async*/) {
	// Add your code here
	gs.eventQueue('maintenance_flag',current,current.sys_updated_on,current.cmdb_ci);
})(current, previous);

ritesh1_2-1696623083049.png

And finally I created a script action:

ritesh1_3-1696623186327.png

var tr = new GlideRecord("task_ci");
tr.addEncodedQuery('task.sys_class_name=change_request^task.stateIN-2,-1^ci_item='+event.parm2); 
tr.addQuery('task.ref_change_request.end_date','>=',event.parm1);		
tr.addQuery('task.ref_change_request.start_date','<=',event.parm1); 
tr.query();																	
while(tr.next())
{
current.maintenance=true;
current.update();
}

 

But this approach is not working, the incidents are still created.
Please help me.

Thanks 🙂  

2 REPLIES 2

athm
Tera Guru

The most likely reason could be the business rule firing after the incident has been created or Alert Management Flow already triggered and past the maintenance checkpoint.
Try changing the business rule to run before insert and with the same logic you have to populate the maintenance flag at the time of insert. ( This essentially means, you need not have to use the event you created creation 'maintenance_flag' - using this would delay the script action execution by Alert Management and hence is the reason the incident is being created).

Hope this helps you ritesh1.

Harsh1
Tera Contributor

There is already OOTB functionality to prevent incident creation during change window.
So whenever change is in implementation state, alert will be marked in maintenance & incident won't be created due to condition present in flow designer attached to alert management rule.