mirror of
				https://github.com/librenms/librenms.git
				synced 2024-10-07 16:52:45 +00:00 
			
		
		
		
	Fix some broken things.
git-svn-id: http://www.observium.org/svn/observer/trunk@91 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
		@@ -5,7 +5,7 @@ include("includes/functions.php");
 | 
			
		||||
 | 
			
		||||
# Discover interfaces
 | 
			
		||||
 | 
			
		||||
$device_query = mysql_query("SELECT id,hostname,community,snmpver FROM `devices` WHERE `id` LIKE '%" . $argv[1] . "' AND status = '1' AND os != 'Snom' ORDER BY id DESC");
 | 
			
		||||
$device_query = mysql_query("SELECT device_id,hostname,community,snmpver FROM `devices` WHERE `device_id` LIKE '%" . $argv[1] . "' AND status = '1' AND os != 'Snom' ORDER BY device_id DESC");
 | 
			
		||||
while ($device = mysql_fetch_row($device_query)) {
 | 
			
		||||
 | 
			
		||||
  $id = $device['0'];
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@ if($bg == $list_colour_a) { $bg = $list_colour_b; } else { $bg=$list_colour_a; }
 | 
			
		||||
      " . $entry['datetime'] . "
 | 
			
		||||
    </td>");
 | 
			
		||||
  if(!$_GET[id] && !$overview) {
 | 
			
		||||
    $dev['id'] = $entry['host'];
 | 
			
		||||
    $dev['device_id'] = $entry['host'];
 | 
			
		||||
    $dev['hostname'] = $hostname;
 | 
			
		||||
    echo("<td class=list-bold width=250>
 | 
			
		||||
      " . generatedevicelink($dev) . "
 | 
			
		||||
 
 | 
			
		||||
@@ -47,9 +47,12 @@ while($device = mysql_fetch_array($device_query)) {
 | 
			
		||||
      $graph_type = "cpu";              include ("includes/print-device-graph.php");
 | 
			
		||||
      echo("<br />");
 | 
			
		||||
      if($device[os] == "m0n0wall" || $device[os] == "pfSense" || $device[os] == "Voswall" || $device[monowall]) {
 | 
			
		||||
        echo("<div class=graphhead>Device Uptime</div>");
 | 
			
		||||
        $graph_type = "uptime";         include ("includes/print-device-graph.php"); break;
 | 
			
		||||
        echo("<div class=graphhead>IP Statistics</div>");
 | 
			
		||||
        $graph_type = "ip_graph";           include ("includes/print-device-graph.php");
 | 
			
		||||
        echo("<br />");
 | 
			
		||||
        echo("<div class=graphhead>Device Uptime</div>");
 | 
			
		||||
        $graph_type = "uptime";         include ("includes/print-device-graph.php");
 | 
			
		||||
        break;
 | 
			
		||||
      }
 | 
			
		||||
      if($device['os'] != "NetBSD") {
 | 
			
		||||
      echo("<div class=graphhead>Memory Utilisation</div>");
 | 
			
		||||
@@ -57,13 +60,13 @@ while($device = mysql_fetch_array($device_query)) {
 | 
			
		||||
      echo("<br />");
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if(mysql_result(mysql_query("SELECT count(storage_id) FROM storage WHERE host_id = '$device[id]'"),0)) {
 | 
			
		||||
      if(mysql_result(mysql_query("SELECT count(storage_id) FROM storage WHERE host_id = '" . $device['device_id'] . "'"),0)) {
 | 
			
		||||
        echo("<div class=graphhead>Storage</div>");
 | 
			
		||||
        $graph_type = "unixfs";           include ("includes/print-device-graph.php");
 | 
			
		||||
        echo("<br />");
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if(mysql_result(mysql_query("SELECT count(*) FROM temperature WHERE temp_host = '$device[id]'"),0)) {
 | 
			
		||||
      if(mysql_result(mysql_query("SELECT count(*) FROM temperature WHERE temp_host = '" . $device['device_id'] . "'"),0)) {
 | 
			
		||||
        echo("<div class=graphhead>Temperatures</div>");
 | 
			
		||||
        $graph_type = "temp";           include ("includes/print-device-graph.php");
 | 
			
		||||
        echo("<br />");
 | 
			
		||||
 
 | 
			
		||||
@@ -393,26 +393,6 @@ function fixIOSHardware($hardware){
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function updateHost ($host, $community, $snmpver)
 | 
			
		||||
{
 | 
			
		||||
#        $soft = `snmpget -O vq -$snmpver -c $community $host sysDescr.0 | grep IOS | sed s/Cisco\ IOS\ Software\,// | sed s/\"\ //g | sed s/IOS\  \(tm\)\ // | sed s/\,\ RELEASE\ SOFTWARE.*// | sed s/.*\ Software\ // | sed s/\,\ /\|\|/ | sed s/\Version\ // | sed s/,\ EARLY\ DEPLOYMENT\ RELEASE\ SOFTWARE\ .*//`;
 | 
			
		||||
        $sysdescr = `snmpget -O vq -$snmpver -c $community $host sysDescr.0`;
 | 
			
		||||
        $sysdecr = str_replace("\"","", $sysdescr);
 | 
			
		||||
	$location = str_replace("\"","", `snmpget -O vq -v2c -c $community $host sysLocation.0`);
 | 
			
		||||
        list ($features, $version) = explode('||', $soft);
 | 
			
		||||
        $features = str_replace("(","", $features);
 | 
			
		||||
        $features = str_replace(")","", $features);
 | 
			
		||||
        $version = str_replace("\n","", $version);
 | 
			
		||||
        $version = trim($version);
 | 
			
		||||
        $location = trim($location);
 | 
			
		||||
        list ($hardware, $features) = explode("-", $features);
 | 
			
		||||
        $hardware = fixIOSHardware($hardware);
 | 
			
		||||
        $features = fixIOSFeatures($features);
 | 
			
		||||
        $sql = "UPDATE `devices` SET `hardware` = '$hardware', `features` = '$features', `version` = '$version', `sysdesc` = '$sysdescr', `location` = '$location' WHERE `hostname` = '$host'";
 | 
			
		||||
#	echo("$sql \n");    
 | 
			
		||||
#        mysql_query($sql);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function getHostOS($host, $community, $snmpver) {
 | 
			
		||||
	$sysDescr = trim(`snmpget -O qv -$snmpver -c $community $host sysDescr.0`);
 | 
			
		||||
        if ($sysDescr == "") {$sysDescr = trim(`snmpget -O qv -$snmpver -c $community $host 1.3.6.1.2.1.7526.2.4`);}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,9 +2,6 @@
 | 
			
		||||
 | 
			
		||||
$id = $device['device_id'];
 | 
			
		||||
$hostname = $device['hostname'];
 | 
			
		||||
$hardware = $device['hardware'];
 | 
			
		||||
$version = $device['version'];
 | 
			
		||||
$features = $device['features'];
 | 
			
		||||
 | 
			
		||||
$loadrrd  = "rrd/" . $hostname . "-load.rrd";
 | 
			
		||||
$loadgraph = "public_html/graphs/" . $hostname . "-load.png";
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								ips.php
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								ips.php
									
									
									
									
									
								
							@@ -3,11 +3,11 @@
 | 
			
		||||
include("config.php");
 | 
			
		||||
include("includes/functions.php");
 | 
			
		||||
  
 | 
			
		||||
$sql = "SELECT * FROM devices WHERE id LIKE '%$argv[1]' AND status = '1' AND os != 'Snom' order by id DESC";
 | 
			
		||||
$sql = "SELECT * FROM devices WHERE device_id LIKE '%$argv[1]' AND status = '1' AND os != 'Snom' order by device_id DESC";
 | 
			
		||||
$q = mysql_query($sql);
 | 
			
		||||
while ($device = mysql_fetch_array($q)) {
 | 
			
		||||
  $hostname = $device['hostname'];
 | 
			
		||||
  $hostid = $device['id'];
 | 
			
		||||
  $hostid = $device['device_id'];
 | 
			
		||||
  $community = $device['community'];
 | 
			
		||||
  echo("$hostname\n");
 | 
			
		||||
  $oids = `snmpbulkwalk -v2c -Osq -c $community $hostname ipAdEntIfIndex | sed s/ipAdEntIfIndex.//g`;
 | 
			
		||||
 
 | 
			
		||||
@@ -30,6 +30,7 @@ while ($device = mysql_fetch_array($device_query)) {
 | 
			
		||||
    $snmpdata = `$snmp_cmd`;
 | 
			
		||||
    $snmpdata = preg_replace("/^.*IOS/","", $snmpdata);
 | 
			
		||||
    $snmpdata = trim($snmpdata);
 | 
			
		||||
    $snmpdata = str_replace("\"", "", $snmpdata);
 | 
			
		||||
    list($sysUptime, $sysLocation, $ciscomodel, $sysDescr) = explode("\n", $snmpdata);
 | 
			
		||||
    $sysUptime = str_replace("(", "", $sysUptime);
 | 
			
		||||
    $sysUptime = str_replace(")", "", $sysUptime); 
 | 
			
		||||
@@ -50,23 +51,23 @@ while ($device = mysql_fetch_array($device_query)) {
 | 
			
		||||
    case "Voswall":
 | 
			
		||||
    case "NetBSD":
 | 
			
		||||
    case "pfSense":
 | 
			
		||||
      if($device['os'] == "FreeBSD") {
 | 
			
		||||
      if ($device['os'] == "FreeBSD") {
 | 
			
		||||
        $sysDescr = str_replace(" 0 ", " ", $sysDescr);
 | 
			
		||||
        list(,,$version) = explode (" ", $sysDescr);
 | 
			
		||||
        $hardware = "i386";
 | 
			
		||||
        $features = "GENERIC";
 | 
			
		||||
      } elseif($device['os'] == "DragonFly") {
 | 
			
		||||
      } elseif ($device['os'] == "DragonFly") {
 | 
			
		||||
        list(,,$version,,,$features,,$hardware) = explode (" ", $sysDescr);
 | 
			
		||||
      } elseif($device['os'] == "NetBSD") {
 | 
			
		||||
      } elseif ($device['os'] == "NetBSD") {
 | 
			
		||||
        list(,,$version,,,$features) = explode (" ", $sysDescr);
 | 
			
		||||
        $features = str_replace("(", "", $features);
 | 
			
		||||
        $features = str_replace(")", "", $features);
 | 
			
		||||
        list(,,$hardware) = explode ("$features", $sysDescr);
 | 
			
		||||
      } elseif($device['os'] == "OpenBSD") {
 | 
			
		||||
      } elseif ($device['os'] == "OpenBSD") {
 | 
			
		||||
        list(,,$version,$features,$hardware) = explode (" ", $sysDescr);
 | 
			
		||||
        $features = str_replace("(", "", $features);
 | 
			
		||||
        $features = str_replace(")", "", $features);
 | 
			
		||||
      } elseif($device['os'] == "m0n0wall" || $device['os'] == "Voswall") { 
 | 
			
		||||
      } elseif ($device['os'] == "m0n0wall" || $device['os'] == "Voswall") { 
 | 
			
		||||
	list(,,$version,$hardware,$freebsda, $freebsdb, $arch) = split(" ", $sysDescr);
 | 
			
		||||
	$features = $freebsda . " " . $freebsdb;
 | 
			
		||||
	$hardware = "$hardware ($arch)";	
 | 
			
		||||
@@ -143,26 +144,32 @@ while ($device = mysql_fetch_array($device_query)) {
 | 
			
		||||
    $status = '0';
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  unset( $update ) ;
 | 
			
		||||
 | 
			
		||||
  if ( $sysDescr && $sysDescr != $device['sysDescr'] ) {
 | 
			
		||||
    $update = "`sysDescr` = '$sysDescr'";
 | 
			
		||||
    $update .= "`sysDescr` = '$sysDescr'";
 | 
			
		||||
    $seperator = ", ";
 | 
			
		||||
    mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'sysDescr -> $sysDescr')");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if ( $location && $device['location'] != $location ) {
 | 
			
		||||
    $update = "`location` = '$location'";
 | 
			
		||||
    $update .= "`location` = '$location'";
 | 
			
		||||
    $seperator = ", ";
 | 
			
		||||
    mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Location -> $location')");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if ( $version && $device['version'] != $version ) {
 | 
			
		||||
    $update .= $seperator . "`version` = '$version'";
 | 
			
		||||
    $seperator = ", ";
 | 
			
		||||
    mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'OS Version -> $version')");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if ( $features && $features != $device['features'] ) {
 | 
			
		||||
    $update .= $seperator . "`features` = '$features'";
 | 
			
		||||
    $seperator = ", ";
 | 
			
		||||
    mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'OS Features -> $features')");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if ( $hardware && $hardware != $device['hardware'] ) {
 | 
			
		||||
    $update .= $seperator . "`hardware` = '$hardware'";
 | 
			
		||||
    $seperator = ", ";
 | 
			
		||||
 
 | 
			
		||||
@@ -72,12 +72,12 @@ while ($interface = mysql_fetch_array($interface_query)) {
 | 
			
		||||
     mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Desc  -> $ifAlias')");
 | 
			
		||||
  }
 | 
			
		||||
  if ( $interface['ifOperStatus'] != $ifOperStatus && $ifOperStatus != "" ) {
 | 
			
		||||
     $update .= $seperator . "`up` = '$ifOperStatus'";
 | 
			
		||||
     $update .= $seperator . "`ifOperStatus` = '$ifOperStatus'";
 | 
			
		||||
     $seperator = ", ";
 | 
			
		||||
     mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Interface went $ifOperStatus')");
 | 
			
		||||
  }
 | 
			
		||||
  if ( $interface['ifAdminStatus'] != $ifAdminStatus && $ifAdminStatus != "" ) {
 | 
			
		||||
     $update .= $seperator . "`up_admin` = '$ifAdminStatus'";
 | 
			
		||||
     $update .= $seperator . "`ifAdminStatus` = '$ifAdminStatus'";
 | 
			
		||||
     $seperator = ", ";
 | 
			
		||||
     if($ifAdminStatus == "up") { $admin = "enabled"; } else { $admin = "disabled"; }
 | 
			
		||||
     mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Interface $admin')");
 | 
			
		||||
 
 | 
			
		||||
@@ -16,8 +16,8 @@ while($l = mysql_fetch_array($q)){
 | 
			
		||||
  unset($maybehost);
 | 
			
		||||
  unset($perhapshost);
 | 
			
		||||
 | 
			
		||||
  $maybehost = @mysql_result(mysql_query("SELECT D.id as id FROM ipaddr AS A, interfaces AS I, devices AS D WHERE A.addr = '$l[host]' AND I.id = A.interface_id AND D.id = I.host"),0);
 | 
			
		||||
  $perhapshost = @mysql_result(mysql_query("SELECT id FROM devices WHERE `hostname` = '$l[host]'"),0);
 | 
			
		||||
  $maybehost = @mysql_result(mysql_query("SELECT D.device_id as device_id FROM ipaddr AS A, interfaces AS I, devices AS D WHERE A.addr = '" . $l['host'] . "' AND I.interface_id = A.interface_id AND D.device_id = I.device_id"),0);
 | 
			
		||||
  $perhapshost = @mysql_result(mysql_query("SELECT device_id FROM devices WHERE `hostname` = '$l[host]'"),0);
 | 
			
		||||
 | 
			
		||||
  if($maybehost) { 
 | 
			
		||||
    $host = $maybehost;
 | 
			
		||||
@@ -27,7 +27,7 @@ while($l = mysql_fetch_array($q)){
 | 
			
		||||
 | 
			
		||||
  if($host) {
 | 
			
		||||
 | 
			
		||||
    if(mysql_result(mysql_query("SELECT os FROM `devices` WHERE `id` = '$host'"),0) == "IOS") {
 | 
			
		||||
    if(mysql_result(mysql_query("SELECT os FROM `devices` WHERE `device_id` = '$host'"),0) == "IOS") {
 | 
			
		||||
      list(,$l[msg]) = split(": %", $l[msg]);
 | 
			
		||||
      $l[msg] = "%" . $l[msg];
 | 
			
		||||
      $l[msg] = preg_replace("/^%(.+):\ /", "\\1||", $l[msg]);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user