Page 1 of 1

Monitor a running log file of Unix server using Nagios core

Posted: Tue Aug 27, 2019 2:14 am
by Srinija544
Hi All,

We have new requirement to monitor a running log file of a unix server using Nagios core. I have checked for all ways to get a plugin to do this but unfortunately i couldn't find the plugin.

Original requirement:
Server: dc2drpas008
Logfilename: testfile.log
Logfilepath: /root/linux-nrpe-agent/testfile.log
Error message: error and warn

Please help me in finding the script to monitor a running log files.

Thanks and Regards,
Srinija.

Re: Monitor a running log file of Unix server using Nagios c

Posted: Tue Aug 27, 2019 9:14 am
by scottwilkerson
One of the most common Log plugins is check_logfiles
https://exchange.nagios.org/directory/P ... es/details

Re: Monitor a running log file of Unix server using Nagios c

Posted: Tue Aug 27, 2019 10:37 pm
by Srinija544
Hi scottwilkerson,

Thank you for your response.

I have tried to configure the check_logfiles which was provided in the below URL and made some changes. Please find my script:

cat /usr/local/nagios/libexec/check_logfiles.cfg

$scriptpath = '/usr/local/nagios/libexec';
$MACROS = {
MY_ERROR_MACRO => 'ERROR',
MY_VOLUME => '10'
};

@searches = (
{
tag => 'ERROR',
logfile => '/root/srinija.cfg',
criticalpatterns => 'ERROR',
script => 'check_logfiles.sh',
scriptparams => '$MY_VOLUME$'
options => 'noprotocol,script,perfdata'
},
);

AND

cat /usr/local/nagios/etc/check_logfiles.sh

#! /bin/sh
if [ -n "$1" ]; then
VOLUME=$1
fi
printf "It is %d:%d and my status is %s\n" \
$CHECK_LOGFILES_DATE_HH \
$CHECK_LOGFILES_DATE_MI \
$CHECK_LOGFILES_SERVICESTATE

printf "I found something funny: %s\n" "$CHECK_LOGFILES_SERVICEOUTPUT"
if [ "$VOLUME" == "X10" ]; then
echo "$CHECK_LOGFILES_MY_ERROR_MACRO" | tr 'a-z' 'A-Z'
else
echo "$CHECK_LOGFILES_MY_ERROR_MACRO"
fi
printf "Thank you, %s.Found the ERROR.\n" "$CHECK_LOGFILES_USERNAME"


Command in nrpe.cfg:
command[check_logfiles]=/usr/local/nagios/libexec/check_logfiles --config logdefs.cfg


Service:
define service{
use generic-service,srv-pnp
host_name hostname
# contact_groups cg_infra_unix_t2
# servicegroups sg_infra_unix
service_description Log file
check_command check_nrpe!check_logfiles
}

Error message after configuring the above scripts and command in Nagios:
NRPE: Unable to read output

=======================================================

Please help me in knowing whether the scripts and command which i wrote is appropriate or not.

Thanks and regards,
Srinija.

Re: Monitor a running log file of Unix server using Nagios c

Posted: Wed Aug 28, 2019 7:49 am
by scottwilkerson
I'm not an expert on this plugin but one thing that stands out is this

Code: Select all

logfile => '/root/srinija.cfg',
You need to make sure that the user NRPE is running as has access to this file.

Also, the file name you are showing don't match with the commands, for example, you have this

Code: Select all

cat /usr/local/nagios/libexec/check_logfiles.cfg
but you seem to be calling --config logdefs.cfg

Code: Select all

command[check_logfiles]=/usr/local/nagios/libexec/check_logfiles --config logdefs.cfg
and you showed this

Code: Select all

cat /usr/local/nagios/etc/check_logfiles.sh
but your NRPE command doesn't have the .sh on it

Code: Select all

command[check_logfiles]=/usr/local/nagios/libexec/check_logfiles --config logdefs.cfg
So I am a bit confused at how this is all working together.

Which begs the question, is it working? If not, what are you getting?

Re: Monitor a running log file of Unix server using Nagios c

Posted: Thu Aug 29, 2019 1:47 am
by Srinija544
Hi scottwilkerson,

Even I am confused how this plugin works. :?

Please find my changes on client server:

Nagios is owner for this file:
-rw-r--r-- 1 nagios nagios 14 Aug 29 16:44 srinija.cfg


Command in nrpe.cfg:
command[check_logfiles]=/usr/local/nagios/libexec/check_logfiles.cfg --config check_logfiles.sh


Error message after configuring in Nagios:
NRPE: Unable to read output

please let me know if any changes needs be done.

Regards,
Srinija.

Re: Monitor a running log file of Unix server using Nagios c

Posted: Thu Aug 29, 2019 6:49 am
by scottwilkerson
Srinija544 wrote:Command in nrpe.cfg:
command[check_logfiles]=/usr/local/nagios/libexec/check_logfiles.cfg --config check_logfiles.sh
this certainly isn't right, it looks like you are trying to execute a .cfg file (check_logfiles.cfg) and pass a shell script as a config (--config check_logfiles.sh)?

Before trying to add it to the nrpe.cfg, you need to make sure you can get the expected results running it from the command line on the system you are running it on.

Only once you know the proper syntax for the command should you move on to create the entry in the nrpe.cfg