sms wont work with zabbix

Hi Experts,

I have a permission issue with my zabbix installation I think, my knowledge is not that far to troubleshoot it.

I have a working zabbix 2.2 installation on a Debian wheezy.

And I use the mobile 3G module inside the portable to send the messages, I do this with gammu, with the script sendsms.

When I launch gammu manually, the sms is working, because it runs as user root.

root@monitor:~# echo "test final" | gammu-smsd-inject TEXT 0479123456
gammu-smsd-inject[27701]: Warning: No PIN code in /etc/gammu-smsdrc file
gammu-smsd-inject[27701]: Created outbox message OUTC20140028_111024_00_0479123456_sms0.smsbackup
Written message with ID /var/spool/gammu/outbox/OUTC20140028_111024_00_0479123456_sms0.smsbackup
root@monitor:~#

Open in new window


When I try with the user zabbix, I dont get anything back:
root@monitor:~# su zabbix -c 'echo "test zabix user" | gammu-smsd-inject TEXT 0479123456'
root@monitor:~#

Open in new window


When I try with the desktop user JFS, I get more info back, probably permissions, because I didnt grant this user rights to the logging folder etc.
root@monitor:~# su jfs -c 'echo "test zabix user" | gammu-smsd-inject TEXT 0479123456'

gammu-smsd-inject[27757]: Warning: No PIN code in /etc/gammu-smsdrc file
Failed to inject message: Can not open specified file.
root@monitor:~#

Open in new window


What I did: put zabbix in the admin group.

Does someone know, what I am doing wrong?
trivinAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
trivinConnect With a Mentor Author Commented:
Thanks Mazdajai, it works now.
I did some changes also.

I changed the visudo like you told me, did a chmod 777 on the folders error/inbox/outbook/sent under /var/spool/gammu.

And used another script:
#!/bin/sh
HOME=/etc
PATH=/bin:/sbin:/usr/bin:/usr/sbin
LOGFILE="/var/log/zabbix/zabbix-sms.log"
echo "Recipient='$1' Message='$3'" >> ${LOGFILE}
MOBILE_NUMBER=`echo "$1" | sed s#\s##`
# Log it
echo "echo $3 | /usr/bin/gammu-smsd-inject TEXT ${MOBILE_NUMBER}" >>${LOGFILE}
# Send it
echo "$3" | /usr/bin/gammu-smsd-inject TEXT "${MOBILE_NUMBER}" 1>>${LOGFILE} 2>&1
# EOF

Open in new window


The main goal was the permissions, and its now working perfect!
0
 
Joseph GanSystem AdminCommented:
Is admin group get all root privileges ?
0
 
trivinAuthor Commented:
don't know?  How can i check it?

I just put the user also in the root group with the command:
root@monitor:~# usermod -a -G root zabbix

root@monitor:~# cat /etc/group | grep root                                                  
root:x:0:zabbix
dialout:x:20:root,gammu
root@monitor:~#


But again when I try to run the command:

root@monitor:~# echo "test final" | gammu-smsd-inject TEXT 0479704525
gammu-smsd-inject[21693]: Warning: No PIN code in /etc/gammu-smsdrc file
gammu-smsd-inject[21693]: Created outbox message OUTC20140029_101029_00_0479704525_sms0.smsbackup
Written message with ID /var/spool/gammu/outbox/OUTC20140029_101029_00_0479704525_sms0.smsbackup
root@monitor:~# su zabbix -c 'echo "test zabix user" | gammu-smsd-inject TEXT 0479704525'
root@monitor:~#

It works with the root user, but not with the zabbix user.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
Joseph GanSystem AdminCommented:
Have you created zabbix account? Look at piont two of this link:

https://www.zabbix.com/documentation/2.2/manual/installation/install
0
 
MazdajaiConnect With a Mentor Commented:
It is recommended to use sudo for non-root user to control zabbix service. Append the following line in the sudoer with visudo. (man sudo)
zabbix 	ALL=(ALL)	NOPASSWD: ALL <gammu-smsd-inject path>

Open in new window

https://www.zabbix.com/documentation/1.8/manual/tutorials
 
Then try to run the inject command with sudo -
echo "test zabix user" | sudo gammu-smsd-inject TEXT 0479704525

Open in new window

0
 
trivinAuthor Commented:
@ Ganjos thx for your comment, but zabbix user is already installed,  you can see this also when I ran the command cat /etc/group | grep root.


@ Mazdaja
I tried that, but doesnt seems to work:
I enterd the following line in visudo:      

zabbix ALL=(ALL)        NOPASSWD: ALL /usr/bin/gammu-smsd-inject

I closed it, saved it, and rebooted the machine.
When I run the echo... command, I got an error.

I opened again the visudo, and commented the line.
And added a new line:
zabbix ALL=NOPASSWD: ALL
no error, but no notification either, so same issue as when I started the topic.

It only works with the root user.
What else can I do?


In the zabbix-server log, I also get an error on the script:
/usr/lib/zabbix/alertscripts/sendsms: 9: /usr/lib/zabbix/alertscripts/sendsms: Syntax error: "&" unexpected

The script:
#!/bin/sh

# $1    recipient
# $2    subject
# $3    message
 
TMPFILE=`mktemp -t`
 
echo "$3" &gt;&gt; $TMPFILE
 
cat $TMPFILE | gammu-smsd-inject TEXT $1
 
rm $TMPFILE
chmod a+x /usr/lib/zabbix/alertscripts/sendsms

Open in new window

0
 
gheistCommented:
gammu says you dont have PIN
can you confirm that with handy and SMS sim card?
0
 
MazdajaiCommented:
>>When I run the echo... command, I got an error.
I can't guess what the error is. What is it?
It only works with the root user. 

Open in new window


Sudo works with most applications. It runs with root privileges. Most of the time is improper configuration. (Unless the above statement is made by the vendor) For example, the non-root user was not able to read files that root owned files.

What is the following output ?
echo "test zabix user" | sudo gammu-smsd-inject TEXT 0479704525

Open in new window

0
 
trivinAuthor Commented:
@ Gheist, indeed it works without a pincode.  When I run this code: echo "test final" | gammu-smsd-inject TEXT 0479704525
I do receive the message.

@Mazdajai:
It got an error, when I change the visudo file, and add the folowing line:
zabbix ALL=(ALL)        NOPASSWD: ALL /usr/bin/gammu-smsd-inject
the error is:

root@monitor:~# echo "test zabix user" | sudo gammu-smsd-inject TEXT 0479704525
sudo: parse error in /etc/sudoers near line 29
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

So I add a # in front of the line, so its disabled again, and I run the folowwing command again:

root@monitor:~# echo "test zabix user" | sudo gammu-smsd-inject TEXT 0479704525
OUTPUT:
gammu-smsd-inject[8067]: Warning: No PIN code in /etc/gammu-smsdrc file
gammu-smsd-inject[8067]: Created outbox message OUTC20140103_094910_00_0479704525_sms0.smsbackup
Written message with ID /var/spool/gammu/outbox/OUTC20140103_094910_00_0479704525_sms0.smsbackup

This one works perfect.  But it needs to work with zabbix ;)

Permissions and linux... damn not that easy...
0
 
MazdajaiConnect With a Mentor Commented:
Sorry, have a type on the command. Try adding -

zabbix 	ALL=(ALL)	NOPASSWD: ALL

Open in new window


Issue visudo -c -f to validate and re-run the sudo command.
0
 
trivinAuthor Commented:
script gave errors, tried another script like in my last answer.   And also change the gammu-smsd-inject in the script.

It's thanks to Mazdajai, that the permissions errors are solved.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.