Solved

sms wont work with zabbix

Posted on 2014-01-28
11
1,822 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
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 16

Expert Comment

by:Joseph Gan
Comment Utility
Is admin group get all root privileges ?
0
 

Author Comment

by:trivin
Comment Utility
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
Comment Utility
Have you created zabbix account? Look at piont two of this link:

https://www.zabbix.com/documentation/2.2/manual/installation/install
0
 
LVL 21

Assisted Solution

by:Mazdajai
Mazdajai earned 500 total points
Comment Utility
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
Comment Utility
@ 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 61

Expert Comment

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

Expert Comment

by:Mazdajai
Comment Utility
>>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
Comment Utility
@ 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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now