You can of course use your SMS Gateway to send alarms from Icinga 2 via SMS.

For this purpose you first need the script sendsms.pl. Download it and save it in your Icinga server in the /usr/lib/nagios/plugins/ directory.
The script is composed of the following Perl modules:

  • LWP::UserAgent
  • URI::Escape
  • Text::Icon

In the next step commands must now be configured for the SMS configuration in Icinga. Corresponding contacts must also be created.

Example: Definition for SMS notifications in /etc/icinga2/conf.d/commands.conf 

object NotificationCommand "braintower-host-notification" {
	import "plugin-notification-command"
	command = [ PluginDir + "/sendsms.pl" ]
	arguments = {
		"-pager" = {
			value = "$braintower_pager$"
			description = "Telephone number of the SMS recipient"
			skip_key = true
		}
		"-message" = {
			value = "$braintower_message$"
			description = "SMS message text"
			skip_key = true
		}
	}
	vars.braintower_pager = "$user.pager$"
	vars.braintower_message = "$notification.type$ - Host $host.display_name$ is $host.state$ since $icinga.long_date_time$ info: $host.output$"
}
object NotificationCommand "braintower-service-notification" {
	import "plugin-notification-command"
	command = [ PluginDir + "/sendsms.pl" ]
	arguments = {
		"-pager" = {
			value = "$braintower_pager$"
			description = "Telephone number of the SMS recipient"
			skip_key = true
		}
		"-message" = {
			value = "$braintower_message$"
			description = "SMS message text"
			skip_key = true
		}
	}
	vars.braintower_pager = "$user.pager$"
	vars.braintower_message = "$notification.type$ - Host $host.display_name$ is $host.state$ since $icinga.long_date_time$ info: $host.output$"
}

Example: Definition of Host-/Service Templates for SMS notifications in /etc/icings2/conf.d/templates.conf

template Notification "braintower-host-notification" {
	command = "braintower-host-notification"
	states = [ Up, Down ]
	types = [ Problem, Acknowledgement, Recovery, Custom, FlappingStart, FlappingEnd, DowntimeStart, DowntimeEnd, DowntimeRemoved ]
	period = "24x7"
}
template Notification "braintower-service-notification" {
	command = "braintower-service-notification"
	states = [ OK, Warning, Critical, Unknown ]
	types = [ Problem, Acknowledgement, Recovery, Custom, FlappingStart, FlappingEnd, DowntimeStart, DowntimeEnd, DowntimeRemoved ]
	period = "24x7"
}

Example: Host-/Service Templates for SMS notifications on a host in /etc/icinga2/conf.d/notifications.conf

apply Notification "braintower-alerts" to Host {
	import "braintower-host-notification"
	user_groups = host.vars.notification.sms.groups
	assign where host.vars.notification.sms
}
apply Notification "braintower-alerts" to Service {
	import "braintower-service-notification"
	user_groups = host.vars.notification.sms.groups
	assign where host.vars.notification.sms
}

Example: Definition of a user group for SMS notifications in /etc/icinga2/conf.d/groups.conf

object UserGroup "smsusers" {
	display_name = "Icinga 2 SMS Group"
}

Example: Adding a contact to the user group for SMS notifications /etc/icinga2/conf.d/users.conf

object User "Max_Muster" {
	import "generic-user"
	display_name = "Max Muster"
	groups = [ "smsusers" ]
	pager = "00491701234567"
}

HTTPS

The script sendsms sends the alarm to the SMS Gateway. As standard this communication takes place without encryption.
You can alter this behaviour in line 43 by converting 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);


If the SSL certificate set up in the SMS Gateway is a self-signed certificate, this may lead to an error message in icinga.logCan't connect to ... (certificate verify failed)
In this case, add the following code in line 35:

$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;