[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

sms wont work with zabbix

Posted on 2014-01-28
11
Medium Priority
?
2,057 Views
Last Modified: 2014-02-09
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?
0
Comment
Question by:trivin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 16

Expert Comment

by:Joseph Gan
ID: 39816448
Is admin group get all root privileges ?
0
 

Author Comment

by:trivin
ID: 39817185
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
 
LVL 16

Expert Comment

by:Joseph Gan
ID: 39818845
Have you created zabbix account? Look at piont two of this link:

https://www.zabbix.com/documentation/2.2/manual/installation/install
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Assisted Solution

by:Mazdajai
Mazdajai earned 2000 total points
ID: 39819954
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
 

Author Comment

by:trivin
ID: 39820588
@ 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
 
LVL 62

Expert Comment

by:gheist
ID: 39826314
gammu says you dont have PIN
can you confirm that with handy and SMS sim card?
0
 
LVL 21

Expert Comment

by:Mazdajai
ID: 39828204
>>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
 

Author Comment

by:trivin
ID: 39828980
@ 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
 
LVL 21

Assisted Solution

by:Mazdajai
Mazdajai earned 2000 total points
ID: 39831590
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
 

Accepted Solution

by:
trivin earned 0 total points
ID: 39832038
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
 

Author Closing Comment

by:trivin
ID: 39845096
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

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Fine Tune your automatic Updates for Ubuntu / Debian
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month12 days, 14 hours left to enroll

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question