LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 12-29-2009, 11:20 PM   #1
Mistro
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Rep: Reputation: 1
Nagios issues command but wont send email


So I have Nagios set up and running fine, except for email notifications.

I checked the nagios debug output, and it seems to be invoking the mail command fine, and returning ok, however no email is sent. In the mail.log file, there is also no output. I've tried changing the mail command in Nagios to be something simpler to narrow down the problem... Here are the details of the log files:

Nagios debug log
Code:
[1262146455.848179] [2320.2] [pid=10198] Raw Command Input: /usr/bin/mailx -s "test" myemail@gmail.com
[1262146455.848197] [2320.2] [pid=10198] Expanded Command Output: /usr/bin/mailx -s "test" myemail@gmail.com
[1262146455.848253] [256.1] [pid=10198] Running command '/usr/bin/mailx -s "test" myemail@gmail.com'...
[1262146455.855333] [256.1] [pid=10198] Execution time=0.007 sec, early timeout=0, result=0, output=Null message body; hope that's ok
Of course, that Null message body doesn't appear when I pipe in some output using printf like Nagios does by default. This is the output in that case:

Code:
[1262146587.138937] [2320.2] [pid=10294] Raw Command Input: /usr/bin/printf "Test Email" | /usr/bin/mailx -s "test" myemail@gmail.com
[1262146587.138959] [2320.2] [pid=10294] Expanded Command Output: /usr/bin/printf "Test Email" | /usr/bin/mailx -s "test" myemail@gmail.com
[1262146587.139016] [256.1] [pid=10294] Running command '/usr/bin/printf "Test Email" | /usr/bin/mailx -s "test" myemail@gmail.com'...
[1262146587.146604] [256.1] [pid=10294] Execution time=0.007 sec, early timeout=0, result=0, output=(null)
Nothing appears in the mail.log output though.

If I cut and paste the command in the debug output into the command line and run it, it runs just fine, and output appears in the mail.log file.

It doesn't seem to be a permissions thing considering that the "Null message body; hope that's ok" message came up... meaning it's actually running the sendmail program I beleive.

I'm using msmtp as my sendmail.

Any Ideas?
 
Old 12-30-2009, 05:15 AM   #2
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291
Hello and Welcome to LinuxQuestions,

First things first, can you mail from the command line as the Nagios user, not root, to your e-mail address and does the mail get to your inbox? I've noticed in your post that you send to a Gmail account. If that's correctly are you using a fixed IP or a dynamic one?

Kind regards,

Eric
 
Old 12-30-2009, 01:21 PM   #3
Mistro
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 1
Thanks for the reply. I didn't know what the default nagios user password was, so I had to reset it as root with passwd. Hopefully that doesn't break anything.

I've tried running the mail command through the nagios user like this (I'm not sure if it's the correct way):

Code:
su - nagios -c "/usr/bin/mailx email@gmail.com"
There is a prompt for the passwrd and I enter it but there is no output, or prompt for the input of the message.

I tried running the command as another user on the system (A normal user of the system, not one of the "special" users). With this user, I got the message and subject prompts like normal.

I also tried running something simple like "ls /" as both users. With the normal user, output appears, but with the nagios users nothing does.

I then tried creating a quick script called test.sh:

Code:
#! /bin/bash
echo "Deleting"
rm /thepath/testfile
echo "deleted"
I then chmoded both the script and "testfile" to 777. I ran the script as the nagios user and no output was created, and the file remained. With the other user, both messages displayed, and the file was deleted.


Currently, I'm on a dynamic IP (DSL at home) and i'm using a dynamic dns service to update the name I use to access the server. The IP doesn't change too often; only when there is a power outage, or when I reset the router which is very rare.

All other services like mdadm and bugzilla which use the sendmail interface seem to work just fine. I'm using msmtp which is set up with my gmail account.

I'm not too interested in receiving emails on the server, just sending them, which is why i was using msmtp since i can easily send emails as my gmail account with it. Would that make a difference though?


EDIT: To add to the above, when I su into the user to get the prompt the normal user works as expected. I get into the console as the other user after entering their password. However, with the nagios user, it just pauses, and then comes back to my own prompt after I enter the password.

Last edited by Mistro; 12-30-2009 at 01:23 PM.
 
Old 12-30-2009, 03:31 PM   #4
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291
Hi,

It seems like something is seriously wrong with the permissions that the nagios user should have. It's very strange that you cannot enter a shell a that user by using:
Code:
su - nagios
How did you set up the user? Which manual did you follow to get Nagios up and running?

All processes that Nagios executes are ran as the nagios user so you should be able to open a shell and perform actions as that users. The fact that your controls seem to work (that's what you said right?) indicates that at least that part is working. I'd retrace the steps you performed to create the nagios user and the permissions you assigned to him.

The IP thing I asked refers to the fact that Gmail doesn't accept relaying from dynamic IPs but it looks like you have that covered with msmtp (didn't know that one, surely will look into it, thanks for pointing to it).

Kind regards,

Eric
 
1 members found this post helpful.
Old 12-30-2009, 03:49 PM   #5
Mistro
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 1
Thanks for the reply. I'm using Ubuntu, so I had just apt-get'ed the nagios3 package. I then followed the resolution in this bug to get the external commands working:
https://lists.ubuntu.com/archives/ub...ne/013748.html

I was looking through the passwd file and I noticed that the nagios user has /bin/false as it's shell. Maybe this could be the problem? I'll try perhaps changing it to /bin/bash and report back.

EDIT: Ok so now i can su into the user. When I try executing a mail, I get the prompts to enter the message and subject, but then the following message comes up when sending.

send-mail: account default not found: no configuration file available
Can't send mail: sendmail process failed with error code 78

This is probably a problem with the msmtp configuration I think... but atleast it's getting somewhere

I'll report back if I find a solution so future googlers have some info.

Last edited by Mistro; 12-30-2009 at 03:54 PM.
 
Old 12-30-2009, 03:59 PM   #6
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291
Hi,

At least now you can really test stuff and get an output on screen. Looking forward to what you find concerning the mail error.

Kind regards,

Eric
 
Old 12-30-2009, 04:26 PM   #7
Mistro
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 1
Ok so that last error was in fact an msmtp permissions problem to the msmtprc config file.
I set the permissions to 644 (it was 640 before) and now it seems to be working, even if the console is set to /bin/false.

Since that rc file contains passwords, I just created a group called emailusers and added myself, nagios and root to it. I set the users for that file to be myself:emailusers and the permissions back to 640, however it doesn't seem to read the file that way for some strange reason even though the nagios user is part of the group. I'll keep tinkering with it, but atleast for now I can get email to work if needed.

Thanks again for pointing me in the right direction!

Last edited by Mistro; 12-30-2009 at 04:30 PM.
 
Old 12-30-2009, 05:01 PM   #8
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291
Hi Mistro,

Glad you got it working and for pointing out the msmtp.

Kind regards,

Eric
 
Old 12-30-2009, 05:03 PM   #9
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291
Sorry, forgot this:

if you consider the thread as solved then please mark it as such using the thread tools.

Kind regards,

Eric
 
Old 12-30-2009, 05:03 PM   #10
Mistro
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 1
Done, and thanks again!
 
  


Reply

Tags
email, nagios, ubuntu


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nagios plugin wont send email alerts investmentbnker75 Programming 0 11-18-2008 09:49 AM
nagios wont run command noob_d Linux - Server 2 05-23-2008 09:14 AM
qmail wont send email to addresses not in my domain robmainella Linux - Software 2 02-02-2004 06:37 PM
Postfix wont send email robmainella Linux - Software 3 12-05-2003 12:05 AM


All times are GMT -5. The time now is 10:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration