mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-12 08:02:23 +02:00
new funky discovery stuff (autodiscovery works now for discovery protocols)
git-svn-id: http://www.observium.org/svn/observer/trunk@2460 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
+2
-2
@@ -179,11 +179,11 @@ function ifclass($ifOperStatus, $ifAdminStatus)
|
||||
return $ifclass;
|
||||
}
|
||||
|
||||
function device_by_id_cache($device_id)
|
||||
function device_by_id_cache($device_id, $refresh = '0')
|
||||
{
|
||||
global $device_cache;
|
||||
|
||||
if (isset($device_cache[$device_id]) && is_array($device_cache[$device_id]))
|
||||
if (!$refresh && isset($device_cache[$device_id]) && is_array($device_cache[$device_id]))
|
||||
{
|
||||
$device = $device_cache[$device_id];
|
||||
} else {
|
||||
|
||||
@@ -34,8 +34,9 @@ $config['virsh'] = "/usr/bin/virsh";
|
||||
|
||||
if (isset($_SERVER["SERVER_NAME"]) && isset($_SERVER["SERVER_PORT"]))
|
||||
{
|
||||
$config['base_url'] = "http://" . $_SERVER["SERVER_NAME"] .":".$_SERVER["SERVER_PORT"];
|
||||
$config['base_url'] = "http://" . $_SERVER["SERVER_NAME"] .":".$_SERVER["SERVER_PORT"]."/";
|
||||
}
|
||||
|
||||
$config['title_image'] = "images/observium-logo.png";
|
||||
$config['stylesheet'] = "css/styles.css";
|
||||
$config['mono_font'] = "DejaVuSansMono";
|
||||
|
||||
Executable
+113
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
/* Observium Network Management and Monitoring System
|
||||
* Copyright (C) 2006-2011, Observium Developers - http://www.observium.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* See COPYING for more details.
|
||||
*/
|
||||
|
||||
|
||||
function discover_new_device($hostname)
|
||||
{
|
||||
|
||||
global $config;
|
||||
|
||||
if ( isDomainResolves($hostname . "." . $config['mydomain']) ) {
|
||||
$dst_host = $hostname . "." . $config['mydomain'];
|
||||
} else {
|
||||
$dst_host = $hostname;
|
||||
}
|
||||
$ip = gethostbyname($dst_host);
|
||||
|
||||
if ( match_network($config['nets'], $ip) )
|
||||
{
|
||||
$remote_device_id = addHost ($dst_host, NULL, "v2c");
|
||||
if($remote_device_id) {
|
||||
$remote_device = device_by_id_cache($remote_device_id, 1);
|
||||
echo("+[".$remote_device['hostname']."(".$remote_device['device_id'].")]");
|
||||
discover_device($remote_device);
|
||||
$remote_device = device_by_id_cache($remote_device_id, 1);
|
||||
return $remote_device_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function discover_device($device, $options = NULL)
|
||||
{
|
||||
|
||||
global $config;
|
||||
$valid = array(); ## Reset $valid array
|
||||
|
||||
$attribs = get_dev_attribs($device['device_id']);
|
||||
|
||||
$device_start = utime(); // Start counting device poll time
|
||||
|
||||
echo($device['hostname'] . " ".$device['device_id']." ".$device['os']." ");
|
||||
|
||||
if($device['os'] == 'generic') // verify if OS has changed from generic
|
||||
{
|
||||
$device['os']= getHostOS($device);
|
||||
if($device['os'] != 'generic')
|
||||
{
|
||||
echo "Device os was updated to".$device['os']."!";
|
||||
dbUpdate(array('os' => $device['os']), 'devices', '`device_id` = ?', array($device['device_id']));
|
||||
}
|
||||
}
|
||||
|
||||
if ($config['os'][$device['os']]['group'])
|
||||
{
|
||||
$device['os_group'] = $config['os'][$device['os']]['group'];
|
||||
echo("(".$device['os_group'].")");
|
||||
}
|
||||
|
||||
echo("\n");
|
||||
|
||||
### If we've specified a module, use that, else walk the modules array
|
||||
if ($options['m'])
|
||||
{
|
||||
if (is_file("includes/discovery/".$options['m'].".inc.php"))
|
||||
{
|
||||
include("includes/discovery/".$options['m'].".inc.php");
|
||||
}
|
||||
} else {
|
||||
foreach($config['discovery_modules'] as $module => $module_status)
|
||||
{
|
||||
if ($attribs['discover_'.$module] || ( $module_status && !isset($attribs['discover_'.$module])))
|
||||
{
|
||||
include('includes/discovery/'.$module.'.inc.php');
|
||||
} elseif (isset($attribs['discover_'.$module]) && $attribs['discover_'.$module] == "0") {
|
||||
echo("Module [ $module ] disabled on host.\n");
|
||||
} else {
|
||||
echo("Module [ $module ] disabled globally.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
### Set type to a predefined type for the OS if it's not already set
|
||||
|
||||
if ($device['type'] == "unknown" || $device['type'] == "")
|
||||
{
|
||||
if ($config['os'][$device['os']]['type'])
|
||||
{
|
||||
$device['type'] = $config['os'][$device['os']]['type'];
|
||||
}
|
||||
}
|
||||
|
||||
$device_end = utime(); $device_run = $device_end - $device_start; $device_time = substr($device_run, 0, 5);
|
||||
|
||||
dbUpdate(array('last_discovered' => array('NOW()'), 'type' => $device['type'], 'last_discovered_timetaken' => $device_time), 'devices', '`device_id` = ?', array($device['device_id']));
|
||||
|
||||
echo("Discovered in $device_time seconds\n");
|
||||
|
||||
global $discovered_devices;
|
||||
|
||||
echo("\n"); $discovered_devices++;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -21,7 +21,12 @@ if ($device['os'] == "ironware")
|
||||
{
|
||||
$fdp = $fdp_if_array[$entry_key];
|
||||
$remote_device_id = @mysql_result(mysql_query("SELECT `device_id` FROM `devices` WHERE `sysName` = '".$fdp['snFdpCacheDeviceId']."' OR `hostname`='".$fdp['snFdpCacheDeviceId']."'"), 0);
|
||||
|
||||
|
||||
if(!$remote_device_id)
|
||||
{
|
||||
$remote_device_id = discover_new_device($fdp['snFdpCacheDeviceId']);
|
||||
}
|
||||
|
||||
if ($remote_device_id)
|
||||
{
|
||||
$if = $fdp['snFdpCacheDevicePort'];
|
||||
@@ -49,6 +54,12 @@ if ($cdp_array)
|
||||
$cdp = $cdp_if_array[$entry_key];
|
||||
$remote_device_id = @mysql_result(mysql_query("SELECT `device_id` FROM `devices` WHERE `sysName` = '".$cdp['cdpCacheDeviceId']."' OR `hostname`='".$cdp['cdpCacheDeviceId']."'"), 0);
|
||||
|
||||
if(!$remote_device_id)
|
||||
{
|
||||
$remote_device_id = discover_new_device($cdp['cdpCacheDeviceId']);
|
||||
}
|
||||
|
||||
|
||||
if ($remote_device_id)
|
||||
{
|
||||
$if = $cdp['cdpCacheDevicePort'];
|
||||
@@ -89,13 +100,20 @@ if ($lldp_array)
|
||||
{
|
||||
$lldp = $lldp_instance[$entry_instance];
|
||||
$remote_device_id = @mysql_result(mysql_query("SELECT `device_id` FROM `devices` WHERE `sysName` = '".$lldp['lldpRemSysName']."' OR `hostname`='".$lldp['lldpRemSysName']."'"), 0);
|
||||
|
||||
|
||||
if(!$remote_device_id)
|
||||
{
|
||||
$remote_device_id = discover_new_device($lldp['lldpRemSysName']);
|
||||
}
|
||||
|
||||
if ($remote_device_id)
|
||||
{
|
||||
$if = $lldp['lldpRemPortDesc']; $id = $lldp['lldpRemPortId'];
|
||||
$remote_interface_id = @mysql_result(mysql_query("SELECT interface_id FROM `ports` WHERE (`ifDescr` = '$if' OR `ifName`='$if' OR `ifDescr`= '$id' OR `ifName`='$id') AND `device_id` = '".$remote_device_id."'"),0);
|
||||
} else { $remote_interface_id = "0"; }
|
||||
|
||||
} else {
|
||||
$remote_interface_id = "0";
|
||||
}
|
||||
|
||||
if (is_numeric($interface['interface_id']) && isset($lldp['lldpRemSysName']) && isset($lldp['lldpRemPortId']))
|
||||
{
|
||||
discover_link($interface['interface_id'], 'lldp', $remote_interface_id, $lldp['lldpRemSysName'], $lldp['lldpRemPortId'], NULL, $lldp['lldpRemSysDesc']);
|
||||
|
||||
+21
-10
@@ -175,7 +175,7 @@ function delete_device($id)
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function addHost($host, $community, $snmpver, $port = '161', $transport = 'udp')
|
||||
function addHost($host, $community = NULL, $snmpver = 'v2c', $port = '161', $transport = 'udp')
|
||||
{
|
||||
global $config;
|
||||
|
||||
@@ -194,23 +194,26 @@ function addHost($host, $community, $snmpver, $port = '161', $transport = 'udp')
|
||||
foreach ($config['snmp']['community'] as $community)
|
||||
{
|
||||
$device = deviceArray($host, $community, $snmpver, $port, $transport);
|
||||
|
||||
if (isSNMPable($device))
|
||||
{
|
||||
print_message("Trying community $community");
|
||||
$snmphost = snmp_get($device, "sysName.0", "-Oqv", "SNMPv2-MIB");
|
||||
if ($snmphost == "" || ($snmphost && ($snmphost == $host || $hostshort = $host)))
|
||||
{
|
||||
$added = createHost ($host, $community, $snmpver, $port, $transport);
|
||||
if($added) { echo($added . "\n"); }
|
||||
$device_id = createHost ($host, $community, $snmpver, $port, $transport);
|
||||
return $device_id;
|
||||
} else {
|
||||
print_error("Given hostname does not match SNMP-read hostname ($snmphost)!");
|
||||
}
|
||||
} else {
|
||||
print_error("No reply on community $community");
|
||||
}
|
||||
}
|
||||
if (!$added)
|
||||
if (!$device_id)
|
||||
{
|
||||
/// Faild SNMP
|
||||
print_error("Could not reach $host with given SNMP community"); }
|
||||
print_error("Could not reach $host with given SNMP community");
|
||||
}
|
||||
} else {
|
||||
/// failed Reachability
|
||||
print_error("Could not ping $host"); }
|
||||
@@ -364,17 +367,25 @@ function utime()
|
||||
function createHost($host, $community, $snmpver, $port = 161, $transport = 'udp')
|
||||
{
|
||||
$host = trim(strtolower($host));
|
||||
$device = array('hostname' => $host, 'sysName' => $host, 'community' => $community, 'port' => $port, 'transport' => $transport, 'status' => '1', 'snmpver' => $snmpver);
|
||||
|
||||
$device = array('hostname' => $host,
|
||||
'sysName' => $host,
|
||||
'community' => $community,
|
||||
'port' => $port,
|
||||
'transport' => $transport,
|
||||
'status' => '1',
|
||||
'snmpver' => $snmpver);
|
||||
|
||||
$device['os'] = getHostOS($device);
|
||||
|
||||
if ($device['os'])
|
||||
{
|
||||
|
||||
$id = dbInsert($device, 'devices');
|
||||
$device_id = dbInsert($device, 'devices');
|
||||
|
||||
if ($id)
|
||||
if ($device_id)
|
||||
{
|
||||
return("Created host : $host (id:".$id.") (os:".$device['os'].")");
|
||||
return($device_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user