From adb036759e30be2ffafba8986a9643b609960b0c Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 13 Jul 2015 11:52:38 +0100 Subject: [PATCH] Updated autodiscovery to use log_event better --- .../discovery/discovery-protocols.inc.php | 28 +++---------------- includes/discovery/functions.inc.php | 11 ++++++-- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/includes/discovery/discovery-protocols.inc.php b/includes/discovery/discovery-protocols.inc.php index 114c1dcd8d..53d2e144b3 100644 --- a/includes/discovery/discovery-protocols.inc.php +++ b/includes/discovery/discovery-protocols.inc.php @@ -24,12 +24,7 @@ if ($device['os'] == "ironware" && $config['autodiscovery']['xdp'] === TRUE) if (!$remote_device_id) { - $remote_device_id = discover_new_device($fdp['snFdpCacheDeviceId']); - if ($remote_device_id) - { - $int = ifNameDescr($interface); - log_event("Device autodiscovered through FDP on " . $device['hostname'] . " (port " . $int['label'] . ")", $remote_device_id, 'interface', $int['port_id']); - } + $remote_device_id = discover_new_device($fdp['snFdpCacheDeviceId'], $device,'FDP', $interface); } if ($remote_device_id) @@ -63,12 +58,7 @@ if ($cdp_array && $config['autodiscovery']['xdp'] === TRUE) if (!$remote_device_id) { - $remote_device_id = discover_new_device($cdp['cdpCacheDeviceId']); - if ($remote_device_id) - { - $int = ifNameDescr($interface); - log_event("Device autodiscovered through CDP on " . $device['hostname'] . " (port " . $int['label'] . ")", $remote_device_id, 'interface', $int['port_id']); - } + $remote_device_id = discover_new_device($cdp['cdpCacheDeviceId'], $device, 'CDP', $interface); } if ($remote_device_id) @@ -119,12 +109,7 @@ if ($lldp_array && $config['autodiscovery']['xdp'] === TRUE) if (!$remote_device_id && is_valid_hostname($lldp['lldpRemSysName'])) { - $remote_device_id = discover_new_device($lldp['lldpRemSysName']); - if ($remote_device_id) - { - $int = ifNameDescr($interface); - log_event("Device autodiscovered through LLDP on " . $device['hostname'] . " (port " . $int['label'] . ")", $remote_device_id, 'interface', $int['port_id']); - } + $remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP',$interface); } if ($remote_device_id) @@ -159,12 +144,7 @@ if ($config['autodiscovery']['ospf'] === TRUE) { continue; } $name = gethostbyaddr($ip); - $remote_device_id = discover_new_device($name); - if (isset($remote_device_id) && $remote_device_id > 0) { - log_event("Device $name ($ip) autodiscovered through OSPF", $remote_device_id, 'system'); - } else { - log_event("OSPF discovery of $name ($ip) failed - check ping and SNMP access", $device['device_id'], 'system'); - } + $remote_device_id = discover_new_device($name, $device, 'OSPF'); } } else { echo "disabled\n"; diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 3db6f57fca..7dbdad2527 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -11,7 +11,7 @@ * See COPYING for more details. */ -function discover_new_device($hostname,$device,$method) +function discover_new_device($hostname,$device='',$method='', $interface='') { global $config, $debug; @@ -46,8 +46,13 @@ function discover_new_device($hostname,$device,$method) echo("+[".$remote_device['hostname']."(".$remote_device['device_id'].")]"); discover_device($remote_device); device_by_id_cache($remote_device_id, 1); - if ($remote_device_id) { - log_event("Device $". $remote_device['hostname'] ." ($ip) autodiscovered through $method on ".$device['hostname'], $remote_device_id, 'system'); + if ($remote_device_id && is_array($device) && !empty($method)) { + $extra_log = ''; + $int = ifNameDescr($interface); + if (is_array($int)) { + $extra_log = " (port " . $int['label'] . ") "; + } + log_event("Device $". $remote_device['hostname'] ." ($ip) $extra_log autodiscovered through $method on ".$device['hostname'], $remote_device_id, 'system'); } else { log_event("$method discovery of ". $remote_device['hostname'] ." ($ip) failed - check ping and SNMP access", $device['device_id'], 'system'); }