Hello Nagios and good day to you, thanks in advance,
I've been struggling for a bout a week now. tried almost everything I know possible.
It is time to plea for a knowledgeable guru for help.
I've been trying to instrument a Nagios Plugin, the Check_logfiles plugin.
ok, now, I've got it working on Windows box. it works like a dream. it is working as expected.
however, this setup is all standalone on the windows machine.
I want to be able to either have Nagios Core issue the invokation on plugin OR somehow get statistics back to Nagios.
The Windows box ONLY has the NCPA agent on it. So, I'm trying to invoke it with NCPA call.
TESTING ON THE NAGIOS SERVER
1. check_ncpa.py -v -H 10.14.28.11 -t 'gold3726' -P 5693 -M 'plugins/check_logfiles.exe' -q "args=-f C:\\NagiosAncillaryScrips\\check_logfiles.cfg"
Connecting to: https://10.14.28.11:5693/api/plugins/ch ... gfiles.cfg
An error occurred:<urlopen error [Errno 104] Connection reset by peer>
2. check_ncpa.py -v -H 10.14.28.11 -t 'gold3726' -P 5693 -M 'plugins/check_logfiles.exe' -a '-f "C:\\NagiosAncillaryScrips\\check_logfiles.cfg"'
Connecting to: https://10.14.28.11:5693/api/plugins/ch ... 26&check=1
An error occurred:<urlopen error [Errno 104] Connection reset by peer>
The documentation on this plugin shows it communicating with Nagios with NRPE agent.
however, I do not have the NRPE agent on this box. hoping I don't need to intall another agent, ...
Also, communicates with $postscript = 'send_nsca'; AND I DO NOT have this NSCA script on the box.
can you tell me if what I'm doing is doable? why am I getting the 104 Error? do I need to install NRPE? where do I get this 'send_nsca' script. I can't find it. how can I get this talking to Nagios?
THANK YOU!!!
NCPA question - cannot get to work
Re: NCPA question - cannot get to work
thank you everyone !!!
I hope this helps others using the plugin Check_logfiles, because support for this plugin $ucks. There isn't any. the owner creator, well, abandoned thier post. also, many sites, you'll just get ignored asking questions surrounding this plugin.
But, it truly is a nice plugin, worth the pain of getting it working. to get it to work on Linux/Unix is fairly straight forward and EASY, to get it to work under windows is somewhat magic, lots of tinkering.
I first set it up to run as a windows service under TASK Scheduler. I couldn 't get it to call a perl script from inside, however, it calls a perl subroutine without issue.
it does work with NCPA agent.
After installation and configuration, follow the README.exe for windows. add .PL extension recognition to Win OS, install Strawberry Perl, make all PATH and VAR settings. after building the service, you must place it under the path designated for NCPA plugins. I tried pointing it to another path, didn't work for me. if you will tie it in to Nagios for statistics, and have Nagios call it, you'll need to do this, as this is where Nagios NCPA finds the plugins it can execute.
AN EXAMPLE CHECK_LOGFILES.CFG file
This check logfiles config searches and when finds the exception statement in the logfile will call the SUB under script, and copies or refeeds a file to an ingestion endpoint. since Windows doesn't have a mail utility available, I verifed SMTP works, and then used CMAIL on Windows to issue independent emails.
$scriptpath = 'C:\Program Files (x86)\Nagios\NCPA\contrib';
$protocolsdir = 'C:\Program Files (x86)\Nagios\NCPA\protocols';
$seekfilesdir = 'C:\Program Files (x86)\Nagios\NCPA\seek';
$MACROS = {
LOGS_DIR => 'C:\\APMConnect\\Logs',
PP_INGESTION_EP => 'C:\\APMConnect\\AutoDataLoader\\Scandir\\ManageAPM',
SRC_DIR => '\\\\win.alpeife.corporate.com\\APM_Data_Storage\\Zip File Archive',
CL_CMAIL_SMTP_HOST => 'mail.ad.com',
CL_CMAIL_TO => '[email protected]',
CL_CMAIL_FROM => '[email protected]',
CL_CMAIL_SUBJECT => 'APM Loader - Upload Failure Notification - PreProduction'
};
@searches = (
{
tag => '504 Gateway Time-Out',
logfile => '$LOGS_DIR$\AutoLoader.log',
rotation => 'AutoLoader.log.\d{1,2}',
type => 'rotating',
criticalpatterns => [
'^java.lang.Exception:Method failed: HTTP/1.1 504 Gateway Time-out Please check configuration details and replace or update the file :.*'
],
options => 'protocol,perfdata,script,supersmartscript',
scriptdelay => 1,
script => sub {
use File::Copy;
my $other_cmd = 'net use E: \\\\win.alpeif.corporate.com\\APM_Data_Storage /USER:logon.ds.com\\lg8174sv xnEDhPaD3gT /PERSISTENT:YES';
my $other_status = system($other_cmd);
my $sout = "$ENV{CHECK_LOGFILES_SERVICEOUTPUT}";
my $result = rindex($sout, 'FaultData');
my $_file_name = substr($sout, $result, length($sout));
my $_source_dir = $ENV{CHECK_LOGFILES_SRC_DIR};
my $_target_dir = $ENV{CHECK_LOGFILES_PP_INGESTION_EP};
my $Host = $ENV{CHECK_LOGFILES_CMAIL_SMTP_HOST};
my $To = $ENV{CHECK_LOGFILES_CMAIL_TO};
my $From = $ENV{CHECK_LOGFILES_CMAIL_FROM};
my $Subject = $ENV{CHECK_LOGFILES_CMAIL_SUBJECT};
my $Body = "The APM Loader Upload Failed.\n\n Failed to refeed file: $_file_name\n\n Please see attached.\n\n For more information, see logs under 'C:\\\\Program Files (x86)\\\\Nagios\\\\NCPA\\\\protocols'";
my $Attachment = 'C:\\Program Files (x86)\\Nagios\\NCPA\\seek\\check_logfiles.C__APMConnect_Logs_AutoLoader.log.504 Gateway Time-Out';
my @cmd = ('C:\\Program Files (x86)\\Nagios\\NCPA\contrib\\cmail.exe');
push @cmd, "-host:$Host";
push @cmd, "-to:$To";
push @cmd, "-from:$From";
push @cmd, "-subject:$Subject";
push @cmd, "-body:$Body";
push @cmd, "-a:$Attachment";
opendir (dir, $_source_dir);
my $_result = rindex($sout, 'FaultData');
my $_sout = substr($sout, $_result, length($_file_name)) = "$_file_name";
if( -f "$_source_dir/$_file_name" ) {
copy ("$_source_dir\\$_file_name", "$_target_dir\\$_file_name");
if ( $? ) {
printf 'OK - File Copy Successful!';
printf " Copied File to Refeed APM: $_source_dir\\$_file_name";
return 0;
} else {
require $Attachment;
$state->{'serviceoutput'} = "$_sout";
system(@cmd);
printf 'CRITICAL - File Copy Failed!';
printf " - Source dir: $_source_dir\\$_file_name\n";
return 2;
}
} else {
require $Attachment;
$state->{'serviceoutput'} = "$_sout";
system(@cmd);
printf 'CRITICAL - File Copy Failed, File CANNOT be located! Resource may not be Mounted!';
printf " - Source dir: $_source_dir\\$_file_name\n";
return 2;
}
closedir($dir);
}
}
);
To make configs work easier without all the escaping - I used Symbolic Links 'mklink /D target source'.
Test on Command line on windows box
c:\Program Files (x86)\Nagios\NCPA\plugins>check_logfiles.exe -f "c:\NagiosAncillaryScrips\check_logfiles.cfg"
Also, test on Task Scheduler. you can just leave it on task scheduler and leave it run as a windows task, or have NAgios call the plugin.
I worked out all issues under task scheduler then moved to Nagios.
FROM the NAGIOS MONITORING SERVER
test command line
[root@alpc1083 objects]# check_ncpa.py -v -H 10.14.12.11 -t 'password' -P 5693 -M 'plugins/check_logfiles.exe' -a '-f "C:\\NagiosAncillaryScrips\\check_logfiles.cfg"'
define host {
host_name ALPC881
address 10.14.12.11
check_command check_ncpa!-t 'password' -P 5693 -M system/agent_version
max_check_attempts 3
check_interval 10
retry_interval 5
check_period 24x7
contacts delta-AV-Preprocessor
notification_interval 0
notification_period 24x7
notifications_enabled 1
icon_image ncpa.png
statusmap_image ncpa.png
register 1
}
define service {
host_name ALPC881
service_description Check APM Loader - Pre-Production
check_command check_ncpa!-t 'password' -P 5693 -M 'plugins/check_logfiles.exe' -a '-f 'C:\\NagiosAncillaryScrips\\check_logfiles.cfg''
max_check_attempts 1
check_interval 10
retry_interval 1
check_period 24x7
notification_interval 0
notification_period 24x7
notification_options c,r
contact_groups admins
register 1
}
define service {
host_name ALPC881
service_description Check APM Loader - Production
check_command check_ncpa!-t 'password' -P 5693 -M 'plugins/check_logfiles_prod.exe' -a '-f 'C:\\NagiosAncillaryScrips\\check_logfiles_prod.cfg''
max_check_attempts 1
check_interval 10
retry_interval 1
check_period 24x7
notification_interval 0
notification_period 24x7
notification_options c,r
contact_groups admins
register 1
}
I hope this helps others using the plugin Check_logfiles, because support for this plugin $ucks. There isn't any. the owner creator, well, abandoned thier post. also, many sites, you'll just get ignored asking questions surrounding this plugin.
But, it truly is a nice plugin, worth the pain of getting it working. to get it to work on Linux/Unix is fairly straight forward and EASY, to get it to work under windows is somewhat magic, lots of tinkering.
I first set it up to run as a windows service under TASK Scheduler. I couldn 't get it to call a perl script from inside, however, it calls a perl subroutine without issue.
it does work with NCPA agent.
After installation and configuration, follow the README.exe for windows. add .PL extension recognition to Win OS, install Strawberry Perl, make all PATH and VAR settings. after building the service, you must place it under the path designated for NCPA plugins. I tried pointing it to another path, didn't work for me. if you will tie it in to Nagios for statistics, and have Nagios call it, you'll need to do this, as this is where Nagios NCPA finds the plugins it can execute.
AN EXAMPLE CHECK_LOGFILES.CFG file
This check logfiles config searches and when finds the exception statement in the logfile will call the SUB under script, and copies or refeeds a file to an ingestion endpoint. since Windows doesn't have a mail utility available, I verifed SMTP works, and then used CMAIL on Windows to issue independent emails.
$scriptpath = 'C:\Program Files (x86)\Nagios\NCPA\contrib';
$protocolsdir = 'C:\Program Files (x86)\Nagios\NCPA\protocols';
$seekfilesdir = 'C:\Program Files (x86)\Nagios\NCPA\seek';
$MACROS = {
LOGS_DIR => 'C:\\APMConnect\\Logs',
PP_INGESTION_EP => 'C:\\APMConnect\\AutoDataLoader\\Scandir\\ManageAPM',
SRC_DIR => '\\\\win.alpeife.corporate.com\\APM_Data_Storage\\Zip File Archive',
CL_CMAIL_SMTP_HOST => 'mail.ad.com',
CL_CMAIL_TO => '[email protected]',
CL_CMAIL_FROM => '[email protected]',
CL_CMAIL_SUBJECT => 'APM Loader - Upload Failure Notification - PreProduction'
};
@searches = (
{
tag => '504 Gateway Time-Out',
logfile => '$LOGS_DIR$\AutoLoader.log',
rotation => 'AutoLoader.log.\d{1,2}',
type => 'rotating',
criticalpatterns => [
'^java.lang.Exception:Method failed: HTTP/1.1 504 Gateway Time-out Please check configuration details and replace or update the file :.*'
],
options => 'protocol,perfdata,script,supersmartscript',
scriptdelay => 1,
script => sub {
use File::Copy;
my $other_cmd = 'net use E: \\\\win.alpeif.corporate.com\\APM_Data_Storage /USER:logon.ds.com\\lg8174sv xnEDhPaD3gT /PERSISTENT:YES';
my $other_status = system($other_cmd);
my $sout = "$ENV{CHECK_LOGFILES_SERVICEOUTPUT}";
my $result = rindex($sout, 'FaultData');
my $_file_name = substr($sout, $result, length($sout));
my $_source_dir = $ENV{CHECK_LOGFILES_SRC_DIR};
my $_target_dir = $ENV{CHECK_LOGFILES_PP_INGESTION_EP};
my $Host = $ENV{CHECK_LOGFILES_CMAIL_SMTP_HOST};
my $To = $ENV{CHECK_LOGFILES_CMAIL_TO};
my $From = $ENV{CHECK_LOGFILES_CMAIL_FROM};
my $Subject = $ENV{CHECK_LOGFILES_CMAIL_SUBJECT};
my $Body = "The APM Loader Upload Failed.\n\n Failed to refeed file: $_file_name\n\n Please see attached.\n\n For more information, see logs under 'C:\\\\Program Files (x86)\\\\Nagios\\\\NCPA\\\\protocols'";
my $Attachment = 'C:\\Program Files (x86)\\Nagios\\NCPA\\seek\\check_logfiles.C__APMConnect_Logs_AutoLoader.log.504 Gateway Time-Out';
my @cmd = ('C:\\Program Files (x86)\\Nagios\\NCPA\contrib\\cmail.exe');
push @cmd, "-host:$Host";
push @cmd, "-to:$To";
push @cmd, "-from:$From";
push @cmd, "-subject:$Subject";
push @cmd, "-body:$Body";
push @cmd, "-a:$Attachment";
opendir (dir, $_source_dir);
my $_result = rindex($sout, 'FaultData');
my $_sout = substr($sout, $_result, length($_file_name)) = "$_file_name";
if( -f "$_source_dir/$_file_name" ) {
copy ("$_source_dir\\$_file_name", "$_target_dir\\$_file_name");
if ( $? ) {
printf 'OK - File Copy Successful!';
printf " Copied File to Refeed APM: $_source_dir\\$_file_name";
return 0;
} else {
require $Attachment;
$state->{'serviceoutput'} = "$_sout";
system(@cmd);
printf 'CRITICAL - File Copy Failed!';
printf " - Source dir: $_source_dir\\$_file_name\n";
return 2;
}
} else {
require $Attachment;
$state->{'serviceoutput'} = "$_sout";
system(@cmd);
printf 'CRITICAL - File Copy Failed, File CANNOT be located! Resource may not be Mounted!';
printf " - Source dir: $_source_dir\\$_file_name\n";
return 2;
}
closedir($dir);
}
}
);
To make configs work easier without all the escaping - I used Symbolic Links 'mklink /D target source'.
Test on Command line on windows box
c:\Program Files (x86)\Nagios\NCPA\plugins>check_logfiles.exe -f "c:\NagiosAncillaryScrips\check_logfiles.cfg"
Also, test on Task Scheduler. you can just leave it on task scheduler and leave it run as a windows task, or have NAgios call the plugin.
I worked out all issues under task scheduler then moved to Nagios.
FROM the NAGIOS MONITORING SERVER
test command line
[root@alpc1083 objects]# check_ncpa.py -v -H 10.14.12.11 -t 'password' -P 5693 -M 'plugins/check_logfiles.exe' -a '-f "C:\\NagiosAncillaryScrips\\check_logfiles.cfg"'
define host {
host_name ALPC881
address 10.14.12.11
check_command check_ncpa!-t 'password' -P 5693 -M system/agent_version
max_check_attempts 3
check_interval 10
retry_interval 5
check_period 24x7
contacts delta-AV-Preprocessor
notification_interval 0
notification_period 24x7
notifications_enabled 1
icon_image ncpa.png
statusmap_image ncpa.png
register 1
}
define service {
host_name ALPC881
service_description Check APM Loader - Pre-Production
check_command check_ncpa!-t 'password' -P 5693 -M 'plugins/check_logfiles.exe' -a '-f 'C:\\NagiosAncillaryScrips\\check_logfiles.cfg''
max_check_attempts 1
check_interval 10
retry_interval 1
check_period 24x7
notification_interval 0
notification_period 24x7
notification_options c,r
contact_groups admins
register 1
}
define service {
host_name ALPC881
service_description Check APM Loader - Production
check_command check_ncpa!-t 'password' -P 5693 -M 'plugins/check_logfiles_prod.exe' -a '-f 'C:\\NagiosAncillaryScrips\\check_logfiles_prod.cfg''
max_check_attempts 1
check_interval 10
retry_interval 1
check_period 24x7
notification_interval 0
notification_period 24x7
notification_options c,r
contact_groups admins
register 1
}
Re: NCPA question - cannot get to work
Please feel free to close this case/ticket.
thank you
thank you
Re: NCPA question - cannot get to work
The documentation on this plugin shows it communicating with Nagios with NRPE agent.
however, I do not have the NRPE agent on this box. hoping I don't need to intall another agent, ...
however, I do not have the NRPE agent on this box. hoping I don't need to intall another agent, ...