Nagios can't send SMS (smstools)

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
User avatar
Ulfandu
Posts: 26
Joined: Thu Jun 14, 2018 4:53 am

Nagios can't send SMS (smstools)

Post by Ulfandu »

Hello,

I recently purchased a simple GSM module with a working 3G SIM-card and I connected it to my CentOS box via a USB-RS232-cable. I installed and configure a package called 'smstools' and I'm able to send text messages using /usr/bin/smssend

I've created two new command-objects in /usr/local/nagios/etc/objects/commands.cfg and it looks like this:

Code: Select all

define command {
    command_name    notify-host-by-sms
    command_line    /usr/bin/printf "%b" "Notification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | smssend $CONTACTPAGER$
}

define command {
    command_name    notify-service-by-sms
    command_line    /usr/bin/printf "%b" "Notification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | smssend $CONTACTPAGER$
}
And after I create a custom alert in Nagios' web-management to test it out, I get the following output in /usr/local/nagios/var/nagios.log:

Code: Select all

[1559637530] wproc:   host=TEST.example.com; service=(none); contact=admin-sms
[1559637530] wproc:   early_timeout=0; exited_ok=1; wait_status=256; error_code=0;
[1559637530] wproc:   stderr line 01: chown: changing ownership of ‘/tmp/smsd_m94Z6S’: Operation not permitted
[1559637530] wproc:   stderr line 02: mktemp: failed to create file via template ‘/var/spool/sms/outgoing/send_XXXXXX’: Permission denied
[1559637530] wproc:   stderr line 03: mv: missing destination file operand after ‘/tmp/smsd_m94Z6S’
[1559637530] wproc:   stderr line 04: Try 'mv --help' for more information.
[1559637530] wproc:   stdout line 01: Text: --
[1559637530] wproc:   stdout line 02: Text: Notification Type: CUSTOM
[1559637530] wproc:   stdout line 03: To: +000000000000
I've tried giving the nagios and smstools users privileges to the folder in question using the following commands:

Code: Select all

 chown -R smstools /tmp
chown -R nagios /tmp
Here is also the output of ls -la /tmp:

Code: Select all

drwxrwxrwt. 19 nagios root    4096 Jun  4 12:08 .
dr-xr-xr-x. 17 root   root     242 Mar 29 12:20 ..
drwx------   2 nagios admin     20 Jun  3 15:00 .esd-1000
drwxrwxrwt.  2 nagios root       6 Jan  3 15:36 .font-unix
drwxr-xr-x   2 nagios root      20 Jun  3 15:19 hsperfdata_root
drwxrwxrwt.  2 nagios root      20 Jun  3 15:00 .ICE-unix
-rw-r--r--   1 nagios root      73 Jun  3 15:18 lua_L9LeWE
-rw-------   1 nagios nagios   224 Jun  4 11:53 smsd_a5wm3y
-rw-------   1 nagios nagios   219 Jun  4 11:56 smsd_F8rdsZ
-rw-------   1 nagios nagios   251 Jun  4 12:00 smsd_yPXRPw
drwx------   2 nagios admin     26 Jun  3 15:00 ssh-cXuQ7JQyb1XS
drwx------   3 nagios root      17 Mar 29 12:19 systemd-private-0ee8350dee3e4e798afd38a273d9a121-bolt.service-zavhv1
drwx------   3 nagios root      17 Mar 29 12:19 systemd-private-0ee8350dee3e4e798afd38a273d9a121-colord.service-na8EpT
drwx------   3 nagios root      17 Mar 29 12:19 systemd-private-0ee8350dee3e4e798afd38a273d9a121-cups.service-nQuDub
drwx------   3 nagios root      17 May  3 08:08 systemd-private-0ee8350dee3e4e798afd38a273d9a121-fwupd.service-jTe3jS
drwx------   3 root   root      17 Jun  4 12:08 systemd-private-0ee8350dee3e4e798afd38a273d9a121-httpd.service-twwnqD
drwx------   3 nagios root      17 May 13 22:01 systemd-private-0ee8350dee3e4e798afd38a273d9a121-ntpd.service-h4OBYK
drwx------   3 nagios root      17 Mar 29 12:19 systemd-private-0ee8350dee3e4e798afd38a273d9a121-rtkit-daemon.service-hfIfha
drwx------   3 nagios root      17 Mar 29 12:19 systemd-private-0ee8350dee3e4e798afd38a273d9a121-systemd-machined.service-TloSTk
drwxrwxrwt.  2 nagios root       6 Jan  3 15:36 .Test-unix
drwx------   2 nagios admin      6 Jun  4 11:06 tracker-extract-files.1000
-r--r--r--   1 nagios root      11 May  3 08:09 .X0-lock
drwxrwxrwt.  2 nagios root      16 May  3 08:09 .X11-unix
drwxrwxrwt.  2 nagios root       6 Jan  3 15:36 .XIM-unix
-rw-------   1 nagios root   61259 Jun  3 15:01 yum_save_tx.2019-06-03.15-01.X99X1H.yumtx
Also note that I've edited the host's name and the phone number to which the SMS-notification would go to.
User avatar
Ulfandu
Posts: 26
Joined: Thu Jun 14, 2018 4:53 am

