#!/usr/local/bin/perl

# Extreme Networks SNMP Information Gathering and Inventory Tool for Net-SNMP
# (c) 2002 Ben Rockwood - HOMESTEAD INC
# v0.2 - Thu Dec 12 13:02:37 PST 2002

#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


# Devices Community String
$COMMUNITY = "public";
# Location of the Extreme MIB
$MIB = "./extreme620.mib";
# Location of the SNMPGET command
$SNMPGETCMD = "/usr/local/bin/snmpget";

######################################
# Usage
$ARGS = @ARGV;
unless ($ARGS > 0) { die("Usage: $0 [-report|-page] <host> \n"); }

######################################
# Convience

$HOST = $ARGV[1];
$SNMPGET = "$SNMPGETCMD -v1 -c $COMMUNITY $HOST -m $MIB -Oqv";
$DATE = `date`;
chomp($DATE);

######################################

if ( $ARGV[0] !~ /^\-/ ) { die("Usage: $0 [-report|-page] <host> \n"); }

if ( $ARGV[0] eq "-report" ) {
	 if (`/usr/local/sbin/fping $HOST 2> /dev/null`) {
		&__check_bd();
			
          } else {
		print("$HOST is not reachable.\n");
		exit(1);
	}

} else {
	print("Not implemented yet.\n");
	exit(0);
}


##################################################
# Check_BD
sub __check_bd {

$MSMMaster = `$SNMPGET EXTREME-SYSTEM-MIB::extremeMasterMSMSlot.0`;
$SOFT_PRI = `$SNMPGET EXTREME-SYSTEM-MIB::extremePrimarySoftwareRev.0`;
$SOFT_SEC = `$SNMPGET EXTREME-SYSTEM-MIB::extremeSecondarySoftwareRev.0`;
$NEXT_IMG =  `$SNMPGET EXTREME-SYSTEM-MIB::extremeImageToUseOnReboot.0`;
$SYSID = `$SNMPGET EXTREME-SYSTEM-MIB::extremeSystemID.0`;
$TEMP = `$SNMPGET EXTREME-SYSTEM-MIB::extremeCurrentTemperature.0`;
$VOLTS = `$SNMPGET EXTREME-SYSTEM-MIB::extremeInputPowerVoltage.0`;

chomp($MSMMaster);
chomp($SOFT_PRI);
chomp($SOFT_SEC);
chomp($NEXT_IMG);
chomp($SYSID);
$SYSID =~ s/\"//g;
chomp($TEMP);
chomp($VOLTS);

## Change the MSM slot numbers from 9/10 to A/B 
$MSM_SLOT9 = `$SNMPGET EXTREME-SYSTEM-MIB::extremeSlotName.9`;
$MSM_SLOT10 = `$SNMPGET EXTREME-SYSTEM-MIB::extremeSlotName.10`;
 chomp($MSM_SLOT9);
 chomp($MSM_SLOT10);
 $MSM_SLOT9 =~ s/\"//g;
 $MSM_SLOT10 =~ s/\"//g;
$ID_SLOT9 = `$SNMPGET EXTREME-SYSTEM-MIB::extremeSlotNumber.9`;
$ID_SLOT10 = `$SNMPGET EXTREME-SYSTEM-MIB::extremeSlotNumber.10`;
 chomp($ID_SLOT10);
 chomp($ID_SLOT9); 
if($MSMMaster eq $ID_SLOT9) {
	$MSMMaster = $MSM_SLOT9;
	} elsif ($MSMMaster eq $ID_SLOT10) {
	$MSMMaster = $MSM_SLOT10;
	} else {
	print("DEBUG: Error in MSM Slot checking!\n");
	exit(1);
}
##

  for($i = 1; $i < 11; $i++) {
	$slotname[$i] = `$SNMPGET EXTREME-SYSTEM-MIB::extremeSlotName.$i`;
	chomp($slotname[$i]);
	$slotname[$i] =~ s/\"//g;
	$slotinstalled[$i] = `$SNMPGET EXTREME-SYSTEM-MIB::extremeSlotModuleInsertedType.$i`;
	chomp($slotinstalled[$i]);
	$slotstate[$i] = `$SNMPGET EXTREME-SYSTEM-MIB::extremeSlotModuleState.$i`;
	chomp($slotstate[$i]);
	$slot_sn[$i] = `$SNMPGET EXTREME-SYSTEM-MIB::extremeSlotModuleSerialNumber.$i`;
	chomp($slot_sn[$i]);
	$slot_sn[$i] =~ s/\"//g;
  }

 print("In $HOST [SN: $SYSID] you have the following installed:\n");
 print("SLOT\tBOARD\tSTATE\t\tSERIAL\n");
 print("----\t-----\t-----\t\t------\n");

	for($g=1; $g < 11; $g++) {
		print("$slotname[$g]\t$slotinstalled[$g]\t$slotstate[$g]\t$slot_sn[$g]\n");
	}

 print("The Master MSM is in slot $MSMMaster\n");
 print("The primary firmware rev is $SOFT_PRI and the secondary is $SOFT_SEC\n");
 print("The image that will be used on reboot is: $NEXT_IMG\n");
 print("Temp(c): $TEMP \tInput Voltage: $VOLTS\n");
 print("Community: $COMMUNITY \tDate: $DATE\n");
}



  ####   #    #  #####   #####   #       ######   #####  ######   ####   #    #
 #    #  #    #  #    #  #    #  #       #          #    #       #    #  #    #
 #       #    #  #    #  #    #  #       #####      #    #####   #       ######
 #       #    #  #    #  #    #  #       #          #    #       #       #    #
 #    #  #    #  #    #  #    #  #       #          #    #       #    #  #    #
  ####    ####   #####   #####   ######  ######     #    ######   ####   #    #


