Unable to send sms notification

Hi Guys,

I want to send sms notification and I’m using these scripts:


I’m running CentOS 7 with Icinga2 version: 2.11.2-1
I have configured commands.conf, notifications.conf, templates.conf, users.conf and hosts.conf but when for example host is down I cannot receive SMS.

The error in log file is:
warning/PluginNotificationTask: Notification command for checkable ‘TEST HOST’ and notification ‘TEST HOST!Host Alarm By SMS’ (PID: 18873, arguments: ‘/etc/icinga2/scripts/host-by-sms.sh’ ‘-d’ ‘2020-01-10 17:17:44 -0500’ ‘-l’ ‘TEST HOST’ ‘-n’ ‘TEST HOST’ ‘-o’ ‘CRITICAL - Plugin timed out’ ‘-r’ ‘’ ‘-s’ ‘DOWN’ ‘-t’ ‘PROBLEM’) terminated with exit code 128, output: execvpe(/etc/icinga2/scripts/host-by-sms.sh) failed: Permission denied

When I try to test script from cmd like this:

sudo -u nagios ./host-by-sms.sh
-d ‘LONGDATE’
-l ‘HOSTALIAS’
-n ‘HOSTDISPLAYNAME’
-o ‘HOSTOUTPUT’
-r ‘+mynumber‬’
-s ‘HOSTSTATE’
-t ‘NOTIFICATIONTYPE’

sudo -u nagios ./service-by-sms.sh
-d ‘LONGDATE’
-e ‘SERVICENAME’
-l ‘HOSTALIAS’
-n ‘HOSTDISPLAYNAME’
-o ‘HOSTOUTPUT’
-r ‘+mynumber‬’
-s ‘SERVICESTATE’
-t ‘NOTIFICATIONTYPE’
-u 'SERVICEDISPLAYNAME

I receive this error: sudo: unable to execute ./host-by-sms.sh: Permission denied

When I run script with sudo user, there is no output but also there is no sms message received.

I have give all permissions to script files and also to Nagios user but obviously I’m missing something important.

Can you please be kind and try to help me if you have experience with this ?

I want to send sms notification and I’m using these scripts:
https://github.com/GabrielUlici/icinga2-sms

What happens if you try to run the “useful” part of that script manually?

curl -s -X POST \
https://api.twilio.com/2010-04-01/Accounts/$ACCOUNTSID/Messages.json
–data-urlencode “Body=$SUBJECT”
–data-urlencode “MessagingServiceSid=$MESSAGINSERVICESID”
–data-urlencode “To=$PHONE”
-u $ACCOUNTSID:$AUTHTOKEN

(Obviously with the variables replaced by appropriate values for your Twilio
account etc).

I receive this error: sudo: unable to execute ./host-by-sms.sh: Permission
denied

What is in /etc/sudoers for the user which will be running the script (icinga
or nagios, I’m not sure which CentOS uses)?

Antony.

1 Like

Hi Antony and thank you very much for kind answer.

  • When I run the script manually the SMS gets sent.
  • Selinux is disabled
  • The file permissions are the following: -rwxrwxrwx. 1 icinga icinga 2975 Jan 10 15:29 host-by-sms.sh
  • Icinga process is run by user “icinga”
  • In /etc/sudoers:
    nagios ALL=(ALL) NOPASSWD:/etc/icinga2/scripts/host-by-sms.sh, /etc/icinga2/scripts/service-by-sms.sh
    icinga ALL=(ALL) NOPASSWD:/etc/icinga2/scripts/host-by-sms.sh, /etc/icinga2/scripts/service-by-sms.sh
  • And the error is still:
    warning/PluginNotificationTask: Notification command for checkable ‘TEST HOST’ and notification ‘TEST HOST!Host Alarm By SMS’ (PID: 18873, arguments: ‘/etc/icinga2/scripts/host-by-sms.sh’ ‘-d’ ‘2020-01-10 17:17:44 -0500’ ‘-l’ ‘TEST HOST’ ‘-n’ ‘TEST HOST’ ‘-o’ ‘CRITICAL - Plugin timed out’ ‘-r’ ‘’ ‘-s’ ‘DOWN’ ‘-t’ ‘PROBLEM’) terminated with exit code 128, output: execvpe(/etc/icinga2/scripts/host-by-sms.sh) failed: Permission denied

Here is my .conf files:

  • commands.conf

object NotificationCommand “Host Alarm By SMS” {
import “plugin-notification-command”
command = [ ConfigDir + “/scripts/service-by-sms.sh” ]
arguments += {
“-d” = {
required = true
value = “$icinga.long_date_time$”
}
“-l” = {
required = true
value = “$host.name$”
}
“-n” = {
required = true
value = “$host.display_name$”
}
“-o” = {
required = true
value = “$host.output$”
}
“-r” = {
required = true
value = “$user.pager$”
}
“-s” = {
required = true
value = “$host.state$”
}
“-t” = {
required = true
value = “$notification.type$”
}
“-v” = “$notification_logtosyslog$”
}
}

  • notifications.conf

apply Notification “Host Alarm By SMS” to Host {
import “Host Alarm By SMS”

user_groups = host.vars.notification.pager.groups
users = host.vars.notification.pager.users

interval = 0

assign where host.vars.notification.pager
}

  • templates.conf

template Notification “Host Alarm By SMS” {
command = “Host Alarm By SMS”

states = [ Down ]
types = [ Problem, Recovery ]

period = “24x7”
}

  • users.conf

object User “icingaadmin” {
import “generic-user”

display_name = “Icinga 2 Admin”
groups = [ “icingaadmins” ]
vars.user.pager = “+MyMobileNumber”
email = “icinga@localhost”
}

object UserGroup “icingaadmins” {
display_name = “Icinga 2 Admin Group”
}

  • hosts.conf

object Host “TEST HOST2” {
import “generic-host”
vars.ping_wrta = “190, 5%”
vars.ping_crta = “230, 15%”
address = "ServerAddress
vars.os = “WebSites”
vars.notification[“pager”] = {
users = [ “icingaadmin” ]
}
}
Maybe my eyes are tired but I still not getting where I’m wrong, do you have any suggestions ?

  • When I run the script manually the SMS gets sent.

Okay, that’s a start :slight_smile:

  • In /etc/sudoers:
    nagios ALL=(ALL) NOPASSWD:/etc/icinga2/scripts/host-by-sms.sh,
    /etc/icinga2/scripts/service-by-sms.sh
    icinga ALL=(ALL) NOPASSWD:/etc/icinga2/scripts/host-by-sms.sh,
    /etc/icinga2/scripts/service-by-sms.sh

Okay, so long as sudo is getting invoked, that looks good…

  • And the error is still:
    warning/PluginNotificationTask: Notification command for checkable ‘TEST
    HOST’ and notification ‘TEST HOST!Host Alarm By SMS’ (PID: 18873,
    arguments: ‘/etc/icinga2/scripts/host-by-sms.sh’ ‘-d’ ‘2020-01-10 17:17:44
    -0500’ ‘-l’ ‘TEST HOST’ ‘-n’ ‘TEST HOST’ ‘-o’ ‘CRITICAL - Plugin timed
    out’ ‘-r’ ‘’ ‘-s’ ‘DOWN’ ‘-t’ ‘PROBLEM’) terminated with exit code 128,
    output: execvpe(/etc/icinga2/scripts/host-by-sms.sh) failed: Permission
    denied

That looks different from the previous error message to me - previously you
posted “sudo: unable to execute ./host-by-sms.sh: Permission denied”.

This time I don’t see any mention of sudo…

Here is my .conf files:

I don’t see sudo being called in any of those either.

Can you get a “standard” email notification script to work (eg: the sample ones
that come with Icinga2)?

Antony.

Hi Antony