Re: Nagios can't send SMS (smstools)

Post by Ulfandu »

I've now used the command chmod -R 777 /var/spool/sms/ and Nagios's log no longer shows errors regarding SMS. The snippet below indicates that Nagios was able to move the SMS notification to the correct folder:

Code: Select all

[1559650721] EXTERNAL COMMAND: SEND_CUSTOM_HOST_NOTIFICATION;TEST-HOST;3;nagiosadmin;test
[1559650721] HOST NOTIFICATION: antti;TEST-HOST;CUSTOM (UP);notify-host-by-email;PING OK - Packet loss = 0%, RTA = 0.38 ms;nagiosadmin;test
[1559650721] HOST NOTIFICATION: antti-sms;TEST-HOST;CUSTOM (UP);notify-host-by-sms;PING OK - Packet loss = 0%, RTA = 0.38 ms;nagiosadmin;test
[1559650721] HOST NOTIFICATION: inmics;TEST-HOST;CUSTOM (UP);notify-host-by-sms;PING OK - Packet loss = 0%, RTA = 0.38 ms;nagiosadmin;test
But I'm still not receiving SMS messages to the numbers I've configured in the contact groups. However, the SMS program I use, SMSTools, has a log and it shows the following:

Code: Select all

/var/log/smsd/smsd.log:
2019-06-04 15:18:50,3, smsd: Cannot handle /var/spool/sms/outgoing/send_bbm0Pe: Access denied. Check the file and directory permissions.
2019-06-04 15:18:50,3, smsd: Cannot handle /var/spool/sms/outgoing/send_471M8z: Access denied. Check the file and directory permissions.
So there must still be some issue with permissions. I'm at a loss here.

For the reference, the SMS program is running:

Code: Select all

smsd.service - SYSV: sms server tools sends and receives short messages via GSM
   Loaded: loaded (/etc/rc.d/init.d/smsd; bad; vendor preset: disabled)
   Active: active (running) since Tue 2019-06-04 15:12:39 EEST; 14min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 96771 ExecStop=/etc/rc.d/init.d/smsd stop (code=exited, status=0/SUCCESS)
  Process: 96799 ExecStart=/etc/rc.d/init.d/smsd start (code=exited, status=0/SUCCESS)
    Tasks: 2
   CGroup: /system.slice/smsd.service
           ├─96809 /usr/sbin/smsd
           └─96811 /usr/sbin/smsd

Jun 04 15:12:39 nagios systemd[1]: Starting SYSV: sms server tools sends and receives short messages via GSM...
Jun 04 15:12:39 nagios smsd[96799]: Starting smsd: [  OK  ]
Jun 04 15:12:39 nagios systemd[1]: Started SYSV: sms server tools sends and receives short messages via GSM.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios can't send SMS (smstools)

Post by scottwilkerson »

I'm not familiar with this tool so have no idea what permissions are required, you may want to contact the author of the sms tool you are using.

What are the permissions on all the paths above /var/spool/sms/outgoing/send_bbm0Pe ?
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
User avatar
Ulfandu
Posts: 26
Joined: Thu Jun 14, 2018 4:53 am

Re: Nagios can't send SMS (smstools)

Post by Ulfandu »

Here are the permissions you requested:

/var/spool/sms/outgoing/send_bbm0Pe

Code: Select all

-rw------- 1 nagios nagios 44 Jun  4 15:18 /var/spool/sms/outgoing/send_bbm0Pe
/var/spool/sms/outgoing

Code: Select all

drwxrwxrwx 2 smstools smstools 44 Jun  5 08:39 .
drwxrwxrwx 7 smstools smstools 79 Jun  3 15:24 ..
-rw------- 1 nagios   nagios   44 Jun  4 15:18 send_471M8z
-rw------- 1 nagios   nagios   44 Jun  4 15:18 send_bbm0Pe
/var/spool/sms/

Code: Select all

drwxrwxrwx   7 smstools smstools  79 Jun  3 15:24 .
drwxr-xr-x. 14 root     root     165 Jun  3 15:24 ..
drwxrwxrwx   2 smstools smstools   6 Jun  4 15:13 checked
drwxrwxrwx   2 smstools smstools   6 Jul 14  2015 failed
drwxrwxrwx   2 smstools smstools   6 Jun  4 15:12 incoming
drwxrwxrwx   2 smstools smstools  44 Jun  5 08:39 outgoing
drwxrwxrwx   2 smstools smstools   6 Jul 14  2015 sent
/var/spool

Code: Select all

drwxr-xr-x. 14 root     root      165 Jun  3 15:24 .
drwxr-xr-x. 21 root     root     4096 Jan  9 13:29 ..
drwxr-x--x.  2 root     abrt        6 Nov 13  2018 abrt
drwx------.  2 abrt     abrt        6 Nov 13  2018 abrt-upload
drwxr-xr-x.  2 root     root       63 Nov 20  2018 anacron
drwx------.  3 root     root       31 Jan  3 15:43 at
drwx------.  2 root     root        6 Nov 20  2018 cron
drwx--x---.  3 root     lp         17 Jan  3 15:39 cups
drwxr-xr-x.  2 root     root        6 Apr 11  2018 lpd
drwxrwxr-x.  2 root     mail       56 Jun  5 03:52 mail
drwxr-xr-x.  2 nagios   nagios     27 Jan 17 02:00 nagios
drwxr-xr-x.  2 root     root        6 Apr 13  2018 plymouth
drwxr-xr-x. 16 root     root      201 Jan  3 15:43 postfix
drwxrwxrwx   7 smstools smstools   79 Jun  3 15:24 sms
/var

Code: Select all

drwxr-xr-x. 21 root root 4096 Jan  9 13:29 .
dr-xr-xr-x. 17 root root  242 Mar 29 12:20 ..
drwxr-xr-x.  2 root root   19 Jan  3 15:43 account
drwxr-xr-x.  2 root root    6 Apr 11  2018 adm
drwxr-xr-x. 13 root root  154 Jan  9 13:29 cache
EDIT: Found a possible solution from Red Hat's Bugzilla and I tried it but to no avail. What I did was add the 'smstools' user to the dialout group of CentOS.

EDIT #2: I went in to the folder where the outgoing messages are stuck and set 777 permission on all of them, and immediately after that I received them on my phone:

Code: Select all

cd /var/spool/sms/outgoing/
ls
send_0npIiX  send_L7KDrw
chmod 777 send_0npIiX
chmod 777 send_L7KDrw
So if I understood it correctly, nagios creates the outgoing messages to /var/spool/sms/outgoing/ but the smstools-user doesn't have permission to send them. I haven't yet figured out a way to automatically give those new files the same permissions as the parent folder.
User avatar
Ulfandu
Posts: 26
Joined: Thu Jun 14, 2018 4:53 am

Re: Nagios can't send SMS (smstools)

Post by Ulfandu »

I tried setting the new files to inherit permissions from the parent folder:

chmod g+s /var/spool/sms/outgoing but for some reason it didn't work. I tried creating a new nagios alert and the new SMS-files created in the outgoing-folder still have the old permissions - which would be the following:

Code: Select all

drwxrwsrwx 2 smstools smstools  44 Jun  5 14:08 .
drwxrwxrwx 7 smstools smstools  79 Jun  3 15:24 ..
-rw------- 1 nagios   nagios   202 Jun  5 14:00 send_T4O3jd
-rw------- 1 nagios   nagios   202 Jun  5 14:00 send_vsRK7D
I also tried adding the user 'nagios' to the group 'smstools' and vice versa. Still no luck.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios can't send SMS (smstools)

Post by scottwilkerson »

Ulfandu wrote:So if I understood it correctly, nagios creates the outgoing messages to /var/spool/sms/outgoing/ but the smstools-user doesn't have permission to send them. I haven't yet figured out a way to automatically give those new files the same permissions as the parent folder.
NBagios is just running the commands you specified, and these are piping the output to smssend which is then handling them after that.

From that point nagios is out of the picture, and not being familiar with how smssend processes messages and what permissions are required, I would defer you to the makers of that software.
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
User avatar
Ulfandu
Posts: 26
Joined: Thu Jun 14, 2018 4:53 am

Re: Nagios can't send SMS (smstools)

Post by Ulfandu »

Alright. But doing chmod -R 777 /var/spool/sms/outgoing makes it work for the messages stuck there. Is there a way to make new files created in that folder automatically inherit the parent folder's permissions? Here the highlighted permissions are the ones that work:

Image
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios can't send SMS (smstools)

Post by scottwilkerson »

Technically this should inherit the groups permissions

Code: Select all

drwxrwsr-x
and this the user

Code: Select all

drwsrwsr-x
But again, I'm not sure about settings on your server or what manipulation smssend does to the files.
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
User avatar
Ulfandu
Posts: 26
Joined: Thu Jun 14, 2018 4:53 am

Re: Nagios can't send SMS (smstools)

Post by Ulfandu »

scottwilkerson wrote:Technically this should inherit the groups permissions

Code: Select all

drwxrwsr-x
and this the user

Code: Select all

drwsrwsr-x
But again, I'm not sure about settings on your server or what manipulation smssend does to the files.
Okay, thank you. What kind of commands could I accomplish that with?

EDIT: Nevermind, I figured this out myself. I didn't know what type of permissions to set, so I took a shortcut and edited the script used to send a SMS which is located in /usr/bin/smssend. I simply added the following line to automatically set proper permissions to the generated SMS-file:

Image

This topic can be closed now. Hopefully this will be helpful for someone dealing with the same issue.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios can't send SMS (smstools)

Post by scottwilkerson »

Ulfandu wrote:
scottwilkerson wrote:Technically this should inherit the groups permissions

Code: Select all

drwxrwsr-x
and this the user

Code: Select all

drwsrwsr-x
But again, I'm not sure about settings on your server or what manipulation smssend does to the files.
Okay, thank you. What kind of commands could I accomplish that with?

EDIT: Nevermind, I figured this out myself. I didn't know what type of permissions to set, so I took a shortcut and edited the script used to send a SMS which is located in /usr/bin/smssend. I simply added the following line to automatically set proper permissions to the generated SMS-file:

Image

This topic can be closed now. Hopefully this will be helpful for someone dealing with the same issue.
glad you got it sorted out

Locking
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked