Dear All ,
I want to add a SMS (PHP API) when Nagios send alert Email , i just need the script code when Nagios send alert emails .
Best Regards
Mohammad Alshoaibi
SMS in Nagios Core
Re: SMS in Nagios Core
You might want to review this documentation:
https://assets.nagios.com/downloads/nag ... dlers.html
If you're using the stock Nagios Core configurations, you should have the following command definitions:
And the way those command definitions get referenced is in terms of contacts:
Notice the service_notification_commands and host_notification_commands variables in the above contact definition. Those commands are what gets fired when Nagios receives information that a notification should be sent to a specific contact. The commands can be anything; an echo to stdout, a blaring alarm located in some NOC, a rube goldberg maching that dumps water on your sysadmin, whatever.
So, if you wanted a custom PHP script that is responsible for sending SMS messages to be called when notifications occur:
https://assets.nagios.com/downloads/nag ... dlers.html
If you're using the stock Nagios Core configurations, you should have the following command definitions:
Code: Select all
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
Code: Select all
define contact{
name generic-contact ; The name of this contact template
service_notification_period 24x7 ; service notifications can be sent anytime
host_notification_period 24x7 ; host notifications can be sent anytime
service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events
service_notification_commands notify-service-by-email ; send service notifications via email
host_notification_commands notify-host-by-email ; send host notifications via email
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}
So, if you wanted a custom PHP script that is responsible for sending SMS messages to be called when notifications occur:
- Write the PHP script
- Define it as a Nagios command
- Assign that Nagios command to a Nagios contact
- Assign that Nagios contact to whatever Nagios hosts/services
Last edited by mcapra on Thu Jun 22, 2017 11:56 am, edited 1 time in total.
Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/
-
- Former Nagios Staff
- Posts: 4583
- Joined: Wed Sep 21, 2016 10:29 am
- Location: NoLo, Minneapolis, MN
- Contact:
Re: SMS in Nagios Core
Additionally, if you want to dig into how it all gets handled on the back end, the code is available at https://github.com/NagiosEnterprises/nagioscore/
Re: SMS in Nagios Core
this is PHP script for example :Write the PHP script
Code: Select all
$url_API = "http://sms.provider.co/http/send_sms_http.php?login_name='.$user_name.'&login_password='.$pass.'&msg='.$body.'&mobile_number='.$to.'&from='.$from.'&charset='.$charset.'&dlr=1 ";
$result = file_get_contents($url_API);
Q2 : how i can get the value of " SMS body " variable .. the body of notification that Nagios Sent by Email. ?!
Re: SMS in Nagios Core
mohamadsh wrote: Q1 : where i should add this code .. in any file ?!
You wouldn't add the code anywhere. You would create it as a script that accepts arguments, then use that script in a Nagios command definition, then assign that command to the Nagios contact's service_notification_commands and host_notification_commands variables.mcapra wrote: Notice the service_notification_commands and host_notification_commands variables in the above contact definition. Those commands are what gets fired when Nagios receives information that a notification should be sent to a specific contact.
In your Nagios command definition, you have macros available to you. You can see several of them on the stock notify-service-by-email and notify-host-by-email command definitions. Stuff like $HOSTOUTPUT$, $HOSTNAME$, $HOSTSTATE$, etc. If you wanted the SMS body to be the output of the check that was run, you might use $SERVICEOUTPUT$ or $LONGSERVICEOUTPUT$.mohamadsh wrote: Q2 : how i can get the value of " SMS body " variable .. the body of notification that Nagios Sent by Email. ?!
Here's all the available Nagios macros and their respective contexts. Your context would be "Service Notifications" and "Host Notifications", so anything with a green "Yes" is something you can use in the command definition.
https://assets.nagios.com/downloads/nag ... olist.html
Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/
-
- Former Nagios Staff
- Posts: 4583
- Joined: Wed Sep 21, 2016 10:29 am
- Location: NoLo, Minneapolis, MN
- Contact:
Re: SMS in Nagios Core
Thanks @mcapra!
-
- Posts: 49
- Joined: Thu Feb 14, 2013 9:32 am
Re: SMS in Nagios Core
I don't know about SMS, but I am receiving alerts by Telegram
I followed the steps as on https://pommi.nethuis.nl/nagios-notific ... a-telegram
But be aware that there is missing information on the step-by-step. You must install Unofficial Telegram Bot API Client (https://github.com/datamachine/twx.botapi) to get it working.
Hope it helps you.
I followed the steps as on https://pommi.nethuis.nl/nagios-notific ... a-telegram
But be aware that there is missing information on the step-by-step. You must install Unofficial Telegram Bot API Client (https://github.com/datamachine/twx.botapi) to get it working.
Hope it helps you.
-
- Former Nagios Staff
- Posts: 4583
- Joined: Wed Sep 21, 2016 10:29 am
- Location: NoLo, Minneapolis, MN
- Contact:
Re: SMS in Nagios Core
@mohamadsh, were you able to resolve your issue? Are we ready to lock this up?
@DiegoAnjos, thanks so much for the helpful tip!
@DiegoAnjos, thanks so much for the helpful tip!