disable port using nagios core

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.
DOkuwa
Posts: 114
Joined: Tue Aug 15, 2017 3:54 pm

disable port using nagios core

Post by DOkuwa »

I use Nagios Core and want a device not to show any status or information on a particular port of a device e.g port is down or interface is down
In other NMS we disable the port using the OID (SNMP)
Is there any way Nagios can do this
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: disable port using nagios core

Post by npolovenko »

Hello, @DOkuwa. How are you monitoring the device? Do you have separate service checks defined for each port of the device? Or are you using SNMP trap?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
DOkuwa
Posts: 114
Joined: Tue Aug 15, 2017 3:54 pm

Re: disable port using nagios core

Post by DOkuwa »

we are using snmp to monitor the devices
we have a check for all the ports for a group of devices but Nagios keeps reporting that a some specific port is down which is correct because they are alcatel devices which it's port cannot be disabled from the terminal
so we want nagios to exclude monitoring this specific port using the sysOID
or maybe put in in maintenance mode for this group of devices
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: disable port using nagios core

Post by npolovenko »

@DOkuwa, Can you upload the snmptt.conf file from your Nagios server?

Code: Select all

/etc/snmp/snmptt.conf 
Usually that configuration file defines how your trap information is processed by Nagios. So we might be able to modify it..
Also, please share with us a screenshot of your SNMP check output on Service Detail page.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
DOkuwa
Posts: 114
Joined: Tue Aug 15, 2017 3:54 pm

Re: disable port using nagios core

Post by DOkuwa »

The first service is the actual service that monitors the port
the second service is the generic services it uses and the third is the script that the service uses
I have the snmp oid which relates to the desired port on the alcatel devices that needs to be filtered out and don't know if this can be adjusted in the script

Code: Select all

