Can I connect my Braintower SMS Gateway to Nagios?
Of course you can use your Braintower SMS Gateway to send alarms from Nagios via SMS.
You will need first the script
sendsms. Download the file and place it on your Nagios server in the folder /usr/local/bin/off.
The script needs the following Perl modules to work:
LWP::UserAgent
URI::Escape
Text::Icon
In the next step, the commands for SMS alerts in configuring Nagios need to be defined. In addition, the defined contacts must be provided with the following commands.
Examples: Definition of SMS alerts in/etc/nagios3/commands.cfg
----------------------------------------------------------------------------------------------
define command
{
command_name notify-host-by-sms
command_line /usr/local/bin/sendsms.pl $CONTACTPAGER$ "$NOTIFICATIONTYPE$ - Host $HOSTALIAS$ is $HOSTSTATE$ since $SHORTDATETIME$ info: $HOSTOUTPUT$"
}
----------------------------------------------------------------------------------------------
define command
{
command_name notify-service-by-sms
command_line /usr/local/bin/sendsms.pl $CONTACTPAGER$ "$NOTIFICATIONTYPE$ - $SERVICEDESC$ on $HOSTNAME$ state: $SERVICESTATE$ since $SHORTDATETIME$ info: $SERVICEOUTPUT$"
}
----------------------------------------------------------------------------------------------
Example: Definition of a contact in /etc/nagios3/contacts.cfg
define contact
{
contact_name Max_Sample
alias Max Sample
host_notification_period 24x7
service_notification_period 24x7
host_notification_options d,u,r
service_notification_options u,c,r
pager 00491701234567
host_notification_commands notify-host-by-sms
service_notification_commands notify-service-by-sms
}
HTTPS
The script sendsms transmits the Nagios alarm to the SMS gateway. By default, this communication is not encrypted.
In line 43, you can change this behavior by switching the request to HTTPS:
my $response = $lwp->get('https://'.$smsgw_host.':'.$smsgw_sendsms_port.$smsgw_sendsms_path.'?username='.$smsgw_username.'&password='. $smsgw_password.'&to='.$recipient.'&text='.$message);
-----------------------------------------------------------
Provided the SSL certificate used in the Braintower SMS Gateway is a self-signed certificate, there could be a error message in nagios.log. Can't connect to ... (certificate verify failed). In this case, insert the following code at line 35:
$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;
-----------------------------------------------------------