Merge pull request #1438 from laf/autodiscovery

Updated autodiscovery to use log_event better
This commit is contained in:
Daniel Preussker 2015-07-13 12:59:24 +02:00
commit 4a98df105f
2 changed files with 12 additions and 27 deletions

View File

@ -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";

View File

@ -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');
}