define service{
        name                            alcatel-network-ports
        service_description             Alcatel_Network_Ports
        use                             generic-service
        is_volatile                     0
        check_command                   check_alcatel_network_ports
        max_check_attempts                      3
        normal_check_interval           3
        retry_check_interval            1
        active_checks_enabled           1
        check_period                    24x7
        parallelize_check                       1
        obsess_over_service             0
        check_freshness                 0
        flap_detection_enabled          0
        process_perf_data                       0
        retain_status_information               1
        retain_nonstatus_information    0
        notification_interval           180
        notification_period             24x7
        notification_options            w,c,r
        notifications_enabled           1
        contact_groups                  Core_Team
        register                                0
}
define service{
        name                            generic-service
        service_description             generic-service
        is_volatile                     0
        max_check_attempts                      3
        normal_check_interval           5
        retry_check_interval            1
        active_checks_enabled           1
        passive_checks_enabled          0
        check_period                    24x7
        parallelize_check                       1
        obsess_over_service             0
        process_perf_data                       1
        retain_status_information               1
        retain_nonstatus_information    0
        notification_interval           60
        notification_period             24x7

Code: Select all

more check_alcatel_ports.pl
#!/usr/bin/perl

=pod

=head1 NAME

check_alcatel_ports.pl


=head1 SYNOPSIS

 check_alcatel_ports.pl community-string agent


=head1 DESCRIPTION

Uses Net::SNMP to query an Alcatel 7450 VPLS switch to find status of the
network ports. Alarms critical if the ports are UP/DOWN.

=head1 NOTES

=head1 TODO

=head1 REFERENCES

TIMETRA-PORT-MIB.mib

=cut

# Modules
use strict;
use warnings;
use Net::SNMP;
use Getopt::Long;
Getopt::Long::Configure("bundling");
use lib qw( /usr/local/nagios/libexec );
use utils qw($TIMEOUT %ERRORS &print_revision &support);

# Globals
use vars qw|$PROGNAME $DEBUG $VERSION|;
$DEBUG = 0;
$VERSION = '01.00';
$PROGNAME = "$0";

my $agent;
my $comm_string;
my $ok;
my $state = $ERRORS{'OK'};
my ($opt_V, $opt_h);

# Just in case of problems, let's not hang Nagios
$SIG{'ALRM'} = sub {
     print ("ERROR: Unable to get status from $agent (alarm timeout)\n");
     exit $ERRORS{"UNKNOWN"};
};
alarm($TIMEOUT);

#Option checking
$ok = GetOptions(
                "V"   => \$opt_V,   "version"    => \$opt_V,
                "h"   => \$opt_h,   "help"       => \$opt_h,
                "H=s" => \$agent,  "hostname=s" => \$agent,
                "C=s" => \$comm_string, "community=s" => \$comm_string,
                );

unless ( $ok ) {
    exit $ERRORS{'OK'};
}

if ($opt_V) {
    exit $ERRORS{'OK'};
}

if ($opt_h) {
    exit $ERRORS{'OK'};
}

if (!$comm_string) {
    print STDERR "No community string specified!\n";
    exit $ERRORS{'UNKNOWN'};
}

unless ( utils::is_hostname($agent) ) {
    print "Invalid hostname\n";
    exit $ERRORS{"UNKNOWN"};
}

# Alcatel OIDs
my $port_name_oid = '1.3.6.1.4.1.6527.3.1.2.2.4.2.1.6';
my $port_desc_oid = '1.3.6.1.4.1.6527.3.1.2.2.4.2.1.5';
my $port_mode_oid = '1.3.6.1.4.1.6527.3.1.2.2.4.2.1.11';
my $port_admin_oid = '1.3.6.1.4.1.6527.3.1.2.2.4.2.1.37';
my $port_oper_oid = '1.3.6.1.4.1.6527.3.1.2.2.4.2.1.38';
my $port_state_oid = '1.3.6.1.4.1.6527.3.1.2.2.4.2.1.39';

my %ports;
my $answer = '';
my $error = 0;

# Initiate SNMP session
my $session = Net::SNMP->session(
              -hostname => $agent,
              -version => 'snmpv2c',
              -community => $comm_string,
              -port => 161,
              -timeout => 2,
              -retries => 1,
              -maxmsgsize => 20000,
);

# Port Name
my $table = $session->get_table( -baseoid => $port_name_oid );
if ($session->error) {
    print $session->error . "\n";
    exit(1);
}

foreach my $entry (sort keys %{$table}) {
        my $index = (split /\./, $entry)[16];
        $ports{$index} = [ $table->{$entry} ];
}

# Port Mode
$table = $session->get_table( -baseoid => $port_mode_oid );
if ($session->error) {
    print $session->error . "\n";
    exit(1);
}

foreach my $entry (sort keys %{$table}) {
        my $index = (split /\./, $entry)[16];
        $ports{$index}->[1] = $table->{$entry};
}


# Port Admin Status
$table = $session->get_table( -baseoid => $port_admin_oid );
if ($session->error) {
    print $session->error . "\n";
    exit(1);
}

foreach my $entry (sort keys %{$table}) {
        my $index = (split /\./, $entry)[16];
        $ports{$index}->[2] = $table->{$entry};
}

# Port Oper Status
$table = $session->get_table( -baseoid => $port_oper_oid );
if ($session->error) {
    print $session->error . "\n";
    exit(1);
}

foreach my $entry (sort keys %{$table}) {
        my $index = (split /\./, $entry)[16];
        $ports{$index}->[3] = $table->{$entry};
}

# Port Desc
$table = $session->get_table( -baseoid => $port_desc_oid );
if ($session->error) {
    print $session->error;
    exit(1);
}

foreach my $entry (sort keys %{$table}) {
        my $index = (split /\./, $entry)[16];
        $ports{$index}->[4] = $table->{$entry};
}

# Port State
$table = $session->get_table( -baseoid => $port_state_oid );
if ($session->error) {
    print $session->error;
    exit(1);
}

foreach my $entry (sort keys %{$table}) {
        my $index = (split /\./, $entry)[16];
        $ports{$index}->[5] = $table->{$entry};
}


foreach my $port (sort keys %ports) {

    my $name = $ports{$port}->[0];
    my $desc = $ports{$port}->[4];
    my $mode = $ports{$port}->[1];
    my $admin = $ports{$port}->[2];
    my $oper = $ports{$port}->[3];
        my $port_state = $ports{$port}->[5];


# Skip if not network port
    if ($mode != 2) {
        next;
    }

# Skip if admin down
    elsif ($admin == 3) {
        next;
    }

# Skip if state is 'ghost' (port provisioned by not physically present)
    elsif ($port_state == 2){
        next;
        }

# Alarm if oper down
    elsif ($oper != 2) {
        $error = 1;
        $state = $ERRORS{'CRITICAL'};
        $answer .= "[$desc OperStatus down] ";
        next;
    }

}

if (!$error) {
    $answer .= "All ports OK.";
    print $answer;
}

else {
    print "$answer";
}

exit $state;




Last edited by dwhitfield on Fri Nov 10, 2017 3:50 pm, edited 1 time in total.
Reason: breaking up the code block since it's two different things
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: disable port using nagios core

Post by npolovenko »

@DOkuwa, I'm not a pro at programming but I think you could add a new else if statement to the script to filter out that particular port based on some criteria? I haven't seen the actual output of this script so it's hard to tell. As an option, you could email customer support for a custom development.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
DOkuwa
Posts: 114
Joined: Tue Aug 15, 2017 3:54 pm

Re: disable port using nagios core

Post by DOkuwa »

yes this is true
I will need to figure this out
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: disable port using nagios core

Post by dwhitfield »

I'm not seeing any references online to this plugin. Where did you get it from? Did it originally have a different name? Is it just something someone in your organization wrote? I ask because there might be newer versions with the features you want.
DOkuwa
Posts: 114
Joined: Tue Aug 15, 2017 3:54 pm

Re: disable port using nagios core

Post by DOkuwa »

i have not seen any plugin for this but i might need to modify the check_alcatel_ports.pl
This request has been ordered by the network team as the alarms caused by this network port down is flooding their mails
and hence this needs to be removed/disabled
User avatar
tacolover101
Posts: 432
Joined: Mon Apr 10, 2017 11:55 am

Re: disable port using nagios core

Post by tacolover101 »

you need to modify the plugin, and build logic to handle the returned message properly.
Locked