From 4e10de77a7d604fd67a1c57cff6eb6c4722f8bb8 Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Thu, 3 Apr 2008 19:04:24 +0000 Subject: [PATCH] Lots of nice new things! Yum. git-svn-id: http://www.observium.org/svn/observer/trunk@220 61d68cd4-352d-0410-923a-c4978735b2b8 --- config.php | 114 +++++++++++++++++++++ discovery-test.php | 50 +++++++++ discovery.php | 5 +- html/.htaccess | 2 + html/includes/print-menubar.php | 5 +- html/pages/default.php | 47 +++++---- html/pages/interfaces.php | 20 +++- includes/functions.php | 6 +- includes/osdiscovery/discover-screenos.php | 4 +- includes/polling/device-screenos.inc.php | 2 +- includes/unix-graphing.php | 2 +- ipv6.php | 55 ++++++++++ poll-device.php | 4 + 13 files changed, 281 insertions(+), 35 deletions(-) create mode 100755 config.php create mode 100755 discovery-test.php create mode 100755 ipv6.php diff --git a/config.php b/config.php new file mode 100755 index 000000000..4373850f7 --- /dev/null +++ b/config.php @@ -0,0 +1,114 @@ +"; +$config['email_headers'] = "From: " . $config['email_from'] . "\r\n"; + + +### Which interface sections should we show? + +$config['int_customers'] = 1; # Enable Customer Port Parsing +$config['int_transit'] = 1; # Enable Transit Types +$config['int_peering'] = 1; # Enable Peering Types +$config['int_core'] = 1; # Enable Core Port Types +$config['int_l2tp'] = 1; # Enable L2TP Port Types + +$config['show_locations'] = 1; # Enable Locations on menu + +### Which additional features should we enable? + +$config['enable_bgp'] = 1; # Enable BGP session collection and display +$config['enable_syslog'] = 1; # Enable Syslog + +## If a syslog entry contails these strings it is deleted from the database +$config['syslog_filter'] = array("last message repeated", "Connection from UDP: [127.0.0.1]:"); + +$config['syslog_age'] = "1 month"; ## Time to keep syslog for in + ## MySQL DATE_SUB format (eg '1 day', '1 month') + +### Interface name strings to ignore +$config['bad_if'] = array("null", "virtual-", "unrouted", "eobc", "mpls", "sl0", "lp0", "faith0", + "-atm layer", "-atm subif", "-shdsl", "-adsl", "-aal5", "-atm", + "async", "plip", "-physical", "-signalling", "control plane", + "bri", "-bearer", "ng", "bluetooth", "isatap", "ras", "qos", "miniport"); + +### Mountpoints to ignore + +$config['ignore_mount'] = array("/kern", "/mnt/cdrom", "/dev", "/dev/pts", "/proc/bus/usb"); + +### Style Options + +$list_colour_a = "#ffffff"; +$list_colour_b = "#e5e5e5"; + +$warn_colour_a = "#ffeeee"; +$warn_colour_b = "#ffcccc"; + +?> diff --git a/discovery-test.php b/discovery-test.php new file mode 100755 index 000000000..90fb4e2eb --- /dev/null +++ b/discovery-test.php @@ -0,0 +1,50 @@ +#!/usr/bin/php + Poll single device\n"); + echo("--os Poll all devices of a given OS\n"); + echo("--all Poll all devices\n\n"); + echo("No polling type specified!\n"); + exit; +} + + +$devices_polled = 0; + +$device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1' $where ORDER BY device_id DESC"); +while ($device = mysql_fetch_array($device_query)) { + + echo($device['hostname'] ."\n"); + + include("includes/discovery/unix-memory.php"); + + echo("\n"); $devices_polled++; +} + +$end = utime(); $run = $end - $start; +$proctime = substr($run, 0, 5); + +echo("$devices_polled devices polled in $proctime secs\n"); + + +?> diff --git a/discovery.php b/discovery.php index 6c4fb51a7..c3ad3104c 100755 --- a/discovery.php +++ b/discovery.php @@ -49,13 +49,16 @@ while ($device = mysql_fetch_array($device_query)) { include("includes/discovery/storage.php"); } + if($device['os'] == "Netscreen") { + + } + if($device['os'] == "IOS") { include("includes/discovery/cisco-vlans.php"); include("includes/discovery/cisco-physical.php"); include("includes/discovery/bgp-peers.php"); } - echo("\n"); $devices_polled++; } diff --git a/html/.htaccess b/html/.htaccess index 994950273..d3a58c4bd 100644 --- a/html/.htaccess +++ b/html/.htaccess @@ -15,6 +15,8 @@ RewriteRule ^devices/alerted/ ?page=devices&status=alerted RewriteRule ^devices/alerted/ ?page=devices&status=alerted RewriteRule ^devices/(.+)/ ?page=devices&type=$1 +RewriteRule ^interfaces/(.+)/ ?page=interfaces&type=$1 + RewriteRule ^bill/([0-9]+) ?page=bills&bill=$1 RewriteRule ^device/([0-9]+) ?page=device&id=$1 diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index fca04b3a8..ca1613d24 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -123,7 +123,7 @@ if($_SESSION['userlevel'] >= '5') { if($config['int_core']) { echo("
  • Core
  • "); $ifbreak = 1;} } -if($ifbreak && $interface_alerts) { echo("

  • "); } +if($ifbreak) { echo("

  • "); } if($interface_alerts) { echo("
  • Alerts ($interface_alerts)
  • "); @@ -131,6 +131,9 @@ echo("
  • Down Ports
  • +
  • Disabled Ports
  • + diff --git a/html/pages/default.php b/html/pages/default.php index 0a6ce2af7..c9624f319 100644 --- a/html/pages/default.php +++ b/html/pages/default.php @@ -1,23 +1,28 @@ - - - - - - -
    - ".$content." -
    - - - - - - - "); +echo("
    + $content +
    "); + + +# echo("
    +# +# +# +# +# +# +#
    +# ".$content." +#
    +# +# +# +# +# +# +#
    "); } echo("
    "); @@ -25,12 +30,10 @@ echo("
    -
    ".generatedevicelink($device, shorthost($device['hostname']))."
    + generate_front_box("alert", "
    ".generatedevicelink($device, shorthost($device['hostname']))."
    Device Down - ".truncate($device['location'], 20)." -
    "); + "); } @@ -75,7 +78,7 @@ while($device = mysql_fetch_array($sql)){ generate_front_box("info", "
    ".generatedevicelink($device, shorthost($device['hostname']))."
    - Device
    Rebooted

    + Device
    Rebooted

    ".formatUptime($device['attrib_value'])."
    "); diff --git a/html/pages/interfaces.php b/html/pages/interfaces.php index ff4f6813e..4637e9598 100644 --- a/html/pages/interfaces.php +++ b/html/pages/interfaces.php @@ -1,11 +1,20 @@ = '5') { +#if ($_SESSION['userlevel'] >= '5') { $sql = "SELECT * FROM `interfaces` AS I, `devices` AS D WHERE I.device_id = D.device_id ORDER BY D.hostname, I.ifDescr"; -} else { - $sql = "SELECT * FROM `interfaces` AS I, `devices` AS D, `devices_perms` AS P WHERE I.device_id = D.device_id AND D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' ORDER BY D.hostname, I.ifDescr"; +#} else { +# $sql = "SELECT * FROM `interfaces` AS I, `devices` AS D, `devices_perms` AS P WHERE I.device_id = D.device_id AND D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' ORDER BY D.hostname, I.ifDescr"; +#} + + +if($_GET['type'] == "down") { + $where = "AND I.ifAdminStatus = 'up' AND I.ifOperStatus = 'down'"; +} elseif ($_GET['type'] == "admindown") { + $where = "AND I.ifAdminStatus = 'down'"; } +$sql = "SELECT * FROM `interfaces` AS I, `devices` AS D WHERE I.device_id = D.device_id $where ORDER BY D.hostname, I.ifDescr"; + $query = mysql_query($sql); echo(""); @@ -25,7 +34,8 @@ while($interface = mysql_fetch_array($query)) { $error_img = generateiflink($interface,"Interface Errors",errors); } else { $error_img = ""; } - + if( interfacepermitted($interface['interface_id']) ) { + echo(" @@ -36,6 +46,8 @@ while($interface = mysql_fetch_array($query)) { $row++; + } + } echo("
    " . generatedevicelink($interface) . " " . generateiflink($interface, makeshortif(fixifname($interface['ifDescr']))) . " $error_img
    "); diff --git a/includes/functions.php b/includes/functions.php index ec3087ebf..b4e344262 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -111,11 +111,11 @@ function interfacepermitted($interface_id) { global $_SESSION; if($_SESSION['userlevel'] >= "5") { - $allowed = true; + $allowed = TRUE; } elseif ( devicepermitted(mysql_result(mysql_query("SELECT device_id FROM interface WHERE interface_id = '$interface_id'"),0))) { - $allowed = true; + $allowed = TRUE; } elseif ( @mysql_result(mysql_query("SELECT count(*) FROM interface_perms WHERE `user_id` = '" . $_SESSION['user_id'] . "' AND `interface_id` = $interface_id"), 0) > '0') { - $allowed = true; + $allowed = TRUE; } else { $allowed = FALSE; } return $allowed; } diff --git a/includes/osdiscovery/discover-screenos.php b/includes/osdiscovery/discover-screenos.php index fec9a8c01..2bba100aa 100755 --- a/includes/osdiscovery/discover-screenos.php +++ b/includes/osdiscovery/discover-screenos.php @@ -2,8 +2,8 @@ if(!$os) { - $sysObjectId = shell_exec($config['snmpget'] . " -Ovq -m ".$config['installdir']."/mibs/NS-PRODUCTS.mib -v2c -c ". $community ." ". $hostname ." .1.3.6.1.2.1.1.2.0"); - if(strstr($sysObjectId, "netscreen")) { $os = "Netscreen"; } + $sysObjectId = shell_exec($config['snmpget'] . " -Ovq -m ".$config['mibs_dir']."/NS-PRODUCTS.mib -v2c -c ". $community ." ". $hostname ." .1.3.6.1.2.1.1.2.0"); + if(strstr($sysObjectId, "netscreen")) { $os = "ScreenOS"; } } diff --git a/includes/polling/device-screenos.inc.php b/includes/polling/device-screenos.inc.php index ae04ed3f1..4ae4cca78 100755 --- a/includes/polling/device-screenos.inc.php +++ b/includes/polling/device-screenos.inc.php @@ -1,6 +1,6 @@ '0' && $cidr < '129' && $comp != '::1') { + $i_query = "SELECT interface_id FROM `interfaces` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"; + $interface_id = mysql_result(mysql_query($i_query), 0); + if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ip6addr` WHERE `addr` = '$address' AND `cidr` = '$cidr' AND `interface_id` = '$interface_id'"), 0) == '0') { + mysql_query("INSERT INTO `ip6addr` (`addr`, `comp_addr`, `cidr`, `origin`, `network`, `interface_id`) VALUES ('$address', '$comp', '$cidr', '$origin', '$network', '$interface_id')"); + echo("+"); + } + if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ip6networks` WHERE `cidr` = '$network'"), 0) < '1') { + mysql_query("INSERT INTO `ip6networks` (`id`, `cidr`) VALUES ('', '$network')"); + echo("N"); + } + $network_id = @mysql_result(mysql_query("SELECT id from `ip6networks` WHERE `cidr` = '$network'"), 0); + if (match_network($nets, $address) && mysql_result(mysql_query("SELECT COUNT(*) FROM `ip6adjacencies` WHERE `network_id` = '$network_id' AND `interface_id` = '$interface_id'"), 0) < '1') { + mysql_query("INSERT INTO `ip6adjacencies` (`network_id`, `interface_id`) VALUES ('$network_id', '$interface_id')"); + echo("A"); + } + } else { echo("."); } + } +} +?> diff --git a/poll-device.php b/poll-device.php index 2110fdf6a..f27ee1142 100755 --- a/poll-device.php +++ b/poll-device.php @@ -66,7 +66,10 @@ while ($device = mysql_fetch_array($device_query)) { $ciscomodel = str_replace("\"", "", trim(`$snmp_cmdb`)); } else { unset($ciscomodel); } + echo("$snmp_cmd \n"); + $snmpdata = shell_exec($snmp_cmd); + echo("completed"); $snmpdata = preg_replace("/^.*IOS/","", $snmpdata); $snmpdata = trim($snmpdata); $snmpdata = str_replace("\"", "", $snmpdata); @@ -137,6 +140,7 @@ while ($device = mysql_fetch_array($device_query)) { case "ScreenOS": $version = preg_replace("/(.+)\ version\ (.+)\ \(SN:\ (.+)\,\ (.+)\)/", "Juniper Netscreen \\1||\\2||\\3||\\4", $sysDescr); + echo("$version\n"); list($hardware,$version,$serial,$features) = explode("||", $version); include("includes/polling/device-screenos.inc.php"); break;