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 :
check_logfiles plugin
check_logfiles plugin
You do not have the required permissions to view the files attached to this post.
Re: check_logfiles plugin
How often is the log file rotated?
Re: check_logfiles plugin
Actually logfile gets updated when we receive an error . So the last error we received was on 16th .
Re: check_logfiles plugin
This is a tough one, I'm trying some things and will update shortly.
Re: check_logfiles plugin
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
That will get the latest file in that directory.
- 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;Re: check_logfiles plugin
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 ?
[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
Please attach this file:
Code: Select all
C:\Program Files\NSClient++\Tomcat8_BMC.txtRe: check_logfiles plugin
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;
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
EDITED.
It's the spaces in the name, try this:
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
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
[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