Welcome, Guest. Please login or register.

Author Topic: SNMP-location 24 characters long only :-(  (Read 2291 times)

mpamio

  • Newbie
  • *
  • Posts: 5
    • View Profile
SNMP-location 24 characters long only :-(
« on: June 01, 2009, 09:26:57 AM »
We have, in our campus, some HP 1800 switches that support only 24 characters in the snmp-location string.
So the hierarchy can not be in order.
(e.g.:    UNIUD;Pordenone;CepoPN;CentroStella  )

Its it possible to statically assign a particolar snmp-location (in seedlist ?) to override what readed from the device?

A workaround is to, at the end of the discover, put those strings directly in mysqlDB, but is seem not so beautiful...
Thank you,
Marco Pamio - University of Udine - IT
« Last Edit: June 01, 2009, 09:51:42 AM by mpamio »

ms

  • Guest
Re: SNMP-location 24 characters long only :-(
« Reply #1 on: March 23, 2010, 04:32:30 PM »
My network contains devices with such disabilities:
1. Comtrend CT-320/520 - in snmp sysname returns “Network Management System”, and instead syslocation - "".
2. Proscend 5110G - sysname limited by 15 characters, syslocation value not available from the management interface.

These values, of course, I can set via snmp write community, but after rebooting they are restored to factory settings.

My solution to the problem is not too pretty, but effective:

libmisc.pl.diff
Code: [Select]
--- libmisc.pl.orig 2009-12-08 19:13:54.000000000 +0200
+++ libmisc.pl 2010-03-16 14:12:56.000000000 +0200
@@ -16,6 +16,7 @@
 use vars qw(%comms %login %map %doip %snmpini %ouineb %sysobj %ifmac %ifip);
 use vars qw(%oui %arp %rarp %arpc %arpn %portprop %portnew);
 use vars qw(@todo @donenam @doneid @doneip @failid @failip @comms @seeds @users @curcfg);
+use vars qw(%sysname_ovr %syslocation_ovr);
 
 # Experimental thus not in config yet...
 $scancmd = "nmap -sSU -F";
@@ -958,4 +959,66 @@
  store \%main::vlan, "$main::p/vlan.db";
 }
 
+#===================================================================
+# Read list devices to sysname and syslocation overrides.
+# Parameters: -
+# Global: -
+# Return: -
+#===================================================================
+sub InitSysOverride {
+
+ my $ovrlist = "$misc::nedipath/ovr_sysname";
+ if ( -e "$ovrlist" ){
+ print "Using override sysname list $ovrlist\n" if $main::opt{v};
+ open  (LIST, "$ovrlist");
+ my @list = <LIST>;
+ close(LIST);
+ chomp @list;
+ foreach my $l (@list){
+ if ($l !~ /^[#;]|^$/){
+ my @f  = split(/\t+/,$l);
+ my $name = $f[0];
+ my @iplist = split(/,/,$f[1]);
+ foreach my $addr (@iplist){
+ my $ip = join('.',unpack( 'C4',gethostbyname($addr) ) );
+ if($ip){
+ if($name){
+ $sysname_ovr{$ip} = $name;
+ print "for $ip defined $name as sysname override\n" if $main::opt{v};
+ }
+ }else{
+ print "Error resolving $addr!\n" if $main::opt{v};
+ }
+ }
+ }
+ }
+ }else{
+ print "$ovrlist not found!\n" if $main::opt{v};
+ }
+
+ $ovrlist = "$misc::nedipath/ovr_syslocation";
+ if ( -e "$ovrlist" ){
+ print "Using override syslocation list $ovrlist\n" if $main::opt{v};
+ open  (LIST, "$ovrlist");
+ my @list = <LIST>;
+ close(LIST);
+ chomp @list;
+ foreach my $l (@list){
+ if ($l !~ /^[#;]|^$/){
+ my @f  = split(/\t+/,$l);
+ if($f[0]){
+ if($f[1]){
+ $syslocation_ovr{$f[0]} = $f[1];
+ print "for $f[0] defined $f[1] as syslocation override\n" if $main::opt{v};
+ }
+ }
+ }
+ }
+ }else{
+ print "$ovrlist not found!\n" if $main::opt{v};
+ }
+
+}
+
+
 1;

libsnmp.pl.diff
Code: [Select]
--- libsnmp.pl.orig 2009-12-08 19:13:54.000000000 +0200
+++ libsnmp.pl 2010-03-16 14:14:23.000000000 +0200
@@ -101,7 +101,11 @@
  print "No name, not discoverable\t\t";
  }else{
  print "+ " if $main::opt{d};
+ if ( defined $misc::sysname_ovr{$peer} ){
+ $name = $misc::sysname_ovr{$peer};
+ }else{
  $name = &misc::Strip($r->{$namO});
+ }
  if ($name =~ /^\s*$/){
  $name = $peer;
  }else{
@@ -218,9 +222,13 @@
  $r = $session->get_request($conO);
  $err = $session->error;
  if(!$err){$main::dev{$name}{co} = &misc::Strip($r->{$conO})}
- $r = $session->get_request($locO);
- $err = $session->error;
- if(!$err){$main::dev{$name}{lo} = &misc::Strip($r->{$locO})}
+ if(defined $misc::syslocation_ovr{$name}){
+ $main::dev{$name}{lo} = &misc::Strip($misc::syslocation_ovr{$name});
+ }else{
+ $r = $session->get_request($locO);
+ $err = $session->error;
+ if(!$err){$main::dev{$name}{lo} = &misc::Strip($r->{$locO})}
+ }
  $r = $session->get_request($srvO);
  $err = $session->error;
  if($err or $r->{$srvO} !~ /^\d+$/){

nedi.pl.diff
Code: [Select]
--- nedi.pl.orig 2009-12-08 19:13:54.000000000 +0200
+++ nedi.pl 2010-03-15 18:58:45.000000000 +0200
@@ -204,6 +204,7 @@
  &db::ReadLink('type','STAT'); # Static links will override DP
 
  my $nseed = &misc::InitSeeds();
+ &misc::InitSysOverride();
 
  &db::SetSystem('threads','value+1'); # Register new thread
 

ovr_syslocation
Code: [Select]
# list of overrides syslocations devices
# separated by tab(s).
# sysname syslocation



ovr_sysname
Code: [Select]
# list of overrides sysname devices
# separated by tab(s).
# sysname ip1,ip2,...,ipn



file ovr_syslocation and ovr_sysname must be located in folder, where point variable nedipath (/var/nedi)

Perhaps the authors NeDi eventually make it more elegant?