Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
I have a number of servers using RHEL 6 that I have been monitoring without issue using the following "check_remote_monit" plugin (As well as other remote checks) *in usr/lib64/nagios/plugins*:
#!/usr/bin/perl
#Libraries
use strict;
use warnings;
use lib qw(/usr/local/nagios/libexec);
use feature qw(switch say);
#Pull Host variable from command.cfg
use Getopt::Long;
my $host = '';
GetOptions ('Host=s' => \$host);
#set pattern to search for
my $good_pattern = "is running";
my $warning_pattern = "not running";
my $critical_pattern = "is stopped";
#Get status variable from ssh and chomp it to remove new lines
chomp(my $status = qx|/usr/bin/ssh ${host} '/sbin/service monit status'|);
#Search for good pattern if not exit with error
if ($status =~ m/$good_pattern/)
{
printf "OK: %s\n", $status;
exit(0);
}if ($status =~ m/$critical_pattern/){
printf "CRITICAL: %s\n", $status;
exit(2);
}if ($status =~ m/$warning_pattern/){
printf "WARNING: %s\n", $status;
exit(1);
}
printf "UNKNOWN: %s\n", $status;
exit(3);
Unfortunately, RHEL7 had to change the way you look things up. I am wondering if Nagios has some updated plugin to use with RHEL7 to check statuses of Hardware (CPU, Disk_Drive, Memory, etc.) and well as specific services that we are checking for our application running on RHEL6 (And now RHEL7)?
Chris
Last edited by scottwilkerson on Wed Mar 07, 2018 2:22 pm, edited 1 time in total.
Reason:code wrap
Also, to follow up on this, I have tried to use check_process_snmp with a number of "Processes" and it keeps coming back with unknown status in the Nagios Core webpage. I am thinking this is not set right for RHEL 7.4 either:
!/bin/perl
use strict;
use warnings;
use Net::SNMP;
use Net::SNMP::Util;
use lib qw(/usr/lib/nagios/libexec);
use feature qw(switch say);
use Getopt::Long;
my $host = '';
my $process = '';
GetOptions('Host=s' => \$host,
'Process=s' => \$process);
my $oid = '.1.3.6.1.2.1.25.4.2.1.4';
my ($session, $error) = Net::SNMP->session(
-hostname => shift || $host,
-community => shift || 'nagios',
);
if (!defined $session){
printf "ERROR: %s.\n", $error;
}
#my @result = $session->walk_request(-varbindlist => [ $oid ],);
my @result = '';
(@result, $error) = snmpwalk(
snmp => $session,
oids => [ $oid ],);
for my $i (0..$#result){
if ($process =~ m/$result[$i]/)
{
printf "OK: %s is running\n", $process;
exit 0;
}
$i++;
}
printf "ERROR %s is not running\n", $process;
exit 1;
tgriep wrote:I found this plugin you can use to monitor services on Redhat / Centos 7 servers that use the systemctl command. https://exchange.nagios.org/directory/P ... ce/details
Try it out and see if it works for you.
I believe this would work if I was running the service locally to the Nagios Core server but I am running it remotely. I have reached out to Taha to see if he has any ideas. Will keep you all updated.
I ended up going with NRPE. It just seemed like the next logical step on this, not to mention that it was able to do everything I needed from checking CPU, to verifying users logged in, Memory and watching all the processes and services that I had running on that machine. Thank you all for your help and input.