Page 1 of 2

check_logfiles plugin

Posted: Mon Aug 02, 2021 10:58 am
by deek
Hi Team ,

We have a requirement to monitor a string from a log file . The log file is dynamic and has date stamp but the log file is not rotated on a daily basis and I see that check_logfiles is trying to search for log file with latest date .
I have tried monitoring but im not getting the required output .

Below is the text file saved under C:/Program Files/NSClient++ folder .

$protocolsdir = 'C:\Nagios\NSClient++';
$seekfilesdir = 'C:\Nagios\NSClient++';
@searches = (
{
tag => 'logfile',
type => 'simple',
logfile => 'D:\Program Files\Apache Software Foundation\Tomcat 8.5_Tomcat8_BMC_SmartIT\logs\localhost.$CL_DATE_YYYY$-$CL_DATE_MM$-$CL_DATE_DD$.log',
criticalpatterns => ['java.net.SocketException: Connection reset by peer'],
}
);


I have updated the nsclient++ file as below under [/settings/external scripts/scripts] :
check_logfile_Tomcat8_BMC=scripts\check_logfiles.exe -f "C:\Program Files\NSClient++\Tomcat8_BMC.txt

Im getting below output in Nagios :

[nagios@xyz ~]$ /usr/local/nagios/libexec/check_nrpe -H 172.**.***.** -u -t 100 -c check_logfile_Tomcat8_BMC
UNKNOWN - (1 unknown in Tomcat8_BMC.protocol-2021-08-02-11-51-29) - could not find logfile D:\Program Files\Apache Software Foundation\Tomcat 8.5_Tomcat8_BMC_SmartIT\logs\localhost.2021-08-02.log |'logfile_lines'=0 'logfile_warnings'=0 'logfile_criticals'=0 'logfile_unknowns'=1

Im pasting the screenshot of log file localhost below :
Capture_logfiles.PNG

Re: check_logfiles plugin

Posted: Tue Aug 03, 2021 9:06 am
by ssax
How often is the log file rotated?

Re: check_logfiles plugin

Posted: Tue Aug 03, 2021 10:18 am
by deek
Actually logfile gets updated when we receive an error . So the last error we received was on 16th .

Re: check_logfiles plugin

Posted: Wed Aug 04, 2021 2:02 pm
by ssax
This is a tough one, I'm trying some things and will update shortly.

Re: check_logfiles plugin

Posted: Wed Aug 04, 2021 4:34 pm
by ssax
Try this:
- Apparently it's just perl and you can use perl code but you must have 1; at the bottom to make it work

Code: Select all

use File::stat;

$protocolsdir = 'C:\Nagios\NSClient++';
$seekfilesdir = 'C:\Nagios\NSClient++';

my @files = sort {stat($a)->mtime <=> stat($b)->mtime} glob 'D:\Program Files\Apache Software Foundation\Tomcat 8.5_Tomcat8_BMC_SmartIT\logs\localhost.*.log';
my $latest_file = $files[-1];

@searches = ();

push(@searches, {
    tag => basename("$latest_file"),
    logfile => "$latest_file",
    criticalpatterns => ['java.net.SocketException: Connection reset by peer']
});

1;
That will get the latest file in that directory.

Re: check_logfiles plugin

Posted: Thu Aug 05, 2021 4:31 am
by deek
I tried this . And im getting below output .

[nagios@xyz ~]$ /usr/local/nagios/libexec/check_nrpe -H 172.**.***.** -u -t 100 -c check_logfile_Tomcat8_BMC
UNKNOWN - syntax error Can't call method "mtime" on an undefined value at C:\Program Files\NSClient++\Tomcat8_BMC.txt line 6.

The target server is windows server , is that why there is mtime error ?

Re: check_logfiles plugin

Posted: Thu Aug 05, 2021 3:14 pm
by ssax
Please attach this file:

Code: Select all

C:\Program Files\NSClient++\Tomcat8_BMC.txt

Re: check_logfiles plugin

Posted: Fri Aug 06, 2021 12:43 am
by deek
I have put whatever you had provided me .

use File::stat;

$protocolsdir = 'C:\Nagios\NSClient++';
$seekfilesdir = 'C:\Nagios\NSClient++';

my @files = sort {stat($a)->mtime <=> stat($b)->mtime} glob 'D:\Program Files\Apache Software Foundation\Tomcat 8.5_Tomcat8_BMC_SmartIT\logs\localhost.*.log';
my $latest_file = $files[-1];

@searches = ();

push(@searches, {
tag => basename("$latest_file"),
logfile => "$latest_file",
criticalpatterns => ['java.net.SocketException: Connection reset by peer']
});

1;

Re: check_logfiles plugin

Posted: Fri Aug 06, 2021 4:21 pm
by ssax
EDITED.

It's the spaces in the name, try this:

Code: Select all

use File::stat;

$protocolsdir = 'C:\Nagios\NSClient++';
$seekfilesdir = 'C:\Nagios\NSClient++';

my @files = sort {stat($a)->mtime <=> stat($b)->mtime} glob '"D:\Program Files\Apache Software Foundation\Tomcat 8.5_Tomcat8_BMC_SmartIT\logs\localhost.*.log"';
my $latest_file = $files[-1];

@searches = ();

push(@searches, {
    tag => basename("$latest_file"),
    logfile => "$latest_file",
    criticalpatterns => ['java.net.SocketException: Connection reset by peer']
});

1;

Re: check_logfiles plugin

Posted: Mon Aug 09, 2021 12:24 pm
by deek
Im getting below output .

[nagios@xyz ~]$ /usr/local/nagios/libexec/check_nrpe -H 172.**.***.** -u -t 100 -c check_logfile_Tomcat8_BMC
CRITICAL - (1 errors, 1 unknown in Tomcat8_BMC.protocol-2021-08-09-13-20-55) - cannot write status file C:\Nagios\NSClient++/Tomcat8_BMC...\! check your filesystem (permissions/usage/integrity) and disk devices |'.\_lines'=0 '.\_warnings'=0 '.\_criticals'=1 '.\_unknowns'=1


And below is the Tomcat8_BMC.protocol file under C:\Nagios\NSClient++ .

CRITICAL Errors in .\ (tag .\)
cannot write status file C:\Nagios\NSClient++/Tomcat8_BMC...\! check your filesystem (permissions/usage/integrity) and disk devices
UNKNOWN Errors in .\ (tag .\)
could not find logfile