Page 1 of 2

Monitor File Contents

Posted: Thu Mar 12, 2020 6:06 am
by mccrakem
Hi

I have tried the check_log and the check_log3.pl plugins but these seem to on monitor local files on the nagios server itself
I am looking to monitor a file on a remote server for 1 word "Critical" and then send a notification if that word is present
Can you tell me of any plugin that can complete this task

At present we are running NagiosXI 5.2.7

Thanks

Re: Monitor File Contents

Posted: Thu Mar 12, 2020 2:12 pm
by benjaminsmith
Hello,

To run the checks on a local server you can either install an agent such as NCPA or use ssh to log into the remote server and run the plugin. I posted a few links below with documentation to help get you started.

NCPA Agent Installation Instructions

Using Scripts Plugins with NCPA

Monitoring Hosts Using SSH

Re: Monitor File Contents

Posted: Thu Mar 12, 2020 2:59 pm
by mccrakem
Hi Benjamin

Thanks but I am trying to monitor the contents of a file on a Remote Server
I should also mention this is on a Linux Server

Re: Monitor File Contents

Posted: Thu Mar 12, 2020 4:03 pm
by benjaminsmith
Hi,

For Linux systems, you can use NRPE as well to execute plugin checks. The following instructions will install NRPE as well as the nagios plugins. You might find that easier since you'll have check_log on the remote host.

https://support.nagios.com/kb/article/n ... rpe-8.html

Then on the remote host you'll set up your commands and call them from the XI server.

NRPE - Configuring NRPE Commands To Accept Arguments

Re: Monitor File Contents

Posted: Fri Mar 13, 2020 8:38 am
by mccrakem
Cheers Benjamin
I looked at the links you sent which got me looking at other pages as well
This is how I stand at the moment
When I run the command locally on the server I get back results

nagiosscreenshot1

on the local server I create a check_file_content.cfg file in the /etc/nrpe.d directory
with content of

nagiosscreenshot2

So now I configure the nagios GUI with the details as such

nagiosscreenshot3

But the Results are

nagiosscreenshot4


Can you see where I am going wrong or is it just not possible to run this check_file_content remotley

Thanks

Re: Monitor File Contents

Posted: Fri Mar 13, 2020 11:08 am
by benjaminsmith
Hello,

Looks good and thanks for sending the screenshots. I noticed when running the command, you are logged as root and the command requires sudo to run. When Nagios is connects over NRPE it will run the plugin as the nagios user, so you'll need to edit the sudoers file to grant permissions.

The following guide has step-by-step instructions for adding this to the /etc/sudoers file.

NRPE - NRPE: Unable To Read Output

To verify this working locally, log in as nagios user and run the plugin.

Code: Select all

su - nagios
Let me know if this resolves the issue for you.

Re: Monitor File Contents

Posted: Mon Mar 16, 2020 7:08 am
by mccrakem
Hi Benjamin
Thanks for the information, I'm still not getting the correct return but I am making progress

I add the following line to the sudoers file on the server running the file

nagios ALL = NOPASSWD:/usr/lib64/nagios/plugins/check_file_content.pl

now I can switch to the nagios user and when I run the command as nagios user
sudo /usr/lib64/nagios/plugins/check_file_content.pl -f /opt/IBM_app_users/TestFolder/lastbackuptest.txt

I get the return of
OK for /opt/IBM_app_users/TestFolder/lastbackuptest.txt
Which is exactly what I am looking for

So looks like the nagios user is able to access the text file and read the output

But when I try and run if from the GUI I still get
NRPE: Unable to read output

Attached is the makeup of the monitor again incase I am configuring that incorrectly
When I click on Test Check Command, it asks me for the server name which I input and then it returns the NRPE: Unable to Read Output

Thanks

Re: Monitor File Contents

Posted: Mon Mar 16, 2020 3:48 pm
by jdunitz
In addition to testing it as root (via sudo, as you did), can you also test the command as the nagios user, without sudo?

Code: Select all

nagios$ /usr/lib64/nagios/plugins/check_file_content.pl -f /opt/IBM_app_users/TestFolder/lastbackuptest.txt
Also, can you post your nrpe.cfg file from your remote machine? Feel free to redact any secret information before posting.

Thanks!

Re: Monitor File Contents

Posted: Wed Mar 18, 2020 5:26 am
by mccrakem
Hi

I have run the command without sudo but just to be sure I have attached a screenshot
The first run is as root and then I switched to the nagios user and ran the command again and both times I got the same result
also find attached a copy of the nrpe.cfg file

Re: Monitor File Contents

Posted: Wed Mar 18, 2020 3:18 pm
by lmiltchev
I don't see the check_file_content command defined in your nrpe.cfg file...

Try adding the command, for example:

Code: Select all

command[check_file_content]=/usr/lib64/nagios/plugins/check_file_content.pl -f /opt/IBM/app_users/TestFolder/lastbackuptest.txt -i Successful -n 0
save, exit, and restart nrpe on the client.

Test your check from the command line on the Nagios XI server:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H <client ip> -c check_file_content