#!/bin/perl
######################################################################################
#
# checkArubaOScx.pl
#
# checkmk Individual program call instead of agent access
#
# script queries parameters from Aruba CX Switches and deliveres output for checkmk
# individual program call ...
#
# Monitores Health Parameters like
# - VsxKeepAliveOperState
# - VsxDeviceRole
# - VsxConfigSync
# - VsxIslOperSate
# - PowerSupply
# - Temperature
#
# - see also: https://www.circitor.fr/Mibs/Html/A/ARUBAWIRED-VSX-MIB.php#arubaWiredVsxKeepAliveOperState
#
# sample output:
# <<<check_mk>>>
# Version: pn-v2023-07-08
# <<<local>>>
# 0 arubaOScx-VsxKeepAliveStatus - OK: vsx KeepAliveOperState: inSyncEstablished.
# 0 arubaOScx-VsxDeviceRole - OK: vsx device role: secondary.
# 0 arubaOScx-VsxConfigSync - OK: vsx config sync: enabled.
# 0 arubaOScx-VsxIslOperState - OK: vsx isl operating state: inSync.
# 0 arubaOScx-PowerSupply-1/1 - OK: 1/1 power supply state is ok
# 0 arubaOScx-PowerSupply-1/2 - OK: 1/2 power supply state is ok
# 0 arubaOScx-Temp-1/1-1 temp=23 OK Temp=23, State=normal, TempMin=19.5, TempMax=34
# 0 arubaOScx-Temp-1/1-2 temp=22 OK Temp=22, State=normal, TempMin=18.5, TempMax=33
# 0 arubaOScx-Temp-1/1-3 temp=20.5 OK Temp=20.5, State=normal, TempMin=17, TempMax=31.5
#
# (c) s4c
#
######################################################################################
my $version= '2023-07-08';
use Data::Dumper;
use strict;
my $debug=0; #1=on

if ($ARGV[0] eq '' ){
print "Usage: checkArubaOScx.pl <hostname or ip-address> <snmp community> --vsx\n";
print " example checkArubaOScx.pl 192.168.2.1 public \n";
print " or\n";
print " example checkArubaOScx.pl 192.168.2.1 public --vsx\n";
print "\n";
exit(1);
}
my $argument_count = scalar @ARGV;
my $ip= $ARGV[0];
my $community = $ARGV[1];
my $vsxmode = 0;

if ($argument_count == 3){
$vsxmode = 1 if $ARGV[2] eq '--vsx';
print "vsxmode is on" if $debug;
}

my $debug=0; #1=on
my %foundHash={};
my $line='';

print "<<<check_mk>>>\n";
print "Version: pn-v$version\n";
print "<<<local>>>\n";

if ($vsxmode){
#arubaWiredVsxKeepAliveOperState
my %matrix=();
$matrix{1}='init';
$matrix{2}='configured';
$matrix{3}='inSyncEstablished';
$matrix{4}='outofSyncEstablished';
$matrix{5}='initEstablished';
$matrix{6}='failed';
$matrix{7}='stopped';
my $service="arubaOScx-VsxKeepAliveStatus";
my $value = getSNMPInt(".1.3.6.1.4.1.47196.4.1.1.3.7.2.2.1");
if (($value >= 1) && ($value <=2)){
print "1 $service - Warning: vsx KeepAliveOperState: $matrix{$value}.\n";
}elsif ($value==3){
print "0 $service - OK: vsx KeepAliveOperState: $matrix{$value}.\n";
}elsif (($value >= 4) && ($value <=7)){
print "1 $service - Warning: vsx KeepAliveOperState: $matrix{$value}.\n";
}else{
print "3 $service - Unknown value\n";
}
}

if ($vsxmode){
#arubaWiredVsxDeviceRole
my %matrix=();
$matrix{1}='primary';
$matrix{2}='secondary';
$matrix{3}='notConfigured';
my $service="arubaOScx-VsxDeviceRole";
my $value = getSNMPInt(".1.3.6.1.4.1.47196.4.1.1.3.7.1.4.1");
if (($value >= 1) && ($value <=3)){
print "0 $service - OK: vsx device role: $matrix{$value}.\n";
}else{
print "3 $service - Unknown value\n";
}
}


if ($vsxmode){
#arubaWiredVsxConfigSync
my %matrix=();
$matrix{1}='enabled';
$matrix{2}='disabled';
my $service="arubaOScx-VsxConfigSync";
my $value = getSNMPInt(".1.3.6.1.4.1.47196.4.1.1.3.7.1.4.2");
if (($value >= 1) && ($value <=2)){
print "0 $service - OK: vsx config sync: $matrix{$value}.\n";
}else{
print "3 $service - Unknown value\n";
}
}

if ($vsxmode){
#arubaWiredVsxIslOperState
my %matrix=();
$matrix{1}='init';
$matrix{2}='outSync';
$matrix{3}='inSync';
my $service="arubaOScx-VsxIslOperState";
my $value = getSNMPInt(".1.3.6.1.4.1.47196.4.1.1.3.7.2.1.1");
if ($value == 1){
print "1 $service - Warning: vsx isl operating state: $matrix{$value}.\n";
}elsif ($value==2){
print "2 $service - Critical: vsx isl operating state: $matrix{$value}.\n";
}elsif ($value==3){
print "0 $service - OK: vsx isl operating state: $matrix{$value}.\n";
}else{
print "3 $service - Unknown value\n";
}
}

#psu
#name: .1.3.6.1.4.1.47196.4.1.1.3.11.2.1.1.3
#state: .1.3.6.1.4.1.47196.4.1.1.3.11.2.1.1.4

#$debug=1;
#psu 1) get names
my $service="arubaOScx-PowerSupply";
my %psuname=();
my $i=0;
open(IN,"snmpwalk -v 2c -c $community $ip .1.3.6.1.4.1.47196.4.1.1.3.11.2.1.1.3 2>/dev/null |");
while(<IN>){
$line = $_;
chomp($line);
$i++;
print "[$i] $line\n" if $debug;
if ($line =~ /STRING: \"(.*)\"$/){
$psuname{$i}=$1;
}
}
close(IN);
print Dumper(\%psuname) if $debug;


#psu 1) get state
my $i=0;
my $psustate='';
open(IN,"snmpwalk -v 2c -c $community $ip .1.3.6.1.4.1.47196.4.1.1.3.11.2.1.1.4 2>/dev/null |");
while(<IN>){
$line = $_;
chomp($line);
$i++;
print "[$i] $line\n" if $debug;
if ($line =~ /STRING: \"(.*)\"$/){
$psustate=$1;
if ($psustate =~ /ok/i){
print "0 $service-$psuname{$i} - OK: $psuname{$i} power supply state is ok\n";
}else{
print "1 $service-$psuname{$i} - Warning: $psuname{$i} power supply state is warning!\n";
}
}
}
close(IN);

