Trigger notification only if MID server is down for a certain period of time?

twoodruff
Kilo Explorer

Hello, friends!

I'm having a devil of a time trying to figure out how to do the following:

Trigger a (single) notification, ONLY if a (any) MID server is in DOWN state for 6 hours or more.

I figure I can create a notification that triggers when the server state changes and is down, but where to go from there? I've been searching the wiki, but couldn't find anything on how to tell the system to do something like...

Wait for 6 hours...

Then trigger the notification...

Except if the state changes to UP during those 6 hours...

Abort (do not send notification).

Has anyone got any ideas?

Thanks so much for any help you can provide. This has really bent my mind today. 😛

1 ACCEPTED SOLUTION

bernyalvarado
Mega Sage

Hi, there's actually multiple ways of doing this:



There's a script include called MonitorMIDServer. That same script include has a function named: hasRecentActivity the one you could leverage to see if a MID server haven't have any recent activity for the last 6hours




You also have the option to monitor the events "mid_server.down" and event "mid_server.up" and based on the time of those trigger the respective notification.




Here goes the script include function hasRecentActivity that you could leverage as a basline for your code


      /*


        * Check if the given agent name has written to the ecc_queue more recently than the given time.


        * This protects against marking an overloaded (but functioning) mid server as 'down' inappropriately.


        */


      hasRecentActivity: function(agentName, time) {


              var gr = new GlideRecord('ecc_queue');


              gr.addQuery('sys_created_on', '>', time);


              gr.addQuery('sys_created_on', '<=', gs.minutesAgo(0));


              gr.addQuery('agent', 'mid.server.' + agentName);


              gr.addQuery('queue', 'input');


              gr.query();


              if (gr.hasNext())


                      return true;


             


              return false;


      },



Thanks,


Berny


View solution in original post

9 REPLIES 9

bernyalvarado
Mega Sage

Hi, there's actually multiple ways of doing this:



There's a script include called MonitorMIDServer. That same script include has a function named: hasRecentActivity the one you could leverage to see if a MID server haven't have any recent activity for the last 6hours




You also have the option to monitor the events "mid_server.down" and event "mid_server.up" and based on the time of those trigger the respective notification.




Here goes the script include function hasRecentActivity that you could leverage as a basline for your code


      /*


        * Check if the given agent name has written to the ecc_queue more recently than the given time.


        * This protects against marking an overloaded (but functioning) mid server as 'down' inappropriately.


        */


      hasRecentActivity: function(agentName, time) {


              var gr = new GlideRecord('ecc_queue');


              gr.addQuery('sys_created_on', '>', time);


              gr.addQuery('sys_created_on', '<=', gs.minutesAgo(0));


              gr.addQuery('agent', 'mid.server.' + agentName);


              gr.addQuery('queue', 'input');


              gr.query();


              if (gr.hasNext())


                      return true;


             


              return false;


      },



Thanks,


Berny


Berny, seriously, this isn't the first time you've correctly answered one of my questions, and you're amazing. Thank you so much.


Hi,




Can you please give me the steps exactly what you have done to achieve this?



Thanks!



Regards,


Raj


It's in the reply right above mine.