[SOLVED] Nagios issues command but wont send email
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:
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.
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?
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:
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.
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).
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.
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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.