Unable to access /var/log files

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
djs
Posts: 9
Joined: Tue Jan 06, 2015 11:12 am

Unable to access /var/log files

Post 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
Last edited by djs on Wed Jan 07, 2015 9:25 am, edited 1 time in total.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Help with Nagios

Post 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?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
djs
Posts: 9
Joined: Tue Jan 06, 2015 11:12 am

Re: Help with Nagios

Post by djs »

Hi,

The only edit i added to the /etc/sudoers file was:
nrpe ALL=NOPASSWD: ALL
djs
Posts: 9
Joined: Tue Jan 06, 2015 11:12 am

Re: Help with Nagios

Post 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
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Unable to access /var/log files

Post 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?
Be sure to check out our Knowledgebase for helpful articles and solutions!
djs
Posts: 9
Joined: Tue Jan 06, 2015 11:12 am

Re: Unable to access /var/log files

Post 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
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Unable to access /var/log files

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked