Page 1 of 1

Unable to access /var/log files

Posted: Tue Jan 06, 2015 11:23 am
by djs
Hello all (unfortunatly I cannot post in the Nagios core forum - so have had to post here)

I am trying to cat a log file held in /var/logs/ e.g /var/log/messages.
I appreciate this is likely to be a large file but bare with me! I can create any other file by doing a touch file1 put some random stuff init.
When I run the command ./check_nrpe -H 00.00.00.001-c check_log it will return the contents of the file i created. (Brilliant)
If i move the file i created in to /var/log/ it works (again brilliant)
If i try and access /var/log/messages it complains saying no output from nrpe. I have played around with permissions (etc/sudoers) created a group and tried adding the user nrpe to that group.

If anybody has any ideas as to what can be done to access files in /var that would be great!

Thanks

Re: Help with Nagios

Posted: Tue Jan 06, 2015 11:48 am
by abrist
/var/log/messages is usually owned by root. You will need a sudoers rule to allow the nagios user to read the file. Can you post your additions to the sudoers file?

Re: Help with Nagios

Posted: Wed Jan 07, 2015 2:47 am
by djs
Hi,

The only edit i added to the /etc/sudoers file was:
nrpe ALL=NOPASSWD: ALL

Re: Help with Nagios

Posted: Wed Jan 07, 2015 6:00 am
by djs
Just an update.

I can run the script to cat the file when i am logged into nagios (su nrpe -s /bin/bash) however on the webpage this displays nothing to me. Well it displays a '\n'

The script I am running consists of:

Code: Select all

#!/bin/bash
echo $(pwd)
echo $(whoami)
#echo $(hostname)
echo $(ls -l /var/log/messages)
echo $(cat /var/log/messages)
echo $(head /var/log/messages)
This is being called in /etc/nagios/object/commands.cfg

Code: Select all

define command{
  command_name    view_log_messages
  command_line       sh /etc/nagios/plugins/viewmessages
}
Any help would be great.

Thanks

Re: Unable to access /var/log files

Posted: Wed Jan 07, 2015 9:35 am
by lmiltchev
I am a bit confused about your use of check_nrpe... You are using:

Code: Select all

./check_nrpe -H 00.00.00.001-c check_log
This implies you are running a check against a remote box (this is what check_nrpe is used for). On the other hand, you have a command, defined locally (on the nagios server):

Code: Select all

define command{
  command_name    view_log_messages
  command_line       sh /etc/nagios/plugins/viewmessages
}
The command "check_log" should be defined on the client and on the nagios box, you should have a service defined with the following directive:

Code: Select all

check_command			check_nrpe!check_log!
Can you elaborate? Where are you actually running the check - locally or on the remote box?

Re: Unable to access /var/log files

Posted: Wed Jan 07, 2015 9:50 am
by djs
Sorry i forgot to edit my original post. Ive been trying all sorts to get it working.

The script is located locally on the same box and i can log into the user nrpe/nagios shell and run it (again locally) however on the nagios website/dashboard this does not display the information i was previosulay able to get from logging into the nrpe/nagios user.

Basically it works fine from the shell however as soon as it goes on the gui it fails

Re: Unable to access /var/log files

Posted: Wed Jan 07, 2015 12:27 pm
by lmiltchev
I sent you a PM. Let me know if this worked for you so that I can lock the post. Thanks!

Update: Issue resolved after disabling SELinux.