check_logfiles plugin

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
deek
Posts: 194
Joined: Fri Apr 26, 2019 2:01 am

check_logfiles plugin

Post 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
You do not have the required permissions to view the files attached to this post.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: check_logfiles plugin

Post by ssax »

How often is the log file rotated?
deek
Posts: 194
Joined: Fri Apr 26, 2019 2:01 am

Re: check_logfiles plugin

Post by deek »

Actually logfile gets updated when we receive an error . So the last error we received was on 16th .
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: check_logfiles plugin

Post by ssax »

This is a tough one, I'm trying some things and will update shortly.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: check_logfiles plugin

Post 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.
deek
Posts: 194
Joined: Fri Apr 26, 2019 2:01 am

Re: check_logfiles plugin

Post 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 ?
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: check_logfiles plugin

Post by ssax »

Please attach this file:

Code: Select all

C:\Program Files\NSClient++\Tomcat8_BMC.txt
deek
Posts: 194
Joined: Fri Apr 26, 2019 2:01 am

Re: check_logfiles plugin

Post 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;
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: check_logfiles plugin

Post 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;
deek
Posts: 194
Joined: Fri Apr 26, 2019 2:01 am

Re: check_logfiles plugin

Post 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
Locked