191 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			Perl
		
	
	
	
	
	
			
		
		
	
	
			191 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			Perl
		
	
	
	
	
	
| # SNMP::Info::Layer3::Qtech - SNMP Interface to Qtech Devices
 | |
| #
 | |
| # Copyright (c) 2020 by The 135.
 | |
| 
 | |
| 
 | |
| package SNMP::Info::Layer3::Qtech;
 | |
| 
 | |
| use strict;
 | |
| use warnings;
 | |
| use Exporter;
 | |
| use SNMP::Info::Layer3;
 | |
| use Data::Dumper;
 | |
| 
 | |
| @SNMP::Info::Layer3::Qtech::ISA       = qw/SNMP::Info::Layer3 Exporter/;
 | |
| @SNMP::Info::Layer3::Qtech::EXPORT_OK = qw//;
 | |
| 
 | |
| our ($VERSION, %GLOBALS, %FUNCS, %MIBS, %MUNGE);
 | |
| 
 | |
| $VERSION = '3.70-135';
 | |
| 
 | |
| %MIBS = ( %SNMP::Info::Layer3::MIBS, );
 | |
| 
 | |
| %GLOBALS = (
 | |
|     %SNMP::Info::Layer3::GLOBALS,
 | |
|     'hostname'    => 'mib-2.47.1.1.1.1.7.1',
 | |
|     'model_oid'   => 'mib-2.47.1.1.1.1.13.1',
 | |
|     'hw_oid'      => 'mib-2.47.1.1.1.1.8.1',
 | |
|     'serial_oid'  => 'mib-2.47.1.1.1.1.11.1',
 | |
|     'bootrom_oid' => 'mib-2.47.1.1.1.1.9.1',
 | |
|     'os_ver_oid'  => 'mib-2.47.1.1.1.1.10.1',
 | |
| );
 | |
| 
 | |
| %FUNCS = ( %SNMP::Info::Layer3::FUNCS, );
 | |
| 
 | |
| %MUNGE = ( %SNMP::Info::Layer3::MUNGE, );
 | |
| 
 | |
| sub main {
 | |
|     #no strict 'refs';
 | |
|     my $obj = shift;
 | |
|     my $response = undef; my $serial = undef; my $model = undef; my $hw = undef; my $os_ver = undef; my $brom = undef;
 | |
|     if ( $obj->id() =~ /27514\.1\.3\./ ) {
 | |
|         #QSW-2900 enterprises.27514.1.3.25.2
 | |
|         #QSW-2900-24T enterprises.27514.1.3.13
 | |
|         #QSW-3900 enterprises.27514.1.3.26.2 and other...
 | |
|         $response = $obj->session()->get('enterprises.27514.1.2.1.1.2.2.0');
 | |
|         $response =~ s/QTECH\s+//;
 | |
|         ($model, $os_ver) = $response =~ /([\w,\d,-]+)\s([\w,\d]+)$/;
 | |
|         $hw = $obj->session()->get('enterprises.27514.1.2.1.1.2.8.0');
 | |
|         $brom =  $obj->session()->get('enterprises.27514.1.2.1.1.2.9.0');
 | |
|         $serial = $obj->session()->get('enterprises.27514.1.2.1.1.2.19.0');
 | |
|     }
 | |
|     elsif ( $obj->id() =~ /27514\.6\.55$/ ) {
 | |
|         #QSW-2500E enterprises.27514.6.55
 | |
|         ($os_ver, $model) = $obj->session->get('enterprises.27514.6.1.1.1.1.0') =~ /QOS_([\d,\.]+)\.(QSW[-,\w,\d]+)/;
 | |
|     }
 | |
|     else {
 | |
|         $model = $obj->model_oid;
 | |
|         $hw = $obj->hw_oid;
 | |
|         $os_ver = $obj->os_ver_oid;
 | |
|         $brom = $obj->bootrom_oid;
 | |
|         $serial = $obj->serial_oid;
 | |
|     }
 | |
| 
 | |
|     if (not defined($serial) or $serial eq "N/A") {
 | |
|         #QSW-2800 enterprises.27514.1.1.1.48 could be N/A serial under specific OID.
 | |
|         #Try to get from Descr.0
 | |
|         my $descr = $obj->description();
 | |
|         ($serial) = $descr =~ /Serial\sNo\.:\s*([\d,\w]+)/;
 | |
|     }
 | |
| 
 | |
|     $model = join ' HW:', ($model, $hw) if defined($model) and defined($hw);
 | |
|     $os_ver = join ' bootrom:', ($os_ver, $brom) if defined($os_ver) and defined($brom);
 | |
|     return { 'model' => $model, 'os_ver' => $os_ver, 'serial' => $serial};
 | |
| }
 | |
