Commit c7976c5f authored by ueli heuer's avatar ueli heuer 👾
Browse files

Add IfAliase in the search for an named Interface (#Interfacename)

parent 2850a522
......@@ -270,14 +270,28 @@ sub get_intnum_byname ($$$$$) {
$interface =~ s/^#//; # drop '#'
$get_interface_h->execute($host_id,$interface,$interface,undef);
if ($get_interface_h->rows == 1) {
($hi_id, $ifindex, $_device_id, $macaddr, $lastcheck) =
$get_interface_h->fetchrow;
# search for an existing enyry:
$get_interface_h->execute($host_id,$interface,$interface,$interface);
my $interfaces_count = $get_interface_h->rows;
if ($interfaces_count == 0 ) {
# there is no matching entry in the database, so we'll scan the host ...
Unix::Syslog::syslog(LOG_DEBUG,'calling: _get_interfaces(host_id=%d, interface=%s)',$host_id,,$interface);
$result_id = _get_interfaces($host_id, $session, $interface);
# now try again to match the entry
$get_interface_h->execute($host_id,$interface,$interface,$interface);
my $interfaces_count = $get_interface_h->rows;
}
if ($interfaces_count > 1 ) {
# too mutch entries ... this shuldn't happend (index 'host_device' of the table host_interfaces shoud prevent this)
Unix::Syslog::syslog(LOG_INFO,"ERROR: get_intnum_byname: too many entries(%d) for (host_id=%d,interface=%s)",$interfaces_count,$host_id,$interface);
} elsif ($interfaces_count == 1 ) {
($hi_id, $ifindex, $_device_id, $macaddr, $lastcheck) = $get_interface_h->fetchrow;
my $timedelta = time() - $lastcheck;
# it the time delta is small enough, use this entry
if ( ($timedelta) < DVG_config::interface_max_unchecked_time() &&
if ( ($timedelta) < DVG_config::interface_max_unchecked_time() &&
($timedelta >= 0) ) {
if (! defined($macaddr) ) { $macaddr_ = 'null';}
Unix::Syslog::syslog(LOG_DEBUG,'1: update_interface(ifindex:%d,%d,dev_id:%d,"mac:%s",%d)',$ifindex, $lastcheck, $device_id,$macaddr_,$hi_id);
......@@ -285,42 +299,39 @@ sub get_intnum_byname ($$$$$) {
$macaddr,$hi_id);
return $ifindex;
}
Unix::Syslog::syslog(LOG_INFO,'get_intnum_byname: ' .
'cached entry is too old: host_id=%d, int=%s,ifindex=%d delta=%d',
$host_id,$interface,$ifindex,$timedelta) ;# if $DEBUG > 3;
# it the delta is too big, recheck the entry
# TODO: use the device entry for the device, instead to glue the
# snmpparemters ...
$int_name = $session->get(sprintf('ifName.%d',$ifindex));
$int_desc = $session->get(sprintf('ifDescr.%d',$ifindex));
$int_alias = $session->get(sprintf('ifAlias.%d',$ifindex));
if (defined($int_name) && ($int_name eq $interface)) {
Unix::Syslog::syslog(LOG_DEBUG,'2: update_interface(%d,%d,%d,"%s",%d)',$ifindex, time(), $device_id,$macaddr,$hi_id);
Unix::Syslog::syslog(LOG_DEBUG,'2: update_interface[name](%d,%d,%d,"%s",%d)',$ifindex, time(), $device_id,$macaddr,$hi_id);
$update_interface_h->execute($ifindex, time(), $device_id,
$macaddr, $hi_id);
Unix::Syslog::syslog(LOG_INFO,'get_intnum_byname: Update entry ' .
'IfName') ; # if $DEBUG > 3;
Unix::Syslog::syslog(LOG_INFO,'get_intnum_byname: Update entry IfName') ; # if $DEBUG > 3;
return $ifindex;
} elsif (defined($int_desc) && ($int_desc eq $interface)) {
Unix::Syslog::syslog(LOG_DEBUG,'3: update_interface(%d,%d,%d,"%s",%d)',$ifindex, time(), $device_id,$macaddr,$hi_id);
Unix::Syslog::syslog(LOG_DEBUG,'3: update_interface[description](%d,%d,%d,"%s",%d)',$ifindex, time(), $device_id,$macaddr,$hi_id);
$update_interface_h->execute($ifindex, time(), $device_id,
$macaddr, $hi_id);
Unix::Syslog::syslog(LOG_INFO,'get_intnum_byname: Update entry ' .
'IfDescr');# if $DEBUG > 3;
Unix::Syslog::syslog(LOG_INFO,'get_intnum_byname: Update entry IfDescr');# if $DEBUG > 3;
return $ifindex;
}
} elsif (defined($int_alias) && ($int_alias eq $interface)) {
Unix::Syslog::syslog(LOG_DEBUG,'3: update_interface[alias](%d,%d,%d,"%s",%d)',$ifindex, time(), $device_id,$macaddr,$hi_id);
$update_interface_h->execute($ifindex, time(), $device_id,
$macaddr, $hi_id);
Unix::Syslog::syslog(LOG_INFO,'get_intnum_byname: Update entry ifAlias');# if $DEBUG > 3;
return $ifindex;
}
# the founded dvg_host_interface entry seams to be wrong ...
# we should delete it ...
Unix::Syslog::syslog(LOG_DEBUG,'delete_interface_h(%s), dev_id=%s name=%s, desc=%s',$hi_id,$device_id, $int_name, $int_desc);
$delete_interface_h->execute($hi_id);
$result_id = undef;
}
# there is no matching entry in the database, so we'll scan the host ...
Unix::Syslog::syslog(LOG_DEBUG,'calling: _get_interfaces(host_id=%d, session, interface=%s)',$host_id,,$interface);
$result_id = _get_interfaces($host_id, $session, $interface);
if (!defined($result_id)) {
Unix::Syslog::syslog(LOG_INFO,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment