Monitor a running log file of Unix server using Nagios core

This forum is intended for the discussion of Nagios plugin development. Feature requests, patches, bug fixes, and all types of development-related discussions are welcome!

NOTE: The SourceForge.net nagiosplug-devel mailing list has been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

Monitor a running log file of Unix server using Nagios core

Postby Srinija544 » Tue Aug 27, 2019 2:14 am

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.
Srinija544
 
Posts: 25
Joined: Mon Oct 15, 2018 9:30 pm

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

Postby scottwilkerson » Tue Aug 27, 2019 9:14 am

One of the most common Log plugins is check_logfiles
https://exchange.nagios.org/directory/Plugins/Log-Files/check_logfiles/details
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 17023
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

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

Postby Srinija544 » Tue Aug 27, 2019 10:37 pm

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.
Srinija544
 
Posts: 25
Joined: Mon Oct 15, 2018 9:30 pm

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

Postby scottwilkerson » Wed Aug 28, 2019 7:49 am

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?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 17023
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

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

Postby Srinija544 » Thu Aug 29, 2019 1:47 am

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.
Srinija544
 
Posts: 25
Joined: Mon Oct 15, 2018 9:30 pm

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

Postby scottwilkerson » Thu Aug 29, 2019 6:49 am

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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 17023
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises


Return to Nagios Plugin Development

Who is online

Users browsing this forum: No registered users and 1 guest