#!/bin/perl
use strict;
######################################################################################
#
# checkNetman.pl
#
# get data from a netman snmp component, that is for example build in, in a riello usv
#
# base snmpwalk call:
# snmpwalk -v 2c -c public 10.10.10.10 SNMPv2-SMI::mib-2.33
#
######################################################################################

if ($ARGV[0] eq '' ){
print "Usage: checkNetman.pl <hostname or ip-address> <snmp-community> <load-warning> <load-critical>\n";
print " example checkNetman.pl 192.168.2.1 public 80 90\n";
print "\n";
exit(1);
}
my $ip= $ARGV[0];
my $community = $ARGV[1];
my $warning = $ARGV[2];
my $critical= $ARGV[3];


$warning=80 if $warning eq '';
$critical=90 if $critical eq '';

$community='public' if $community eq '';
my $debug=0; #1=on
my %foundHash={};
my $name='';
my $line='';
my $status='';
my $statustxt='';
my $alarm='';



print "<<<check_mk>>>\n";
print "Version: pn-v2022-03-14\n";
print "<<<local>>>\n";
open(IN,"snmpwalk -v 2c -c $community $ip SNMPv2-SMI::mib-2.33.1.6.1.0 2>/dev/null |");
while(<IN>){
$line = $_;
chomp($line);
print "$line\n" if $debug;
#SNMPv2-SMI::mib-2.33.1.6.1.0 = Gauge32: 0
if ($line =~ /33.1.6.1.0 = .*:\s(\d)$/){
print "alarm=$1\n" if $debug;
$alarm=$1;
}
}
close(IN);

open(IN,"snmpwalk -v 2c -c $community $ip SNMPv2-SMI::mib-2.33.1.4.4 2>/dev/null |");
while(<IN>){
$line = $_;
chomp($line);
print "$line\n" if $debug;

#Real Power in Watt
if ($line =~ /33.1.4.4.1.4.1 = INTEGER:\s(\d*)$/){
$foundHash{'pL1'}=$1/1000;
}
if ($line =~ /33.1.4.4.1.4.2 = INTEGER:\s(\d*)$/){
$foundHash{'pL2'}=$1/1000;
}
if ($line =~ /33.1.4.4.1.4.3 = INTEGER:\s(\d*)$/){
$foundHash{'pL3'}=$1/1000;
}

#load
if ($line =~ /33.1.4.4.1.5.1 = INTEGER:\s(\d*)$/){
$foundHash{'loadL1'}=$1;
}
if ($line =~ /33.1.4.4.1.5.2 = INTEGER:\s(\d*)$/){
$foundHash{'loadL2'}=$1;
}
if ($line =~ /33.1.4.4.1.5.3 = INTEGER:\s(\d*)$/){
$foundHash{'loadL3'}=$1;
}
}
close(IN);

if (exists $foundHash{'loadL1'}){
$status=0;
$statustxt=">> Warning/Critical: $warning".'/'.$critical.'. ';
if ($foundHash{'loadL1'} > $critical){$status=2;$statustxt.="L1 has critical value! ";}
if (($foundHash{'loadL1'} > $warning) and ($foundHash{'loadL1'}<= $critical)){$status=1;$statustxt.="L1 has warning value! ";}

if ($foundHash{'loadL2'} > $critical){$status=2;$statustxt.="L2 has critical value! ";}
if (($foundHash{'loadL2'} > $warning) and ($foundHash{'loadL2'}<= $critical)){
$status=1 if $status < 1;
$statustxt.="L2 has warning value! ";}

if ($foundHash{'loadL3'} > $critical){$status=2;$statustxt.="L3 has critical value! ";}
if (($foundHash{'loadL3'} > $warning) and ($foundHash{'loadL3'}<= $critical)){$status=1;$statustxt.="L3 has warning value! ";}

print "$status ups-load L1=$foundHash{'loadL1'}|L2=$foundHash{'loadL2'}|L3=$foundHash{'loadL3'} upsOutputPercentLoad L1=$foundHash{'loadL1'}%, L2=$foundHash{'loadL2'}% ,L3=$foundHash{'loadL3'}%. $statustxt\n";
}else{
print "1 ups-load L1=|L2=|L3= no values found!\n";
}

if (exists $foundHash{'pL1'}){
my $summary=$foundHash{'pL1'} + $foundHash{'pL2'} + $foundHash{'pL3'};
print "0 ups-power Sum=$summary|L1=$foundHash{'pL1'}|L2=$foundHash{'pL2'}|L3=$foundHash{'pL3'} Power L1-L3 and Summary in Kilo-Watts: Summary=".$summary."KW, L1=$foundHash{'pL1'}KW, L2=$foundHash{'pL2'}KW ,L3=$foundHash{'pL3'}KW.\n";
}else{
print "1 ups-power Sum=|L1=|L2=|L3= no values found!\n";
}

if ($alarm==0){
print "0 ups-alarm - No alarm present!\n";
}else{
print "2 ups-alarm - UPS alarm found! Please check your USV!!\n";
}

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