Page 1 of 1

SMS notification - Delay before sending next

Posted: Thu Dec 18, 2014 1:31 pm
by rogersochieng
I have SMS notification command working if specify one or two contacts but has problem when there are more contacts. It seems my SMS gateway requires delay before submitting another request.I have below command, please let me know if there is a way to introuduce delay before next contact in the service notification is processed

/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$ \nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | wget "http://192.168.155.6:8000/sms?usr=nagio ... sh=0&text=** $NOTIFICATIONTYPE$ Service Alert: $SERVICEDESC$ on $HOSTNAME$ State: $SERVICESTATE$ @ $LONGDATETIME$ **"

Re: SMS notification - Delay before sending next

Posted: Thu Dec 18, 2014 1:56 pm
by tmcdonald
Without making some modifications to the Core code and recompiling, the only thing I could think of at the moment is maybe to put a "sleep" call somewhere in there with a random delay:

Code: Select all

sleep \$(( ( RANDOM % 10 )  + 1 ))
Make sure to escape the dollar sign as I have done otherwise it will be treated as a macro. This isn't a perfect solution since the random delay could cause two or more alerts to have the same delay, but it's a good starting point. Someone else might be able to improve on my answer.

Re: SMS notification - Delay before sending next

Posted: Thu Dec 18, 2014 2:27 pm
by rogersochieng
Do you mean add this to the command? I tried inserting it in the notification command but I get "syntax error near unexpected token '('

Re: SMS notification - Delay before sending next

Posted: Thu Dec 18, 2014 2:32 pm
by tmcdonald
It would go before the "/usr/bin/printf" part. It might take some fiddling with to get it to run. Like I said, not the most elegant solution but it was the first thing that came to mind.

Edit: Might also be worth making a command queue using "at": http://linux.about.com/library/cmd/blcmdl1_at.htm

Edit2: Using a name pipe might also be an interesting approach: http://stackoverflow.com/questions/1300 ... mmand-line

Then just submit the command along with a delay to that pipe, so they will be executed in the order they are received but with the delay.