| 
 | |
| sub model {
 | |
|     my $qtech = shift;
 | |
|     return $qtech->main->{model};
 | |
| }
 | |
| 
 | |
| sub vendor {
 | |
|     return 'qtech';
 | |
| }
 | |
| 
 | |
| sub os {
 | |
|     return 'qsw';
 | |
| }
 | |
| 
 | |
| sub os_ver {
 | |
|     my $qtech = shift;
 | |
|     return $qtech->main->{os_ver};
 | |
| }
 | |
| 
 | |
| sub serial {
 | |
|     my $qtech = shift;
 | |
|     return $qtech->main->{serial};
 | |
| }
 | |
| 
 | |
| 1;
 | |
| __END__
 | |
| 
 | |
| =head1 NAME
 | |
| 
 | |
| SNMP::Info::Layer3::Qtech - SNMP Interface to Qtech Devices
 | |
| 
 | |
| =head1 SYNOPSIS
 | |
| 
 | |
|  # Let SNMP::Info determine the correct subclass for you.
 | |
|  my $qtech = new SNMP::Info(
 | |
|                           AutoSpecify => 1,
 | |
|                           Debug       => 1,
 | |
|                           DestHost    => 'myrouter',
 | |
|                           Community   => 'public',
 | |
|                           Version     => 2
 | |
|                         )
 | |
|     or die "Can't connect to DestHost.\n";
 | |
| 
 | |
|  my $class      = $qtech->class();
 | |
|  print "SNMP::Info determined this device to fall under subclass : $class\n";
 | |
| 
 | |
| =head1 DESCRIPTION
 | |
| 
 | |
| Subclass for Qtech devices.
 | |
| 
 | |
| =head2 Inherited Classes
 | |
| 
 | |
| =over
 | |
| 
 | |
| =item SNMP::Info::Layer3
 | |
| 
 | |
| =back
 | |
| 
 | |
| =head2 Inherited Classes' MIBs
 | |
| 
 | |
| See L<SNMP::Info::Layer3/"Required MIBs"> for its own MIB requirements.
 | |
| 
 | |
| =head1 GLOBALS
 | |
| 
 | |
| These are methods that return scalar value from SNMP
 | |
| 
 | |
| =over
 | |
| 
 | |
| =item $qtech->model()
 | |
| 
 | |
| Returns the ID or else description.
 | |
| 
 | |
| =item $qtech->vendor()
 | |
| 
 | |
| Returns 'qtech'.
 | |
| 
 | |
| =item $qtech->serial()
 | |
| 
 | |
| Returns serial number.
 | |
| 
 | |
| =item $qtech->fwver()
 | |
| 
 | |
| Returns the firmware version.
 | |
| 
 | |
| =item $qtech->hwver()
 | |
| 
 | |
| Returns the hardware version.
 | |
| 
 | |
| =item $qtech->stp_i_root_port()
 | |
| 
 | |
| Returns the STP root port.
 | |
| 
 | |
| =back
 | |
| 
 | |
| =head2 Globals imported from SNMP::Info::Layer3
 | |
| 
 | |
| See documentation in L<SNMP::Info::Layer3/"GLOBALS"> for details.
 | |
| 
 | |
| =head1 TABLE METHODS
 | |
| 
 | |
| These are methods that return tables of information in the form of a reference
 | |
| to a hash.
 | |
| 
 | |
| =over
 | |
| 
 | |
| =item $qtech->interfaces();
 | |
| 
 | |
| Returns the map between SNMP Interface Identifier (iid) and C<ifName>.
 | |
| 
 | |
| =back
 | |
| 
 | |
| =head2 Table Methods imported from SNMP::Info::Layer3
 | |
| 
 | |
| See documentation in L<SNMP::Info::Layer3/"TABLE METHODS"> for details.
 | |
| 
 | |
| =cut
 |