Email notifications will work for sure.
About errors.

  • If I run this from command line with nagios user:
    sudo -u nagios ./host-by-sms.sh \ -d ‘LONGDATE’ \ -l ‘HOSTALIAS’ \ -n ‘HOSTDISPLAYNAME’ \ -o ‘HOSTOUTPUT’ \ -r ‘+15142375458’ \ -s ‘HOSTSTATE’ \ -t ‘NOTIFICATIONTYPE’
    I get error: sudo: unable to execute ./host-by-sms.sh: Permission denied

  • But if I run this from command line with icinga user:
    sudo -u icinga ./host-by-sms.sh \ -d ‘LONGDATE’ \ -l ‘HOSTALIAS’ \ -n ‘HOSTDISPLAYNAME’ \ -o ‘HOSTOUTPUT’ \ -r ‘+15142375458’ \ -s ‘HOSTSTATE’ \ -t ‘NOTIFICATIONTYPE’
    There is no error.

  • Thi is from Icinga2 log file when Host goes down, SMS not send and this is error:
    warning/PluginNotificationTask: Notification command for checkable ‘TEST
    HOST’ and notification ‘TEST HOST!Host Alarm By SMS’ (PID: 18873,
    arguments: ‘/etc/icinga2/scripts/host-by-sms.sh’ ‘-d’ ‘2020-01-10 17:17:44
    -0500’ ‘-l’ ‘TEST HOST’ ‘-n’ ‘TEST HOST’ ‘-o’ ‘CRITICAL - Plugin timed
    out’ ‘-r’ ‘’ ‘-s’ ‘DOWN’ ‘-t’ ‘PROBLEM’) terminated with exit code 128,
    output: execvpe(/etc/icinga2/scripts/host-by-sms.sh) failed: Permission
    denied

  • In .conf files there is no need to call sudo, I attach that .conf files because maybe I have configured something wrong, this is my first time to trying SMS notification configuration.

About errors.

  • If I run this from command line with nagios user:
    sudo -u nagios ./host-by-sms.sh \ -d ‘LONGDATE’ \ -l ‘HOSTALIAS’ \ -n
    ‘HOSTDISPLAYNAME’ \ -o ‘HOSTOUTPUT’ \ -r ‘+15142375458’ \ -s ‘HOSTSTATE’
    -t ‘NOTIFICATIONTYPE’ I get error: sudo: unable to execute
    ./host-by-sms.sh: Permission denied

What do you get for “grep nagios /etc/passwd”?

  • But if I run this from command line with icinga user:
    sudo -u icinga ./host-by-sms.sh \ -d ‘LONGDATE’ \ -l ‘HOSTALIAS’ \ -n
    ‘HOSTDISPLAYNAME’ \ -o ‘HOSTOUTPUT’ \ -r ‘+15142375458’ \ -s ‘HOSTSTATE’
    -t ‘NOTIFICATIONTYPE’ There is no error.

What do you get for “grep icinga /etc/passwd”?

  • Thi is from Icinga2 log file when Host goes down, SMS not send and this
    is error: warning/PluginNotificationTask: Notification command for
    checkable ‘TEST HOST’ and notification ‘TEST HOST!Host Alarm By SMS’ (PID:
    18873,
    arguments: ‘/etc/icinga2/scripts/host-by-sms.sh’ ‘-d’ ‘2020-01-10 17:17:44
    -0500’ ‘-l’ ‘TEST HOST’ ‘-n’ ‘TEST HOST’ ‘-o’ ‘CRITICAL - Plugin timed
    out’ ‘-r’ ‘’ ‘-s’ ‘DOWN’ ‘-t’ ‘PROBLEM’) terminated with exit code 128,
    output: execvpe(/etc/icinga2/scripts/host-by-sms.sh) failed: Permission
    denied

So, you;re saying that if you set up a notification by email, the script gets
run, but substituting that for host-by-sms.sh, it gives this error?

I’m getting as puzzled as you are now :frowning:

  • In .conf files there is no need to call sudo,

Okay, I was confused by your original posting which showed an error message
from sudo - I thought that’s what was being output by the notification handler.

Antony.

Hi Antony,

  • For: What do you get for “grep nagios /etc/passwd”?
    nagios:x:996:993::/var/spool/nagios:/bin/bash
  • For: What do you get for “grep icinga /etc/passwd”?
    icinga:x:997:995:icinga:/var/spool/icinga2:/bin/bash
  • So, you;re saying that if you set up a notification by email, the script gets
    run, but substituting that for host-by-sms.sh, it gives this error?
    Exactly :frowning:

I definitely configured something badly wrong

Hi Antony,

Believe or not, I resolve issue buy adding this “/usr/bin/sudo”, in
command = [ ConfigDir + “/scripts/host-by-sms.sh” ]

So issue is finaly resolved, now SMS notification are working !

command = [ “/usr/bin/sudo”, ConfigDir + “/scripts/host-by-sms.sh” ]

Thank you for your time and answers !

1 Like