#ARUBAWIRED-TEMPSENSOR-MIB get temperature
#we have something like that:
#1] .1.3.6.1.4.1.47196.4.1.1.3.11.3.1.1.5.1.3.1.1 = STRING: "1/1-1"
#[2] .1.3.6.1.4.1.47196.4.1.1.3.11.3.1.1.5.1.3.1.2 = STRING: "1/1-2"
#[3] .1.3.6.1.4.1.47196.4.1.1.3.11.3.1.1.5.1.3.1.3 = STRING: "1/1-3"
#[4] .1.3.6.1.4.1.47196.4.1.1.3.11.3.1.1.6.1.3.1.1 = STRING: "normal"
#[5] .1.3.6.1.4.1.47196.4.1.1.3.11.3.1.1.6.1.3.1.2 = STRING: "normal"
#[6] .1.3.6.1.4.1.47196.4.1.1.3.11.3.1.1.6.1.3.1.3 = STRING: "normal"
#[7] .1.3.6.1.4.1.47196.4.1.1.3.11.3.1.1.7.1.3.1.1 = INTEGER: 27000
#[8] .1.3.6.1.4.1.47196.4.1.1.3.11.3.1.1.7.1.3.1.2 = INTEGER: 26500
#[9] .1.3.6.1.4.1.47196.4.1.1.3.11.3.1.1.7.1.3.1.3 = INTEGER: 25500
#[10] .1.3.6.1.4.1.47196.4.1.1.3.11.3.1.1.8.1.3.1.1 = INTEGER: 19500
#[11] .1.3.6.1.4.1.47196.4.1.1.3.11.3.1.1.8.1.3.1.2 = INTEGER: 18500
#[12] .1.3.6.1.4.1.47196.4.1.1.3.11.3.1.1.8.1.3.1.3 = INTEGER: 17000
#[13] .1.3.6.1.4.1.47196.4.1.1.3.11.3.1.1.9.1.3.1.1 = INTEGER: 34000
#[14] .1.3.6.1.4.1.47196.4.1.1.3.11.3.1.1.9.1.3.1.2 = INTEGER: 33000
#[15] .1.3.6.1.4.1.47196.4.1.1.3.11.3.1.1.9.1.3.1.3 = INTEGER: 31500
my $service="arubaOScx-Temp";
my $i=0;
$debug=0;
my $tempname; #5.1.3.1.1
my $tempstate; #6.1.3.1.1
my $temp; #7.1.3.1.1
my $tempmin; #8.1.3.1.1
my $tempmax; #9.1.3.1.1
my %tempHash;
my $numOfTemp=0;
open(IN,"snmpwalk -v 2c -On -c $community $ip .1.3.6.1.4.1.47196.4.1.1.3.11.3.1.1 2>/dev/null |");
while(<IN>){
$line = $_;
chomp($line);
$i++;
print "[$i] $line\n" if $debug;
#grep the oid before the string
if ($line =~ /(\d\.\d\.\d\.\d\.\d*) = STRING: \"(.*)\"$/){
print "val1=$1, val2=$2\n" if $debug;
$tempHash{$1}=$2;
$numOfTemp++ if ($1 =~ /^5\.1\.3\.1\./);
}
if ($line =~ /(\d\.\d\.\d\.\d\.\d*) = INTEGER: (.*)$/){
print "val1=$1, val2=$2\n" if $debug;
$tempHash{$1}=$2/1000;
}
}
close(IN);
print "i=$i / number of Temp=$numOfTemp.\n" if $debug;
print Dumper(\%tempHash) if $debug;

for (my $i=1;$i<=$numOfTemp;$i++){
$tempname=$tempHash{"5.1.3.1.$i"};
$tempstate=$tempHash{"6.1.3.1.$i"};
$temp=$tempHash{"7.1.3.1.$i"};
$tempmin=$tempHash{"8.1.3.1.$i"};
$tempmax=$tempHash{"9.1.3.1.$i"};

if ($tempstate =~ /^normal$/i){
print "0 $service-$tempname temp=$temp OK Temp=$temp, State=$tempstate, TempMin=$tempmin, TempMax=$tempmax\n";
}else{
print "1 $service-$tempname temp=$temp Warning Temp=$temp, State=$tempstate, TempMin=$tempmin, TempMax=$tempmax\n";
}
}

###########################
#other sub routines
###########################
sub getSNMPStr($){
my $mib=$_[0];
my $found="not found";
open(IN,"snmpwalk -v 2c -c $community $ip $mib 2>/dev/null |");
while(<IN>){
$line = $_;
chomp($line);
#print "$line\n" if $debug;
if ($line =~ /STRING: \"(.*)\"$/){
$found=$1;
#print "found=$found!!\n";
}
}
close(IN);
return $found;
}

sub getSNMPInt($){
my $mib=$_[0];
my $found="not found";
open(IN,"snmpwalk -v 2c -c $community $ip $mib 2>/dev/null |");
while(<IN>){
$line = $_;
chomp($line);
print "$line\n" if $debug;
if ($line =~ /INTEGER: (.*)$/){
$found=$1;
#print "found=$found!!\n";
}
}
close(IN);
return $found;
}

computer2know :: thank you for your visit :: have a nice day :: © 2024