From 6501cd29b5ecd91fbd7088b16dfd932cd7f21ae3 Mon Sep 17 00:00:00 2001 From: Geert Hauwaerts Date: Tue, 22 Mar 2011 20:27:39 +0000 Subject: [PATCH] - Code cleanup by Bastian Widmer. git-svn-id: http://www.observium.org/svn/observer/trunk@1957 61d68cd4-352d-0410-923a-c4978735b2b8 --- addhost.php | 110 +-- adduser.php | 36 +- alerts.php | 18 +- check-errors.php | 32 +- check-services.php | 102 +- cleanup.php | 158 +-- config.php.default | 5 +- contrib/generate-dnstext.php | 72 +- contrib/generate-vegadns.php | 234 ++--- delhost.php | 20 +- discovery.php | 282 +++--- generate-iplist.php | 32 +- html/ajax_listports.php | 22 +- html/billing-graph.php | 150 +-- html/collectd-graph.php | 220 ++--- html/graph.php | 2 +- html/index.php | 80 +- html/map.php | 266 ++--- html/netcmd.php | 58 +- html/php.php | 2 +- includes/billing.php | 262 ++--- includes/cisco-entities.php | 36 +- includes/common.php | 191 ++-- includes/defaults.inc.php | 22 +- includes/functions.php | 960 +++++++++--------- includes/polling/applications.inc.php | 26 +- includes/polling/bgp-peers.inc.php | 438 ++++----- includes/polling/netstats-icmp.inc.php | 80 +- includes/polling/netstats-ip.inc.php | 72 +- includes/polling/netstats-snmp.inc.php | 74 +- includes/polling/netstats-tcp.inc.php | 82 +- includes/polling/netstats-udp.inc.php | 66 +- includes/polling/netstats.inc.php | 14 +- includes/polling/ports.inc.php | 476 ++++----- includes/port-descr-parser.inc.php | 22 +- includes/rewrites.php | 664 ++++++------- includes/rrdtool.inc.php | 34 +- includes/services.inc.php | 8 +- includes/snmp.inc.php | 1234 ++++++++++++------------ includes/snmptrap/linkDown.inc.php | 6 +- includes/snom-graphing.php | 50 +- irc.php | 48 +- poll-billing.php | 166 ++-- poll-reachability.php | 78 +- scripts/geshi-ios.php | 304 +++--- 45 files changed, 3658 insertions(+), 3656 deletions(-) diff --git a/addhost.php b/addhost.php index c3b1f719b5..d6b7633e3c 100755 --- a/addhost.php +++ b/addhost.php @@ -7,65 +7,65 @@ include("includes/functions.php"); if (isset($argv[1]) && $argv[1]) { - $host = strtolower($argv[1]); - $community = $argv[2]; - $snmpver = strtolower($argv[3]); + $host = strtolower($argv[1]); + $community = $argv[2]; + $snmpver = strtolower($argv[3]); - if (is_numeric($argv[4])) - { - $port = $argv[4]; - } - else - { - $port = 161; - } - - if (@!$argv[5]) - { - $transport = 'udp'; - } - else - { - $transport = $argv[5]; - } - - if (!$snmpver) $snmpver = "v2c"; - - if ($community) - { - unset($config['snmp']['community']); - $config['snmp']['community'][] = $community; - } - - list($hostshort) = explode(".", $host); - if (mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '".mres($host)."'"), 0) == '0' ) - { - if (isDomainResolves($argv[1])) + if (is_numeric($argv[4])) { - if (isPingable($argv[1])) - { - $added = 0; - - foreach ($config['snmp']['community'] as $community) + $port = $argv[4]; + } + else + { + $port = 161; + } + + if (@!$argv[5]) + { + $transport = 'udp'; + } + else + { + $transport = $argv[5]; + } + + if (!$snmpver) $snmpver = "v2c"; + + if ($community) + { + unset($config['snmp']['community']); + $config['snmp']['community'][] = $community; + } + + list($hostshort) = explode(".", $host); + if (mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '".mres($host)."'"), 0) == '0' ) + { + if (isDomainResolves($argv[1])) { - $device = deviceArray($host, $community, $snmpver, $port, $transport); - - if (isSNMPable($device)) - { - $snmphost = snmp_get($device, "sysName.0", "-Oqv", "SNMPv2-MIB"); - if ($snmphost == "" || ($snmphost && ($snmphost == $host || $hostshort = $host))) + if (isPingable($argv[1])) { - $added = createHost ($host, $community, $snmpver, $port, $transport); - if($added) { echo($added . "\n"); break; } + $added = 0; - } else { echo("Given hostname does not match SNMP-read hostname ($snmphost)!\n"); } - } - } - - if (!$added) { echo("Could not reach $host with given SNMP community\n"); } - } else { echo("Could not ping $host\n"); } - } else { echo("Could not resolve $host\n"); } - } else { echo("Already got host $host\n"); } + foreach ($config['snmp']['community'] as $community) + { + $device = deviceArray($host, $community, $snmpver, $port, $transport); + + if (isSNMPable($device)) + { + $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"); break; } + + } else { echo("Given hostname does not match SNMP-read hostname ($snmphost)!\n"); } + } + } + + if (!$added) { echo("Could not reach $host with given SNMP community\n"); } + } else { echo("Could not ping $host\n"); } + } else { echo("Could not resolve $host\n"); } + } else { echo("Already got host $host\n"); } } else { echo("Add Host Tool\nUsage: ./addhost.php [community] [v1|v2c] [port] [" . join("|",$config['snmp']['transports']) . "]\n"); } -?> \ No newline at end of file +?> diff --git a/adduser.php b/adduser.php index 34ea943c72..76ecace796 100755 --- a/adduser.php +++ b/adduser.php @@ -7,38 +7,38 @@ include("includes/functions.php"); if (file_exists('html/includes/authentication/' . $config['auth_mechanism'] . '.inc.php')) { - include('html/includes/authentication/' . $config['auth_mechanism'] . '.inc.php'); + include('html/includes/authentication/' . $config['auth_mechanism'] . '.inc.php'); } else { - echo("ERROR: no valid auth_mechanism defined.\n"); - exit(); + echo("ERROR: no valid auth_mechanism defined.\n"); + exit(); } if (auth_usermanagement()) { - if (isset($argv[1]) && isset($argv[2]) && isset($argv[3])) - { - if (!user_exists($argv[1])) + if (isset($argv[1]) && isset($argv[2]) && isset($argv[3])) { - if (adduser($argv[1],$argv[2],$argv[3],@$argv[4])) - { - echo("User ".$argv[1]." added successfully\n"); - } + if (!user_exists($argv[1])) + { + if (adduser($argv[1],$argv[2],$argv[3],@$argv[4])) + { + echo("User ".$argv[1]." added successfully\n"); + } + } + else + { + echo("User ".$argv[1]." already exists!\n"); + } } else { - echo("User ".$argv[1]." already exists!\n"); + echo("Add User Tool\nUsage: ./adduser.php [email]\n"); } - } - else - { - echo("Add User Tool\nUsage: ./adduser.php [email]\n"); - } } else { - echo("Auth module does not allow adding users!\n"); + echo("Auth module does not allow adding users!\n"); } -?> \ No newline at end of file +?> diff --git a/alerts.php b/alerts.php index 353d3f6051..b3093bfd2b 100755 --- a/alerts.php +++ b/alerts.php @@ -8,19 +8,19 @@ include("includes/functions.php"); $alert_query = mysql_query("SELECT *, A.id as id FROM `alerts` as A, `devices` as D where A.device_id = D.device_id AND alerted = '0'"); while ($alert = mysql_fetch_array($alert_query)) { - $id = $alert['id']; - $host = $alert['hostname']; - $date = $alert['time_logged']; - $msg = $alert['message']; - $alert_text .= "$date $host $msg"; + $id = $alert['id']; + $host = $alert['hostname']; + $date = $alert['time_logged']; + $msg = $alert['message']; + $alert_text .= "$date $host $msg"; - mysql_query("UPDATE `alerts` SET alerted = '1' WHERE `id` = '$id'"); + mysql_query("UPDATE `alerts` SET alerted = '1' WHERE `id` = '$id'"); } if ($alert_text) { - echo("$alert_text"); -# `echo '$alert_text' | gnokii --sendsms `; + echo("$alert_text"); + # `echo '$alert_text' | gnokii --sendsms `; } -?> \ No newline at end of file +?> diff --git a/check-errors.php b/check-errors.php index 6e2e8c5272..5613c5ed42 100755 --- a/check-errors.php +++ b/check-errors.php @@ -15,28 +15,28 @@ $interface_query = mysql_query("SELECT * FROM `ports` AS I, `devices` AS D WHERE while ($interface = mysql_fetch_array($interface_query)) { - $errors = $interface['ifInErrors_delta'] + $interface['ifOutErrors_delta']; - if ($errors > '1') - { - $errored[] = $interface['hostname'] . " - " . $interface['ifDescr'] . " - " . $interface['ifAlias'] . " - " . $interface['ifInErrors_delta'] . " - " . $interface['ifOutErrors_delta']; - } - $i++; + $errors = $interface['ifInErrors_delta'] + $interface['ifOutErrors_delta']; + if ($errors > '1') + { + $errored[] = $interface['hostname'] . " - " . $interface['ifDescr'] . " - " . $interface['ifAlias'] . " - " . $interface['ifInErrors_delta'] . " - " . $interface['ifOutErrors_delta']; + } + $i++; } echo("Checked $i Interfaces\n"); if ($errored) { ## If there are errored ports - $i=0; - $msg = "Interfaces with errors : \n\n"; + $i=0; + $msg = "Interfaces with errors : \n\n"; - foreach ($errored as $int) - { - $msg .= "$int\n"; ## Add a line to the report email warning about them - $i++; - } - ## Send the alert email - notify($device, "Observium detected errors on $i interface" . ($i != 1 ? 's' : ''), $msg); + foreach ($errored as $int) + { + $msg .= "$int\n"; ## Add a line to the report email warning about them + $i++; + } + ## Send the alert email + notify($device, "Observium detected errors on $i interface" . ($i != 1 ? 's' : ''), $msg); } -?> \ No newline at end of file +?> diff --git a/check-services.php b/check-services.php index bbccd16584..b306419aef 100755 --- a/check-services.php +++ b/check-services.php @@ -8,61 +8,61 @@ $sql = "SELECT * FROM devices AS D, services AS S WHERE S.device_id = D.device_i $query = mysql_query($sql); while ($service = mysql_fetch_array($query)) { - if ($service['status'] = "1") - { - unset($check, $service_status, $time, $status); - $service_status = $service['service_status']; - $service_type = strtolower($service['service_type']); - $service_param = $service['service_param']; - $checker_script = $config['install_dir'] . "/includes/services/" . $service_type . "/check.inc"; + if ($service['status'] = "1") + { + unset($check, $service_status, $time, $status); + $service_status = $service['service_status']; + $service_type = strtolower($service['service_type']); + $service_param = $service['service_param']; + $checker_script = $config['install_dir'] . "/includes/services/" . $service_type . "/check.inc"; - if (is_file($checker_script)) - { - include($checker_script); - } - else - { - $status = "2"; - $check = "Error : Script not found ($checker_script)"; + if (is_file($checker_script)) + { + include($checker_script); + } + else + { + $status = "2"; + $check = "Error : Script not found ($checker_script)"; + } + + if ($service_status != $status) + { + $updated = ", `service_changed` = '" . time() . "' "; + if ($service['sysContact']) { $email = $service['sysContact']; } else { $email = $config['email_default']; } + if ($status == "1") + { + $msg = "Service Up: " . $service['service_type'] . " on " . $service['hostname']; + $msg .= " at " . date($config['timestamp_format']); + notify($device, "Service Up: " . $service['service_type'] . " on " . $service['hostname'], $msg); + } + elseif ($status == "0") + { + $msg = "Service Down: " . $service['service_type'] . " on " . $service['hostname']; + $msg .= " at " . date($config['timestamp_format']); + notify($device, "Service Down: " . $service['service_type'] . " on " . $service['hostname'], $msg); + } + } else { unset($updated); } + + $update_sql = "UPDATE `services` SET `service_status` = '$status', `service_message` = '" . addslashes($check) . "', `service_checked` = '" . time() . "' $updated WHERE `service_id` = '" . $service['service_id']. "'"; + mysql_query($update_sql); + } else { + $status = "0"; } - if ($service_status != $status) + $rrd = $config['rrd_dir'] . "/" . $service['hostname'] . "/" . safename("service-" . $service['service_type'] . "-" . $service['service_id'] . ".rrd"); + + if (!is_file($rrd)) { - $updated = ", `service_changed` = '" . time() . "' "; - if ($service['sysContact']) { $email = $service['sysContact']; } else { $email = $config['email_default']; } - if ($status == "1") - { - $msg = "Service Up: " . $service['service_type'] . " on " . $service['hostname']; - $msg .= " at " . date($config['timestamp_format']); - notify($device, "Service Up: " . $service['service_type'] . " on " . $service['hostname'], $msg); - } - elseif ($status == "0") - { - $msg = "Service Down: " . $service['service_type'] . " on " . $service['hostname']; - $msg .= " at " . date($config['timestamp_format']); - notify($device, "Service Down: " . $service['service_type'] . " on " . $service['hostname'], $msg); - } - } else { unset($updated); } + rrdtool_create($rrd,"--step 300 \ + DS:status:GAUGE:600:0:1 \ + RRA:AVERAGE:0.5:1:1200 \ + RRA:AVERAGE:0.5:12:2400"); + } - $update_sql = "UPDATE `services` SET `service_status` = '$status', `service_message` = '" . addslashes($check) . "', `service_checked` = '" . time() . "' $updated WHERE `service_id` = '" . $service['service_id']. "'"; - mysql_query($update_sql); - } else { - $status = "0"; - } - - $rrd = $config['rrd_dir'] . "/" . $service['hostname'] . "/" . safename("service-" . $service['service_type'] . "-" . $service['service_id'] . ".rrd"); - - if (!is_file($rrd)) - { - rrdtool_create($rrd,"--step 300 \ - DS:status:GAUGE:600:0:1 \ - RRA:AVERAGE:0.5:1:1200 \ - RRA:AVERAGE:0.5:12:2400"); - } - - if ($status == "1" || $status == "0") - { - rrdtool_update($rrd,"N:".$status); - } + if ($status == "1" || $status == "0") + { + rrdtool_update($rrd,"N:".$status); + } } # while ?> diff --git a/cleanup.php b/cleanup.php index 6f102bfe9d..2dab8ce9d4 100755 --- a/cleanup.php +++ b/cleanup.php @@ -8,23 +8,23 @@ include("config.php"); include("includes/functions.php"); $query = "SELECT *,A.id as id FROM ipv4_addresses AS A, ports as I, devices as D - WHERE A.interface_id = I.interface_id AND I.device_id = D.device_id AND D.status = '1'"; + WHERE A.interface_id = I.interface_id AND I.device_id = D.device_id AND D.status = '1'"; $data = mysql_query($query); while ($row = mysql_fetch_array($data)) { - $addr = Net_IPv4::parseAddress($row['ipv4_address']."/".$row['ipv4_prefixlen']); - $mask = $addr->netmask; - $response = explode(" ", snmp_get($row, "ipAdEntIfIndex.".$row['ipv4_address'], "-Osq")); - $response = $response[1]; - $maskcheck = explode(" ", snmp_get($row, "ipAdEntNetMask.".$row['ipv4_address'], "-Osq")); - $maskcheck = $maskcheck[1]; + $addr = Net_IPv4::parseAddress($row['ipv4_address']."/".$row['ipv4_prefixlen']); + $mask = $addr->netmask; + $response = explode(" ", snmp_get($row, "ipAdEntIfIndex.".$row['ipv4_address'], "-Osq")); + $response = $response[1]; + $maskcheck = explode(" ", snmp_get($row, "ipAdEntNetMask.".$row['ipv4_address'], "-Osq")); + $maskcheck = $maskcheck[1]; - if ($response != $row['ifIndex'] || $mask != $maskcheck) - { - mysql_query("delete from ipv4_address where id = '".$row['ipv4_address_id']."'"); - echo("Deleted ".$row['ipv4_address']." from $row[hostname]\n"); - } + if ($response != $row['ifIndex'] || $mask != $maskcheck) + { + mysql_query("delete from ipv4_address where id = '".$row['ipv4_address_id']."'"); + echo("Deleted ".$row['ipv4_address']." from $row[hostname]\n"); + } } $sql = "SELECT * FROM devices WHERE status = '1'"; @@ -32,29 +32,29 @@ $query = mysql_query($sql); while ($device = mysql_fetch_array($query)) { - echo($device['hostname'] . " \n\n"); + echo($device['hostname'] . " \n\n"); - $oids = snmp_walk($device, "ipAddressIfIndex.ipv6", "-Osq"); - $oids = str_replace("ipAddressIfIndex.ipv6.", "", $oids); - $oids = str_replace("\"", "", $oids); $oids = trim($oids); + $oids = snmp_walk($device, "ipAddressIfIndex.ipv6", "-Osq"); + $oids = str_replace("ipAddressIfIndex.ipv6.", "", $oids); + $oids = str_replace("\"", "", $oids); $oids = trim($oids); - unset($valid_ips); - foreach (explode("\n", $oids) as $data) { - $data = trim($data); - list($ipv6addr,$ifIndex) = explode(" ", $data); - $valid_ips[] = $ipv6addr; - } - $sql = "SELECT * FROM ip6addr AS A, ports AS I, devices as D WHERE A.interface_id = I.interface_id AND I.device_id = '".$device['device_id']."'"; - $data = mysql_query($sql); - while ($row = mysql_fetch_array($data)) - { - echo($row['ipv6_address'] . "\n"); - unset($valid); - foreach ($valid_ips as $valid_ip) - { - echo($row['ipv6_address'] . " = $valid_ip ? \n"); + unset($valid_ips); + foreach (explode("\n", $oids) as $data) { + $data = trim($data); + list($ipv6addr,$ifIndex) = explode(" ", $data); + $valid_ips[] = $ipv6addr; + } + $sql = "SELECT * FROM ip6addr AS A, ports AS I, devices as D WHERE A.interface_id = I.interface_id AND I.device_id = '".$device['device_id']."'"; + $data = mysql_query($sql); + while ($row = mysql_fetch_array($data)) + { + echo($row['ipv6_address'] . "\n"); + unset($valid); + foreach ($valid_ips as $valid_ip) + { + echo($row['ipv6_address'] . " = $valid_ip ? \n"); + } } - } } @@ -62,33 +62,33 @@ $query = "SELECT * FROM ports AS I, devices as D WHERE I.device_id = D.device_id $data = mysql_query($query); while ($row = mysql_fetch_array($data)) { - $index = $row['ifIndex']; + $index = $row['ifIndex']; - $response = explode(" ", snmp_get($row, "ifIndex.$index", "-Osq")); - $response = $response[1]; + $response = explode(" ", snmp_get($row, "ifIndex.$index", "-Osq")); + $response = $response[1]; - if ($response != $index) - { - mysql_query("DELETE from ports where interface_id = '" . $row['interface_id'] . "'"); - mysql_query("DELETE from `adjacencies` WHERE `interface_id` = '" . $row['interface_id'] . "'"); - mysql_query("DELETE from `links` WHERE `local_interface_id` = '" . $row['interface_id'] . "'"); - mysql_query("DELETE from `links` WHERE `remote_interface_id` = '" . $row['interface_id'] . "'"); - mysql_query("DELETE from `ipaddr` WHERE `interface_id` = '" . $row['interface_id'] . "'"); - echo("Removed interface " . $row['ifDescr'] . " from " . $row['hostname'] . "
"); - } + if ($response != $index) + { + mysql_query("DELETE from ports where interface_id = '" . $row['interface_id'] . "'"); + mysql_query("DELETE from `adjacencies` WHERE `interface_id` = '" . $row['interface_id'] . "'"); + mysql_query("DELETE from `links` WHERE `local_interface_id` = '" . $row['interface_id'] . "'"); + mysql_query("DELETE from `links` WHERE `remote_interface_id` = '" . $row['interface_id'] . "'"); + mysql_query("DELETE from `ipaddr` WHERE `interface_id` = '" . $row['interface_id'] . "'"); + echo("Removed interface " . $row['ifDescr'] . " from " . $row['hostname'] . "
"); + } } echo(mysql_result(mysql_query("SELECT COUNT(*) FROM `ports`"), 0) . " ports at start\n"); $interface_query = mysql_query("SELECT interface_id,device_id FROM `ports`"); while ($interface = mysql_fetch_array($interface_query)) { - $device_id = $interface['device_id']; - $interface_id = $interface['interface_id']; - if (mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `device_id` = '$device_id'"), 0) == '0') - { - mysql_query("delete from ports where `interface_id` = '$interface_id'"); - echo("Deleting if $interface_id \n"); - } + $device_id = $interface['device_id']; + $interface_id = $interface['interface_id']; + if (mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `device_id` = '$device_id'"), 0) == '0') + { + mysql_query("delete from ports where `interface_id` = '$interface_id'"); + echo("Deleting if $interface_id \n"); + } } echo(mysql_result(mysql_query("SELECT COUNT(*) FROM `ports`"), 0) . " ports at end\n"); @@ -97,14 +97,14 @@ echo(mysql_result(mysql_query("SELECT COUNT(id) FROM `links`"), 0) . " links at $link_query = mysql_query("SELECT id,local_interface_id,remote_interface_id FROM `links`"); while ($link = mysql_fetch_array($link_query)) { - $id = $link['id']; - $src = $link['local_interface_id']; - $dst = $link['remote_interface_id']; - if (mysql_result(mysql_query("SELECT COUNT(interface_id) FROM `ports` WHERE `interface_id` = '$src'"), 0) == '0' || mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `interface_id` = '$dst'"), 0) == '0') - { - mysql_query("delete from links where `id` = '$id'"); - echo("Deleting link $id \n"); - } + $id = $link['id']; + $src = $link['local_interface_id']; + $dst = $link['remote_interface_id']; + if (mysql_result(mysql_query("SELECT COUNT(interface_id) FROM `ports` WHERE `interface_id` = '$src'"), 0) == '0' || mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `interface_id` = '$dst'"), 0) == '0') + { + mysql_query("delete from links where `id` = '$id'"); + echo("Deleting link $id \n"); + } } echo(mysql_result(mysql_query("SELECT COUNT(id) FROM `links`"), 0) . " links at end\n"); @@ -112,33 +112,33 @@ echo(mysql_result(mysql_query("SELECT COUNT(adj_id) FROM `adjacencies`"), 0) . " $link_query = mysql_query("SELECT * FROM `adjacencies` AS A, `ports` AS I, `devices` AS D, networks AS N WHERE I.interface_id = A.interface_id AND D.device_id = I.device_id AND N.id = A.network_id"); while ($link = mysql_fetch_array($link_query)) { - $id = $link['adj_id']; - $netid = $link['network_id']; - $ifid = $link['interface_id']; - if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `interface_id` = '$ifid'"), 0) == '0' || mysql_result(mysql_query("SELECT COUNT(id) FROM `networks` WHERE `id` = '$netid'"), 0) == '0') - { - $remove = 1; - echo("Removed Interface!\n"); - } + $id = $link['adj_id']; + $netid = $link['network_id']; + $ifid = $link['interface_id']; + if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `interface_id` = '$ifid'"), 0) == '0' || mysql_result(mysql_query("SELECT COUNT(id) FROM `networks` WHERE `id` = '$netid'"), 0) == '0') + { + $remove = 1; + echo("Removed Interface!\n"); + } - list($network, $cidr) = explode("/", $link['cidr']); + list($network, $cidr) = explode("/", $link['cidr']); - $checksql = "SELECT COUNT(*) FROM `ipaddr` WHERE `interface_id` = '" . $link['interface_id'] . "' AND `cidr` = '$cidr' AND `network` = '$network'"; - if (mysql_result(mysql_query($checksql),0) == 0) { $remove = 1; } + $checksql = "SELECT COUNT(*) FROM `ipaddr` WHERE `interface_id` = '" . $link['interface_id'] . "' AND `cidr` = '$cidr' AND `network` = '$network'"; + if (mysql_result(mysql_query($checksql),0) == 0) { $remove = 1; } -# echo($link['if'] . " (" . $link['interface_id'] . ") -> " . $link['cidr'] . " \n"); + # echo($link['if'] . " (" . $link['interface_id'] . ") -> " . $link['cidr'] . " \n"); - if ($link['cidr'] == "") { $remove = 1; echo("Broken CIDR entry!"); } + if ($link['cidr'] == "") { $remove = 1; echo("Broken CIDR entry!"); } - if ($remove) - { - mysql_query("delete from adjacencies where `adj_id` = '$id'"); - echo("Deleting link $id (".$link['cidr']." - ". $link['hostname'] ." - ". $link['ifDescr'] .")\n"); - } + if ($remove) + { + mysql_query("delete from adjacencies where `adj_id` = '$id'"); + echo("Deleting link $id (".$link['cidr']." - ". $link['hostname'] ." - ". $link['ifDescr'] .")\n"); + } - unset($remove); + unset($remove); } echo(mysql_result(mysql_query("SELECT COUNT(adj_id) FROM `adjacencies`"), 0) . " adjacencies at end\n"); -?> \ No newline at end of file +?> diff --git a/config.php.default b/config.php.default index a253fa3b1c..e999c38e16 100755 --- a/config.php.default +++ b/config.php.default @@ -26,8 +26,9 @@ $config['log_file'] = $config['install_dir'] . "/observium.log"; $config['snmp']['community'][] = "public"; ### Enable php_snmp -$config['snmp']['internal'] = false; # Enable php_snmp functions to make gets faster - # Often doesn't work, because jwh can't code for shit. +# Enable php_snmp functions to make gets faster +# Often doesn't work, because jwh can't code for shit, +$config['snmp']['internal'] = false; ### Authentication Model $config['auth_mechanism'] = "mysql"; # default, other options: ldap, http-auth diff --git a/contrib/generate-dnstext.php b/contrib/generate-dnstext.php index 23c84e270d..cd25253a48 100755 --- a/contrib/generate-dnstext.php +++ b/contrib/generate-dnstext.php @@ -11,57 +11,57 @@ $db = mysql_select_db($config['db_name'], $link); $query = "SELECT * FROM ipaddr AS A, ports as I, devices as D WHERE A.interface_id = I.interface_id AND I.device_id = D.device_id AND D.os = 'ios'"; $data = mysql_query($query, $link); while($ip = mysql_fetch_array($data)) { - unset($sub); - $hostname = $ip['hostname']; + unset($sub); + $hostname = $ip['hostname']; - $real_hostname = $hostname; + $real_hostname = $hostname; - $hostname = str_replace(".jtibs.net", "", $hostname); - $hostname = str_replace(".wtibs.net", "", $hostname); - $hostname = str_replace(".jerseytelecom.net", "", $hostname); + $hostname = str_replace(".jtibs.net", "", $hostname); + $hostname = str_replace(".wtibs.net", "", $hostname); + $hostname = str_replace(".jerseytelecom.net", "", $hostname); - list($cc, $loc, $host) = explode(".", $hostname); - if($host) { - $hostname = "$host.$loc.$cc.v4.jerseytelecom.net"; - } else { - $host = $cc; unset ($cc); - $hostname = "$host.v4.jerseytelecom.net"; - } + list($cc, $loc, $host) = explode(".", $hostname); + if($host) { + $hostname = "$host.$loc.$cc.v4.jerseytelecom.net"; + } else { + $host = $cc; unset ($cc); + $hostname = "$host.v4.jerseytelecom.net"; + } - $interface = $ip['ifDescr']; - $address = $ip['addr']; - $cidr = $ip['cidr']; - $interface = strtolower(makeshortif(fixifname($interface))); - $interface = str_replace("/", "-", $interface); - $interface = str_replace(":", "_", $interface); - list($interface, $sub) = explode(".", $interface); - if($sub) { - $sub = str_replace(" ", "", $sub); - $sub = str_replace("aal5", "", $sub); - $interface = "$sub.$interface"; - } - $hostip = trim(gethostbyname($real_hostname)); + $interface = $ip['ifDescr']; + $address = $ip['addr']; + $cidr = $ip['cidr']; + $interface = strtolower(makeshortif(fixifname($interface))); + $interface = str_replace("/", "-", $interface); + $interface = str_replace(":", "_", $interface); + list($interface, $sub) = explode(".", $interface); + if($sub) { + $sub = str_replace(" ", "", $sub); + $sub = str_replace("aal5", "", $sub); + $interface = "$sub.$interface"; + } + $hostip = trim(gethostbyname($real_hostname)); - list($first, $second, $third, $fourth) = explode(".", $address); - $revzone = "$third.$second.$first.in-addr.arpa"; - $reverse = "$fourth.$revzone"; - $dnsname = "$interface.$hostname"; + list($first, $second, $third, $fourth) = explode(".", $address); + $revzone = "$third.$second.$first.in-addr.arpa"; + $reverse = "$fourth.$revzone"; + $dnsname = "$interface.$hostname"; - $dns_list[] = str_pad($revzone, 24) . "|" . str_pad($reverse, 30)."IN ADDR ".str_pad($dnsname, 30); + $dns_list[] = str_pad($revzone, 24) . "|" . str_pad($reverse, 30)."IN ADDR ".str_pad($dnsname, 30); } sort ($dns_list); foreach ($dns_list as $entry) { - list($zone, $entry) = explode("|", $entry); - $zone = trim($zone); + list($zone, $entry) = explode("|", $entry); + $zone = trim($zone); - if($zone != $oldzone) { echo("\n$$zone\n------------------------------\n"); } + if($zone != $oldzone) { echo("\n$$zone\n------------------------------\n"); } - echo("$entry \n"); + echo("$entry \n"); - $oldzone = $zone; + $oldzone = $zone; } diff --git a/contrib/generate-vegadns.php b/contrib/generate-vegadns.php index 2b75e6bded..eae396b001 100755 --- a/contrib/generate-vegadns.php +++ b/contrib/generate-vegadns.php @@ -15,143 +15,143 @@ $db = mysql_select_db($config['db_name'], $link); $query = "SELECT * FROM ipaddr AS A, ports as I, devices as D WHERE A.interface_id = I.interface_id AND I.device_id = D.device_id AND D.hostname LIKE '%.vostron.net' AND D.hostname NOT LIKE '%.cust.%' AND D.os = 'ios'"; $data = mysql_query($query, $link); while($ip = mysql_fetch_array($data)) { - unset($sub); - $hostname = $ip['hostname']; + unset($sub); + $hostname = $ip['hostname']; - $real_hostname = $hostname; + $real_hostname = $hostname; - $hostname = str_replace(".vostron.net", "", $hostname); - list($loc, $host) = explode("-", $hostname); - if($host) { - $hostname = "$host.$loc.v4.vostron.net"; - } else { - $host = $loc; unset ($loc); - $hostname = "$host.v4.vostron.net"; - } + $hostname = str_replace(".vostron.net", "", $hostname); + list($loc, $host) = explode("-", $hostname); + if($host) { + $hostname = "$host.$loc.v4.vostron.net"; + } else { + $host = $loc; unset ($loc); + $hostname = "$host.v4.vostron.net"; + } - $interface = $ip['ifDescr']; - $address = $ip['addr']; - $cidr = $ip['cidr']; - $interface = strtolower(makeshortif(fixifname($interface))); - $interface = str_replace("/", "-", $interface); - list($interface, $sub) = explode(".", $interface); - if($sub) { - $sub = str_replace(" ", "", $sub); - $sub = str_replace("aal5", "", $sub); - $interface = "$sub.$interface"; - } - $hostip = trim(gethostbyname($real_hostname)); - if(strstr($hostname, ".vostron.net")) { - list($first, $second, $third, $fourth) = explode(".", $address); - $revzone = "$third.$second.$first.in-addr.arpa"; - $reverse = "$fourth.$revzone"; - $dnsname = "$interface.$hostname"; - $rev_sql = "SELECT `domain_id` FROM `domains` WHERE domain = '" . $revzone . "'"; - $rev_domain_id = @mysql_result(mysql_query($rev_sql, $dnsdblink),0); + $interface = $ip['ifDescr']; + $address = $ip['addr']; + $cidr = $ip['cidr']; + $interface = strtolower(makeshortif(fixifname($interface))); + $interface = str_replace("/", "-", $interface); + list($interface, $sub) = explode(".", $interface); + if($sub) { + $sub = str_replace(" ", "", $sub); + $sub = str_replace("aal5", "", $sub); + $interface = "$sub.$interface"; + } + $hostip = trim(gethostbyname($real_hostname)); + if(strstr($hostname, ".vostron.net")) { + list($first, $second, $third, $fourth) = explode(".", $address); + $revzone = "$third.$second.$first.in-addr.arpa"; + $reverse = "$fourth.$revzone"; + $dnsname = "$interface.$hostname"; + $rev_sql = "SELECT `domain_id` FROM `domains` WHERE domain = '" . $revzone . "'"; + $rev_domain_id = @mysql_result(mysql_query($rev_sql, $dnsdblink),0); - $rows_exist = mysql_result(mysql_query("SELECT COUNT(record_id) FROM `records` WHERE `host` = '$reverse'", $dnsdblink),0); + $rows_exist = mysql_result(mysql_query("SELECT COUNT(record_id) FROM `records` WHERE `host` = '$reverse'", $dnsdblink),0); - if($rows_exist > '1') { $rows_exist = 1; echo("DELETE FROM `records` WHERE `host` = '$reverse' LIMIT $rows_exist;\n"); } + if($rows_exist > '1') { $rows_exist = 1; echo("DELETE FROM `records` WHERE `host` = '$reverse' LIMIT $rows_exist;\n"); } - if($address == $hostip) { - if($rows_exist < '1') { - $reverse_query = "INSERT INTO `records` (`host`, `ttl`, `type`, `val`, `domain_id`) "; - $reverse_query .= "VALUES ('$reverse','38400','P','$real_hostname','$rev_domain_id')"; - } else { - $reverse_query = "UPDATE `records` SET `val` = '$real_hostname' WHERE `host` = '".$reverse.".'"; - } - } else { - if($rows_exist < '1') { - $reverse_query = "INSERT INTO `records` (`host`, `ttl`, `type`, `val`, `domain_id`) "; - $reverse_query .= "VALUES ('$reverse','38400','P','$dnsname','$rev_domain_id')"; - } else { - $reverse_query = "UPDATE `records` SET `val` = '".$dnsname.".' WHERE `host` = '".$reverse."'"; - } - } - - if($rev_domain_id) { - echo("$reverse_query; \n"); - #mysql_query($reverse_query, $dnsdblink); - } else { - #echo("$hostname - $interface - $reverse FAILED\n"); - } - - $i = 1; - unset($exist); - while ($i <= count($zoneupdated)) { - $thiszone = "$revzone"; - if ($zoneupdated[$i] == $thiszone) { $exist = "yes"; } - $i++; - } - if(!$exist) { $zoneupdated[] = "$revzone"; } - - unset ($forward_query); - - if($address != $hostip) { - - $rows_exist = mysql_result(mysql_query("SELECT COUNT(record_id) FROM `records` WHERE `host` = '$dnsname'", $dnsdblink),0); - if($rows_exist > '1') { $rows_exist--; echo("DELETE FROM `records` WHERE `host` = '$hostname' LIMIT $rows_exist;\n"); } - - if($rows_exist < '1') { - $forward_query = "INSERT INTO `records` (`host`, `ttl`, `type`, `val`, `domain_id`) "; - $forward_query .= "VALUES ('$dnsname','38400','A','$address','381')"; - } elseif ($address != $hostip) { - $forward_query = "UPDATE `records` SET `val` = '$address' WHERE `host` = '$dnsname'"; + if($address == $hostip) { + if($rows_exist < '1') { + $reverse_query = "INSERT INTO `records` (`host`, `ttl`, `type`, `val`, `domain_id`) "; + $reverse_query .= "VALUES ('$reverse','38400','P','$real_hostname','$rev_domain_id')"; + } else { + $reverse_query = "UPDATE `records` SET `val` = '$real_hostname' WHERE `host` = '".$reverse.".'"; + } + } else { + if($rows_exist < '1') { + $reverse_query = "INSERT INTO `records` (`host`, `ttl`, `type`, `val`, `domain_id`) "; + $reverse_query .= "VALUES ('$reverse','38400','P','$dnsname','$rev_domain_id')"; + } else { + $reverse_query = "UPDATE `records` SET `val` = '".$dnsname.".' WHERE `host` = '".$reverse."'"; + } } - - } - if($forward_query && $rev_domain_id) { - echo("$forward_query; \n"); - } + if($rev_domain_id) { + echo("$reverse_query; \n"); + #mysql_query($reverse_query, $dnsdblink); + } else { + #echo("$hostname - $interface - $reverse FAILED\n"); + } + + $i = 1; + unset($exist); + while ($i <= count($zoneupdated)) { + $thiszone = "$revzone"; + if ($zoneupdated[$i] == $thiszone) { $exist = "yes"; } + $i++; + } + if(!$exist) { $zoneupdated[] = "$revzone"; } + + unset ($forward_query); + + if($address != $hostip) { + + $rows_exist = mysql_result(mysql_query("SELECT COUNT(record_id) FROM `records` WHERE `host` = '$dnsname'", $dnsdblink),0); + if($rows_exist > '1') { $rows_exist--; echo("DELETE FROM `records` WHERE `host` = '$hostname' LIMIT $rows_exist;\n"); } + + if($rows_exist < '1') { + $forward_query = "INSERT INTO `records` (`host`, `ttl`, `type`, `val`, `domain_id`) "; + $forward_query .= "VALUES ('$dnsname','38400','A','$address','381')"; + } elseif ($address != $hostip) { + $forward_query = "UPDATE `records` SET `val` = '$address' WHERE `host` = '$dnsname'"; + } + + } + + if($forward_query && $rev_domain_id) { + echo("$forward_query; \n"); + } - mysql_query($forward_query, $dnsdblink); -# $i = 1; -# unset($exist) -# while ($i <= count($linkdone)) { -# $thiszone = "$"; -# if ($zoneupdated[$i] == $thiszone) { $exist = "yes"; } -# $i++; -# } + mysql_query($forward_query, $dnsdblink); + # $i = 1; + # unset($exist) + # while ($i <= count($linkdone)) { + # $thiszone = "$"; + # if ($zoneupdated[$i] == $thiszone) { $exist = "yes"; } + # $i++; + # } - } + } } $i = 0; while ($i < count($zoneupdated)) { -# $sSQL = "update zones set name = '" . $name . "', ttl = " . $ttl . ", rdtype = -# '" . $rdtype1 . "', rdata = '" . $rdata . "' where zoneid = " . $id; -# $result = mysql_query($sSQL, $dnsdblink); + # $sSQL = "update zones set name = '" . $name . "', ttl = " . $ttl . ", rdtype = + # '" . $rdtype1 . "', rdata = '" . $rdata . "' where zoneid = " . $id; + # $result = mysql_query($sSQL, $dnsdblink); - $domain = $zoneupdated[$i]; + $domain = $zoneupdated[$i]; - $sSQL = "select rdata, zoneid from zones where domain_name = '" . $domain . "' and rdtype = 'SOA'"; - # $result = mysql_query($sSQL, $dnsdblink); -# $row = mysql_fetch_array($result); - $soa = explode(" ", $row[0]); - $year = substr($soa[2],0,4); - $month = substr($soa[2],4,2); - $day = substr($soa[2],6,2); - $serial = substr($soa[2],8,2); - $thisday = date("d",time()); - $thismonth = date("m",time()); - $thisyear = date("Y", time()); - if($day == $thisday && $month == $thismonth && $year = $thisyear) { - $serial++; - } - else { - $serial = "01"; - } - $date = $thisyear . $thismonth . $thisday . sprintf("%02s",$serial); - $rdata = $soa[0] . " " . $soa[1] . " " . $date . " " . $soa[3] . " " . $soa[4] . " " . $soa[5] . " " . $soa[6]; - $sSQL = "update zones set rdata = '" . $rdata . "' where zoneid = " . $row[1]; - # echo("$sSQL\n"); -# $result = mysql_query($sSQL, $dnsdblink); + $sSQL = "select rdata, zoneid from zones where domain_name = '" . $domain . "' and rdtype = 'SOA'"; + # $result = mysql_query($sSQL, $dnsdblink); + # $row = mysql_fetch_array($result); + $soa = explode(" ", $row[0]); + $year = substr($soa[2],0,4); + $month = substr($soa[2],4,2); + $day = substr($soa[2],6,2); + $serial = substr($soa[2],8,2); + $thisday = date("d",time()); + $thismonth = date("m",time()); + $thisyear = date("Y", time()); + if($day == $thisday && $month == $thismonth && $year = $thisyear) { + $serial++; + } + else { + $serial = "01"; + } + $date = $thisyear . $thismonth . $thisday . sprintf("%02s",$serial); + $rdata = $soa[0] . " " . $soa[1] . " " . $date . " " . $soa[3] . " " . $soa[4] . " " . $soa[5] . " " . $soa[6]; + $sSQL = "update zones set rdata = '" . $rdata . "' where zoneid = " . $row[1]; + # echo("$sSQL\n"); + # $result = mysql_query($sSQL, $dnsdblink); - $i++; + $i++; } ?> diff --git a/delhost.php b/delhost.php index 63922690cd..56c15be4ca 100755 --- a/delhost.php +++ b/delhost.php @@ -9,17 +9,17 @@ include("includes/functions.php"); if ($argv[1]) { - $host = strtolower($argv[1]); - $id = getidbyname($host); - if ($id) - { - echo(delete_device($id)); - echo("Removed $host\n"); - } else { - echo("Host doesn't exist!\n"); - } + $host = strtolower($argv[1]); + $id = getidbyname($host); + if ($id) + { + echo(delete_device($id)); + echo("Removed $host\n"); + } else { + echo("Host doesn't exist!\n"); + } } else { - echo("Host Removal Tool\nUsage: ./delhost.php \n"); + echo("Host Removal Tool\nUsage: ./delhost.php \n"); } ?> diff --git a/discovery.php b/discovery.php index d0eb1eca5e..f4394c301d 100755 --- a/discovery.php +++ b/discovery.php @@ -28,116 +28,116 @@ $options = getopt("h:t:i:n:d::a::"); if (isset($options['h'])) { - if ($options['h'] == "odd") { $options['n'] = "1"; $options['i'] = "2"; } - elseif ($options['h'] == "even") { $options['n'] = "0"; $options['i'] = "2"; } - elseif ($options['h'] == "all") { $where = " "; $doing = "all"; } - elseif ($options['h'] == "new") { $where = "AND `last_discovered` IS NULL"; $doing = "new"; } - elseif ($options['h']) - { - if (is_numeric($options['h'])) + if ($options['h'] == "odd") { $options['n'] = "1"; $options['i'] = "2"; } + elseif ($options['h'] == "even") { $options['n'] = "0"; $options['i'] = "2"; } + elseif ($options['h'] == "all") { $where = " "; $doing = "all"; } + elseif ($options['h'] == "new") { $where = "AND `last_discovered` IS NULL"; $doing = "new"; } + elseif ($options['h']) { - $where = "AND `device_id` = '".$options['h']."'"; - $doing = $options['h']; + if (is_numeric($options['h'])) + { + $where = "AND `device_id` = '".$options['h']."'"; + $doing = $options['h']; + } + else + { + $where = "AND `hostname` LIKE '".str_replace('*','%',mres($options['h']))."'"; + $doing = $options['h']; + } } - else - { - $where = "AND `hostname` LIKE '".str_replace('*','%',mres($options['h']))."'"; - $doing = $options['h']; - } - } } if (isset($options['i']) && $options['i'] && isset($options['n'])) { - $where = "AND MOD(device_id,".$options['i'].") = '" . $options['n'] . "'"; - $doing = $options['n'] ."/".$options['i']; + $where = "AND MOD(device_id,".$options['i'].") = '" . $options['n'] . "'"; + $doing = $options['n'] ."/".$options['i']; } if (isset($options['d'])) { - echo("DEBUG!\n"); - $debug = TRUE; - ini_set('display_errors', 1); - ini_set('display_startup_errors', 1); - ini_set('log_errors', 1); - ini_set('error_reporting', 1); + echo("DEBUG!\n"); + $debug = TRUE; + ini_set('display_errors', 1); + ini_set('display_startup_errors', 1); + ini_set('log_errors', 1); + ini_set('error_reporting', 1); } else { - $debug = FALSE; -# ini_set('display_errors', 0); - ini_set('display_startup_errors', 0); - ini_set('log_errors', 0); -# ini_set('error_reporting', 0); + $debug = FALSE; + # ini_set('display_errors', 0); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + # ini_set('error_reporting', 0); } if (!$where) { - echo("-h | Poll single device\n"); - echo("-h odd Poll odd numbered devices (same as -i 2 -n 0)\n"); - echo("-h even Poll even numbered devices (same as -i 2 -n 1)\n"); - echo("-h all Poll all devices\n"); - echo("-h new Poll all devices that have not had a discovery run before\n\n"); - echo("-i -n Poll as instance of \n"); - echo(" Instances start at 0. 0-3 for -n 4\n\n"); - echo("-d Enable debugging output\n"); - echo("\n"); - echo("No polling type specified!\n"); - exit; - } + echo("-h | Poll single device\n"); + echo("-h odd Poll odd numbered devices (same as -i 2 -n 0)\n"); + echo("-h even Poll even numbered devices (same as -i 2 -n 1)\n"); + echo("-h all Poll all devices\n"); + echo("-h new Poll all devices that have not had a discovery run before\n\n"); + echo("-i -n Poll as instance of \n"); + echo(" Instances start at 0. 0-3 for -n 4\n\n"); + echo("-d Enable debugging output\n"); + echo("\n"); + echo("No polling type specified!\n"); + exit; +} if (file_exists('.svn')) { - list(,$dbu_rev) = preg_split('/: /',@shell_exec('svn info database-update.sql|grep ^Revision')); + list(,$dbu_rev) = preg_split('/: /',@shell_exec('svn info database-update.sql|grep ^Revision')); - $device_query = mysql_query("SELECT revision FROM `dbSchema`"); - if ($rev = @mysql_fetch_array($device_query)) - { - $db_rev = $rev['revision']; - } - else - { - $db_rev = 0; - } - - if ($db_rev+0 < 1223) - { - include('upgrade-scripts/fix-events.php'); ## Fix events table (needs to copy some data around, so needs script) - } - - if ($db_rev+0 < 1656) - { - include('upgrade-scripts/fix-port-rrd.php'); ## Rewrites all port RRDs. Nothing will work without this after 1656 - } - - if ($db_rev+0 < 1757) - { - include('upgrade-scripts/fix-sensor-rrd.php'); ## Rewrites all sensor RRDs. Nothing will work without this after 1757 - } - - if ($dbu_rev+0 > $db_rev) - { - echo("SVN revision changed.\n"); - if ($db_rev+0 < "1000") + $device_query = mysql_query("SELECT revision FROM `dbSchema`"); + if ($rev = @mysql_fetch_array($device_query)) { - echo("Running pre-revision 1000 SQL update script...\n"); - shell_exec("scripts/update-sql.php database-update-pre1000.sql"); - } - if ($db_rev+0 < "1435") - { - echo("Running pre-revision 1435 SQL update script...\n"); - shell_exec("scripts/update-sql.php database-update-pre1435.sql"); - } - echo("Running development SQL update script to update from r$db_rev to r" . trim($dbu_rev) . "...\n"); - shell_exec("scripts/update-sql.php database-update.sql"); - if ($db_rev == 0) - { - mysql_query("INSERT INTO dbSchema VALUES ($dbu_rev)"); + $db_rev = $rev['revision']; } else { - mysql_query("UPDATE dbSchema set revision=$dbu_rev"); + $db_rev = 0; + } + + if ($db_rev+0 < 1223) + { + include('upgrade-scripts/fix-events.php'); ## Fix events table (needs to copy some data around, so needs script) + } + + if ($db_rev+0 < 1656) + { + include('upgrade-scripts/fix-port-rrd.php'); ## Rewrites all port RRDs. Nothing will work without this after 1656 + } + + if ($db_rev+0 < 1757) + { + include('upgrade-scripts/fix-sensor-rrd.php'); ## Rewrites all sensor RRDs. Nothing will work without this after 1757 + } + + if ($dbu_rev+0 > $db_rev) + { + echo("SVN revision changed.\n"); + if ($db_rev+0 < "1000") + { + echo("Running pre-revision 1000 SQL update script...\n"); + shell_exec("scripts/update-sql.php database-update-pre1000.sql"); + } + if ($db_rev+0 < "1435") + { + echo("Running pre-revision 1435 SQL update script...\n"); + shell_exec("scripts/update-sql.php database-update-pre1435.sql"); + } + echo("Running development SQL update script to update from r$db_rev to r" . trim($dbu_rev) . "...\n"); + shell_exec("scripts/update-sql.php database-update.sql"); + if ($db_rev == 0) + { + mysql_query("INSERT INTO dbSchema VALUES ($dbu_rev)"); + } + else + { + mysql_query("UPDATE dbSchema set revision=$dbu_rev"); + } } - } } $discovered_devices = 0; @@ -146,66 +146,66 @@ $device_query = mysql_query("SELECT * FROM `devices` WHERE status = 1 AND disabl while ($device = mysql_fetch_array($device_query)) { - $device_start = utime(); // Start counting device poll time + $device_start = utime(); // Start counting device poll time - echo($device['hostname'] . " ".$device['device_id']." ".$device['os']." "); - if ($device['os'] != strtolower($device['os'])) - { - mysql_query("UPDATE `devices` SET `os` = '".strtolower($device['os'])."' WHERE device_id = '".$device['device_id']."'"); - $device['os'] = strtolower($device['os']); - echo("OS lowercased."); - } - if ($config['os'][$device['os']]['group']) - { - $device['os_group'] = $config['os'][$device['os']]['group']; - echo("(".$device['os_group'].")"); - } - - echo("\n"); - - #include("includes/discovery/os.inc.php"); - - include("includes/discovery/ports.inc.php"); - include("includes/discovery/entity-physical.inc.php"); - include("includes/discovery/processors.inc.php"); - include("includes/discovery/mempools.inc.php"); - include("includes/discovery/ipv4-addresses.inc.php"); - include("includes/discovery/ipv6-addresses.inc.php"); - include("includes/discovery/sensors.inc.php"); - include("includes/discovery/storage.inc.php"); - include("includes/discovery/hr-device.inc.php"); - include("includes/discovery/discovery-protocols.inc.php"); - include("includes/discovery/arp-table.inc.php"); - include("includes/discovery/junose-atm-vp.inc.php"); - include("includes/discovery/bgp-peers.inc.php"); - include("includes/discovery/q-bridge-mib.inc.php"); - include("includes/discovery/cisco-vlans.inc.php"); - include("includes/discovery/cisco-mac-accounting.inc.php"); - include("includes/discovery/cisco-pw.inc.php"); - include("includes/discovery/cisco-vrf.inc.php"); - include("includes/discovery/toner.inc.php"); - include("includes/discovery/ucd-diskio.inc.php"); - include("includes/discovery/services.inc.php"); - - if ($device['type'] == "unknown" || $device['type'] == "") - { - if ($config['os'][$device['os']]['type']) + echo($device['hostname'] . " ".$device['device_id']." ".$device['os']." "); + if ($device['os'] != strtolower($device['os'])) { - $device['type'] = $config['os'][$device['os']]['type']; + mysql_query("UPDATE `devices` SET `os` = '".strtolower($device['os'])."' WHERE device_id = '".$device['device_id']."'"); + $device['os'] = strtolower($device['os']); + echo("OS lowercased."); + } + if ($config['os'][$device['os']]['group']) + { + $device['os_group'] = $config['os'][$device['os']]['group']; + echo("(".$device['os_group'].")"); } - } - $device_end = utime(); $device_run = $device_end - $device_start; $device_time = substr($device_run, 0, 5); + echo("\n"); - $update_query = "UPDATE `devices` SET "; - $update_query .= " `last_discovered` = NOW(), `type` = '" . $device['type'] . "'"; - $update_query .= ", `last_discovered_timetaken` = '$device_time'"; - $update_query .= " WHERE `device_id` = '" . $device['device_id'] . "'"; - $update_result = mysql_query($update_query); + #include("includes/discovery/os.inc.php"); - echo("Discovered in $device_time seconds\n"); - unset($cache); // Clear cache (unify all things here?) - echo("\n"); $discovered_devices++; + include("includes/discovery/ports.inc.php"); + include("includes/discovery/entity-physical.inc.php"); + include("includes/discovery/processors.inc.php"); + include("includes/discovery/mempools.inc.php"); + include("includes/discovery/ipv4-addresses.inc.php"); + include("includes/discovery/ipv6-addresses.inc.php"); + include("includes/discovery/sensors.inc.php"); + include("includes/discovery/storage.inc.php"); + include("includes/discovery/hr-device.inc.php"); + include("includes/discovery/discovery-protocols.inc.php"); + include("includes/discovery/arp-table.inc.php"); + include("includes/discovery/junose-atm-vp.inc.php"); + include("includes/discovery/bgp-peers.inc.php"); + include("includes/discovery/q-bridge-mib.inc.php"); + include("includes/discovery/cisco-vlans.inc.php"); + include("includes/discovery/cisco-mac-accounting.inc.php"); + include("includes/discovery/cisco-pw.inc.php"); + include("includes/discovery/cisco-vrf.inc.php"); + include("includes/discovery/toner.inc.php"); + include("includes/discovery/ucd-diskio.inc.php"); + include("includes/discovery/services.inc.php"); + + 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); + + $update_query = "UPDATE `devices` SET "; + $update_query .= " `last_discovered` = NOW(), `type` = '" . $device['type'] . "'"; + $update_query .= ", `last_discovered_timetaken` = '$device_time'"; + $update_query .= " WHERE `device_id` = '" . $device['device_id'] . "'"; + $update_result = mysql_query($update_query); + + echo("Discovered in $device_time seconds\n"); + unset($cache); // Clear cache (unify all things here?) + echo("\n"); $discovered_devices++; } $end = utime(); $run = $end - $start; @@ -213,8 +213,8 @@ $proctime = substr($run, 0, 5); if ($discovered_devices) { - mysql_query("INSERT INTO `perf_times` (`type`, `doing`, `start`, `duration`, `devices`) - VALUES ('discover', '$doing', '$start', '$proctime', '$discovered_devices')"); + mysql_query("INSERT INTO `perf_times` (`type`, `doing`, `start`, `duration`, `devices`) + VALUES ('discover', '$doing', '$start', '$proctime', '$discovered_devices')"); } $string = $argv[0] . " $doing " . date("F j, Y, G:i") . " - $discovered_devices devices discovered in $proctime secs"; diff --git a/generate-iplist.php b/generate-iplist.php index 5b6ca1c5a0..6635546d06 100755 --- a/generate-iplist.php +++ b/generate-iplist.php @@ -10,24 +10,24 @@ $handle = fopen("ips.txt", "w"); $query = mysql_query("SELECT * FROM `ipv4_networks`"); while ($data = mysql_fetch_array($query)) { - $cidr = $data['ipv4_network']; - list ($network, $bits) = explode("/", $cidr); - if ($bits != '32' && $bits != '32' && $bits > '22') - { - $addr = Net_IPv4::parseAddress($cidr); - $broadcast = $addr->broadcast; - $ip = ip2long($network) + '1'; - $end = ip2long($broadcast); - while ($ip < $end) + $cidr = $data['ipv4_network']; + list ($network, $bits) = explode("/", $cidr); + if ($bits != '32' && $bits != '32' && $bits > '22') { - $ipdotted = long2ip($ip); - if (mysql_result(mysql_query("SELECT count(ipv4_address_id) FROM ipv4_addresses WHERE ipv4_address = '$ipdotted'"),0) == '0' && match_network($config['nets'], $ipdotted)) - { - fputs($handle, $ipdotted . "\n"); - } - $ip++; + $addr = Net_IPv4::parseAddress($cidr); + $broadcast = $addr->broadcast; + $ip = ip2long($network) + '1'; + $end = ip2long($broadcast); + while ($ip < $end) + { + $ipdotted = long2ip($ip); + if (mysql_result(mysql_query("SELECT count(ipv4_address_id) FROM ipv4_addresses WHERE ipv4_address = '$ipdotted'"),0) == '0' && match_network($config['nets'], $ipdotted)) + { + fputs($handle, $ipdotted . "\n"); + } + $ip++; + } } - } } fclose($handle); diff --git a/html/ajax_listports.php b/html/ajax_listports.php index 543384a063..7ddb1a084b 100755 --- a/html/ajax_listports.php +++ b/html/ajax_listports.php @@ -2,11 +2,11 @@ if ($_GET['debug']) { - ini_set('display_errors', 1); - ini_set('display_startup_errors', 0); - ini_set('log_errors', 0); - ini_set('allow_url_fopen', 0); - ini_set('error_reporting', E_ALL); + ini_set('display_errors', 1); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + ini_set('allow_url_fopen', 0); + ini_set('error_reporting', E_ALL); } include("../includes/defaults.inc.php"); @@ -20,11 +20,11 @@ if (!$_SESSION['authenticated']) { echo("unauthenticated"); exit; } if (is_numeric($_GET['device_id'])) { - $ports = mysql_query("SELECT * FROM ports WHERE device_id = '".$_GET['device_id']."'"); - while ($interface = mysql_fetch_array($ports)) - { - echo("obj.options[obj.options.length] = new Option('".$interface['ifDescr']." - ".$interface['ifAlias']."','".$interface['interface_id']."');\n"); - } + $ports = mysql_query("SELECT * FROM ports WHERE device_id = '".$_GET['device_id']."'"); + while ($interface = mysql_fetch_array($ports)) + { + echo("obj.options[obj.options.length] = new Option('".$interface['ifDescr']." - ".$interface['ifAlias']."','".$interface['interface_id']."');\n"); + } } -?> \ No newline at end of file +?> diff --git a/html/billing-graph.php b/html/billing-graph.php index d6cda027d8..f0d7ba2dd3 100644 --- a/html/billing-graph.php +++ b/html/billing-graph.php @@ -2,11 +2,11 @@ if ($_GET['debug']) { - ini_set('display_errors', 1); - ini_set('display_startup_errors', 0); - ini_set('log_errors', 0); - ini_set('allow_url_fopen', 0); - ini_set('error_reporting', E_ALL); + ini_set('display_errors', 1); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + ini_set('allow_url_fopen', 0); + ini_set('error_reporting', E_ALL); } else { ini_set('display_errors', 0); } include("../includes/defaults.inc.php"); @@ -21,16 +21,16 @@ include("includes/jpgraph/src/jpgraph_utils.inc.php"); if (is_numeric($_GET['bill_id'])) { - if (bill_permitted($_GET['bill_id'])) - { - $bill_id = $_GET['bill_id']; - } else { + if (bill_permitted($_GET['bill_id'])) + { + $bill_id = $_GET['bill_id']; + } else { + echo("Unauthorised Access Prohibited."); + exit; + } +} else { echo("Unauthorised Access Prohibited."); exit; - } -} else { - echo("Unauthorised Access Prohibited."); - exit; } $start = $_GET[from]; @@ -86,68 +86,68 @@ $data = mysql_query($sql); while ($row = mysql_fetch_array($data)) { - @$timestamp = $row['formatted_date']; - if (!$first) { $first = $timestamp; } - @$delta = $row['delta']; - @$period = $row['period']; - @$in_delta = $row['in_delta']; - @$out_delta = $row['out_delta']; - @$in_value = round($in_delta * 8 / $period / $div, 2); - @$out_value = round($out_delta * 8 / $period / $div, 2); + @$timestamp = $row['formatted_date']; + if (!$first) { $first = $timestamp; } + @$delta = $row['delta']; + @$period = $row['period']; + @$in_delta = $row['in_delta']; + @$out_delta = $row['out_delta']; + @$in_value = round($in_delta * 8 / $period / $div, 2); + @$out_value = round($out_delta * 8 / $period / $div, 2); - #@$data[] = $in_value + $out_value; - #@$in_data[] = $in_value; - #@$out_data[] = $out_value; -# @$ticks[] = $timestamp; - #@$per_data[] = $rate_95th / 1000; - #@$ave_data[] = $rate_average / 1000; + #@$data[] = $in_value + $out_value; + #@$in_data[] = $in_value; + #@$out_data[] = $out_value; + # @$ticks[] = $timestamp; + #@$per_data[] = $rate_95th / 1000; + #@$ave_data[] = $rate_average / 1000; - @$last = $timestamp; + @$last = $timestamp; - $iter_in = $iter_in + $in_delta; - $iter_out = $iter_out + $out_delta; - $iter_period = $iter_period + $period; + $iter_in = $iter_in + $in_delta; + $iter_out = $iter_out + $out_delta; + $iter_period = $iter_period + $period; - if ($iter == $count) - { - $out_data[$i] = round($iter_out * 8 / $iter_period / $div, 2); - $in_data[$i] = round($iter_in * 8 / $iter_period / $div, 2); - $tot_data[$i] = $out_data[$i] + $in_data[$i]; - $ticks[$i] = date('M j g:ia', $timestamp); - $ticks[$i] = $timestamp; - - if ($dur < 172800) + if ($iter == $count) { - $hour = date('h', $timestamp); - if ($hour != $lasthour) { $tickPositions[] = $i; $tickLabels[] = date('ga', $timestamp); } - $lasthour = $hour; - } elseif ($dur < 604800) { - $day = date('d', $timestamp); - if ($day != $lastday) { $tickPositions[] = $i; $tickLabels[] = date('D', $timestamp); $h = 0; } - $lastday = $day; + $out_data[$i] = round($iter_out * 8 / $iter_period / $div, 2); + $in_data[$i] = round($iter_in * 8 / $iter_period / $div, 2); + $tot_data[$i] = $out_data[$i] + $in_data[$i]; + $ticks[$i] = date('M j g:ia', $timestamp); + $ticks[$i] = $timestamp; - $hour = trim(date('g', $timestamp)); - if ($hour != $lasthour) - { - if ($hour == '12') { $tickMinPositions[] = $i; $h = 0; } $h++; - } + if ($dur < 172800) + { + $hour = date('h', $timestamp); + if ($hour != $lasthour) { $tickPositions[] = $i; $tickLabels[] = date('ga', $timestamp); } + $lasthour = $hour; + } elseif ($dur < 604800) { + $day = date('d', $timestamp); + if ($day != $lastday) { $tickPositions[] = $i; $tickLabels[] = date('D', $timestamp); $h = 0; } + $lastday = $day; - $lasthour = $hour; - } else { - $day = date('d', $timestamp); - if ($day != $lastday) { $tickPositions[] = $i; $tickLabels[] = date('dS', $timestamp); } - $lastday = $day; + $hour = trim(date('g', $timestamp)); + if ($hour != $lasthour) + { + if ($hour == '12') { $tickMinPositions[] = $i; $h = 0; } $h++; + } + + $lasthour = $hour; + } else { + $day = date('d', $timestamp); + if ($day != $lastday) { $tickPositions[] = $i; $tickLabels[] = date('dS', $timestamp); } + $lastday = $day; + } + + $per_data[$i] = $rate_95th / $div; + $ave_data[$i] = $rate_average / $div; + $timestamps[$i] = $timestamp; + $iter = "1"; + $i++; + unset($iter_out, $iter_in, $iter_period); } - $per_data[$i] = $rate_95th / $div; - $ave_data[$i] = $rate_average / $div; - $timestamps[$i] = $timestamp; - $iter = "1"; - $i++; - unset($iter_out, $iter_in, $iter_period); - } - - $iter++; + $iter++; } #print_r($ticks); @@ -175,9 +175,9 @@ $graph->xaxis->SetFont(FF_FONT1,FS_BOLD); if (count($tickPositions) > 24) { - $graph->xaxis->SetTextLabelInterval(6); + $graph->xaxis->SetTextLabelInterval(6); } elseif (count($tickPositions) > 12) { - $graph->xaxis->SetTextLabelInterval(2); + $graph->xaxis->SetTextLabelInterval(2); } $graph->xaxis->SetPos('min'); @@ -219,14 +219,14 @@ $lineplot_out->SetColor("blue"); if ($_GET['95th']) { - $lineplot_95th = new LinePlot($per_data); - $lineplot_95th ->SetColor("red"); + $lineplot_95th = new LinePlot($per_data); + $lineplot_95th ->SetColor("red"); } if ($_GET['ave']) { - $lineplot_ave = new LinePlot($ave_data); - $lineplot_ave ->SetColor("red"); + $lineplot_ave = new LinePlot($ave_data); + $lineplot_ave ->SetColor("red"); } #$graph->legend->SetLayout(LEGEND_HOR); @@ -238,14 +238,14 @@ $graph->Add($lineplot_out); if ($_GET['95th']) { - $graph->Add($lineplot_95th); + $graph->Add($lineplot_95th); } if ($_GET['ave']) { - $graph->Add($lineplot_ave); + $graph->Add($lineplot_ave); } $graph->stroke(); -?> \ No newline at end of file +?> diff --git a/html/collectd-graph.php b/html/collectd-graph.php index e74b5dd28b..6fb6436f45 100755 --- a/html/collectd-graph.php +++ b/html/collectd-graph.php @@ -17,11 +17,11 @@ */ if($_GET['debug']) { - ini_set('display_errors', 1); - ini_set('display_startup_errors', 0); - ini_set('log_errors', 0); - ini_set('allow_url_fopen', 0); - ini_set('error_reporting', E_ALL); + ini_set('display_errors', 1); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + ini_set('allow_url_fopen', 0); + ini_set('error_reporting', E_ALL); } include("../includes/defaults.inc.php"); @@ -36,21 +36,21 @@ include("includes/authenticate.inc.php"); if(!$_SESSION['authenticated']) { echo("not authenticated"); exit; } function makeTextBlock($text, $fontfile, $fontsize, $width) { - // TODO: handle explicit line-break! - $words = explode(' ', $text); - $lines = array($words[0]); - $currentLine = 0; - foreach ($words as $word) { - $lineSize = imagettfbbox($fontsize, 0, $fontfile, $lines[$currentLine] . ' ' . $word); - if($lineSize[2] - $lineSize[0] < $width) { - $lines[$currentLine] .= ' ' . $word; - } else { - $currentLine++; - $lines[$currentLine] = $word; - } - } - error_log(sprintf('Handles message "%s", %d words => %d/%d lines', $text, count($words), $currentLine, count($lines))); - return implode("\n", $lines); + // TODO: handle explicit line-break! + $words = explode(' ', $text); + $lines = array($words[0]); + $currentLine = 0; + foreach ($words as $word) { + $lineSize = imagettfbbox($fontsize, 0, $fontfile, $lines[$currentLine] . ' ' . $word); + if($lineSize[2] - $lineSize[0] < $width) { + $lines[$currentLine] .= ' ' . $word; + } else { + $currentLine++; + $lines[$currentLine] = $word; + } + } + error_log(sprintf('Handles message "%s", %d words => %d/%d lines', $text, count($words), $currentLine, count($lines))); + return implode("\n", $lines); } /** @@ -61,65 +61,65 @@ function makeTextBlock($text, $fontfile, $fontsize, $width) { * @msg Complete error message to display in place of graph content */ function error($code, $code_msg, $title, $msg) { - global $config; - header(sprintf("HTTP/1.0 %d %s", $code, $code_msg)); - header("Pragma: no-cache"); - header("Expires: Mon, 01 Jan 2008 00:00:00 CET"); - header("Content-Type: image/png"); - $w = $config['rrd_width']+81; - $h = $config['rrd_height']+79; + global $config; + header(sprintf("HTTP/1.0 %d %s", $code, $code_msg)); + header("Pragma: no-cache"); + header("Expires: Mon, 01 Jan 2008 00:00:00 CET"); + header("Content-Type: image/png"); + $w = $config['rrd_width']+81; + $h = $config['rrd_height']+79; - $png = imagecreate($w, $h); - $c_bkgnd = imagecolorallocate($png, 240, 240, 240); - $c_fgnd = imagecolorallocate($png, 255, 255, 255); - $c_blt = imagecolorallocate($png, 208, 208, 208); - $c_brb = imagecolorallocate($png, 160, 160, 160); - $c_grln = imagecolorallocate($png, 114, 114, 114); - $c_grarr = imagecolorallocate($png, 128, 32, 32); - $c_txt = imagecolorallocate($png, 0, 0, 0); - $c_etxt = imagecolorallocate($png, 64, 0, 0); + $png = imagecreate($w, $h); + $c_bkgnd = imagecolorallocate($png, 240, 240, 240); + $c_fgnd = imagecolorallocate($png, 255, 255, 255); + $c_blt = imagecolorallocate($png, 208, 208, 208); + $c_brb = imagecolorallocate($png, 160, 160, 160); + $c_grln = imagecolorallocate($png, 114, 114, 114); + $c_grarr = imagecolorallocate($png, 128, 32, 32); + $c_txt = imagecolorallocate($png, 0, 0, 0); + $c_etxt = imagecolorallocate($png, 64, 0, 0); - if (function_exists('imageantialias')) - imageantialias($png, true); - imagefilledrectangle($png, 0, 0, $w, $h, $c_bkgnd); - imagefilledrectangle($png, 51, 33, $w-31, $h-47, $c_fgnd); - imageline($png, 51, 30, 51, $h-43, $c_grln); - imageline($png, 48, $h-46, $w-28, $h-46, $c_grln); - imagefilledpolygon($png, array(49, 30, 51, 26, 53, 30), 3, $c_grarr); - imagefilledpolygon($png, array($w-28, $h-48, $w-24, $h-46, $w-28, $h-44), 3, $c_grarr); - imageline($png, 0, 0, $w, 0, $c_blt); - imageline($png, 0, 1, $w, 1, $c_blt); - imageline($png, 0, 0, 0, $h, $c_blt); - imageline($png, 1, 0, 1, $h, $c_blt); - imageline($png, $w-1, 0, $w-1, $h, $c_brb); - imageline($png, $w-2, 1, $w-2, $h, $c_brb); - imageline($png, 1, $h-2, $w, $h-2, $c_brb); - imageline($png, 0, $h-1, $w, $h-1, $c_brb); + if (function_exists('imageantialias')) + imageantialias($png, true); + imagefilledrectangle($png, 0, 0, $w, $h, $c_bkgnd); + imagefilledrectangle($png, 51, 33, $w-31, $h-47, $c_fgnd); + imageline($png, 51, 30, 51, $h-43, $c_grln); + imageline($png, 48, $h-46, $w-28, $h-46, $c_grln); + imagefilledpolygon($png, array(49, 30, 51, 26, 53, 30), 3, $c_grarr); + imagefilledpolygon($png, array($w-28, $h-48, $w-24, $h-46, $w-28, $h-44), 3, $c_grarr); + imageline($png, 0, 0, $w, 0, $c_blt); + imageline($png, 0, 1, $w, 1, $c_blt); + imageline($png, 0, 0, 0, $h, $c_blt); + imageline($png, 1, 0, 1, $h, $c_blt); + imageline($png, $w-1, 0, $w-1, $h, $c_brb); + imageline($png, $w-2, 1, $w-2, $h, $c_brb); + imageline($png, 1, $h-2, $w, $h-2, $c_brb); + imageline($png, 0, $h-1, $w, $h-1, $c_brb); - imagestring($png, 4, ceil(($w-strlen($title)*imagefontwidth(4)) / 2), 10, $title, $c_txt); - imagestring($png, 5, 60, 35, sprintf('%s [%d]', $code_msg, $code), $c_etxt); - if (function_exists('imagettfbbox') && is_file($config['error_font'])) { - // Detailled error message - $fmt_msg = makeTextBlock($msg, $errorfont, 10, $w-86); - $fmtbox = imagettfbbox(12, 0, $errorfont, $fmt_msg); - imagettftext($png, 10, 0, 55, 35+3+imagefontwidth(5)-$fmtbox[7]+$fmtbox[1], $c_txt, $errorfont, $fmt_msg); - } else { - imagestring($png, 4, 53, 35+6+imagefontwidth(5), $msg, $c_txt); - } + imagestring($png, 4, ceil(($w-strlen($title)*imagefontwidth(4)) / 2), 10, $title, $c_txt); + imagestring($png, 5, 60, 35, sprintf('%s [%d]', $code_msg, $code), $c_etxt); + if (function_exists('imagettfbbox') && is_file($config['error_font'])) { + // Detailled error message + $fmt_msg = makeTextBlock($msg, $errorfont, 10, $w-86); + $fmtbox = imagettfbbox(12, 0, $errorfont, $fmt_msg); + imagettftext($png, 10, 0, 55, 35+3+imagefontwidth(5)-$fmtbox[7]+$fmtbox[1], $c_txt, $errorfont, $fmt_msg); + } else { + imagestring($png, 4, 53, 35+6+imagefontwidth(5), $msg, $c_txt); + } - imagepng($png); - imagedestroy($png); + imagepng($png); + imagedestroy($png); } /** * No RRD files found that could match request */ function error404($title, $msg) { - return error(404, "Not found", $title, $msg); + return error(404, "Not found", $title, $msg); } function error500($title, $msg) { - return error(500, "Not found", $title, $msg); + return error(500, "Not found", $title, $msg); } @@ -127,37 +127,37 @@ function error500($title, $msg) { * Incomplete / invalid request */ function error400($title, $msg) { - return error(400, "Bad request", $title, $msg); + return error(400, "Bad request", $title, $msg); } // Process input arguments $host = read_var('host', $_GET, null); if (is_null($host)) - return error400("?/?-?/?", "Missing host name"); + return error400("?/?-?/?", "Missing host name"); else if (!is_string($host)) - return error400("?/?-?/?", "Expecting exactly 1 host name"); + return error400("?/?-?/?", "Expecting exactly 1 host name"); else if (strlen($host) == 0) - return error400("?/?-?/?", "Host name may not be blank"); + return error400("?/?-?/?", "Host name may not be blank"); $plugin = read_var('plugin', $_GET, null); if (is_null($plugin)) - return error400($host.'/?-?/?', "Missing plugin name"); + return error400($host.'/?-?/?', "Missing plugin name"); else if (!is_string($plugin)) - return error400($host.'/?-?/?', "Plugin name must be a string"); + return error400($host.'/?-?/?', "Plugin name must be a string"); else if (strlen($plugin) == 0) - return error400($host.'/?-?/?', "Plugin name may not be blank"); + return error400($host.'/?-?/?', "Plugin name may not be blank"); $pinst = read_var('plugin_instance', $_GET, ''); if (!is_string($pinst)) - return error400($host.'/'.$plugin.'-?/?', "Plugin instance name must be a string"); + return error400($host.'/'.$plugin.'-?/?', "Plugin instance name must be a string"); $type = read_var('type', $_GET, ''); if (is_null($type)) - return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Missing type name"); + return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Missing type name"); else if (!is_string($type)) - return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Type name must be a string"); + return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Type name must be a string"); else if (strlen($type) == 0) - return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Type name may not be blank"); + return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Type name may not be blank"); $tinst = read_var('type_instance', $_GET, ''); @@ -166,10 +166,10 @@ $graph_identifier = $host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/'.$ty $timespan = read_var('timespan', $_GET, $config['timespan'][0]['name']); $timespan_ok = false; foreach ($config['timespan'] as &$ts) - if ($ts['name'] == $timespan) - $timespan_ok = true; + if ($ts['name'] == $timespan) + $timespan_ok = true; if (!$timespan_ok) - return error400($graph_identifier, "Unknown timespan requested"); + return error400($graph_identifier, "Unknown timespan requested"); $logscale = (boolean)read_var('logarithmic', $_GET, false); $tinylegend = (boolean)read_var('tinylegend', $_GET, false); @@ -177,7 +177,7 @@ $tinylegend = (boolean)read_var('tinylegend', $_GET, false); // Check that at least 1 RRD exists for the specified request $all_tinst = collectd_list_tinsts($host, $plugin, $pinst, $type); if (count($all_tinst) == 0) - return error404($graph_identifier, "No rrd file found for graphing"); + return error404($graph_identifier, "No rrd file found for graphing"); // Now that we are read, do the bulk work load_graph_definitions($logscale, $tinylegend); @@ -188,49 +188,49 @@ $tinst = strlen($tinst) == 0 ? null : $tinst; $opts = array(); $opts['timespan'] = $timespan; if ($logscale) - $opts['logarithmic'] = 1; + $opts['logarithmic'] = 1; if ($tinylegend) - $opts['tinylegend'] = 1; + $opts['tinylegend'] = 1; $rrd_cmd = false; if (isset($MetaGraphDefs[$type])) { - $identifiers = array(); - foreach ($all_tinst as &$atinst) - $identifiers[] = collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, $atinst); - collectd_flush($identifiers); - $rrd_cmd = $MetaGraphDefs[$type]($host, $plugin, $pinst, $type, $all_tinst, $opts); + $identifiers = array(); + foreach ($all_tinst as &$atinst) + $identifiers[] = collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, $atinst); + collectd_flush($identifiers); + $rrd_cmd = $MetaGraphDefs[$type]($host, $plugin, $pinst, $type, $all_tinst, $opts); } else { - if (!in_array(is_null($tinst) ? '' : $tinst, $all_tinst)) - return error404($host.'/'.$plugin.(!is_null($pinst) ? '-'.$pinst : '').'/'.$type.(!is_null($tinst) ? '-'.$tinst : ''), "No rrd file found for graphing"); - collectd_flush(collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, is_null($tinst) ? '' : $tinst)); - if (isset($GraphDefs[$type])) - $rrd_cmd = collectd_draw_generic($timespan, $host, $plugin, $pinst, $type, $tinst); - else - $rrd_cmd = collectd_draw_rrd($host, $plugin, $pinst, $type, $tinst); + if (!in_array(is_null($tinst) ? '' : $tinst, $all_tinst)) + return error404($host.'/'.$plugin.(!is_null($pinst) ? '-'.$pinst : '').'/'.$type.(!is_null($tinst) ? '-'.$tinst : ''), "No rrd file found for graphing"); + collectd_flush(collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, is_null($tinst) ? '' : $tinst)); + if (isset($GraphDefs[$type])) + $rrd_cmd = collectd_draw_generic($timespan, $host, $plugin, $pinst, $type, $tinst); + else + $rrd_cmd = collectd_draw_rrd($host, $plugin, $pinst, $type, $tinst); } if(isset($rrd_cmd)) { - if($config['rrdcached']) { $rrd_cmd .= " --daemon ".$config['rrdcached'] . " "; } - if($_GET['from']) { $from = mres($_GET['from']); } - if($_GET['to']) { $to = mres($_GET['to']); } - $rrd_cmd .= " -s " . $from . " -e " . $to; + if($config['rrdcached']) { $rrd_cmd .= " --daemon ".$config['rrdcached'] . " "; } + if($_GET['from']) { $from = mres($_GET['from']); } + if($_GET['to']) { $to = mres($_GET['to']); } + $rrd_cmd .= " -s " . $from . " -e " . $to; } if (isset($_GET['debug'])) { - header('Content-Type: text/plain; charset=utf-8'); - printf("Would have executed:\n%s\n", $rrd_cmd); - return 0; + header('Content-Type: text/plain; charset=utf-8'); + printf("Would have executed:\n%s\n", $rrd_cmd); + return 0; } else if ($rrd_cmd) { - header('Content-Type: image/png'); - header('Cache-Control: max-age=60'); - $rt = 0; - passthru($rrd_cmd, $rt); - if ($rt != 0) - return error500($graph_identifier, "RRD failed to generate the graph: ".$rt); - return $rt; + header('Content-Type: image/png'); + header('Cache-Control: max-age=60'); + $rt = 0; + passthru($rrd_cmd, $rt); + if ($rt != 0) + return error500($graph_identifier, "RRD failed to generate the graph: ".$rt); + return $rt; } else { - return error500($graph_identifier, "Failed to tell RRD how to generate the graph"); + return error500($graph_identifier, "Failed to tell RRD how to generate the graph"); } ?> diff --git a/html/graph.php b/html/graph.php index 97e91d86ff..4f39e82e89 100644 --- a/html/graph.php +++ b/html/graph.php @@ -2,4 +2,4 @@ include("includes/graphs/graph.inc.php"); -?> \ No newline at end of file +?> diff --git a/html/index.php b/html/index.php index 364b4b1121..96ffde317f 100755 --- a/html/index.php +++ b/html/index.php @@ -6,17 +6,17 @@ ini_set('display_errors', 0); if (strpos($_SERVER['REQUEST_URI'], "debug")) { - $debug = "1"; - ini_set('display_errors', 1); - ini_set('display_startup_errors', 1); - ini_set('log_errors', 1); - ini_set('error_reporting', E_ALL); + $debug = "1"; + ini_set('display_errors', 1); + ini_set('display_startup_errors', 1); + ini_set('log_errors', 1); + ini_set('error_reporting', E_ALL); } else { - $debug = FALSE; - ini_set('display_errors', 0); - ini_set('display_startup_errors', 0); - ini_set('log_errors', 0); - ini_set('error_reporting', 0); + $debug = FALSE; + ini_set('display_errors', 0); + ini_set('display_startup_errors', 0); + ini_set('log_errors', 0); + ini_set('error_reporting', 0); } include("../includes/defaults.inc.php"); @@ -35,18 +35,18 @@ $year = time() - (365 * 24 * 60 * 60); # Load the settings for Multi-Tenancy. if (is_array($config['branding'])) { - if ($config['branding'][$_SERVER['SERVER_NAME']]) - { - foreach ($config['branding'][$_SERVER['SERVER_NAME']] as $confitem => $confval) + if ($config['branding'][$_SERVER['SERVER_NAME']]) { - eval("\$config['" . $confitem . "'] = \$confval;"); + foreach ($config['branding'][$_SERVER['SERVER_NAME']] as $confitem => $confval) + { + eval("\$config['" . $confitem . "'] = \$confval;"); + } + } else { + foreach ($config['branding']['default'] as $confitem => $confval) + { + eval("\$config['" . $confitem . "'] = \$confval;"); + } } - } else { - foreach ($config['branding']['default'] as $confitem => $confval) - { - eval("\$config['" . $confitem . "'] = \$confval;"); - } - } } ?> @@ -67,16 +67,16 @@ if ($config['page_refresh']) { echo(" - +
@@ -93,23 +93,23 @@ function popUp(URL)
@@ -125,9 +125,9 @@ echo('
Powered by Observ if (file_exists('.svn/entries')) { - $svn = File('.svn/entries'); - echo('-SVN r' . trim($svn[3])); - unset($svn); + $svn = File('.svn/entries'); + echo('-SVN r' . trim($svn[3])); + unset($svn); } echo('. Copyright © 2006-'. date("Y"). ' by Adam Armstrong. All rights reserved.'); diff --git a/html/map.php b/html/map.php index b08abdd92d..73cdd2eb20 100755 --- a/html/map.php +++ b/html/map.php @@ -12,18 +12,18 @@ include("includes/authenticate.inc.php"); if (is_array($config['branding'])) { - if ($config['branding'][$_SERVER['SERVER_NAME']]) - { - foreach ($config['branding'][$_SERVER['SERVER_NAME']] as $confitem => $confval) + if ($config['branding'][$_SERVER['SERVER_NAME']]) { - eval("\$config['" . $confitem . "'] = \$confval;"); + foreach ($config['branding'][$_SERVER['SERVER_NAME']] as $confitem => $confval) + { + eval("\$config['" . $confitem . "'] = \$confval;"); + } + } else { + foreach ($config['branding']['default'] as $confitem => $confval) + { + eval("\$config['" . $confitem . "'] = \$confval;"); + } } - } else { - foreach ($config['branding']['default'] as $confitem => $confval) - { - eval("\$config['" . $confitem . "'] = \$confval;"); - } - } } if (isset($_GET['device'])) { $where = "WHERE device_id = ".$_GET['device']; } else { $where = ""; } @@ -31,148 +31,148 @@ $deviceresult = mysql_query("SELECT * from devices $where"); if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format'])) { - $map = "digraph G { sep=0.01; size=\"12,5.5\"; pack=100; bgcolor=transparent; splines=true; overlap=scale; concentrate=0; epsilon=0.001; rankdir=0; - node [ fontname=\"helvetica\", fontstyle=bold, style=filled, color=white, fillcolor=lightgrey, overlap=false;]; - edge [ bgcolor=white; fontname=\"helvetica\"; fontstyle=bold; arrowhead=dot; arrowtail=dot]; - graph [bgcolor=transparent;];\n\n"; + $map = "digraph G { sep=0.01; size=\"12,5.5\"; pack=100; bgcolor=transparent; splines=true; overlap=scale; concentrate=0; epsilon=0.001; rankdir=0; + node [ fontname=\"helvetica\", fontstyle=bold, style=filled, color=white, fillcolor=lightgrey, overlap=false;]; + edge [ bgcolor=white; fontname=\"helvetica\"; fontstyle=bold; arrowhead=dot; arrowtail=dot]; + graph [bgcolor=transparent;];\n\n"; - if (!$_SESSION['authenticated']) - { - $map .= "\"Not authenticated\" [fontsize=20 fillcolor=\"lightblue\" URL=\"/\" shape=box3d]\n"; - } - else - { - while ($device = mysql_fetch_array($deviceresult)) + if (!$_SESSION['authenticated']) { - if ($device) - { - $sql = "SELECT * from ports AS I, links AS L WHERE I.device_id = ".$device['device_id']." AND L.local_interface_id = I.interface_id ORDER BY L.remote_hostname"; - $links = mysql_query($sql); - - if (mysql_num_rows($links)) - { - $map .= "\"".$device['hostname']."\" [fontsize=20 fillcolor=\"lightblue\" URL=\"{$config['base_url']}/device/".$device['device_id']."/map/\" shape=box3d]\n"; - } - - while ($link = mysql_fetch_array($links)) - { - $local_interface_id = $link['local_interface_id']; - $remote_interface_id = $link['remote_interface_id']; - - $i = 0; $done = 0; - while (isset($linkdone) && $i < count($linkdone)) - { - if ($linkdone[$i] == "$remote_interface_id $local_interface_id") { $done = 1; } - $i++; - } - - if (!$done) - { - $linkdone[] = "$local_interface_id $remote_interface_id"; - - $links++; - - if ($link['ifSpeed'] >= "10000000000") - { - $info = "color=red3 style=\"setlinewidth(6)\""; - } elseif ($link['ifSpeed'] >= "1000000000") { - $info = "color=lightblue style=\"setlinewidth(4)\""; - } elseif ($link['ifSpeed'] >= "100000000") { - $info = "color=lightgrey style=\"setlinewidth(2)\""; - } elseif ($link['ifSpeed'] >= "10000000") { - $info = "style=\"setlinewidth(1)\""; - } else { - $info = "style=\"setlinewidth(1)\""; - } - - $src = $device['hostname']; - if ($remote_interface_id) - { - $dst = mysql_result(mysql_query("SELECT `hostname` FROM `devices` AS D, `ports` AS I WHERE I.interface_id = '$remote_interface_id' AND D.device_id = I.device_id"),0); - $dst_host = mysql_result(mysql_query("SELECT D.device_id FROM `devices` AS D, `ports` AS I WHERE I.interface_id = '$remote_interface_id' AND D.device_id = I.device_id"),0); - } else { - $dst_host = $link['remote_hostname']; - $dst = $link['remote_hostname']; - } - - $sif = ifNameDescr(mysql_fetch_array(mysql_query("SELECT * FROM ports WHERE `interface_id`=" . $link['local_interface_id'])),$device); - if ($remote_interface_id) - { - $dif = ifNameDescr(mysql_fetch_array(mysql_query("SELECT * FROM ports WHERE `interface_id`=" . $link['remote_interface_id']))); - } else { - $dif['label'] = $link['remote_port']; - $dif['interface_id'] = $link['remote_hostname'] . $link['remote_port']; - } - - $map .= "\"" . $sif['interface_id'] . "\" [label=\"" . $sif['label'] . "\", fontsize=12, fillcolor=lightblue URL=\"{$config['base_url']}/device/".$device['device_id']."/interface/$local_interface_id/\"]\n"; - if (!$ifdone[$src][$sif['interface_id']]) - { - $map .= "\"$src\" -> \"" . $sif['interface_id'] . "\" [weight=500000, arrowsize=0, len=0];\n"; - $ifdone[$src][$sif['interface_id']] = 1; - } - - $map .= "\"$dst\" [URL=\"{$config['base_url']}/device/$dst_host/map/\" fontsize=20 shape=box3d]\n"; - - if ($dst_host == $device['device_id'] || $where == '') { - $map .= "\"" . $dif['interface_id'] . "\" [label=\"" . $dif['label'] . "\", fontsize=12, fillcolor=lightblue, URL=\"{$config['base_url']}/device/$dst_host/interface/$remote_interface_id/\"]\n"; - } else { - $map .= "\"" . $dif['interface_id'] . "\" [label=\"" . $dif['label'] . " \", fontsize=12, fillcolor=lightgray, URL=\"{$config['base_url']}/device/$dst_host/interface/$remote_interface_id/\"]\n"; - } - - if (!$ifdone[$dst][$dif['interface_id']]) - { - $map .= "\"" . $dif['interface_id'] . "\" -> \"$dst\" [weight=500000, arrowsize=0, len=0];\n"; - $ifdone[$dst][$dif['interface_id']] = 1; - } - $map .= "\"" . $sif['interface_id'] . "\" -> \"" . $dif['interface_id'] . "\" [weight=1, arrowhead=normal, arrowtail=normal, len=2, $info] \n"; - } - } - $done = 0; - } + $map .= "\"Not authenticated\" [fontsize=20 fillcolor=\"lightblue\" URL=\"/\" shape=box3d]\n"; } - } + else + { + while ($device = mysql_fetch_array($deviceresult)) + { + if ($device) + { + $sql = "SELECT * from ports AS I, links AS L WHERE I.device_id = ".$device['device_id']." AND L.local_interface_id = I.interface_id ORDER BY L.remote_hostname"; + $links = mysql_query($sql); - $map .= " + if (mysql_num_rows($links)) + { + $map .= "\"".$device['hostname']."\" [fontsize=20 fillcolor=\"lightblue\" URL=\"{$config['base_url']}/device/".$device['device_id']."/map/\" shape=box3d]\n"; + } + + while ($link = mysql_fetch_array($links)) + { + $local_interface_id = $link['local_interface_id']; + $remote_interface_id = $link['remote_interface_id']; + + $i = 0; $done = 0; + while (isset($linkdone) && $i < count($linkdone)) + { + if ($linkdone[$i] == "$remote_interface_id $local_interface_id") { $done = 1; } + $i++; + } + + if (!$done) + { + $linkdone[] = "$local_interface_id $remote_interface_id"; + + $links++; + + if ($link['ifSpeed'] >= "10000000000") + { + $info = "color=red3 style=\"setlinewidth(6)\""; + } elseif ($link['ifSpeed'] >= "1000000000") { + $info = "color=lightblue style=\"setlinewidth(4)\""; + } elseif ($link['ifSpeed'] >= "100000000") { + $info = "color=lightgrey style=\"setlinewidth(2)\""; + } elseif ($link['ifSpeed'] >= "10000000") { + $info = "style=\"setlinewidth(1)\""; + } else { + $info = "style=\"setlinewidth(1)\""; + } + + $src = $device['hostname']; + if ($remote_interface_id) + { + $dst = mysql_result(mysql_query("SELECT `hostname` FROM `devices` AS D, `ports` AS I WHERE I.interface_id = '$remote_interface_id' AND D.device_id = I.device_id"),0); + $dst_host = mysql_result(mysql_query("SELECT D.device_id FROM `devices` AS D, `ports` AS I WHERE I.interface_id = '$remote_interface_id' AND D.device_id = I.device_id"),0); + } else { + $dst_host = $link['remote_hostname']; + $dst = $link['remote_hostname']; + } + + $sif = ifNameDescr(mysql_fetch_array(mysql_query("SELECT * FROM ports WHERE `interface_id`=" . $link['local_interface_id'])),$device); + if ($remote_interface_id) + { + $dif = ifNameDescr(mysql_fetch_array(mysql_query("SELECT * FROM ports WHERE `interface_id`=" . $link['remote_interface_id']))); + } else { + $dif['label'] = $link['remote_port']; + $dif['interface_id'] = $link['remote_hostname'] . $link['remote_port']; + } + + $map .= "\"" . $sif['interface_id'] . "\" [label=\"" . $sif['label'] . "\", fontsize=12, fillcolor=lightblue URL=\"{$config['base_url']}/device/".$device['device_id']."/interface/$local_interface_id/\"]\n"; + if (!$ifdone[$src][$sif['interface_id']]) + { + $map .= "\"$src\" -> \"" . $sif['interface_id'] . "\" [weight=500000, arrowsize=0, len=0];\n"; + $ifdone[$src][$sif['interface_id']] = 1; + } + + $map .= "\"$dst\" [URL=\"{$config['base_url']}/device/$dst_host/map/\" fontsize=20 shape=box3d]\n"; + + if ($dst_host == $device['device_id'] || $where == '') { + $map .= "\"" . $dif['interface_id'] . "\" [label=\"" . $dif['label'] . "\", fontsize=12, fillcolor=lightblue, URL=\"{$config['base_url']}/device/$dst_host/interface/$remote_interface_id/\"]\n"; + } else { + $map .= "\"" . $dif['interface_id'] . "\" [label=\"" . $dif['label'] . " \", fontsize=12, fillcolor=lightgray, URL=\"{$config['base_url']}/device/$dst_host/interface/$remote_interface_id/\"]\n"; + } + + if (!$ifdone[$dst][$dif['interface_id']]) + { + $map .= "\"" . $dif['interface_id'] . "\" -> \"$dst\" [weight=500000, arrowsize=0, len=0];\n"; + $ifdone[$dst][$dif['interface_id']] = 1; + } + $map .= "\"" . $sif['interface_id'] . "\" -> \"" . $dif['interface_id'] . "\" [weight=1, arrowhead=normal, arrowtail=normal, len=2, $info] \n"; + } + } + $done = 0; + } + } + } + + $map .= " };"; - if ($_GET['debug'] == 1) { echo("
$map
");exit(); } +if ($_GET['debug'] == 1) { echo("
$map
");exit(); } - switch ($_GET['format']) - { - case 'svg': +switch ($_GET['format']) +{ +case 'svg': case 'png': - break; + break; default: - $_GET['format'] = 'png'; - } + $_GET['format'] = 'png'; +} - if ($links > 10) ### Unflatten if there are more than 10 links. beyond that it gets messy - { +if ($links > 10) ### Unflatten if there are more than 10 links. beyond that it gets messy +{ $maptool = 'unflatten -f -l 5 |dot'; - } else { +} else { $maptool = 'dot'; - } +} - if ($where == '') { $maptool = 'neato -Gpack'; } +if ($where == '') { $maptool = 'neato -Gpack'; } - $img = shell_exec("echo \"".addslashes($map)."\" | $maptool -T".$_GET['format'].""); - if ($_GET['format'] == "png") { +$img = shell_exec("echo \"".addslashes($map)."\" | $maptool -T".$_GET['format'].""); +if ($_GET['format'] == "png") { header("Content-type: image/".$_GET['format']); - } elseif ($_GET['format'] == "svg") { +} elseif ($_GET['format'] == "svg") { header("Content-type: image/svg+xml"); $img = str_replace(" - - -'); - } + if ($_SESSION['authenticated']) ## FIXME level 10 only? + { + echo('
+ + +
'); + } } -?> \ No newline at end of file +?> diff --git a/html/netcmd.php b/html/netcmd.php index 08cd23a785..cee871c48a 100644 --- a/html/netcmd.php +++ b/html/netcmd.php @@ -5,10 +5,10 @@ ini_set('display_errors', 0); if ($_GET[debug]) { - ini_set('display_errors', 1); - ini_set('display_startup_errors', 1); - ini_set('log_errors', 1); - ini_set('error_reporting', E_ALL); + ini_set('display_errors', 1); + ini_set('display_startup_errors', 1); + ini_set('log_errors', 1); + ini_set('error_reporting', E_ALL); } include("../includes/defaults.inc.php"); @@ -20,36 +20,36 @@ include("includes/authenticate.inc.php"); if (!$_SESSION['authenticated']) { echo("unauthenticated"); exit; } if ($_GET['query'] && $_GET['cmd']) { - $host = $_GET['query']; - if (Net_IPv6::checkIPv6($host)||Net_IPv4::validateip($host)||preg_match("/^[a-zA-Z0-9.-]*$/", $host)) { - switch ($_GET['cmd']) { - case 'whois': - $cmd = $config['whois'] . " $host | grep -v \%"; - break; - case 'ping': - $cmd = $config['ping'] . " -c 5 $host"; - break; - case 'tracert': - $cmd = $config['mtr'] . " -r -c 5 $host"; - break; - case 'nmap': - if ($_SESSION['userlevel'] != '10') - { - echo("insufficient privileges"); - } else { - $cmd = $config['nmap'] . " $host"; + $host = $_GET['query']; + if (Net_IPv6::checkIPv6($host)||Net_IPv4::validateip($host)||preg_match("/^[a-zA-Z0-9.-]*$/", $host)) { + switch ($_GET['cmd']) { + case 'whois': + $cmd = $config['whois'] . " $host | grep -v \%"; + break; + case 'ping': + $cmd = $config['ping'] . " -c 5 $host"; + break; + case 'tracert': + $cmd = $config['mtr'] . " -r -c 5 $host"; + break; + case 'nmap': + if ($_SESSION['userlevel'] != '10') + { + echo("insufficient privileges"); + } else { + $cmd = $config['nmap'] . " $host"; + } + break; } - break; - } - if (!empty($cmd)) - { - $output = `$cmd`; + if (!empty($cmd)) + { + $output = `$cmd`; + } } - } } $output = trim($output); echo("
$output
"); -?> \ No newline at end of file +?> diff --git a/html/php.php b/html/php.php index 99c69bc18f..554a22c8bb 100644 --- a/html/php.php +++ b/html/php.php @@ -1,5 +1,5 @@ diff --git a/includes/billing.php b/includes/billing.php index 8dcf6f0388..d10160f579 100644 --- a/includes/billing.php +++ b/includes/billing.php @@ -2,190 +2,190 @@ function getDates($dayofmonth) { - $dayofmonth = zeropad($dayofmonth); - list($year, $month) = split('-', date('Y-m')); + $dayofmonth = zeropad($dayofmonth); + list($year, $month) = split('-', date('Y-m')); - if (date('d') > $dayofmonth) - { - $newmonth = $month + 1; - if ($newmonth == 13) + if (date('d') > $dayofmonth) { - $newmonth = 1; - $newyear = year + 1; - } else { - $newyear = $year; + $newmonth = $month + 1; + if ($newmonth == 13) + { + $newmonth = 1; + $newyear = year + 1; + } else { + $newyear = $year; + } + + $date_from = $year . $month . $dayofmonth; + $date_to = $newyear . $newmonth . $dayofmonth; + $dt_q = mysql_query("SELECT DATE_SUB(DATE_ADD('$date_from', INTERVAL 1 MONTH), INTERVAL 1 DAY);"); + $date_to = mysql_result($dt_q,0); + $date_to = str_replace("-","",$date_to); + } + else + { + $newmonth = $month - 1; + if ($newmonth == 0) + { + $newmonth = 12; + $newyear = $year - 1; + } else { + $newyear = $year; + } + + $date_from = $newyear . $newmonth . $dayofmonth; + $date_to = $year . $month . $dayofmonth; + $dt_q = mysql_query("SELECT DATE_SUB(DATE_ADD('$date_to', INTERVAL 1 MONTH, INTERVAL 1 DAY);"); + $date_from = mysql_result($dt_q,0); + $date_from = str_replace("-","",$date_from); } - $date_from = $year . $month . $dayofmonth; - $date_to = $newyear . $newmonth . $dayofmonth; - $dt_q = mysql_query("SELECT DATE_SUB(DATE_ADD('$date_from', INTERVAL 1 MONTH), INTERVAL 1 DAY);"); - $date_to = mysql_result($dt_q,0); - $date_to = str_replace("-","",$date_to); - } - else - { - $newmonth = $month - 1; - if ($newmonth == 0) - { - $newmonth = 12; - $newyear = $year - 1; - } else { - $newyear = $year; - } + $lq_from = mysql_query("SELECT DATE_SUB('$date_from', INTERVAL 1 MONTH);"); + $last_from = mysql_result($lq_from,0); + $last_from = str_replace("-","",$last_from); - $date_from = $newyear . $newmonth . $dayofmonth; - $date_to = $year . $month . $dayofmonth; - $dt_q = mysql_query("SELECT DATE_SUB(DATE_ADD('$date_to', INTERVAL 1 MONTH, INTERVAL 1 DAY);"); - $date_from = mysql_result($dt_q,0); - $date_from = str_replace("-","",$date_from); - } + $lq_to = mysql_query("SELECT DATE_SUB('$date_to', INTERVAL 1 MONTH);"); + $last_to = mysql_result($lq_to,0); + $last_to = str_replace("-","",$last_to); - $lq_from = mysql_query("SELECT DATE_SUB('$date_from', INTERVAL 1 MONTH);"); - $last_from = mysql_result($lq_from,0); - $last_from = str_replace("-","",$last_from); + $return['0'] = $date_from . "000000"; + $return['1'] = $date_to . "235959"; + $return['2'] = $last_from . "000000"; + $return['3'] = $last_to . "235959"; - $lq_to = mysql_query("SELECT DATE_SUB('$date_to', INTERVAL 1 MONTH);"); - $last_to = mysql_result($lq_to,0); - $last_to = str_replace("-","",$last_to); - - $return['0'] = $date_from . "000000"; - $return['1'] = $date_to . "235959"; - $return['2'] = $last_from . "000000"; - $return['3'] = $last_to . "235959"; - - return($return); + return($return); } function getValue($host, $port, $id, $inout) { - global $config; + global $config; - $oid = "IF-MIB::ifHC" . $inout . "Octets." . $id; - $device = mysql_fetch_assoc(mysql_query("SELECT * from `devices` WHERE `hostname` = '" . $host . "' LIMIT 1")); - $value = snmp_get($device, $oid, "-O qv"); + $oid = "IF-MIB::ifHC" . $inout . "Octets." . $id; + $device = mysql_fetch_assoc(mysql_query("SELECT * from `devices` WHERE `hostname` = '" . $host . "' LIMIT 1")); + $value = snmp_get($device, $oid, "-O qv"); - if (!is_numeric($value)) - { - $oid = "IF-MIB::if" . $inout . "Octets." . $id; - $value = snmp_get($device, $oid, "-Oqv"); - } + if (!is_numeric($value)) + { + $oid = "IF-MIB::if" . $inout . "Octets." . $id; + $value = snmp_get($device, $oid, "-Oqv"); + } - return $value; + return $value; } function getLastPortCounter($port_id,$inout) { - $query = mysql_query("SELECT count(counter) from port_" . $inout . "_measurements WHERE port_id=" . $port_id); - $rows = mysql_result($query, 0); + $query = mysql_query("SELECT count(counter) from port_" . $inout . "_measurements WHERE port_id=" . $port_id); + $rows = mysql_result($query, 0); - if ($rows > 0) - { - $query = mysql_query("SELECT counter,delta FROM port_" . $inout . "_measurements WHERE port_id=$port_id ORDER BY timestamp DESC"); - $row = mysql_fetch_row($query); - $return[counter] = $row[0]; - $return[delta] = $row[1]; - $return[state] = "ok"; - } else { - $return[state] = "failed"; - } + if ($rows > 0) + { + $query = mysql_query("SELECT counter,delta FROM port_" . $inout . "_measurements WHERE port_id=$port_id ORDER BY timestamp DESC"); + $row = mysql_fetch_row($query); + $return[counter] = $row[0]; + $return[delta] = $row[1]; + $return[state] = "ok"; + } else { + $return[state] = "failed"; + } - return($return); + return($return); } function getLastMeasurement($bill_id) { - $query = mysql_query("SELECT count(delta) from bill_data WHERE bill_id=" . $bill_id); - $rows = mysql_result($query, 0); + $query = mysql_query("SELECT count(delta) from bill_data WHERE bill_id=" . $bill_id); + $rows = mysql_result($query, 0); - if ($rows > 0) - { - $query = mysql_query("SELECT timestamp,delta,in_delta,out_delta FROM bill_data WHERE bill_id=$bill_id ORDER BY timestamp DESC"); - $row = mysql_fetch_row($query); - $return[delta] = $row[1]; - $return[delta] = $row[2]; - $return[delta] = $row[3]; - $return[timestamp] = $row[0]; - $return[state] = "ok"; - } else { - $return[state] = "failed"; - } + if ($rows > 0) + { + $query = mysql_query("SELECT timestamp,delta,in_delta,out_delta FROM bill_data WHERE bill_id=$bill_id ORDER BY timestamp DESC"); + $row = mysql_fetch_row($query); + $return[delta] = $row[1]; + $return[delta] = $row[2]; + $return[delta] = $row[3]; + $return[timestamp] = $row[0]; + $return[state] = "ok"; + } else { + $return[state] = "failed"; + } - return($return); + return($return); } function get95thin($bill_id,$datefrom,$dateto) { - $mq_text = "SELECT count(delta) FROM bill_data WHERE bill_id = $bill_id"; - $mq_text .= " AND timestamp > $datefrom AND timestamp <= $dateto"; - $m_query = mysql_query($mq_text); - $measurements = mysql_result($m_query,0); - $measurement_95th = round($measurements /100 * 95) - 1; + $mq_text = "SELECT count(delta) FROM bill_data WHERE bill_id = $bill_id"; + $mq_text .= " AND timestamp > $datefrom AND timestamp <= $dateto"; + $m_query = mysql_query($mq_text); + $measurements = mysql_result($m_query,0); + $measurement_95th = round($measurements /100 * 95) - 1; - $q_95_text = "SELECT (in_delta / period / 1000 * 8) AS rate FROM bill_data WHERE bill_id = $bill_id"; - $q_95_text .= " AND timestamp > $datefrom AND timestamp <= $dateto ORDER BY in_delta ASC"; - $q_95th = mysql_query($q_95_text); - $m_95th = mysql_result($q_95th,$measurement_95th); + $q_95_text = "SELECT (in_delta / period / 1000 * 8) AS rate FROM bill_data WHERE bill_id = $bill_id"; + $q_95_text .= " AND timestamp > $datefrom AND timestamp <= $dateto ORDER BY in_delta ASC"; + $q_95th = mysql_query($q_95_text); + $m_95th = mysql_result($q_95th,$measurement_95th); - return(round($m_95th, 2)); + return(round($m_95th, 2)); } function get95thout($bill_id,$datefrom,$dateto) { - $mq_text = "SELECT count(delta) FROM bill_data WHERE bill_id = $bill_id"; - $mq_text .= " AND timestamp > $datefrom AND timestamp <= $dateto"; - $m_query = mysql_query($mq_text); - $measurements = mysql_result($m_query,0); - $measurement_95th = round($measurements /100 * 95) - 1; + $mq_text = "SELECT count(delta) FROM bill_data WHERE bill_id = $bill_id"; + $mq_text .= " AND timestamp > $datefrom AND timestamp <= $dateto"; + $m_query = mysql_query($mq_text); + $measurements = mysql_result($m_query,0); + $measurement_95th = round($measurements /100 * 95) - 1; - $q_95_text = "SELECT (out_delta / period / 1000 * 8) AS rate FROM bill_data WHERE bill_id = $bill_id"; - $q_95_text .= " AND timestamp > $datefrom AND timestamp <= $dateto ORDER BY out_delta ASC"; - $q_95th = mysql_query($q_95_text); - $m_95th = mysql_result($q_95th,$measurement_95th); + $q_95_text = "SELECT (out_delta / period / 1000 * 8) AS rate FROM bill_data WHERE bill_id = $bill_id"; + $q_95_text .= " AND timestamp > $datefrom AND timestamp <= $dateto ORDER BY out_delta ASC"; + $q_95th = mysql_query($q_95_text); + $m_95th = mysql_result($q_95th,$measurement_95th); - return(round($m_95th, 2)); + return(round($m_95th, 2)); } function getRates($bill_id,$datefrom,$dateto) { - $mq_text = "SELECT count(delta) FROM bill_data "; - $mq_text = $mq_text . " WHERE bill_id = $bill_id"; - $mq_text = $mq_text . " AND timestamp > $datefrom AND timestamp <= $dateto"; - $m_query = mysql_query($mq_text); - $measurements = mysql_result($m_query,0); - $measurement_95th = round($measurements /100 * 95) - 1; + $mq_text = "SELECT count(delta) FROM bill_data "; + $mq_text = $mq_text . " WHERE bill_id = $bill_id"; + $mq_text = $mq_text . " AND timestamp > $datefrom AND timestamp <= $dateto"; + $m_query = mysql_query($mq_text); + $measurements = mysql_result($m_query,0); + $measurement_95th = round($measurements /100 * 95) - 1; - $q_95_text = "SELECT delta FROM bill_data WHERE bill_id = $bill_id"; - $q_95_text = $q_95_text . " AND timestamp > $datefrom AND timestamp <= $dateto ORDER BY delta ASC"; - $q_95th = mysql_query($q_95_text); - $m_95th = mysql_result($q_95th,$measurement_95th); + $q_95_text = "SELECT delta FROM bill_data WHERE bill_id = $bill_id"; + $q_95_text = $q_95_text . " AND timestamp > $datefrom AND timestamp <= $dateto ORDER BY delta ASC"; + $q_95th = mysql_query($q_95_text); + $m_95th = mysql_result($q_95th,$measurement_95th); - $mt_q = mysql_query("SELECT SUM(delta) FROM bill_data WHERE bill_id = '$bill_id' AND timestamp > '$datefrom' AND timestamp <= '$dateto'"); - $mtot = mysql_result($mt_q,0); - $data['rate_95th_in'] = get95thIn($bill_id,$datefrom,$dateto); - $data['rate_95th_out'] = get95thOut($bill_id,$datefrom,$dateto); + $mt_q = mysql_query("SELECT SUM(delta) FROM bill_data WHERE bill_id = '$bill_id' AND timestamp > '$datefrom' AND timestamp <= '$dateto'"); + $mtot = mysql_result($mt_q,0); + $data['rate_95th_in'] = get95thIn($bill_id,$datefrom,$dateto); + $data['rate_95th_out'] = get95thOut($bill_id,$datefrom,$dateto); - if ($data['rate_95th_out'] > $data['rate_95th_in']) - { - $data['rate_95th'] = $data['rate_95th_out']; - $data['dir_95th'] = 'out'; - } else { - $data['rate_95th'] = $data['rate_95th_in']; - $data['dir_95th'] = 'in'; - } + if ($data['rate_95th_out'] > $data['rate_95th_in']) + { + $data['rate_95th'] = $data['rate_95th_out']; + $data['dir_95th'] = 'out'; + } else { + $data['rate_95th'] = $data['rate_95th_in']; + $data['dir_95th'] = 'in'; + } - $data['total_data'] = round($mtot / 1000 / 1000, 2); - $data['rate_average'] = round($mtot / $measurements / 1000 / 300 * 8, 2); + $data['total_data'] = round($mtot / 1000 / 1000, 2); + $data['rate_average'] = round($mtot / $measurements / 1000 / 300 * 8, 2); - return($data); + return($data); } function getTotal($bill_id,$datefrom,$dateto) { - $mt_q = mysql_query("SELECT sum(delta) FROM bill_data WHERE bill_id = $bill_id AND timestamp > $datefrom AND timestamp <= $dateto"); - $mtot = mysql_result($mt_q,0); + $mt_q = mysql_query("SELECT sum(delta) FROM bill_data WHERE bill_id = $bill_id AND timestamp > $datefrom AND timestamp <= $dateto"); + $mtot = mysql_result($mt_q,0); - return($mtot); + return($mtot); } $dayofmonth = date("j"); //FIXME is this used anywhere? diff --git a/includes/cisco-entities.php b/includes/cisco-entities.php index 4d8cb64d2e..8ced5dc9a3 100755 --- a/includes/cisco-entities.php +++ b/includes/cisco-entities.php @@ -3,23 +3,23 @@ ## List of real names for cisco entities $entPhysicalVendorTypes = array ( - 'cevC7xxxIo1feTxIsl' => 'C7200-IO-FE-MII', - 'cevChassis7140Dualfe' => 'C7140-2FE', - 'cevChassis7204' => "C7204", - 'cevChassis7204Vxr' => 'C7204VXR', - 'cevChassis7206' => 'C7206', - 'cevChassis7206Vxr' => 'C7206VXR', - 'cevCpu7200Npe200' => 'NPE-200', - 'cevCpu7200Npe225' => 'NPE-225', - 'cevCpu7200Npe300' => 'NPE-300', - 'cevCpu7200Npe400' => 'NPE-400', - 'cevCpu7200Npeg1' => 'NPE-G1', - 'cevCpu7200Npeg2' => 'NPE-G2', - 'cevPa1feTxIsl' => 'PA-FE-TX-ISL', - 'cevPa2feTxI82543' => 'PA-2FE-TX', - 'cevPa8e' => 'PA-8E', - 'cevPaA8tX21' => 'PA-8T-X21', - 'cevMGBIC1000BaseLX' => '1000BaseLX GBIC', - 'cevPort10GigBaseLR' => '10GigBaseLR'); + 'cevC7xxxIo1feTxIsl' => 'C7200-IO-FE-MII', + 'cevChassis7140Dualfe' => 'C7140-2FE', + 'cevChassis7204' => "C7204", + 'cevChassis7204Vxr' => 'C7204VXR', + 'cevChassis7206' => 'C7206', + 'cevChassis7206Vxr' => 'C7206VXR', + 'cevCpu7200Npe200' => 'NPE-200', + 'cevCpu7200Npe225' => 'NPE-225', + 'cevCpu7200Npe300' => 'NPE-300', + 'cevCpu7200Npe400' => 'NPE-400', + 'cevCpu7200Npeg1' => 'NPE-G1', + 'cevCpu7200Npeg2' => 'NPE-G2', + 'cevPa1feTxIsl' => 'PA-FE-TX-ISL', + 'cevPa2feTxI82543' => 'PA-2FE-TX', + 'cevPa8e' => 'PA-8E', + 'cevPaA8tX21' => 'PA-8T-X21', + 'cevMGBIC1000BaseLX' => '1000BaseLX GBIC', + 'cevPort10GigBaseLR' => '10GigBaseLR'); ?> diff --git a/includes/common.php b/includes/common.php index ba9d76a600..11e40ab57d 100644 --- a/includes/common.php +++ b/includes/common.php @@ -1,185 +1,186 @@ $max){ return substr_replace($string, $rep, $leave); } else { return $string; } + if (strlen($substring) < 1){ $string = $rep; } else { $string = $substring; } + $leave = $max - strlen ($rep); + if (strlen($string) > $max){ return substr_replace($string, $rep, $leave); } else { return $string; } } function mres($string) { // short function wrapper because the real one is stupidly long and ugly. aestetics. - return mysql_real_escape_string($string); + return mysql_real_escape_string($string); } function getifhost($id) { - $sql = mysql_query("SELECT `device_id` from `ports` WHERE `interface_id` = '$id'"); - $result = @mysql_result($sql, 0); + $sql = mysql_query("SELECT `device_id` from `ports` WHERE `interface_id` = '$id'"); + $result = @mysql_result($sql, 0); - return $result; + return $result; } function gethostbyid($id) { - $sql = mysql_query("SELECT `hostname` FROM `devices` WHERE `device_id` = '$id'"); - $result = @mysql_result($sql, 0); + $sql = mysql_query("SELECT `hostname` FROM `devices` WHERE `device_id` = '$id'"); + $result = @mysql_result($sql, 0); - return $result; + return $result; } function strgen ($length = 16) { - $entropy = array(0,1,2,3,4,5,6,7,8,9,'a','A','b','B','c','C','d','D','e', - 'E','f','F','g','G','h','H','i','I','j','J','k','K','l','L','m','M','n', - 'N','o','O','p','P','q','Q','r','R','s','S','t','T','u','U','v','V','w', - 'W','x','X','y','Y','z','Z'); - $string = ""; + $entropy = array(0,1,2,3,4,5,6,7,8,9,'a','A','b','B','c','C','d','D','e', + 'E','f','F','g','G','h','H','i','I','j','J','k','K','l','L','m','M','n', + 'N','o','O','p','P','q','Q','r','R','s','S','t','T','u','U','v','V','w', + 'W','x','X','y','Y','z','Z'); + $string = ""; - for ($i=0; $i<$length; $i++) - { - $key = mt_rand(0,61); - $string .= $entropy[$key]; - } + for ($i=0; $i<$length; $i++) + { + $key = mt_rand(0,61); + $string .= $entropy[$key]; + } - return $string; + return $string; } function getpeerhost($id) { - $sql = mysql_query("SELECT `device_id` from `bgpPeers` WHERE `bgpPeer_id` = '$id'"); - $result = @mysql_result($sql, 0); + $sql = mysql_query("SELECT `device_id` from `bgpPeers` WHERE `bgpPeer_id` = '$id'"); + $result = @mysql_result($sql, 0); - return $result; + return $result; } function getifindexbyid($id) { - $sql = mysql_query("SELECT `ifIndex` FROM `ports` WHERE `interface_id` = '$id'"); - $result = @mysql_result($sql, 0); + $sql = mysql_query("SELECT `ifIndex` FROM `ports` WHERE `interface_id` = '$id'"); + $result = @mysql_result($sql, 0); - return $result; + return $result; } function getifbyid($id) { - $sql = mysql_query("SELECT * FROM `ports` WHERE `interface_id` = '$id'"); - $result = @mysql_fetch_array($sql); + $sql = mysql_query("SELECT * FROM `ports` WHERE `interface_id` = '$id'"); + $result = @mysql_fetch_array($sql); - return $result; + return $result; } function getifdescrbyid($id) { - $sql = mysql_query("SELECT `ifDescr` FROM `ports` WHERE `interface_id` = '$id'"); - $result = @mysql_result($sql, 0); + $sql = mysql_query("SELECT `ifDescr` FROM `ports` WHERE `interface_id` = '$id'"); + $result = @mysql_result($sql, 0); - return $result; + return $result; } function getidbyname($domain) { - $sql = mysql_query("SELECT `device_id` FROM `devices` WHERE `hostname` = '$domain'"); - $result = @mysql_result($sql, 0); + $sql = mysql_query("SELECT `device_id` FROM `devices` WHERE `hostname` = '$domain'"); + $result = @mysql_result($sql, 0); - return $result; + return $result; } function gethostosbyid($id) { - $sql = mysql_query("SELECT `os` FROM `devices` WHERE `device_id` = '$id'"); - $result = @mysql_result($sql, 0); + $sql = mysql_query("SELECT `os` FROM `devices` WHERE `device_id` = '$id'"); + $result = @mysql_result($sql, 0); - return $result; + return $result; } function safename($name) { - return preg_replace('/[^a-zA-Z0-9,._\-]/', '_', $name); + return preg_replace('/[^a-zA-Z0-9,._\-]/', '_', $name); } -?> \ No newline at end of file +?> diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index ec271e8d70..9c1871ebc7 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -31,7 +31,7 @@ $config['ipmitool'] = "/usr/bin/ipmitool"; 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"; @@ -155,10 +155,10 @@ $config['rancid_ignorecomments'] = 0; # Ignore lines starting with # ### Ignores & Allows $config['bad_if'] = array("voip-null", "virtual-", "unrouted", "eobc", "mpls", "sl0", "lp0", "faith0", - "-atm layer", "-atm subif", "-shdsl", "-aal5", "-atm", "container", - "async", "plip", "-physical", "-signalling", "container", "unrouted", - "bri", "-bearer", "bluetooth", "isatap", "ras", "qos", "miniport", "sonet/sdh", - "span rp", "span sp", "sslvpn"); + "-atm layer", "-atm subif", "-shdsl", "-aal5", "-atm", "container", + "async", "plip", "-physical", "-signalling", "container", "unrouted", + "bri", "-bearer", "bluetooth", "isatap", "ras", "qos", "miniport", "sonet/sdh", + "span rp", "span sp", "sslvpn"); $config['bad_if_regexp'] = array("/serial[0-9]:/"); @@ -195,9 +195,9 @@ $config['ignore_mount'] = array("/kern", "/mnt/cdrom", "/proc", "/dev"); $config['ignore_mount_string'] = array("packages", "devfs", "procfs", "UMA", "MALLOC"); $config['ignore_mount_regexp'] = array("/on: \/packages/", "/on: \/dev/", "/on: \/proc/", "/on: \/junos^/", ## JunOS Drives - "/on: \/junos\/dev/", "/on: \/jail\/dev/", "/^(dev|proc)fs/", "/^\/dev\/md0/", ## JunOS Drives - "/^\/var\/dhcpd\/dev,/", "/UMA/" ## BSD Drives - ); + "/on: \/junos\/dev/", "/on: \/jail\/dev/", "/^(dev|proc)fs/", "/^\/dev\/md0/", ## JunOS Drives + "/^\/var\/dhcpd\/dev,/", "/UMA/" ## BSD Drives +); $config['ignore_mount_removable'] = 1; # Ignore removable disk storage $config['ignore_mount_network'] = 1; # Ignore network mounted storage @@ -206,8 +206,8 @@ $config['ignore_mount_network'] = 1; # Ignore network mounted storage $config['syslog_age'] = "1 month"; ## Entries older than this will be removed $config['syslog_filter'] = array("last message repeated", "Connection from UDP: [", - "ipSystemStatsTable node ipSystemStatsOutFragOKs not implemented", - "diskio.c: don't know how to handle"); ## Ignore some crappy stuff from SNMP daemon + "ipSystemStatsTable node ipSystemStatsOutFragOKs not implemented", + "diskio.c: don't know how to handle"); ## Ignore some crappy stuff from SNMP daemon ### LDAP Authentication @@ -224,4 +224,4 @@ $config['astext'][65333] = "Cymru Bogon Feed"; ### What should we warn about? $config['warn']['ifdown'] = false; -?> \ No newline at end of file +?> diff --git a/includes/functions.php b/includes/functions.php index 22eec592b7..c69bd7970d 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -18,221 +18,221 @@ include_once($config['install_dir'] . "/includes/services.inc.php"); function mac_clean_to_readable($mac) { - $r = substr($mac, 0, 2); - $r .= ":".substr($mac, 2, 2); - $r .= ":".substr($mac, 4, 2); - $r .= ":".substr($mac, 6, 2); - $r .= ":".substr($mac, 8, 2); - $r .= ":".substr($mac, 10, 2); + $r = substr($mac, 0, 2); + $r .= ":".substr($mac, 2, 2); + $r .= ":".substr($mac, 4, 2); + $r .= ":".substr($mac, 6, 2); + $r .= ":".substr($mac, 8, 2); + $r .= ":".substr($mac, 10, 2); - return($r); + return($r); } function zeropad($num, $length = 2) { - while (strlen($num) < $length) - { - $num = '0'.$num; - } + while (strlen($num) < $length) + { + $num = '0'.$num; + } - return $num; + return $num; } function only_alphanumeric($string) { - return preg_replace('/[^a-zA-Z0-9]/', '', $string); + return preg_replace('/[^a-zA-Z0-9]/', '', $string); } function logfile($string) { - global $config; + global $config; - $fd = fopen($config['log_file'],'a'); - fputs($fd,$string . "\n"); - fclose($fd); + $fd = fopen($config['log_file'],'a'); + fputs($fd,$string . "\n"); + fclose($fd); } function set_dev_attrib($device, $attrib_type, $attrib_value) { - $count_sql = "SELECT COUNT(*) FROM devices_attribs WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'"; - if (mysql_result(mysql_query($count_sql),0)) - { - $update_sql = "UPDATE devices_attribs SET attrib_value = '$attrib_value' WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'"; - mysql_query($update_sql); - } - else - { - $insert_sql = "INSERT INTO devices_attribs (`device_id`, `attrib_type`, `attrib_value`) VALUES ('" . mres($device['device_id'])."', '$attrib_type', '$attrib_value')"; - mysql_query($insert_sql); - } + $count_sql = "SELECT COUNT(*) FROM devices_attribs WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'"; + if (mysql_result(mysql_query($count_sql),0)) + { + $update_sql = "UPDATE devices_attribs SET attrib_value = '$attrib_value' WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'"; + mysql_query($update_sql); + } + else + { + $insert_sql = "INSERT INTO devices_attribs (`device_id`, `attrib_type`, `attrib_value`) VALUES ('" . mres($device['device_id'])."', '$attrib_type', '$attrib_value')"; + mysql_query($insert_sql); + } - return mysql_affected_rows(); + return mysql_affected_rows(); } function get_dev_attrib($device, $attrib_type) { - $sql = "SELECT attrib_value FROM devices_attribs WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'"; - if ($row = mysql_fetch_assoc(mysql_query($sql))) - { - return $row['attrib_value']; - } - else - { - return NULL; - } + $sql = "SELECT attrib_value FROM devices_attribs WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'"; + if ($row = mysql_fetch_assoc(mysql_query($sql))) + { + return $row['attrib_value']; + } + else + { + return NULL; + } } function del_dev_attrib($device, $attrib_type) { - $sql = "DELETE FROM devices_attribs WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'"; - return mysql_query($sql); + $sql = "DELETE FROM devices_attribs WHERE `device_id` = '" . mres($device['device_id']) . "' AND `attrib_type` = '$attrib_type'"; + return mysql_query($sql); } function shorthost($hostname, $len=16) { - $parts = explode(".", $hostname); - $shorthost = $parts[0]; - $i=1; - while ($i < count($parts) && strlen($shorthost.'.'.$parts[$i]) < $len) - { - $shorthost = $shorthost.'.'.$parts[$i]; - $i++; - } - return ($shorthost); + $parts = explode(".", $hostname); + $shorthost = $parts[0]; + $i=1; + while ($i < count($parts) && strlen($shorthost.'.'.$parts[$i]) < $len) + { + $shorthost = $shorthost.'.'.$parts[$i]; + $i++; + } + return ($shorthost); } function device_array($device_id) { - $sql = "SELECT * FROM `devices` WHERE `device_id` = '".$device_id."'"; - $query = mysql_query($sql); - $device = mysql_fetch_array($query); - return $device; + $sql = "SELECT * FROM `devices` WHERE `device_id` = '".$device_id."'"; + $query = mysql_query($sql); + $device = mysql_fetch_array($query); + return $device; } function getHostOS($device) { - global $config; + global $config; - $sysDescr = snmp_get ($device, "SNMPv2-MIB::sysDescr.0", "-Ovq"); - $sysObjectId = snmp_get ($device, "SNMPv2-MIB::sysObjectID.0", "-Ovqn"); + $sysDescr = snmp_get ($device, "SNMPv2-MIB::sysDescr.0", "-Ovq"); + $sysObjectId = snmp_get ($device, "SNMPv2-MIB::sysObjectID.0", "-Ovqn"); - echo("| $sysDescr | $sysObjectId | "); + echo("| $sysDescr | $sysObjectId | "); - $dir_handle = @opendir($config['install_dir'] . "/includes/discovery/os") or die("Unable to open $path"); - while ($file = readdir($dir_handle)) - { - if (preg_match("/.php$/", $file) ) + $dir_handle = @opendir($config['install_dir'] . "/includes/discovery/os") or die("Unable to open $path"); + while ($file = readdir($dir_handle)) { - include($config['install_dir'] . "/includes/discovery/os/" . $file); + if (preg_match("/.php$/", $file) ) + { + include($config['install_dir'] . "/includes/discovery/os/" . $file); + } } - } - closedir($dir_handle); + closedir($dir_handle); - if ($os) { return $os; } else { return "generic"; } + if ($os) { return $os; } else { return "generic"; } } function formatRates($rate) { - $rate = format_si($rate) . "bps"; - return $rate; + $rate = format_si($rate) . "bps"; + return $rate; } function formatstorage($rate, $round = '2') { - $rate = format_bi($rate, $round) . "B"; - return $rate; + $rate = format_bi($rate, $round) . "B"; + return $rate; } function format_si($rate) { - if ($rate >= "0.1") - { - $sizes = Array('', 'k', 'M', 'G', 'T', 'P', 'E'); - $round = Array('2','2','2','2','2','2','2','2','2'); - $ext = $sizes[0]; - for ($i=1; (($i < count($sizes)) && ($rate >= 1000)); $i++) { $rate = $rate / 1000; $ext = $sizes[$i]; } - } - else - { - $sizes = Array('', 'm', 'u', 'n'); - $round = Array('2','2','2','2'); - $ext = $sizes[0]; - for ($i=1; (($i < count($sizes)) && ($rate != 0) && ($rate <= 0.1)); $i++) { $rate = $rate * 1000; $ext = $sizes[$i]; } - } + if ($rate >= "0.1") + { + $sizes = Array('', 'k', 'M', 'G', 'T', 'P', 'E'); + $round = Array('2','2','2','2','2','2','2','2','2'); + $ext = $sizes[0]; + for ($i=1; (($i < count($sizes)) && ($rate >= 1000)); $i++) { $rate = $rate / 1000; $ext = $sizes[$i]; } + } + else + { + $sizes = Array('', 'm', 'u', 'n'); + $round = Array('2','2','2','2'); + $ext = $sizes[0]; + for ($i=1; (($i < count($sizes)) && ($rate != 0) && ($rate <= 0.1)); $i++) { $rate = $rate * 1000; $ext = $sizes[$i]; } + } - return round($rate, $round[$i]).$ext; + return round($rate, $round[$i]).$ext; } function format_bi($size, $round = '2') { - $sizes = Array('', 'k', 'M', 'G', 'T', 'P', 'E'); - $ext = $sizes[0]; - for ($i=1; (($i < count($sizes)) && ($size >= 1024)); $i++) { $size = $size / 1024; $ext = $sizes[$i]; } - return round($size, $round).$ext; + $sizes = Array('', 'k', 'M', 'G', 'T', 'P', 'E'); + $ext = $sizes[0]; + for ($i=1; (($i < count($sizes)) && ($size >= 1024)); $i++) { $size = $size / 1024; $ext = $sizes[$i]; } + return round($size, $round).$ext; } function percent_colour($perc) { - $r = min(255, 5 * ($perc - 25)); - $b = max(0, 255 - (5 * ($perc + 25))); - return sprintf('#%02x%02x%02x', $r, $b, $b); + $r = min(255, 5 * ($perc - 25)); + $b = max(0, 255 - (5 * ($perc + 25))); + return sprintf('#%02x%02x%02x', $r, $b, $b); } function interface_errors($rrd_file, $period = '-1d') // Returns the last in/out errors value in RRD { - global $config; - $cmd = $config['rrdtool']." fetch -s $period -e -300s $rrd_file AVERAGE | grep : | cut -d\" \" -f 4,5"; - $data = trim(shell_exec($cmd)); - foreach (explode("\n", $data) as $entry) - { - list($in, $out) = explode(" ", $entry); - $in_errors += ($in * 300); - $out_errors += ($out * 300); - } - $errors['in'] = round($in_errors); - $errors['out'] = round($out_errors); - return $errors; + global $config; + $cmd = $config['rrdtool']." fetch -s $period -e -300s $rrd_file AVERAGE | grep : | cut -d\" \" -f 4,5"; + $data = trim(shell_exec($cmd)); + foreach (explode("\n", $data) as $entry) + { + list($in, $out) = explode(" ", $entry); + $in_errors += ($in * 300); + $out_errors += ($out * 300); + } + $errors['in'] = round($in_errors); + $errors['out'] = round($out_errors); + return $errors; } # FIXME: below function is unused, only commented out in html/pages/device/overview/ports.inc.php - do we still need it? function device_traffic_image($device, $width, $height, $from, $to) { - return ""; + return ""; } function getImage($host) { - global $config; - $sql = "SELECT * FROM `devices` WHERE `device_id` = '$host'"; - $data = mysql_fetch_array(mysql_query($sql)); - $type = strtolower($data['os']); - if ($config['os'][$type]['icon'] && file_exists($config['html_dir'] . "/images/os/" . $config['os'][$type]['icon'] . ".png")) - { - $image = ''; - } elseif ($config['os'][$type]['icon'] && file_exists($config['html_dir'] . "/images/os/". $config['os'][$type]['icon'] . ".gif")) - { - $image = ''; - } else { - if (file_exists($config['html_dir'] . "/images/os/$type" . ".png")){ $image = ''; - } elseif (file_exists($config['html_dir'] . "/images/os/$type" . ".gif")){ $image = ''; } - if ($type == "linux") + global $config; + $sql = "SELECT * FROM `devices` WHERE `device_id` = '$host'"; + $data = mysql_fetch_array(mysql_query($sql)); + $type = strtolower($data['os']); + if ($config['os'][$type]['icon'] && file_exists($config['html_dir'] . "/images/os/" . $config['os'][$type]['icon'] . ".png")) { - $features = strtolower(trim($data['features'])); - list($distro) = split(" ", $features); - if (file_exists($config['html_dir'] . "/images/os/$distro" . ".png")){ $image = ''; - } elseif (file_exists($config['html_dir'] . "/images/os/$distro" . ".gif")){ $image = ''; } + $image = ''; + } elseif ($config['os'][$type]['icon'] && file_exists($config['html_dir'] . "/images/os/". $config['os'][$type]['icon'] . ".gif")) + { + $image = ''; + } else { + if (file_exists($config['html_dir'] . "/images/os/$type" . ".png")){ $image = ''; + } elseif (file_exists($config['html_dir'] . "/images/os/$type" . ".gif")){ $image = ''; } + if ($type == "linux") + { + $features = strtolower(trim($data['features'])); + list($distro) = split(" ", $features); + if (file_exists($config['html_dir'] . "/images/os/$distro" . ".png")){ $image = ''; + } elseif (file_exists($config['html_dir'] . "/images/os/$distro" . ".gif")){ $image = ''; } + } } - } - return $image; + return $image; } function renamehost($id, $new) { - global $config; - $host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0); - rename($config['rrd_dir']."/$host",$config['rrd_dir']."/$new"); - mysql_query("UPDATE devices SET hostname = '$new' WHERE device_id = '$id'"); - eventlog("Hostname changed -> $new (console)", $id); + global $config; + $host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0); + rename($config['rrd_dir']."/$host",$config['rrd_dir']."/$new"); + mysql_query("UPDATE devices SET hostname = '$new' WHERE device_id = '$id'"); + eventlog("Hostname changed -> $new (console)", $id); } function delete_port($int_id) @@ -253,535 +253,535 @@ function delete_port($int_id) function delete_device($id) { - global $config; - $host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0); - mysql_query("DELETE FROM `devices` WHERE `device_id` = '$id'"); - $int_query = mysql_query("SELECT * FROM `ports` WHERE `device_id` = '$id'"); - while ($int_data = mysql_fetch_array($int_query)) - { - $int_if = $int_data['ifDescr']; - $int_id = $int_data['interface_id']; - delete_port($int_id); - $ret .= "Removed interface $int_id ($int_if)\n"; - } - mysql_query("DELETE FROM `entPhysical` WHERE `device_id` = '$id'"); - mysql_query("DELETE FROM `devices_attribs` WHERE `device_id` = '$id'"); - mysql_query("DELETE FROM `devices_perms` WHERE `device_id` = '$id'"); - mysql_query("DELETE FROM `bgpPeers` WHERE `device_id` = '$id'"); - mysql_query("DELETE FROM `vlans` WHERE `device_id` = '$id'"); - mysql_query("DELETE FROM `vrfs` WHERE `device_id` = '$id'"); - mysql_query("DELETE FROM `storage` WHERE `device_id` = '$id'"); - mysql_query("DELETE FROM `alerts` WHERE `device_id` = '$id'"); - mysql_query("DELETE FROM `eventlog` WHERE `host` = '$id'"); - mysql_query("DELETE FROM `syslog` WHERE `device_id` = '$id'"); - mysql_query("DELETE FROM `ports` WHERE `device_id` = '$id'"); - mysql_query("DELETE FROM `services` WHERE `device_id` = '$id'"); - mysql_query("DELETE FROM `alerts` WHERE `device_id` = '$id'"); - mysql_query("DELETE FROM `toner` WHERE `device_id` = '$id'"); - mysql_query("DELETE FROM `frequency` WHERE `device_id` = '$id'"); - mysql_query("DELETE FROM `current` WHERE `device_id` = '$id'"); - mysql_query("DELETE FROM `sensors` WHERE `device_id` = '$id'"); - shell_exec("rm -rf ".trim($config['rrd_dir'])."/$host"); - $ret = "Removed Device $host\n"; - return $ret; + global $config; + $host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0); + mysql_query("DELETE FROM `devices` WHERE `device_id` = '$id'"); + $int_query = mysql_query("SELECT * FROM `ports` WHERE `device_id` = '$id'"); + while ($int_data = mysql_fetch_array($int_query)) + { + $int_if = $int_data['ifDescr']; + $int_id = $int_data['interface_id']; + delete_port($int_id); + $ret .= "Removed interface $int_id ($int_if)\n"; + } + mysql_query("DELETE FROM `entPhysical` WHERE `device_id` = '$id'"); + mysql_query("DELETE FROM `devices_attribs` WHERE `device_id` = '$id'"); + mysql_query("DELETE FROM `devices_perms` WHERE `device_id` = '$id'"); + mysql_query("DELETE FROM `bgpPeers` WHERE `device_id` = '$id'"); + mysql_query("DELETE FROM `vlans` WHERE `device_id` = '$id'"); + mysql_query("DELETE FROM `vrfs` WHERE `device_id` = '$id'"); + mysql_query("DELETE FROM `storage` WHERE `device_id` = '$id'"); + mysql_query("DELETE FROM `alerts` WHERE `device_id` = '$id'"); + mysql_query("DELETE FROM `eventlog` WHERE `host` = '$id'"); + mysql_query("DELETE FROM `syslog` WHERE `device_id` = '$id'"); + mysql_query("DELETE FROM `ports` WHERE `device_id` = '$id'"); + mysql_query("DELETE FROM `services` WHERE `device_id` = '$id'"); + mysql_query("DELETE FROM `alerts` WHERE `device_id` = '$id'"); + mysql_query("DELETE FROM `toner` WHERE `device_id` = '$id'"); + mysql_query("DELETE FROM `frequency` WHERE `device_id` = '$id'"); + mysql_query("DELETE FROM `current` WHERE `device_id` = '$id'"); + mysql_query("DELETE FROM `sensors` WHERE `device_id` = '$id'"); + shell_exec("rm -rf ".trim($config['rrd_dir'])."/$host"); + $ret = "Removed Device $host\n"; + return $ret; } function addHost($host, $community, $snmpver, $port = 161, $transport = 'udp') { - global $config; - list($hostshort) = explode(".", $host); - if (isDomainResolves($host)) - { - if (isPingable($host)) + global $config; + list($hostshort) = explode(".", $host); + if (isDomainResolves($host)) { - if (mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$host'"), 0) == '0' ) - { - # FIXME internalize -- but we don't have $device yet! - # FIXME this needs to be addhost.php's content instead, kindof, also use this function there then. - $snmphost = shell_exec($config['snmpget'] ." -m SNMPv2-MIB -Oqv -$snmpver -c $community $host:$port sysName.0"); - if ($snmphost == $host || $hostshort = $host) + if (isPingable($host)) { - createHost($host, $community, $snmpver, $port, $transport); - } else { echo("Given hostname does not match SNMP-read hostname!\n"); } - } else { echo("Already got host $host\n"); } - } else { echo("Could not ping $host\n"); } - } else { echo("Could not resolve $host\n"); } + if (mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$host'"), 0) == '0' ) + { + # FIXME internalize -- but we don't have $device yet! + # FIXME this needs to be addhost.php's content instead, kindof, also use this function there then. + $snmphost = shell_exec($config['snmpget'] ." -m SNMPv2-MIB -Oqv -$snmpver -c $community $host:$port sysName.0"); + if ($snmphost == $host || $hostshort = $host) + { + createHost($host, $community, $snmpver, $port, $transport); + } else { echo("Given hostname does not match SNMP-read hostname!\n"); } + } else { echo("Already got host $host\n"); } + } else { echo("Could not ping $host\n"); } + } else { echo("Could not resolve $host\n"); } } function scanUDP($host, $port, $timeout) { - $handle = fsockopen($host, $port, $errno, $errstr, 2); - socket_set_timeout ($handle, $timeout); - $write = fwrite($handle,"\x00"); - if (!$write) { next; } - $startTime = time(); - $header = fread($handle, 1); - $endTime = time(); - $timeDiff = $endTime - $startTime; - if ($timeDiff >= $timeout) - { - fclose($handle); return 1; - } else { fclose($handle); return 0; } + $handle = fsockopen($host, $port, $errno, $errstr, 2); + socket_set_timeout ($handle, $timeout); + $write = fwrite($handle,"\x00"); + if (!$write) { next; } + $startTime = time(); + $header = fread($handle, 1); + $endTime = time(); + $timeDiff = $endTime - $startTime; + if ($timeDiff >= $timeout) + { + fclose($handle); return 1; + } else { fclose($handle); return 0; } } function deviceArray($host, $community, $snmpver, $port = 161, $transport = 'udp') { - $device = array(); - $device['hostname'] = $host; - $device['port'] = $port; - $device['community'] = $community; - $device['snmpver'] = $snmpver; - $device['transport'] = $transport; + $device = array(); + $device['hostname'] = $host; + $device['port'] = $port; + $device['community'] = $community; + $device['snmpver'] = $snmpver; + $device['transport'] = $transport; - return $device; + return $device; } function netmask2cidr($netmask) { - $addr = Net_IPv4::parseAddress("1.2.3.4/$netmask"); - return $addr->bitmask; + $addr = Net_IPv4::parseAddress("1.2.3.4/$netmask"); + return $addr->bitmask; } function cidr2netmask() { - return (long2ip(ip2long("255.255.255.255") << (32-$netmask))); + return (long2ip(ip2long("255.255.255.255") << (32-$netmask))); } function formatUptime($diff, $format="long") { - $yearsDiff = floor($diff/31536000); - $diff -= $yearsDiff*31536000; - $daysDiff = floor($diff/86400); - $diff -= $daysDiff*86400; - $hrsDiff = floor($diff/60/60); - $diff -= $hrsDiff*60*60; - $minsDiff = floor($diff/60); - $diff -= $minsDiff*60; - $secsDiff = $diff; + $yearsDiff = floor($diff/31536000); + $diff -= $yearsDiff*31536000; + $daysDiff = floor($diff/86400); + $diff -= $daysDiff*86400; + $hrsDiff = floor($diff/60/60); + $diff -= $hrsDiff*60*60; + $minsDiff = floor($diff/60); + $diff -= $minsDiff*60; + $secsDiff = $diff; - $uptime = ""; + $uptime = ""; - if ($format == "short") - { - if ($yearsDiff > '0') { $uptime .= $yearsDiff . "y "; } - if ($daysDiff > '0') { $uptime .= $daysDiff . "d "; } - if ($hrsDiff > '0') { $uptime .= $hrsDiff . "h "; } - if ($minsDiff > '0') { $uptime .= $minsDiff . "m "; } - if ($secsDiff > '0') { $uptime .= $secsDiff . "s "; } - } - else - { - if ($yearsDiff > '0') { $uptime .= $yearsDiff . " years, "; } - if ($daysDiff > '0') { $uptime .= $daysDiff . " day" . ($daysDiff != 1 ? 's' : '' ) . ", "; } - if ($hrsDiff > '0') { $uptime .= $hrsDiff . "h "; } - if ($minsDiff > '0') { $uptime .= $minsDiff . "m "; } - if ($secsDiff > '0') { $uptime .= $secsDiff . "s "; } - } - return trim($uptime); + if ($format == "short") + { + if ($yearsDiff > '0') { $uptime .= $yearsDiff . "y "; } + if ($daysDiff > '0') { $uptime .= $daysDiff . "d "; } + if ($hrsDiff > '0') { $uptime .= $hrsDiff . "h "; } + if ($minsDiff > '0') { $uptime .= $minsDiff . "m "; } + if ($secsDiff > '0') { $uptime .= $secsDiff . "s "; } + } + else + { + if ($yearsDiff > '0') { $uptime .= $yearsDiff . " years, "; } + if ($daysDiff > '0') { $uptime .= $daysDiff . " day" . ($daysDiff != 1 ? 's' : '' ) . ", "; } + if ($hrsDiff > '0') { $uptime .= $hrsDiff . "h "; } + if ($minsDiff > '0') { $uptime .= $minsDiff . "m "; } + if ($secsDiff > '0') { $uptime .= $secsDiff . "s "; } + } + return trim($uptime); } function isSNMPable($device) { - global $config; + global $config; - $pos = snmp_get($device, "sysObjectID.0", "-Oqv", "SNMPv2-MIB"); - if ($pos === '' || $pos === false) - { - return false; - } else { - return true; - } + $pos = snmp_get($device, "sysObjectID.0", "-Oqv", "SNMPv2-MIB"); + if ($pos === '' || $pos === false) + { + return false; + } else { + return true; + } } function isPingable($hostname) { - global $config; - $status = shell_exec($config['fping'] . " $hostname"); - if (strstr($status, "alive")) - { - return TRUE; - } else { - $status = shell_exec($config['fping6'] . " $hostname"); - if (strstr($status, "alive")) - { - return TRUE; - } else { - return FALSE; - } - } + global $config; + $status = shell_exec($config['fping'] . " $hostname"); + if (strstr($status, "alive")) + { + return TRUE; + } else { + $status = shell_exec($config['fping6'] . " $hostname"); + if (strstr($status, "alive")) + { + return TRUE; + } else { + return FALSE; + } + } } function is_odd($number) { - return $number & 1; // 0 = even, 1 = odd + return $number & 1; // 0 = even, 1 = odd } function isValidInterface($if) { - global $config; - $if = strtolower($if); - $nullintf = 0; - foreach ($config['bad_if'] as $bi) - { + global $config; + $if = strtolower($if); + $nullintf = 0; + foreach ($config['bad_if'] as $bi) + { $pos = strpos($if, $bi); if ($pos !== FALSE) { - $nullintf = 1; - echo("$if matched $bi \n"); + $nullintf = 1; + echo("$if matched $bi \n"); + } + } + if (preg_match('/serial[0-9]:/', $if)) { $nullintf = '1'; } + if ($nullintf != '1') + { + return 1; + } else { + return 0; } - } - if (preg_match('/serial[0-9]:/', $if)) { $nullintf = '1'; } - if ($nullintf != '1') - { - return 1; - } else { - return 0; - } } function utime() { - $time = explode(" ", microtime()); - $usec = (double)$time[0]; - $sec = (double)$time[1]; - return $sec + $usec; + $time = explode(" ", microtime()); + $usec = (double)$time[0]; + $sec = (double)$time[1]; + return $sec + $usec; } # FIXME function unused, superseded by rewrites? function fixIOSFeatures($features) { - $features = preg_replace("/^PK9S$/", "IP w/SSH LAN Only", $features); - $features = str_replace("LANBASEK9", "Lan Base Crypto", $features); - $features = str_replace("LANBASE", "Lan Base", $features); - $features = str_replace("ADVENTERPRISEK9", "Advanced Enterprise Crypto", $features); - $features = str_replace("ADVSECURITYK9", "Advanced Security Crypto", $features); - $features = str_replace("K91P", "Provider Crypto", $features); - $features = str_replace("K4P", "Provider Crypto", $features); - $features = str_replace("ADVIPSERVICESK9", "Adv IP Services Crypto", $features); - $features = str_replace("ADVIPSERVICES", "Adv IP Services", $features); - $features = str_replace("IK9P", "IP Plus Crypto", $features); - $features = str_replace("K9O3SY7", "IP ADSL FW IDS Plus IPSEC 3DES", $features); - $features = str_replace("SPSERVICESK9", "SP Services Crypto", $features); - $features = preg_replace("/^PK9SV$/", "IP MPLS/IPV6 W/SSH + BGP", $features); - $features = str_replace("IS", "IP Plus", $features); - $features = str_replace("IPSERVICESK9", "IP Services Crypto", $features); - $features = str_replace("BROADBAND", "Broadband", $features); - $features = str_replace("IPBASE", "IP Base", $features); - $features = str_replace("IPSERVICE", "IP Services", $features); - $features = preg_replace("/^P$/", "Service Provider", $features); - $features = preg_replace("/^P11$/", "Broadband Router", $features); - $features = preg_replace("/^G4P5$/", "NRP", $features); - $features = str_replace("JK9S", "Enterprise Plus Crypto", $features); - $features = str_replace("IK9S", "IP Plus Crypto", $features); - $features = preg_replace("/^JK$/", "Enterprise Plus", $features); - $features = str_replace("I6Q4L2", "Layer 2", $features); - $features = str_replace("I6K2L2Q4", "Layer 2 Crypto", $features); - $features = str_replace("C3H2S", "Layer 2 SI/EI", $features); - $features = str_replace("_WAN", " + WAN", $features); - return $features; + $features = preg_replace("/^PK9S$/", "IP w/SSH LAN Only", $features); + $features = str_replace("LANBASEK9", "Lan Base Crypto", $features); + $features = str_replace("LANBASE", "Lan Base", $features); + $features = str_replace("ADVENTERPRISEK9", "Advanced Enterprise Crypto", $features); + $features = str_replace("ADVSECURITYK9", "Advanced Security Crypto", $features); + $features = str_replace("K91P", "Provider Crypto", $features); + $features = str_replace("K4P", "Provider Crypto", $features); + $features = str_replace("ADVIPSERVICESK9", "Adv IP Services Crypto", $features); + $features = str_replace("ADVIPSERVICES", "Adv IP Services", $features); + $features = str_replace("IK9P", "IP Plus Crypto", $features); + $features = str_replace("K9O3SY7", "IP ADSL FW IDS Plus IPSEC 3DES", $features); + $features = str_replace("SPSERVICESK9", "SP Services Crypto", $features); + $features = preg_replace("/^PK9SV$/", "IP MPLS/IPV6 W/SSH + BGP", $features); + $features = str_replace("IS", "IP Plus", $features); + $features = str_replace("IPSERVICESK9", "IP Services Crypto", $features); + $features = str_replace("BROADBAND", "Broadband", $features); + $features = str_replace("IPBASE", "IP Base", $features); + $features = str_replace("IPSERVICE", "IP Services", $features); + $features = preg_replace("/^P$/", "Service Provider", $features); + $features = preg_replace("/^P11$/", "Broadband Router", $features); + $features = preg_replace("/^G4P5$/", "NRP", $features); + $features = str_replace("JK9S", "Enterprise Plus Crypto", $features); + $features = str_replace("IK9S", "IP Plus Crypto", $features); + $features = preg_replace("/^JK$/", "Enterprise Plus", $features); + $features = str_replace("I6Q4L2", "Layer 2", $features); + $features = str_replace("I6K2L2Q4", "Layer 2 Crypto", $features); + $features = str_replace("C3H2S", "Layer 2 SI/EI", $features); + $features = str_replace("_WAN", " + WAN", $features); + return $features; } # FIXME function unused, superseded by rewrites? function fixIOSHardware($hardware) { - $hardware = preg_replace("/C([0-9]+)/", "Cisco \\1", $hardware); - $hardware = preg_replace("/CISCO([0-9]+)/", "Cisco \\1", $hardware); - $hardware = str_replace("cat4000","Cisco Catalyst 4000", $hardware); - $hardware = str_replace("s3223_rp","Cisco Catalyst 6500 SUP32", $hardware); - $hardware = str_replace("s222_rp","Cisco Catalyst 6500 SUP2", $hardware); - $hardware = str_replace("c6sup2_rp","Cisco Catalyst 6500 SUP2", $hardware); - $hardware = str_replace("s72033_rp","Cisco Catalyst 6500 SUP720 ", $hardware); - $hardware = str_replace("RSP","Cisco 7500", $hardware); - $hardware = str_replace("C3200XL", "Cisco Catalyst 3200XL", $hardware); - $hardware = str_replace("C3550", "Cisco Catalyst 3550", $hardware); - $hardware = str_replace("C2950", "Cisco Catalyst 2950", $hardware); - $hardware = str_replace("C7301", "Cisco 7301", $hardware); - $hardware = str_replace("CE500", "Catalyst Express 500", $hardware); - return $hardware; + $hardware = preg_replace("/C([0-9]+)/", "Cisco \\1", $hardware); + $hardware = preg_replace("/CISCO([0-9]+)/", "Cisco \\1", $hardware); + $hardware = str_replace("cat4000","Cisco Catalyst 4000", $hardware); + $hardware = str_replace("s3223_rp","Cisco Catalyst 6500 SUP32", $hardware); + $hardware = str_replace("s222_rp","Cisco Catalyst 6500 SUP2", $hardware); + $hardware = str_replace("c6sup2_rp","Cisco Catalyst 6500 SUP2", $hardware); + $hardware = str_replace("s72033_rp","Cisco Catalyst 6500 SUP720 ", $hardware); + $hardware = str_replace("RSP","Cisco 7500", $hardware); + $hardware = str_replace("C3200XL", "Cisco Catalyst 3200XL", $hardware); + $hardware = str_replace("C3550", "Cisco Catalyst 3550", $hardware); + $hardware = str_replace("C2950", "Cisco Catalyst 2950", $hardware); + $hardware = str_replace("C7301", "Cisco 7301", $hardware); + $hardware = str_replace("CE500", "Catalyst Express 500", $hardware); + return $hardware; } function createHost($host, $community, $snmpver, $port = 161, $transport = 'udp') { - $host = trim(strtolower($host)); - $device = deviceArray($host, $community, $snmpver, $port, $transport); - $host_os = getHostOS($device); + $host = trim(strtolower($host)); + $device = deviceArray($host, $community, $snmpver, $port, $transport); + $host_os = getHostOS($device); - if ($host_os) - { - $sql = mysql_query("INSERT INTO `devices` (`hostname`, `sysName`, `community`, `port`, `transport`, `os`, `status`,`snmpver`) VALUES ('$host', '$host', '$community', '$port', '$transport', '$host_os', '1','$snmpver')"); - if (mysql_affected_rows()) + if ($host_os) { - return("Created host : $host (id:".mysql_insert_id().") (os:$host_os)"); + $sql = mysql_query("INSERT INTO `devices` (`hostname`, `sysName`, `community`, `port`, `transport`, `os`, `status`,`snmpver`) VALUES ('$host', '$host', '$community', '$port', '$transport', '$host_os', '1','$snmpver')"); + if (mysql_affected_rows()) + { + return("Created host : $host (id:".mysql_insert_id().") (os:$host_os)"); + } + else + { + return FALSE; + } } else { - return FALSE; + return FALSE; } - } - else - { - return FALSE; - } } function isDomainResolves($domain) { - return (gethostbyname($domain) != $domain || count(dns_get_record($domain)) != 0); + return (gethostbyname($domain) != $domain || count(dns_get_record($domain)) != 0); } function hoststatus($id) { - $sql = mysql_query("SELECT `status` FROM `devices` WHERE `device_id` = '$id'"); - $result = @mysql_result($sql, 0); + $sql = mysql_query("SELECT `status` FROM `devices` WHERE `device_id` = '$id'"); + $result = @mysql_result($sql, 0); - return $result; + return $result; } function match_network($nets, $ip, $first=false) { - $return = false; - if (!is_array ($nets)) $nets = array ($nets); - foreach ($nets as $net) - { - $rev = (preg_match ("/^\!/", $net)) ? true : false; - $net = preg_replace ("/^\!/", "", $net); - $ip_arr = explode('/', $net); - $net_long = ip2long($ip_arr[0]); - $x = ip2long($ip_arr[1]); - $mask = long2ip($x) == $ip_arr[1] ? $x : 0xffffffff << (32 - $ip_arr[1]); - $ip_long = ip2long($ip); - if ($rev) + $return = false; + if (!is_array ($nets)) $nets = array ($nets); + foreach ($nets as $net) { - if (($ip_long & $mask) == ($net_long & $mask)) return false; - } else { - if (($ip_long & $mask) == ($net_long & $mask)) $return = true; - if ($first && $return) return true; + $rev = (preg_match ("/^\!/", $net)) ? true : false; + $net = preg_replace ("/^\!/", "", $net); + $ip_arr = explode('/', $net); + $net_long = ip2long($ip_arr[0]); + $x = ip2long($ip_arr[1]); + $mask = long2ip($x) == $ip_arr[1] ? $x : 0xffffffff << (32 - $ip_arr[1]); + $ip_long = ip2long($ip); + if ($rev) + { + if (($ip_long & $mask) == ($net_long & $mask)) return false; + } else { + if (($ip_long & $mask) == ($net_long & $mask)) $return = true; + if ($first && $return) return true; + } } - } - return $return; + return $return; } function snmp2ipv6($ipv6_snmp) { - $ipv6 = explode('.',$ipv6_snmp); - for ($i = 0;$i <= 15;$i++) { $ipv6[$i] = zeropad(dechex($ipv6[$i])); } - for ($i = 0;$i <= 15;$i+=2) { $ipv6_2[] = $ipv6[$i] . $ipv6[$i+1]; } + $ipv6 = explode('.',$ipv6_snmp); + for ($i = 0;$i <= 15;$i++) { $ipv6[$i] = zeropad(dechex($ipv6[$i])); } + for ($i = 0;$i <= 15;$i+=2) { $ipv6_2[] = $ipv6[$i] . $ipv6[$i+1]; } - return implode(':',$ipv6_2); + return implode(':',$ipv6_2); } function ipv62snmp($ipv6) { - $ipv6_ex = explode(':',Net_IPv6::uncompress($ipv6)); - for ($i = 0;$i < 8;$i++) { $ipv6_ex[$i] = zeropad($ipv6_ex[$i],4); } - $ipv6_ip = implode('',$ipv6_ex); - for ($i = 0;$i < 32;$i+=2) $ipv6_split[] = hexdec(substr($ipv6_ip,$i,2)); + $ipv6_ex = explode(':',Net_IPv6::uncompress($ipv6)); + for ($i = 0;$i < 8;$i++) { $ipv6_ex[$i] = zeropad($ipv6_ex[$i],4); } + $ipv6_ip = implode('',$ipv6_ex); + for ($i = 0;$i < 32;$i+=2) $ipv6_split[] = hexdec(substr($ipv6_ip,$i,2)); - return implode('.',$ipv6_split); + return implode('.',$ipv6_split); } function discover_process_ipv6($ifIndex,$ipv6_address,$ipv6_prefixlen,$ipv6_origin) { - global $valid_v6,$device,$config; + global $valid_v6,$device,$config; - $ipv6_network = Net_IPv6::getNetmask("$ipv6_address/$ipv6_prefixlen") . '/' . $ipv6_prefixlen; - $ipv6_compressed = Net_IPv6::compress($ipv6_address); + $ipv6_network = Net_IPv6::getNetmask("$ipv6_address/$ipv6_prefixlen") . '/' . $ipv6_prefixlen; + $ipv6_compressed = Net_IPv6::compress($ipv6_address); - if (Net_IPv6::getAddressType($ipv6_address) == NET_IPV6_LOCAL_LINK) - { - # ignore link-locals (coming from IPV6-MIB) - return; - } + if (Net_IPv6::getAddressType($ipv6_address) == NET_IPV6_LOCAL_LINK) + { + # ignore link-locals (coming from IPV6-MIB) + return; + } - if (mysql_result(mysql_query("SELECT count(*) FROM `ports` + if (mysql_result(mysql_query("SELECT count(*) FROM `ports` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1') - { - $i_query = "SELECT interface_id FROM `ports` 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 `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1') { - mysql_query("INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES ('$ipv6_network')"); - echo("N"); - } + $i_query = "SELECT interface_id FROM `ports` 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 `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1') + { + mysql_query("INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES ('$ipv6_network')"); + echo("N"); + } - if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1') - { - mysql_query("INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES ('$ipv6_network')"); - echo("N"); - } + if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1') + { + mysql_query("INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES ('$ipv6_network')"); + echo("N"); + } - $ipv6_network_id = @mysql_result(mysql_query("SELECT `ipv6_network_id` from `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0); + $ipv6_network_id = @mysql_result(mysql_query("SELECT `ipv6_network_id` from `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0); - if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = '$ipv6_address' AND `ipv6_prefixlen` = '$ipv6_prefixlen' AND `interface_id` = '$interface_id'"), 0) == '0') - { - mysql_query("INSERT INTO `ipv6_addresses` (`ipv6_address`, `ipv6_compressed`, `ipv6_prefixlen`, `ipv6_origin`, `ipv6_network_id`, `interface_id`) - VALUES ('$ipv6_address', '$ipv6_compressed', '$ipv6_prefixlen', '$ipv6_origin', '$ipv6_network_id', '$interface_id')"); - echo("+"); + if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = '$ipv6_address' AND `ipv6_prefixlen` = '$ipv6_prefixlen' AND `interface_id` = '$interface_id'"), 0) == '0') + { + mysql_query("INSERT INTO `ipv6_addresses` (`ipv6_address`, `ipv6_compressed`, `ipv6_prefixlen`, `ipv6_origin`, `ipv6_network_id`, `interface_id`) + VALUES ('$ipv6_address', '$ipv6_compressed', '$ipv6_prefixlen', '$ipv6_origin', '$ipv6_network_id', '$interface_id')"); + echo("+"); + } + else + { + echo("."); + } + $full_address = "$ipv6_address/$ipv6_prefixlen"; + $valid = $full_address . "-" . $interface_id; + $valid_v6[$valid] = 1; } - else - { - echo("."); - } - $full_address = "$ipv6_address/$ipv6_prefixlen"; - $valid = $full_address . "-" . $interface_id; - $valid_v6[$valid] = 1; - } } function get_astext($asn) { - global $config,$cache; + global $config,$cache; - if (isset($config['astext'][$asn])) - { - return $config['astext'][$asn]; - } - else - { - if (isset($cache['astext'][$asn])) + if (isset($config['astext'][$asn])) { - return $cache['astext'][$asn]; + return $config['astext'][$asn]; } else { - $result = dns_get_record("AS$asn.asn.cymru.com",DNS_TXT); - $txt = explode('|',$result[0]['txt']); - $result = trim(str_replace('"', '', $txt[4])); - $cache['astext'][$asn] = $result; - return $result; + if (isset($cache['astext'][$asn])) + { + return $cache['astext'][$asn]; + } + else + { + $result = dns_get_record("AS$asn.asn.cymru.com",DNS_TXT); + $txt = explode('|',$result[0]['txt']); + $result = trim(str_replace('"', '', $txt[4])); + $cache['astext'][$asn] = $result; + return $result; + } } - } } # DEPRECATED function eventlog($eventtext,$device_id = "", $interface_id = "") { - $event_query = "INSERT INTO eventlog (host, interface, datetime, message) VALUES (" . ($device_id ? $device_id : "NULL"); - $event_query .= ", " . ($interface_id ? $interface_id : "NULL") . ", NOW(), '" . mysql_escape_string($eventtext) . "')"; - mysql_query($event_query); + $event_query = "INSERT INTO eventlog (host, interface, datetime, message) VALUES (" . ($device_id ? $device_id : "NULL"); + $event_query .= ", " . ($interface_id ? $interface_id : "NULL") . ", NOW(), '" . mysql_escape_string($eventtext) . "')"; + mysql_query($event_query); } # Use this function to write to the eventlog table function log_event($text, $device = NULL, $type = NULL, $reference = NULL) { - global $debug; + global $debug; - if (!is_array($device)) { $device = device_by_id_cache($device); } + if (!is_array($device)) { $device = device_by_id_cache($device); } - $event_query = "INSERT INTO eventlog (host, reference, type, datetime, message) VALUES (" . ($device['device_id'] ? $device['device_id'] : "NULL"); - $event_query .= ", '" . ($reference ? $reference : "NULL") . "', '" . ($type ? $type : "NULL") . "', NOW(), '" . mres($text) . "')"; - if ($debug) { echo($event_query . "\n"); } - mysql_query($event_query); + $event_query = "INSERT INTO eventlog (host, reference, type, datetime, message) VALUES (" . ($device['device_id'] ? $device['device_id'] : "NULL"); + $event_query .= ", '" . ($reference ? $reference : "NULL") . "', '" . ($type ? $type : "NULL") . "', NOW(), '" . mres($text) . "')"; + if ($debug) { echo($event_query . "\n"); } + mysql_query($event_query); } function notify($device,$title,$message) { - global $config; + global $config; - if ($config['alerts']['email']['enable']) - { - if ($config['alerts']['email']['default_only']) + if ($config['alerts']['email']['enable']) { - $email = $config['alerts']['email']['default']; - } else { - if ($device['sysContact']) - { - $email = $device['sysContact']; - } else { - $email = $config['alerts']['email']['default']; - } + if ($config['alerts']['email']['default_only']) + { + $email = $config['alerts']['email']['default']; + } else { + if ($device['sysContact']) + { + $email = $device['sysContact']; + } else { + $email = $config['alerts']['email']['default']; + } + } + if ($email) + { + mail($email, $title, $message, $config['email_headers']); + } } - if ($email) - { - mail($email, $title, $message, $config['email_headers']); - } - } } function formatCiscoHardware(&$device, $short = false) { - if ($device['os'] == "ios") - { - if ($device['hardware']) + if ($device['os'] == "ios") { - if (preg_match("/^WS-C([A-Za-z0-9]+).*/", $device['hardware'], $matches)) - { - if (!$short) + if ($device['hardware']) { - $device['hardware'] = "Cisco " . $matches[1] . " (" . $device['hardware'] . ")"; + if (preg_match("/^WS-C([A-Za-z0-9]+).*/", $device['hardware'], $matches)) + { + if (!$short) + { + $device['hardware'] = "Cisco " . $matches[1] . " (" . $device['hardware'] . ")"; + } + else + { + $device['hardware'] = "Cisco " . $matches[1]; + } + } + elseif (preg_match("/^CISCO([0-9]+)$/", $device['hardware'], $matches)) + { + $device['hardware'] = "Cisco " . $matches[1]; + } } else { - $device['hardware'] = "Cisco " . $matches[1]; + if (preg_match("/Cisco IOS Software, C([A-Za-z0-9]+) Software.*/", $device['sysDescr'], $matches)) + { + $device['hardware'] = "Cisco " . $matches[1]; + } + elseif (preg_match("/Cisco IOS Software, ([0-9]+) Software.*/", $device['sysDescr'], $matches)) + { + $device['hardware'] = "Cisco " . $matches[1]; + } } - } - elseif (preg_match("/^CISCO([0-9]+)$/", $device['hardware'], $matches)) - { - $device['hardware'] = "Cisco " . $matches[1]; - } } - else - { - if (preg_match("/Cisco IOS Software, C([A-Za-z0-9]+) Software.*/", $device['sysDescr'], $matches)) - { - $device['hardware'] = "Cisco " . $matches[1]; - } - elseif (preg_match("/Cisco IOS Software, ([0-9]+) Software.*/", $device['sysDescr'], $matches)) - { - $device['hardware'] = "Cisco " . $matches[1]; - } - } - } } # from http://ditio.net/2008/11/04/php-string-to-hex-and-hex-to-string-functions/ function hex2str($hex) { - $string=''; + $string=''; - for ($i=0; $i < strlen($hex)-1; $i+=2) - { - $string .= chr(hexdec($hex[$i].$hex[$i+1])); - } + for ($i=0; $i < strlen($hex)-1; $i+=2) + { + $string .= chr(hexdec($hex[$i].$hex[$i+1])); + } - return $string; + return $string; } # Convert an SNMP hex string to regular string function snmp_hexstring($hex) { - return hex2str(str_replace(' ','',str_replace(' 00','',$hex))); + return hex2str(str_replace(' ','',str_replace(' 00','',$hex))); } # Check if the supplied string is an SNMP hex string function isHexString($str) { - return preg_match("/^[a-f0-9][a-f0-9]( [a-f0-9][a-f0-9])*$/is",trim($str)); + return preg_match("/^[a-f0-9][a-f0-9]( [a-f0-9][a-f0-9])*$/is",trim($str)); } # Include all .inc.php files in $dir function include_dir($dir, $regex = "") { - global $device, $config, $debug; - if ($regex == "") - { - $regex = "/\.inc\.php$/"; - } - - if ($handle = opendir($config['install_dir'] . '/' . $dir)) - { - while (false !== ($file = readdir($handle))) + global $device, $config, $debug; + if ($regex == "") { - if (filetype($config['install_dir'] . '/' . $dir . '/' . $file) == 'file' && preg_match($regex, $file)) - { - if ($debug) { echo("Including: " . $config['install_dir'] . '/' . $dir . '/' . $file . "\n"); } - include($config['install_dir'] . '/' . $dir . '/' . $file); - } + $regex = "/\.inc\.php$/"; } - closedir($handle); - } + if ($handle = opendir($config['install_dir'] . '/' . $dir)) + { + while (false !== ($file = readdir($handle))) + { + if (filetype($config['install_dir'] . '/' . $dir . '/' . $file) == 'file' && preg_match($regex, $file)) + { + if ($debug) { echo("Including: " . $config['install_dir'] . '/' . $dir . '/' . $file . "\n"); } + include($config['install_dir'] . '/' . $dir . '/' . $file); + } + } + + closedir($handle); + } } ?> diff --git a/includes/polling/applications.inc.php b/includes/polling/applications.inc.php index dcbf7982f3..1960c9fbc2 100644 --- a/includes/polling/applications.inc.php +++ b/includes/polling/applications.inc.php @@ -6,20 +6,20 @@ $app_data = mysql_query($sql); if (mysql_affected_rows()) { - echo('Applications: '); - while ($app = mysql_fetch_array($app_data)) - { - $app_include = $config['install_dir'].'/includes/polling/applications/'.$app['app_type'].'.inc.php'; - if (is_file($app_include)) + echo('Applications: '); + while ($app = mysql_fetch_array($app_data)) { - include($app_include); + $app_include = $config['install_dir'].'/includes/polling/applications/'.$app['app_type'].'.inc.php'; + if (is_file($app_include)) + { + include($app_include); + } + else + { + echo($app['app_type'].' include missing! '); + } } - else - { - echo($app['app_type'].' include missing! '); - } - } - echo("\n"); + echo("\n"); } -?> \ No newline at end of file +?> diff --git a/includes/polling/bgp-peers.inc.php b/includes/polling/bgp-peers.inc.php index e2eb659d3f..9edc336d66 100755 --- a/includes/polling/bgp-peers.inc.php +++ b/includes/polling/bgp-peers.inc.php @@ -4,240 +4,240 @@ echo("Polling BGP peers\n"); if (!$config['enable_bgp']) { - echo("BGP Support Disabled\n"); + echo("BGP Support Disabled\n"); } else { - $peers = mysql_query("SELECT * FROM bgpPeers WHERE device_id = '" . $device['device_id'] . "'"); - while ($peer = mysql_fetch_array($peers)) - { - ### Poll BGP Peer - - echo("Checking ".$peer['bgpPeerIdentifier']." "); - - if (!strstr($peer['bgpPeerIdentifier'],':')) + $peers = mysql_query("SELECT * FROM bgpPeers WHERE device_id = '" . $device['device_id'] . "'"); + while ($peer = mysql_fetch_array($peers)) { - # v4 BGP4 MIB - ## FIXME - needs moved to function - $peer_cmd = $config['snmpget'] . " -M ".$config['mibdir'] . " -m BGP4-MIB -OUvq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port'] . " "; - $peer_cmd .= "bgpPeerState." . $peer['bgpPeerIdentifier'] . " bgpPeerAdminStatus." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerOutUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerInTotalMessages." . $peer['bgpPeerIdentifier'] . " "; - $peer_cmd .= "bgpPeerOutTotalMessages." . $peer['bgpPeerIdentifier'] . " bgpPeerFsmEstablishedTime." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdateElapsedTime." . $peer['bgpPeerIdentifier'] . " "; - $peer_cmd .= "bgpPeerLocalAddr." . $peer['bgpPeerIdentifier'] . ""; - $peer_data = trim(`$peer_cmd`); - list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); - } - else - if ($device['os'] == "junos") - { - # v6 for JunOS via Juniper MIB - $peer_ip = ipv62snmp($peer['bgpPeerIdentifier']); + ### Poll BGP Peer - if (!isset($junos_v6)) - { - echo("\nCaching Oids..."); - ## FIXME - needs moved to function - $peer_cmd = $config['snmpwalk'] . " -M ".$config['mibdir'] . "/junos -m BGP4-V2-MIB-JUNIPER -OUnq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port']; - $peer_cmd .= " jnxBgpM2PeerStatus.0.ipv6"; - foreach (explode("\n",trim(`$peer_cmd`)) as $oid) + echo("Checking ".$peer['bgpPeerIdentifier']." "); + + if (!strstr($peer['bgpPeerIdentifier'],':')) { - list($peer_oid) = split(' ',$oid); - $peer_id = explode('.',$peer_oid); - $junos_v6[implode('.',array_slice($peer_id,35))] = implode('.',array_slice($peer_id,18)); + # v4 BGP4 MIB + ## FIXME - needs moved to function + $peer_cmd = $config['snmpget'] . " -M ".$config['mibdir'] . " -m BGP4-MIB -OUvq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port'] . " "; + $peer_cmd .= "bgpPeerState." . $peer['bgpPeerIdentifier'] . " bgpPeerAdminStatus." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerOutUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerInTotalMessages." . $peer['bgpPeerIdentifier'] . " "; + $peer_cmd .= "bgpPeerOutTotalMessages." . $peer['bgpPeerIdentifier'] . " bgpPeerFsmEstablishedTime." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdateElapsedTime." . $peer['bgpPeerIdentifier'] . " "; + $peer_cmd .= "bgpPeerLocalAddr." . $peer['bgpPeerIdentifier'] . ""; + $peer_data = trim(`$peer_cmd`); + list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); } - } - - ## FIXME - move to function (and clean up, wtf?) - $peer_cmd = $config['snmpget'] . " -M ".$config['mibdir'] . "/junos -m BGP4-V2-MIB-JUNIPER -OUvq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port']; - $peer_cmd .= " jnxBgpM2PeerState.0.ipv6." . $junos_v6[$peer_ip]; - $peer_cmd .= " jnxBgpM2PeerStatus.0.ipv6." . $junos_v6[$peer_ip]; # Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented? - $peer_cmd .= " jnxBgpM2PeerInUpdates.0.ipv6." . $junos_v6[$peer_ip]; - $peer_cmd .= " jnxBgpM2PeerOutUpdates.0.ipv6." . $junos_v6[$peer_ip]; - $peer_cmd .= " jnxBgpM2PeerInTotalMessages.0.ipv6." . $junos_v6[$peer_ip]; - $peer_cmd .= " jnxBgpM2PeerOutTotalMessages.0.ipv6." . $junos_v6[$peer_ip]; - $peer_cmd .= " jnxBgpM2PeerFsmEstablishedTime.0.ipv6." . $junos_v6[$peer_ip]; - $peer_cmd .= " jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6." . $junos_v6[$peer_ip]; - $peer_cmd .= " jnxBgpM2PeerLocalAddr.0.ipv6." . $junos_v6[$peer_ip]; - $peer_cmd .= ' -M"' . $config['install_dir'] . '/mibs/junos"|grep -v "No Such Instance"'; - if ($debug) echo("\n$peer_cmd\n"); - $peer_data = trim(`$peer_cmd`); - list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); - - if ($debug) { echo("State = $bgpPeerState - AdminStatus: $bgpPeerAdminStatus\n"); } - - $bgpLocalAddr = str_replace('"','',str_replace(' ','',$bgpLocalAddr)); - if ($bgpLocalAddr == "00000000000000000000000000000000") - { - $bgpLocalAddr = ''; # Unknown? - } - else - { - $bgpLocalAddr = strtolower($bgpLocalAddr); - for ($i = 0;$i < 32;$i+=4) - { - $bgpLocalAddr6[] = substr($bgpLocalAddr,$i,4); - } - $bgpLocalAddr = Net_IPv6::compress(implode(':',$bgpLocalAddr6)); unset($bgpLocalAddr6); - } - } - - if ($bgpPeerFsmEstablishedTime) - { - if ($bgpPeerFsmEstablishedTime < $peer['bgpPeerFsmEstablishedTime'] || $bgpPeerState != $peer['bgpPeerState']) - { - if ($peer['bgpPeerState'] == $bgpPeerState) - { - notify($device, "BGP Session flapped: " . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ' - ' . $peer['astext'] . ')', "BGP Session flapped " . formatUptime($bgpPeerFsmEstablishedTime) . " ago.\n\nHostname : " . $device['hostname'] . "\nPeer IP : " . $peer['bgpPeerIdentifier'] . "\nRemote AS: " . $peer['bgpPeerRemoteAs'] . ' ('.$peer['astext'].')'); - log_event('BGP Session Flap: ' . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ')', $device['device_id'], 'bgpPeer', $bgpPeer_id); - } - else if ($bgpPeerState == "established") - { - notify($device, "BGP Session up: " . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ' - ' . $peer['astext'] . ')', "BGP Session up since " . formatUptime($bgpPeerFsmEstablishedTime) . ".\n\nHostname : " . $device['hostname'] . "\nPeer IP : " . $peer['bgpPeerIdentifier'] . "\nRemote AS: " . $peer['bgpPeerRemoteAs'] . ' ('.$peer['astext'].')'); - log_event('BGP Session Up: ' . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ')', $device['device_id'], 'bgpPeer', $bgpPeer_id); - } - else if ($peer['bgpPeerState'] == "established") - { - notify($device, "BGP Session down: " . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ' - ' . $peer['astext'] . ')', "BGP Session down since " . formatUptime($bgpPeerFsmEstablishedTime) . ".\n\nHostname : " . $device['hostname'] . "\nPeer IP : " . $peer['bgpPeerIdentifier'] . "\nRemote AS: " . $peer['bgpPeerRemoteAs'] . ' ('.$peer['astext'].')'); - log_event('BGP Session Down: ' . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ')', $device['device_id'], 'bgpPeer', $bgpPeer_id); - } - } - } - - $peerrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("bgp-" . $peer['bgpPeerIdentifier'] . ".rrd"); - if (!is_file($peerrrd)) - { - $create_rrd = "DS:bgpPeerOutUpdates:COUNTER:600:U:100000000000 \ - DS:bgpPeerInUpdates:COUNTER:600:U:100000000000 \ - DS:bgpPeerOutTotal:COUNTER:600:U:100000000000 \ - DS:bgpPeerInTotal:COUNTER:600:U:100000000000 \ - DS:bgpPeerEstablished:GAUGE:600:0:U \ - RRA:AVERAGE:0.5:1:600 \ - RRA:AVERAGE:0.5:6:700 \ - RRA:AVERAGE:0.5:24:775 \ - RRA:AVERAGE:0.5:288:797 \ - RRA:MAX:0.5:1:600 \ - RRA:MAX:0.5:6:700 \ - RRA:MAX:0.5:24:775 \ - RRA:MAX:0.5:288:797"; - - rrdtool_create($peerrrd, $create_rrd); - } - - rrdtool_update("$peerrrd", "N:$bgpPeerOutUpdates:$bgpPeerInUpdates:$bgpPeerOutTotalMessages:$bgpPeerInTotalMesages:$bgpPeerFsmEstablishedTime"); - - $update = "UPDATE bgpPeers SET bgpPeerState = '$bgpPeerState', bgpPeerAdminStatus = '$bgpPeerAdminStatus', "; - $update .= "bgpPeerFsmEstablishedTime = '$bgpPeerFsmEstablishedTime', bgpPeerInUpdates = '$bgpPeerInUpdates' , bgpLocalAddr = '$bgpLocalAddr' , bgpPeerOutUpdates = '$bgpPeerOutUpdates'"; - $update .= " WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '" . $peer['bgpPeerIdentifier'] . "'"; - mysql_query($update); - - if ($device['os_group'] == "ios" || $device['os'] == "junos") - { - ## Poll each AFI/SAFI for this peer (using CISCO-BGP4-MIB or BGP4-V2-JUNIPER MIB) - $afi_query = mysql_query("SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '" . $peer['bgpPeerIdentifier'] . "'"); - while ($peer_afi = mysql_fetch_assoc($afi_query)) - { - $afi = $peer_afi['afi']; - $safi = $peer_afi['safi']; - if ($debug) { echo("$afi $safi". $config['afi'][$afi][$safi]. "\n"); } - - if ($device['os_group'] == "ios") - { - ## FIXME - move to function - $cbgp_cmd = $config['snmpget'] . " -M ".$config['mibdir'] . " -m CISCO-BGP4-MIB -Ovq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port']; - $cbgp_cmd .= " cbgpPeerAcceptedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; - $cbgp_cmd .= " cbgpPeerDeniedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; - $cbgp_cmd .= " cbgpPeerPrefixAdminLimit." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; - $cbgp_cmd .= " cbgpPeerPrefixThreshold." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; - $cbgp_cmd .= " cbgpPeerPrefixClearThreshold." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; - $cbgp_cmd .= " cbgpPeerAdvertisedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; - $cbgp_cmd .= " cbgpPeerSuppressedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; - $cbgp_cmd .= " cbgpPeerWithdrawnPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; - - if ($debug) { echo("$cbgp_cmd\n"); } - $cbgp_data = preg_replace("/^OID.*$/", "", trim(`$cbgp_cmd`)); - if ($debug) { echo("$cbgp_data\n"); } - list($cbgpPeerAcceptedPrefixes,$cbgpPeerDeniedPrefixes,$cbgpPeerPrefixAdminLimit,$cbgpPeerPrefixThreshold,$cbgpPeerPrefixClearThreshold,$cbgpPeerAdvertisedPrefixes,$cbgpPeerSuppressedPrefixes,$cbgpPeerWithdrawnPrefixes) = explode("\n", $cbgp_data); - } - - if ($device['os'] == "junos") - { - # Missing: cbgpPeerAdminLimit cbgpPeerPrefixThreshold cbgpPeerPrefixClearThreshold cbgpPeerSuppressedPrefixes cbgpPeerWithdrawnPrefixes - - $safis['unicast'] = 1; - $safis['multicast'] = 2; - - if (!isset($peerIndexes)) - { - $j_bgp = snmpwalk_cache_multi_oid($device, "jnxBgpM2PeerTable", $jbgp, "BGP4-V2-MIB-JUNIPER", $config['install_dir']."/mibs/junos"); - foreach ($j_bgp as $index => $entry) + else + if ($device['os'] == "junos") { - switch ($entry['jnxBgpM2PeerRemoteAddrType']) - { - case 'ipv4': - $ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr'])); - $j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex']; - break; - case 'ipv6': - $ip6 = trim(str_replace(' ','',$entry['jnxBgpM2PeerRemoteAddr']),'"'); - $ip6 = substr($ip6,0,4) . ':' . substr($ip6,4,4) . ':' . substr($ip6,8,4) . ':' . substr($ip6,12,4) . ':' . substr($ip6,16,4) . ':' . substr($ip6,20,4) . ':' . substr($ip6,24,4) . ':' . substr($ip6,28,4); - $ip6 = Net_IPv6::compress($ip6); - $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; - break; - default: - echo("PANIC: Don't know RemoteAddrType " . $entry['jnxBgpM2PeerRemoteAddrType'] . "!\n"); - break; - } + # v6 for JunOS via Juniper MIB + $peer_ip = ipv62snmp($peer['bgpPeerIdentifier']); + + if (!isset($junos_v6)) + { + echo("\nCaching Oids..."); + ## FIXME - needs moved to function + $peer_cmd = $config['snmpwalk'] . " -M ".$config['mibdir'] . "/junos -m BGP4-V2-MIB-JUNIPER -OUnq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port']; + $peer_cmd .= " jnxBgpM2PeerStatus.0.ipv6"; + foreach (explode("\n",trim(`$peer_cmd`)) as $oid) + { + list($peer_oid) = split(' ',$oid); + $peer_id = explode('.',$peer_oid); + $junos_v6[implode('.',array_slice($peer_id,35))] = implode('.',array_slice($peer_id,18)); + } + } + + ## FIXME - move to function (and clean up, wtf?) + $peer_cmd = $config['snmpget'] . " -M ".$config['mibdir'] . "/junos -m BGP4-V2-MIB-JUNIPER -OUvq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port']; + $peer_cmd .= " jnxBgpM2PeerState.0.ipv6." . $junos_v6[$peer_ip]; + $peer_cmd .= " jnxBgpM2PeerStatus.0.ipv6." . $junos_v6[$peer_ip]; # Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented? + $peer_cmd .= " jnxBgpM2PeerInUpdates.0.ipv6." . $junos_v6[$peer_ip]; + $peer_cmd .= " jnxBgpM2PeerOutUpdates.0.ipv6." . $junos_v6[$peer_ip]; + $peer_cmd .= " jnxBgpM2PeerInTotalMessages.0.ipv6." . $junos_v6[$peer_ip]; + $peer_cmd .= " jnxBgpM2PeerOutTotalMessages.0.ipv6." . $junos_v6[$peer_ip]; + $peer_cmd .= " jnxBgpM2PeerFsmEstablishedTime.0.ipv6." . $junos_v6[$peer_ip]; + $peer_cmd .= " jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6." . $junos_v6[$peer_ip]; + $peer_cmd .= " jnxBgpM2PeerLocalAddr.0.ipv6." . $junos_v6[$peer_ip]; + $peer_cmd .= ' -M"' . $config['install_dir'] . '/mibs/junos"|grep -v "No Such Instance"'; + if ($debug) echo("\n$peer_cmd\n"); + $peer_data = trim(`$peer_cmd`); + list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); + + if ($debug) { echo("State = $bgpPeerState - AdminStatus: $bgpPeerAdminStatus\n"); } + + $bgpLocalAddr = str_replace('"','',str_replace(' ','',$bgpLocalAddr)); + if ($bgpLocalAddr == "00000000000000000000000000000000") + { + $bgpLocalAddr = ''; # Unknown? + } + else + { + $bgpLocalAddr = strtolower($bgpLocalAddr); + for ($i = 0;$i < 32;$i+=4) + { + $bgpLocalAddr6[] = substr($bgpLocalAddr,$i,4); + } + $bgpLocalAddr = Net_IPv6::compress(implode(':',$bgpLocalAddr6)); unset($bgpLocalAddr6); + } } - } - $j_prefixes = snmpwalk_cache_multi_oid($device, "jnxBgpM2PrefixCountersTable", $jbgp, "BGP4-V2-MIB-JUNIPER", $config['install_dir']."/mibs/junos"); - - $cbgpPeerAcceptedPrefixes = $j_prefixes[$j_peerIndexes[$peer['bgpPeerIdentifier']].".$afi." . $safis[$safi]]['jnxBgpM2PrefixInPrefixesAccepted']; - $cbgpPeerDeniedPrefixes = $j_prefixes[$j_peerIndexes[$peer['bgpPeerIdentifier']].".$afi." . $safis[$safi]]['jnxBgpM2PrefixInPrefixesRejected']; - $cbgpPeerAdvertisedPrefixes = $j_prefixes[$j_peerIndexes[$peer['bgpPeerIdentifier']].".$afi." . $safis[$safi]]['jnxBgpM2PrefixOutPrefixes']; - - unset($j_prefixes); - unset($j_bgp); - unset($j_peerIndexes); + if ($bgpPeerFsmEstablishedTime) + { + if ($bgpPeerFsmEstablishedTime < $peer['bgpPeerFsmEstablishedTime'] || $bgpPeerState != $peer['bgpPeerState']) + { + if ($peer['bgpPeerState'] == $bgpPeerState) + { + notify($device, "BGP Session flapped: " . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ' - ' . $peer['astext'] . ')', "BGP Session flapped " . formatUptime($bgpPeerFsmEstablishedTime) . " ago.\n\nHostname : " . $device['hostname'] . "\nPeer IP : " . $peer['bgpPeerIdentifier'] . "\nRemote AS: " . $peer['bgpPeerRemoteAs'] . ' ('.$peer['astext'].')'); + log_event('BGP Session Flap: ' . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ')', $device['device_id'], 'bgpPeer', $bgpPeer_id); + } + else if ($bgpPeerState == "established") + { + notify($device, "BGP Session up: " . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ' - ' . $peer['astext'] . ')', "BGP Session up since " . formatUptime($bgpPeerFsmEstablishedTime) . ".\n\nHostname : " . $device['hostname'] . "\nPeer IP : " . $peer['bgpPeerIdentifier'] . "\nRemote AS: " . $peer['bgpPeerRemoteAs'] . ' ('.$peer['astext'].')'); + log_event('BGP Session Up: ' . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ')', $device['device_id'], 'bgpPeer', $bgpPeer_id); + } + else if ($peer['bgpPeerState'] == "established") + { + notify($device, "BGP Session down: " . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ' - ' . $peer['astext'] . ')', "BGP Session down since " . formatUptime($bgpPeerFsmEstablishedTime) . ".\n\nHostname : " . $device['hostname'] . "\nPeer IP : " . $peer['bgpPeerIdentifier'] . "\nRemote AS: " . $peer['bgpPeerRemoteAs'] . ' ('.$peer['astext'].')'); + log_event('BGP Session Down: ' . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ')', $device['device_id'], 'bgpPeer', $bgpPeer_id); + } + } } - # FIXME THESE FIELDS DO NOT EXIST IN THE DATABASE! - $update = "UPDATE bgpPeers_cbgp SET"; - $update .= " `cbgpPeerAcceptedPrefixes` = '$cbgpPeerAcceptedPrefixes'"; - $update .= ", `cbgpPeerDeniedPrefixes` = '$cbgpPeerDeniedPrefixes'"; - $update .= ", `cbgpPeerPrefixAdminLimit` = '$cbgpPeerAdminLimit'"; - $update .= ", `cbgpPeerPrefixThreshold` = '$cbgpPeerPrefixThreshold'"; - $update .= ", `cbgpPeerPrefixClearThreshold` = '$cbgpPeerPrefixClearThreshold'"; - $update .= ", `cbgpPeerAdvertisedPrefixes` = '$cbgpPeerAdvertisedPrefixes'"; - $update .= ", `cbgpPeerSuppressedPrefixes` = '$cbgpPeerSuppressedPrefixes'"; - $update .= ", `cbgpPeerWithdrawnPrefixes` = '$cbgpPeerWithdrawnPrefixes'"; - $update .= " WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '" . $peer['bgpPeerIdentifier'] . "' AND afi = '$afi' AND safi = '$safi'"; - if ($debug) { echo("MYSQL: $update\n"); } + $peerrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("bgp-" . $peer['bgpPeerIdentifier'] . ".rrd"); + if (!is_file($peerrrd)) + { + $create_rrd = "DS:bgpPeerOutUpdates:COUNTER:600:U:100000000000 \ + DS:bgpPeerInUpdates:COUNTER:600:U:100000000000 \ + DS:bgpPeerOutTotal:COUNTER:600:U:100000000000 \ + DS:bgpPeerInTotal:COUNTER:600:U:100000000000 \ + DS:bgpPeerEstablished:GAUGE:600:0:U \ + RRA:AVERAGE:0.5:1:600 \ + RRA:AVERAGE:0.5:6:700 \ + RRA:AVERAGE:0.5:24:775 \ + RRA:AVERAGE:0.5:288:797 \ + RRA:MAX:0.5:1:600 \ + RRA:MAX:0.5:6:700 \ + RRA:MAX:0.5:24:775 \ + RRA:MAX:0.5:288:797"; + + rrdtool_create($peerrrd, $create_rrd); + } + + rrdtool_update("$peerrrd", "N:$bgpPeerOutUpdates:$bgpPeerInUpdates:$bgpPeerOutTotalMessages:$bgpPeerInTotalMesages:$bgpPeerFsmEstablishedTime"); + + $update = "UPDATE bgpPeers SET bgpPeerState = '$bgpPeerState', bgpPeerAdminStatus = '$bgpPeerAdminStatus', "; + $update .= "bgpPeerFsmEstablishedTime = '$bgpPeerFsmEstablishedTime', bgpPeerInUpdates = '$bgpPeerInUpdates' , bgpLocalAddr = '$bgpLocalAddr' , bgpPeerOutUpdates = '$bgpPeerOutUpdates'"; + $update .= " WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '" . $peer['bgpPeerIdentifier'] . "'"; mysql_query($update); - $cbgp_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("cbgp-" . $peer['bgpPeerIdentifier'] . ".$afi.$safi.rrd"); - if (!is_file($cbgp_rrd)) + if ($device['os_group'] == "ios" || $device['os'] == "junos") { - $rrd_create = "DS:AcceptedPrefixes:GAUGE:600:U:100000000000 \ - DS:DeniedPrefixes:GAUGE:600:U:100000000000 \ - DS:AdvertisedPrefixes:GAUGE:600:U:100000000000 \ - DS:SuppressedPrefixes:GAUGE:600:U:100000000000 \ - DS:WithdrawnPrefixes:GAUGE:600:U:100000000000 \ - RRA:AVERAGE:0.5:1:600 \ - RRA:AVERAGE:0.5:6:700 \ - RRA:AVERAGE:0.5:24:775 \ - RRA:AVERAGE:0.5:288:797 \ - RRA:MAX:0.5:1:600 \ - RRA:MAX:0.5:6:700 \ - RRA:MAX:0.5:24:775 \ - RRA:MAX:0.5:288:797"; - rrdtool_create($cbgp_rrd, $rrd_create); - } - rrdtool_update("$cbgp_rrd", "N:$cbgpPeerAcceptedPrefixes:$cbgpPeerDeniedPrefixes:$cbgpPeerAdvertisedPrefixes:$cbgpPeerSuppressedPrefixes:$cbgpPeerWithdrawnPrefixes"); - } # while - } # os=ios | junos - echo("\n"); + ## Poll each AFI/SAFI for this peer (using CISCO-BGP4-MIB or BGP4-V2-JUNIPER MIB) + $afi_query = mysql_query("SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '" . $peer['bgpPeerIdentifier'] . "'"); + while ($peer_afi = mysql_fetch_assoc($afi_query)) + { + $afi = $peer_afi['afi']; + $safi = $peer_afi['safi']; + if ($debug) { echo("$afi $safi". $config['afi'][$afi][$safi]. "\n"); } - } ## End While loop on peers + if ($device['os_group'] == "ios") + { + ## FIXME - move to function + $cbgp_cmd = $config['snmpget'] . " -M ".$config['mibdir'] . " -m CISCO-BGP4-MIB -Ovq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port']; + $cbgp_cmd .= " cbgpPeerAcceptedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $cbgp_cmd .= " cbgpPeerDeniedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $cbgp_cmd .= " cbgpPeerPrefixAdminLimit." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $cbgp_cmd .= " cbgpPeerPrefixThreshold." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $cbgp_cmd .= " cbgpPeerPrefixClearThreshold." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $cbgp_cmd .= " cbgpPeerAdvertisedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $cbgp_cmd .= " cbgpPeerSuppressedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $cbgp_cmd .= " cbgpPeerWithdrawnPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + + if ($debug) { echo("$cbgp_cmd\n"); } + $cbgp_data = preg_replace("/^OID.*$/", "", trim(`$cbgp_cmd`)); + if ($debug) { echo("$cbgp_data\n"); } + list($cbgpPeerAcceptedPrefixes,$cbgpPeerDeniedPrefixes,$cbgpPeerPrefixAdminLimit,$cbgpPeerPrefixThreshold,$cbgpPeerPrefixClearThreshold,$cbgpPeerAdvertisedPrefixes,$cbgpPeerSuppressedPrefixes,$cbgpPeerWithdrawnPrefixes) = explode("\n", $cbgp_data); + } + + if ($device['os'] == "junos") + { + # Missing: cbgpPeerAdminLimit cbgpPeerPrefixThreshold cbgpPeerPrefixClearThreshold cbgpPeerSuppressedPrefixes cbgpPeerWithdrawnPrefixes + + $safis['unicast'] = 1; + $safis['multicast'] = 2; + + if (!isset($peerIndexes)) + { + $j_bgp = snmpwalk_cache_multi_oid($device, "jnxBgpM2PeerTable", $jbgp, "BGP4-V2-MIB-JUNIPER", $config['install_dir']."/mibs/junos"); + foreach ($j_bgp as $index => $entry) + { + switch ($entry['jnxBgpM2PeerRemoteAddrType']) + { + case 'ipv4': + $ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr'])); + $j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex']; + break; + case 'ipv6': + $ip6 = trim(str_replace(' ','',$entry['jnxBgpM2PeerRemoteAddr']),'"'); + $ip6 = substr($ip6,0,4) . ':' . substr($ip6,4,4) . ':' . substr($ip6,8,4) . ':' . substr($ip6,12,4) . ':' . substr($ip6,16,4) . ':' . substr($ip6,20,4) . ':' . substr($ip6,24,4) . ':' . substr($ip6,28,4); + $ip6 = Net_IPv6::compress($ip6); + $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; + break; + default: + echo("PANIC: Don't know RemoteAddrType " . $entry['jnxBgpM2PeerRemoteAddrType'] . "!\n"); + break; + } + } + } + + $j_prefixes = snmpwalk_cache_multi_oid($device, "jnxBgpM2PrefixCountersTable", $jbgp, "BGP4-V2-MIB-JUNIPER", $config['install_dir']."/mibs/junos"); + + $cbgpPeerAcceptedPrefixes = $j_prefixes[$j_peerIndexes[$peer['bgpPeerIdentifier']].".$afi." . $safis[$safi]]['jnxBgpM2PrefixInPrefixesAccepted']; + $cbgpPeerDeniedPrefixes = $j_prefixes[$j_peerIndexes[$peer['bgpPeerIdentifier']].".$afi." . $safis[$safi]]['jnxBgpM2PrefixInPrefixesRejected']; + $cbgpPeerAdvertisedPrefixes = $j_prefixes[$j_peerIndexes[$peer['bgpPeerIdentifier']].".$afi." . $safis[$safi]]['jnxBgpM2PrefixOutPrefixes']; + + unset($j_prefixes); + unset($j_bgp); + unset($j_peerIndexes); + } + + # FIXME THESE FIELDS DO NOT EXIST IN THE DATABASE! + $update = "UPDATE bgpPeers_cbgp SET"; + $update .= " `cbgpPeerAcceptedPrefixes` = '$cbgpPeerAcceptedPrefixes'"; + $update .= ", `cbgpPeerDeniedPrefixes` = '$cbgpPeerDeniedPrefixes'"; + $update .= ", `cbgpPeerPrefixAdminLimit` = '$cbgpPeerAdminLimit'"; + $update .= ", `cbgpPeerPrefixThreshold` = '$cbgpPeerPrefixThreshold'"; + $update .= ", `cbgpPeerPrefixClearThreshold` = '$cbgpPeerPrefixClearThreshold'"; + $update .= ", `cbgpPeerAdvertisedPrefixes` = '$cbgpPeerAdvertisedPrefixes'"; + $update .= ", `cbgpPeerSuppressedPrefixes` = '$cbgpPeerSuppressedPrefixes'"; + $update .= ", `cbgpPeerWithdrawnPrefixes` = '$cbgpPeerWithdrawnPrefixes'"; + $update .= " WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '" . $peer['bgpPeerIdentifier'] . "' AND afi = '$afi' AND safi = '$safi'"; + if ($debug) { echo("MYSQL: $update\n"); } + mysql_query($update); + + $cbgp_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("cbgp-" . $peer['bgpPeerIdentifier'] . ".$afi.$safi.rrd"); + if (!is_file($cbgp_rrd)) + { + $rrd_create = "DS:AcceptedPrefixes:GAUGE:600:U:100000000000 \ + DS:DeniedPrefixes:GAUGE:600:U:100000000000 \ + DS:AdvertisedPrefixes:GAUGE:600:U:100000000000 \ + DS:SuppressedPrefixes:GAUGE:600:U:100000000000 \ + DS:WithdrawnPrefixes:GAUGE:600:U:100000000000 \ + RRA:AVERAGE:0.5:1:600 \ + RRA:AVERAGE:0.5:6:700 \ + RRA:AVERAGE:0.5:24:775 \ + RRA:AVERAGE:0.5:288:797 \ + RRA:MAX:0.5:1:600 \ + RRA:MAX:0.5:6:700 \ + RRA:MAX:0.5:24:775 \ + RRA:MAX:0.5:288:797"; + rrdtool_create($cbgp_rrd, $rrd_create); + } + rrdtool_update("$cbgp_rrd", "N:$cbgpPeerAcceptedPrefixes:$cbgpPeerDeniedPrefixes:$cbgpPeerAdvertisedPrefixes:$cbgpPeerSuppressedPrefixes:$cbgpPeerWithdrawnPrefixes"); + } # while + } # os=ios | junos + echo("\n"); + + } ## End While loop on peers } ## End check for BGP support -?> \ No newline at end of file +?> diff --git a/includes/polling/netstats-icmp.inc.php b/includes/polling/netstats-icmp.inc.php index e57efe0236..54b6f1765f 100755 --- a/includes/polling/netstats-icmp.inc.php +++ b/includes/polling/netstats-icmp.inc.php @@ -2,55 +2,55 @@ if ($device['os'] != "Snom") { - echo(" ICMP"); + echo(" ICMP"); - #### Below have more oids, and are in trees by themselves, so we can snmpwalk_cache_oid them + #### Below have more oids, and are in trees by themselves, so we can snmpwalk_cache_oid them - $oids = array('icmpInMsgs','icmpOutMsgs','icmpInErrors','icmpOutErrors','icmpInEchos','icmpOutEchos','icmpInEchoReps', - 'icmpOutEchoReps','icmpInDestUnreachs','icmpOutDestUnreachs','icmpInParmProbs','icmpInTimeExcds', - 'icmpInSrcQuenchs','icmpInRedirects','icmpInTimestamps','icmpInTimestampReps','icmpInAddrMasks', - 'icmpInAddrMaskReps','icmpOutTimeExcds','icmpOutParmProbs','icmpOutSrcQuenchs','icmpOutRedirects', - 'icmpOutTimestamps','icmpOutTimestampReps','icmpOutAddrMasks','icmpOutAddrMaskReps'); + $oids = array('icmpInMsgs','icmpOutMsgs','icmpInErrors','icmpOutErrors','icmpInEchos','icmpOutEchos','icmpInEchoReps', + 'icmpOutEchoReps','icmpInDestUnreachs','icmpOutDestUnreachs','icmpInParmProbs','icmpInTimeExcds', + 'icmpInSrcQuenchs','icmpInRedirects','icmpInTimestamps','icmpInTimestampReps','icmpInAddrMasks', + 'icmpInAddrMaskReps','icmpOutTimeExcds','icmpOutParmProbs','icmpOutSrcQuenchs','icmpOutRedirects', + 'icmpOutTimestamps','icmpOutTimestampReps','icmpOutAddrMasks','icmpOutAddrMaskReps'); - unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create); - $rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-icmp.rrd"; + unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create); + $rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-icmp.rrd"; - $rrd_create = "RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797 RRA:MAX:0.5:1:600 \ - RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797"; + $rrd_create = "RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797 RRA:MAX:0.5:1:600 \ + RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797"; - foreach ($oids as $oid) - { - $oid_ds = truncate($oid, 19, ''); - $rrd_create .= " DS:$oid_ds:COUNTER:600:U:100000000000"; - $snmpstring .= " $oid.0"; - } - - $data_array = snmpwalk_cache_oid($device, "icmp", array()); - - $rrdupdate = "N"; - - foreach ($oids as $oid) - { - if (is_numeric($data_array[0][$oid])) + foreach ($oids as $oid) { - $value = $data_array[0][$oid]; - } else { - $value = "0"; + $oid_ds = truncate($oid, 19, ''); + $rrd_create .= " DS:$oid_ds:COUNTER:600:U:100000000000"; + $snmpstring .= " $oid.0"; } - $rrdupdate .= ":$value"; - } - unset($snmpstring); + $data_array = snmpwalk_cache_oid($device, "icmp", array()); - if (isset($data_array[0]['icmpInMsgs']) && isset($data_array[0]['icmpOutMsgs'])) - { - if (!file_exists($rrd_file)) { rrdtool_create($rrd_file, $rrd_create); } - rrdtool_update($rrd_file, $rrdupdate); - $graphs['netstat_icmp'] = TRUE; - $graphs['netstat_icmp_info'] = TRUE; - } + $rrdupdate = "N"; - unset($oids, $data, $data_array, $oid, $protos); + foreach ($oids as $oid) + { + if (is_numeric($data_array[0][$oid])) + { + $value = $data_array[0][$oid]; + } else { + $value = "0"; + } + $rrdupdate .= ":$value"; + } + + unset($snmpstring); + + if (isset($data_array[0]['icmpInMsgs']) && isset($data_array[0]['icmpOutMsgs'])) + { + if (!file_exists($rrd_file)) { rrdtool_create($rrd_file, $rrd_create); } + rrdtool_update($rrd_file, $rrdupdate); + $graphs['netstat_icmp'] = TRUE; + $graphs['netstat_icmp_info'] = TRUE; + } + + unset($oids, $data, $data_array, $oid, $protos); } -?> \ No newline at end of file +?> diff --git a/includes/polling/netstats-ip.inc.php b/includes/polling/netstats-ip.inc.php index 7ce35949ec..bc342c082a 100755 --- a/includes/polling/netstats-ip.inc.php +++ b/includes/polling/netstats-ip.inc.php @@ -2,52 +2,52 @@ if ($device['os'] != "Snom") { - echo(" IP"); + echo(" IP"); - #### These are at the start of large trees that we don't want to walk the entirety of, so we snmp_get_multi them + #### These are at the start of large trees that we don't want to walk the entirety of, so we snmp_get_multi them - $oids = array ('ipForwDatagrams','ipInDelivers','ipInReceives','ipOutRequests','ipInDiscards','ipOutDiscards','ipOutNoRoutes', - 'ipReasmReqds','ipReasmOKs','ipReasmFails','ipFragOKs','ipFragFails','ipFragCreates', 'ipInUnknownProtos', - 'ipInHdrErrors', 'ipInAddrErrors'); + $oids = array ('ipForwDatagrams','ipInDelivers','ipInReceives','ipOutRequests','ipInDiscards','ipOutDiscards','ipOutNoRoutes', + 'ipReasmReqds','ipReasmOKs','ipReasmFails','ipFragOKs','ipFragFails','ipFragCreates', 'ipInUnknownProtos', + 'ipInHdrErrors', 'ipInAddrErrors'); - unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create); - $rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-ip.rrd"; + unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create); + $rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-ip.rrd"; - $rrd_create = "RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797 RRA:MAX:0.5:1:600 \ - RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797"; + $rrd_create = "RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797 RRA:MAX:0.5:1:600 \ + RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797"; - foreach ($oids as $oid) - { - $oid_ds = truncate($oid, 19, ''); - $rrd_create .= " DS:$oid_ds:COUNTER:600:U:100000000000"; - $snmpstring .= " $oid.0"; - } - - $data = snmp_get_multi($device, $snmpstring); - - $rrdupdate = "N"; - - foreach ($oids as $oid) - { - if (is_numeric($data[0][$oid])) + foreach ($oids as $oid) { - $value = $data[0][$oid]; - } else { - $value = "0"; + $oid_ds = truncate($oid, 19, ''); + $rrd_create .= " DS:$oid_ds:COUNTER:600:U:100000000000"; + $snmpstring .= " $oid.0"; } - $rrdupdate .= ":$value"; - } - if (isset($data[0]['ipOutRequests']) && isset($data[0]['ipInReceives'])) - { - if (!file_exists($rrd_file)) { rrdtool_create($rrd_file, $rrd_create); } - rrdtool_update($rrd_file, $rrdupdate); - $graphs['netstat_ip'] = TRUE; - $graphs['netstat_ip_frag'] = TRUE; - } + $data = snmp_get_multi($device, $snmpstring); + + $rrdupdate = "N"; + + foreach ($oids as $oid) + { + if (is_numeric($data[0][$oid])) + { + $value = $data[0][$oid]; + } else { + $value = "0"; + } + $rrdupdate .= ":$value"; + } + + if (isset($data[0]['ipOutRequests']) && isset($data[0]['ipInReceives'])) + { + if (!file_exists($rrd_file)) { rrdtool_create($rrd_file, $rrd_create); } + rrdtool_update($rrd_file, $rrdupdate); + $graphs['netstat_ip'] = TRUE; + $graphs['netstat_ip_frag'] = TRUE; + } } unset($oids, $data, $data_array, $oid); -?> \ No newline at end of file +?> diff --git a/includes/polling/netstats-snmp.inc.php b/includes/polling/netstats-snmp.inc.php index c41f2387ed..2abd70a424 100755 --- a/includes/polling/netstats-snmp.inc.php +++ b/includes/polling/netstats-snmp.inc.php @@ -2,51 +2,51 @@ if ($device['os'] != "Snom") { - echo(" SNMP"); + echo(" SNMP"); - #### Below have more oids, and are in trees by themselves, so we can snmpwalk_cache_oid them + #### Below have more oids, and are in trees by themselves, so we can snmpwalk_cache_oid them - $oids = array ('snmpInPkts','snmpOutPkts','snmpInBadVersions','snmpInBadCommunityNames','snmpInBadCommunityUses','snmpInASNParseErrs', - 'snmpInTooBigs','snmpInNoSuchNames','snmpInBadValues','snmpInReadOnlys','snmpInGenErrs','snmpInTotalReqVars','snmpInTotalSetVars', - 'snmpInGetRequests','snmpInGetNexts','snmpInSetRequests','snmpInGetResponses','snmpInTraps','snmpOutTooBigs','snmpOutNoSuchNames', - 'snmpOutBadValues','snmpOutGenErrs','snmpOutGetRequests','snmpOutGetNexts','snmpOutSetRequests','snmpOutGetResponses','snmpOutTraps','snmpSilentDrops','snmpProxyDrops'); + $oids = array ('snmpInPkts','snmpOutPkts','snmpInBadVersions','snmpInBadCommunityNames','snmpInBadCommunityUses','snmpInASNParseErrs', + 'snmpInTooBigs','snmpInNoSuchNames','snmpInBadValues','snmpInReadOnlys','snmpInGenErrs','snmpInTotalReqVars','snmpInTotalSetVars', + 'snmpInGetRequests','snmpInGetNexts','snmpInSetRequests','snmpInGetResponses','snmpInTraps','snmpOutTooBigs','snmpOutNoSuchNames', + 'snmpOutBadValues','snmpOutGenErrs','snmpOutGetRequests','snmpOutGetNexts','snmpOutSetRequests','snmpOutGetResponses','snmpOutTraps','snmpSilentDrops','snmpProxyDrops'); - unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create); - $rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("netstats-snmp.rrd"); + unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create); + $rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("netstats-snmp.rrd"); - $rrd_create = "RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797 RRA:MAX:0.5:1:600 \ - RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797"; + $rrd_create = "RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797 RRA:MAX:0.5:1:600 \ + RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797"; - foreach ($oids as $oid) - { - $oid_ds = truncate($oid, 19, ''); - $rrd_create .= " DS:$oid_ds:COUNTER:600:U:100000000000"; - } - - $data_array = snmpwalk_cache_oid($device, "snmp", array()); - - $rrdupdate = "N"; - - foreach ($oids as $oid) - { - if (is_numeric($data_array[0][$oid])) + foreach ($oids as $oid) { - $value = $data_array[0][$oid]; - } else { - $value = "0"; + $oid_ds = truncate($oid, 19, ''); + $rrd_create .= " DS:$oid_ds:COUNTER:600:U:100000000000"; } - $rrdupdate .= ":$value"; - } - if (isset($data_array[0]['snmpInPkts']) && isset($data_array[0]['snmpOutPkts'])) - { - if (!file_exists($rrd_file)) { rrdtool_create($rrd_file, $rrd_create); } - rrdtool_update($rrd_file, $rrdupdate); - $graphs['netstat_snmp'] = TRUE; - $graphs['netstat_snmp_pkt'] = TRUE; - } + $data_array = snmpwalk_cache_oid($device, "snmp", array()); - unset($oids, $data, $data_array, $oid, $protos); + $rrdupdate = "N"; + + foreach ($oids as $oid) + { + if (is_numeric($data_array[0][$oid])) + { + $value = $data_array[0][$oid]; + } else { + $value = "0"; + } + $rrdupdate .= ":$value"; + } + + if (isset($data_array[0]['snmpInPkts']) && isset($data_array[0]['snmpOutPkts'])) + { + if (!file_exists($rrd_file)) { rrdtool_create($rrd_file, $rrd_create); } + rrdtool_update($rrd_file, $rrdupdate); + $graphs['netstat_snmp'] = TRUE; + $graphs['netstat_snmp_pkt'] = TRUE; + } + + unset($oids, $data, $data_array, $oid, $protos); } -?> \ No newline at end of file +?> diff --git a/includes/polling/netstats-tcp.inc.php b/includes/polling/netstats-tcp.inc.php index 6220329814..c1938a2ac3 100755 --- a/includes/polling/netstats-tcp.inc.php +++ b/includes/polling/netstats-tcp.inc.php @@ -2,56 +2,56 @@ if ($device['os'] != "Snom") { - echo(" TCP"); + echo(" TCP"); - $oids = array ('tcpActiveOpens', 'tcpPassiveOpens', 'tcpAttemptFails', 'tcpEstabResets', 'tcpCurrEstab', - 'tcpInSegs', 'tcpOutSegs', 'tcpRetransSegs', 'tcpInErrs', 'tcpOutRsts'); + $oids = array ('tcpActiveOpens', 'tcpPassiveOpens', 'tcpAttemptFails', 'tcpEstabResets', 'tcpCurrEstab', + 'tcpInSegs', 'tcpOutSegs', 'tcpRetransSegs', 'tcpInErrs', 'tcpOutRsts'); -# $oids['tcp_collect'] = $oids['tcp']; -# $oids['tcp_collect'][] = 'tcpHCInSegs'; -# $oids['tcp_collect'][] = 'tcpHCOutSegs'; + # $oids['tcp_collect'] = $oids['tcp']; + # $oids['tcp_collect'][] = 'tcpHCInSegs'; + # $oids['tcp_collect'][] = 'tcpHCOutSegs'; - unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create); - $rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-tcp.rrd"; + unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create); + $rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-tcp.rrd"; - $rrd_create = "RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797 RRA:MAX:0.5:1:600 \ - RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797"; + $rrd_create = "RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797 RRA:MAX:0.5:1:600 \ + RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797"; - foreach ($oids as $oid) - { - $oid_ds = truncate($oid, 19, ''); - $rrd_create .= " DS:$oid_ds:COUNTER:600:U:10000000"; ## Limit to 10MPPS - $snmpstring .= " $oid.0"; - } - - $snmpstring .= " tcpHCInSegs.0"; - $snmpstring .= " tcpHCOutSegs.0"; - - $data = snmp_get_multi($device, $snmpstring); - - $rrdupdate = "N"; - - foreach ($oids as $oid) - { - if (is_numeric($data[0][$oid])) + foreach ($oids as $oid) { - $value = $data[0][$oid]; - } else { - $value = "0"; + $oid_ds = truncate($oid, 19, ''); + $rrd_create .= " DS:$oid_ds:COUNTER:600:U:10000000"; ## Limit to 10MPPS + $snmpstring .= " $oid.0"; } - $rrdupdate .= ":$value"; - } - unset($snmpstring); + $snmpstring .= " tcpHCInSegs.0"; + $snmpstring .= " tcpHCOutSegs.0"; - if (isset($data[0]['tcpInSegs']) && isset($data[0]['tcpOutSegs'])) - { - if (!file_exists($rrd_file)) { rrdtool_create($rrd_file, $rrd_create); } - rrdtool_update($rrd_file, $rrdupdate); - $graphs['netstat_tcp'] = TRUE; - } + $data = snmp_get_multi($device, $snmpstring); - unset($oids, $data, $data_array, $oid, $protos); + $rrdupdate = "N"; + + foreach ($oids as $oid) + { + if (is_numeric($data[0][$oid])) + { + $value = $data[0][$oid]; + } else { + $value = "0"; + } + $rrdupdate .= ":$value"; + } + + unset($snmpstring); + + if (isset($data[0]['tcpInSegs']) && isset($data[0]['tcpOutSegs'])) + { + if (!file_exists($rrd_file)) { rrdtool_create($rrd_file, $rrd_create); } + rrdtool_update($rrd_file, $rrdupdate); + $graphs['netstat_tcp'] = TRUE; + } + + unset($oids, $data, $data_array, $oid, $protos); } -?> \ No newline at end of file +?> diff --git a/includes/polling/netstats-udp.inc.php b/includes/polling/netstats-udp.inc.php index 382dc5ff45..a47f242473 100755 --- a/includes/polling/netstats-udp.inc.php +++ b/includes/polling/netstats-udp.inc.php @@ -3,48 +3,48 @@ if ($device['os'] != "Snom") { - echo(" UDP"); + echo(" UDP"); - #### These are at the start of large trees that we don't want to walk the entirety of, so we snmpget_multi them + #### These are at the start of large trees that we don't want to walk the entirety of, so we snmpget_multi them - $oids = array ('udpInDatagrams','udpOutDatagrams','udpInErrors','udpNoPorts'); + $oids = array ('udpInDatagrams','udpOutDatagrams','udpInErrors','udpNoPorts'); - unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create); - $rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-udp.rrd"; + unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create); + $rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-udp.rrd"; - $rrd_create = "RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797 RRA:MAX:0.5:1:600 \ - RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797"; + $rrd_create = "RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797 RRA:MAX:0.5:1:600 \ + RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797"; - foreach ($oids as $oid) - { - $oid_ds = truncate($oid, 19, ''); - $rrd_create .= " DS:$oid_ds:COUNTER:600:U:1000000"; ## Limit to 1MPPS? - $snmpstring .= " $oid.0"; - } - - $data = snmp_get_multi($device, $snmpstring); - - $rrdupdate = "N"; - - foreach ($oids as $oid) - { - if (is_numeric($data[0][$oid])) + foreach ($oids as $oid) { - $value = $data[0][$oid]; - } else { - $value = "0"; + $oid_ds = truncate($oid, 19, ''); + $rrd_create .= " DS:$oid_ds:COUNTER:600:U:1000000"; ## Limit to 1MPPS? + $snmpstring .= " $oid.0"; } - $rrdupdate .= ":$value"; - } - if (isset($data[0]['udpInDatagrams']) && isset($data[0]['udpOutDatagrams'])) - { - if (!file_exists($rrd_file)) { rrdtool_create($rrd_file, $rrd_create); } - rrdtool_update($rrd_file, $rrdupdate); - $graphs['netstat_udp'] = TRUE; - } + $data = snmp_get_multi($device, $snmpstring); + + $rrdupdate = "N"; + + foreach ($oids as $oid) + { + if (is_numeric($data[0][$oid])) + { + $value = $data[0][$oid]; + } else { + $value = "0"; + } + $rrdupdate .= ":$value"; + } + + if (isset($data[0]['udpInDatagrams']) && isset($data[0]['udpOutDatagrams'])) + { + if (!file_exists($rrd_file)) { rrdtool_create($rrd_file, $rrd_create); } + rrdtool_update($rrd_file, $rrdupdate); + $graphs['netstat_udp'] = TRUE; + } } unset($oids, $data, $data_array, $oid, $protos, $snmpstring); -?> \ No newline at end of file +?> diff --git a/includes/polling/netstats.inc.php b/includes/polling/netstats.inc.php index 16ac14c37d..d93c877052 100755 --- a/includes/polling/netstats.inc.php +++ b/includes/polling/netstats.inc.php @@ -1,13 +1,13 @@ diff --git a/includes/polling/ports.inc.php b/includes/polling/ports.inc.php index 23dc41ee1c..c3c91156ca 100755 --- a/includes/polling/ports.inc.php +++ b/includes/polling/ports.inc.php @@ -7,25 +7,25 @@ $ports = snmp_cache_ifIndex($device); // Cache Port List // Build SNMP Cache Array $data_oids = array('ifName','ifDescr','ifAlias', 'ifAdminStatus', 'ifOperStatus', 'ifMtu', 'ifSpeed', 'ifHighSpeed', 'ifType', 'ifPhysAddress', - 'ifPromiscuousMode','ifConnectorPresent','ifDuplex'); + 'ifPromiscuousMode','ifConnectorPresent','ifDuplex'); $stat_oids = array('ifInErrors', 'ifOutErrors', 'ifInUcastPkts', 'ifOutUcastPkts', 'ifInNUcastPkts', 'ifOutNUcastPkts', - 'ifHCInMulticastPkts', 'ifHCInBroadcastPkts', 'ifHCOutMulticastPkts', 'ifHCOutBroadcastPkts', - 'ifInOctets', 'ifOutOctets', 'ifHCInOctets', 'ifHCOutOctets', 'ifInDiscards', 'ifOutDiscards', 'ifInUnknownProtos', - 'ifInBroadcastPkts', 'ifOutBroadcastPkts', 'ifInMulticastPkts', 'ifOutMulticastPkts'); + 'ifHCInMulticastPkts', 'ifHCInBroadcastPkts', 'ifHCOutMulticastPkts', 'ifHCOutBroadcastPkts', + 'ifInOctets', 'ifOutOctets', 'ifHCInOctets', 'ifHCOutOctets', 'ifInDiscards', 'ifOutDiscards', 'ifInUnknownProtos', + 'ifInBroadcastPkts', 'ifOutBroadcastPkts', 'ifInMulticastPkts', 'ifOutMulticastPkts'); $stat_oids_db = array('ifInOctets', 'ifOutOctets', 'ifInErrors', 'ifOutErrors', 'ifInUcastPkts', 'ifOutUcastPkts'); // From above for DB $etherlike_oids = array('dot3StatsAlignmentErrors', 'dot3StatsFCSErrors', 'dot3StatsSingleCollisionFrames', 'dot3StatsMultipleCollisionFrames', - 'dot3StatsSQETestErrors', 'dot3StatsDeferredTransmissions', 'dot3StatsLateCollisions', 'dot3StatsExcessiveCollisions', - 'dot3StatsInternalMacTransmitErrors', 'dot3StatsCarrierSenseErrors', 'dot3StatsFrameTooLongs', 'dot3StatsInternalMacReceiveErrors', - 'dot3StatsSymbolErrors'); + 'dot3StatsSQETestErrors', 'dot3StatsDeferredTransmissions', 'dot3StatsLateCollisions', 'dot3StatsExcessiveCollisions', + 'dot3StatsInternalMacTransmitErrors', 'dot3StatsCarrierSenseErrors', 'dot3StatsFrameTooLongs', 'dot3StatsInternalMacReceiveErrors', + 'dot3StatsSymbolErrors'); $cisco_oids = array('locIfHardType', 'locIfInRunts', 'locIfInGiants', 'locIfInCRC', 'locIfInFrame', 'locIfInOverrun', 'locIfInIgnored', 'locIfInAbort', - 'locIfCollisions', 'locIfInputQueueDrops', 'locIfOutputQueueDrops'); + 'locIfCollisions', 'locIfInputQueueDrops', 'locIfOutputQueueDrops'); $pagp_oids = array('pagpOperationMode', 'pagpPortState', 'pagpPartnerDeviceId', 'pagpPartnerLearnMethod', 'pagpPartnerIfIndex', 'pagpPartnerGroupIfIndex', - 'pagpPartnerDeviceName', 'pagpEthcOperationMode', 'pagpDeviceId', 'pagpGroupIfIndex'); + 'pagpPartnerDeviceName', 'pagpEthcOperationMode', 'pagpDeviceId', 'pagpGroupIfIndex'); $ifmib_oids = array_merge($data_oids, $stat_oids); @@ -36,39 +36,39 @@ foreach ($ifmib_oids as $oid) { echo("$oid "); $port_stats = snmpwalk_cache_oid( if ($config['enable_ports_etherlike']) { - echo("dot3Stats "); $port_stats = snmpwalk_cache_oid($device, "dot3StatsEntry", $port_stats, "EtherLike-MIB"); + echo("dot3Stats "); $port_stats = snmpwalk_cache_oid($device, "dot3StatsEntry", $port_stats, "EtherLike-MIB"); } else { - echo("dot3StatsDuplexStatus"); $port_stats = snmpwalk_cache_oid($device, "dot3StatsDuplexStatus", $port_stats, "EtherLike-MIB"); + echo("dot3StatsDuplexStatus"); $port_stats = snmpwalk_cache_oid($device, "dot3StatsDuplexStatus", $port_stats, "EtherLike-MIB"); } if ($config['enable_ports_adsl']) { - $device['adsl_count'] = mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifType` = 'adsl'"),0); + $device['adsl_count'] = mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifType` = 'adsl'"),0); } if ($device['adsl_count'] > "0") { - echo("ADSL "); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.1.1", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.2.1", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.3.1", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.4.1", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.5.1", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.1", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.2", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.3", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.4", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.5", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.6", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.7", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.8", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.1", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.2", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.3", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.4", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.5", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.6", $port_stats, "ADSL-LINE-MIB"); - $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.7", $port_stats, "ADSL-LINE-MIB"); + echo("ADSL "); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.1.1", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.2.1", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.3.1", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.4.1", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.5.1", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.1", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.2", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.3", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.4", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.5", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.6", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.7", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.8", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.1", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.2", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.3", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.4", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.5", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.6", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.7", $port_stats, "ADSL-LINE-MIB"); } echo("\n"); @@ -79,12 +79,12 @@ echo("\n"); if ($device['os_group'] == "ios") { - $port_stats = snmp_cache_portIfIndex ($device, $port_stats); - $port_stats = snmp_cache_portName ($device, $port_stats); - $data_oids[] = "portName"; - #$port_stats = snmpwalk_cache_oid($device, "vmVlan", $port_stats, "CISCO-VLAN-MEMBERSHIP-MIB"); - #$port_stats = snmpwalk_cache_oid($device, "vlanTrunkPortEncapsulationOperType", $port_stats, "CISCO-VTP-MIB"); - #$port_stats = snmpwalk_cache_oid($device, "vlanTrunkPortNativeVlan", $port_stats, "CISCO-VTP-MIB"); + $port_stats = snmp_cache_portIfIndex ($device, $port_stats); + $port_stats = snmp_cache_portName ($device, $port_stats); + $data_oids[] = "portName"; + #$port_stats = snmpwalk_cache_oid($device, "vmVlan", $port_stats, "CISCO-VLAN-MEMBERSHIP-MIB"); + #$port_stats = snmpwalk_cache_oid($device, "vlanTrunkPortEncapsulationOperType", $port_stats, "CISCO-VTP-MIB"); + #$port_stats = snmpwalk_cache_oid($device, "vlanTrunkPortNativeVlan", $port_stats, "CISCO-VTP-MIB"); } $polled = time(); @@ -101,218 +101,218 @@ if ($debug) { print_r($port_stats); } $port_query = mysql_query("SELECT * FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `deleted` = 0"); while ($port = mysql_fetch_array($port_query)) { - echo("Port " . $port['ifDescr'] . " "); - if ($port_stats[$port['ifIndex']] && $port['disabled'] != "1") - { // Check to make sure Port data is cached. - $this_port = &$port_stats[$port['ifIndex']]; + echo("Port " . $port['ifDescr'] . " "); + if ($port_stats[$port['ifIndex']] && $port['disabled'] != "1") + { // Check to make sure Port data is cached. + $this_port = &$port_stats[$port['ifIndex']]; - $polled_period = $polled - $port['poll_time']; + $polled_period = $polled - $port['poll_time']; - $update .= "`poll_time` = '".$polled."'"; - $update .= ", `poll_prev` = '".$port['poll_time']."'"; - $update .= ", `poll_period` = '".$polled_period."'"; + $update .= "`poll_time` = '".$polled."'"; + $update .= ", `poll_prev` = '".$port['poll_time']."'"; + $update .= ", `poll_period` = '".$polled_period."'"; - #echo("\n32bit - In: ".$this_port['ifInOctets']." Out: ".$this_port['ifOutOctets']); - #echo("\n64bit - In: ".$this_port['ifHCInOctets']." Out: ".$this_port['ifHCOutOctets']."\n"); + #echo("\n32bit - In: ".$this_port['ifInOctets']." Out: ".$this_port['ifOutOctets']); + #echo("\n64bit - In: ".$this_port['ifHCInOctets']." Out: ".$this_port['ifHCOutOctets']."\n"); - ### Copy ifHC[In|Out]Octets values to non-HC if they exist - if ($this_port['ifHCInOctets'] > 0 && is_numeric($this_port['ifHCInOctets']) && $this_port['ifHCOutOctets'] > 0 && is_numeric($this_port['ifHCOutOctets'])) - { - echo("HC "); - $this_port['ifInOctets'] = $this_port['ifHCInOctets']; - $this_port['ifOutOctets'] = $this_port['ifHCOutOctets']; - } - - if (is_numeric($this_port['ifHCInBroadcastPkts']) && is_numeric($this_port['ifHCOutBroadcastPkts']) && is_numeric($this_port['ifHCInMulticastPkts']) && is_numeric($this_port['ifHCOutMulticastPkts'])) - { - echo("HC "); - $this_port['ifInBroadcastPkts'] = $this_port['ifHCInBroadcastPkts']; - $this_port['ifOutBroadcastPkts'] = $this_port['ifHCOutBroadcastPkts']; - $this_port['ifInMulticastPkts'] = $this_port['ifHCInMulticastPkts']; - $this_port['ifOutMulticastPkts'] = $this_port['ifHCOutMulticastPkts']; - } - - ### Overwrite ifSpeed with ifHighSpeed if it's over 10G - if (is_numeric($this_port['ifHighSpeed']) && $this_port['ifSpeed'] > "1000000000") - { - echo("HighSpeed "); - $this_port['ifSpeed'] = $this_port['ifHighSpeed'] * 1000000; - } - - ### Overwrite ifDuplex with dot3StatsDuplexStatus if it exists - if (isset($this_port['dot3StatsDuplexStatus'])) - { - echo("dot3Duplex "); - $this_port['ifDuplex'] = $this_port['dot3StatsDuplexStatus']; - } - - ### Update IF-MIB data - foreach ($data_oids as $oid) - { - if ($port[$oid] != $this_port[$oid] && !isset($this_port[$oid])) - { - $update .= ", `$oid` = NULL"; - log_event($oid . ": ".$port[$oid]." -> NULL", $device['device_id'], 'interface', $port['interface_id']); - if ($debug) { echo($oid . ": ".$port[$oid]." -> NULL "); } else { echo($oid . " "); } - } elseif ($port[$oid] != $this_port[$oid] ) { - $update .= ", `$oid` = '".mres($this_port[$oid])."'"; - log_event($oid . ": ".$port[$oid]." -> " . $this_port[$oid], $device['device_id'], 'interface', $port['interface_id']); - if ($debug) { echo($oid . ": ".$port[$oid]." -> " . $this_port[$oid]." "); } else { echo($oid . " "); } - } - } - - /// Parse description (usually ifAlias) if config option set - - if (isset($config['port_descr_parser']) && is_file($config['install_dir'] . "/" . $config['port_descr_parser'])) - { - $port_attribs = array('type','descr','circuit','speed','notes'); - include($config['install_dir'] . "/" . $config['port_descr_parser']); - - foreach ($port_attribs as $attrib) - { - $attrib_key = "port_descr_".$attrib; - if ($port_ifAlias[$attrib] != $port[$attrib_key]) + ### Copy ifHC[In|Out]Octets values to non-HC if they exist + if ($this_port['ifHCInOctets'] > 0 && is_numeric($this_port['ifHCInOctets']) && $this_port['ifHCOutOctets'] > 0 && is_numeric($this_port['ifHCOutOctets'])) { - $update .= ", `".$attrib_key."` = '".$port_ifAlias[$attrib]."'"; - log_event($attrib . ": ".$port[$attrib_key]." -> " . $port_ifAlias[$attrib], $device['device_id'], 'interface', $port['interface_id']); + echo("HC "); + $this_port['ifInOctets'] = $this_port['ifHCInOctets']; + $this_port['ifOutOctets'] = $this_port['ifHCOutOctets']; } - } - } - /// Ende parse ifAlias - - /// Update IF-MIB metrics - foreach ($stat_oids_db as $oid) - { - $update .= ", `$oid` = '".$this_port[$oid]."'"; - $update .= ", `".$oid."_prev` = '".$port[$oid]."'"; - $oid_prev = $oid . "_prev"; - if ($port[$oid]) - { - $oid_diff = $this_port[$oid] - $port[$oid]; - $oid_rate = $oid_diff / $polled_period; - if ($oid_rate < 0) { $oid_rate = "0"; } - $update .= ", `".$oid."_rate` = '".$oid_rate."'"; - $update .= ", `".$oid."_delta` = '".$oid_diff."'"; - if ($debug) {echo("\n $oid ($oid_diff B) $oid_rate Bps $polled_period secs\n"); } - } - } - - /// Update RRDs - $rrdfile = $host_rrd . "/port-" . safename($port['ifIndex'] . ".rrd"); - if (!is_file($rrdfile)) - { - rrdtool_create($rrdfile," --step 300 \ - DS:INOCTETS:DERIVE:600:0:12500000000 \ - DS:OUTOCTETS:DERIVE:600:0:12500000000 \ - DS:INERRORS:DERIVE:600:0:12500000000 \ - DS:OUTERRORS:DERIVE:600:0:12500000000 \ - DS:INUCASTPKTS:DERIVE:600:0:12500000000 \ - DS:OUTUCASTPKTS:DERIVE:600:0:12500000000 \ - DS:INNUCASTPKTS:DERIVE:600:0:12500000000 \ - DS:OUTNUCASTPKTS:DERIVE:600:0:12500000000 \ - DS:INDISCARDS:DERIVE:600:0:12500000000 \ - DS:OUTDISCARDS:DERIVE:600:0:12500000000 \ - DS:INUNKNOWNPROTOS:DERIVE:600:0:12500000000 \ - DS:INBROADCASTPKTS:DERIVE:600:0:12500000000 \ - DS:OUTBROADCASTPKTS:DERIVE:600:0:12500000000 \ - DS:INMULTICASTPKTS:DERIVE:600:0:12500000000 \ - DS:OUTMULTICASTPKTS:DERIVE:600:0:12500000000 \ - RRA:AVERAGE:0.5:1:600 \ - RRA:AVERAGE:0.5:6:700 \ - RRA:AVERAGE:0.5:24:775 \ - RRA:AVERAGE:0.5:288:797 \ - RRA:MAX:0.5:1:600 \ - RRA:MAX:0.5:6:700 \ - RRA:MAX:0.5:24:775 \ - RRA:MAX:0.5:288:797"); - } - - foreach ($stat_oids as $oid) - { /// Copy values from array to global variables and force numeric. - $$oid = $this_port[$oid]; - if (!is_numeric($$oid)) { $$oid = "0"; } - } - - $if_rrd_update = "$polled:$ifInOctets:$ifOutOctets:$ifInErrors:$ifOutErrors:$ifInUcastPkts:$ifOutUcastPkts:$ifInNUcastPkts:$ifOutNUcastPkts:$ifInDiscards:$ifOutDiscards:$ifInUnknownProtos"; - $if_rrd_update .= ":$ifInBroadcastPkts:$ifOutBroadcastPkts:$ifInMulticastPkts:$ifOutMulticastPkts"; - $ret = rrdtool_update("$rrdfile", $if_rrd_update); - -# if ($config['enable_ports_Xbcmc'] && $config['os'][$device['os']]['ifXmcbc']) { -# if (!is_file($ifx_rrd)) { shell_exec($ifx_rrd_cmd); } -# $ifx_rrd_update = "$polled:$ifHCInBroadcastPkts:$ifHCOutBroadcastPkts:$ifHCInMulticastPkts:$ifHCOutMulticastPkts"; -# $ret = rrdtool_update($ifx_rrd, $ifx_rrd_update); -# } - - /// End Update IF-MIB - - /// Update PAgP - if ($this_port['pagpOperationMode']) - { - foreach ($pagp_oids as $oid) - { // Loop the OIDs - if ($this_port[$oid] != $port[$oid] ) - { // If data has changed, build a query - $update .= ", `$oid` = '".mres($this_port[$oid])."'"; - echo("PAgP "); - log_event("$oid -> ".$this_port[$oid], $device['device_id'], 'interface', $port['interface_id']); + if (is_numeric($this_port['ifHCInBroadcastPkts']) && is_numeric($this_port['ifHCOutBroadcastPkts']) && is_numeric($this_port['ifHCInMulticastPkts']) && is_numeric($this_port['ifHCOutMulticastPkts'])) + { + echo("HC "); + $this_port['ifInBroadcastPkts'] = $this_port['ifHCInBroadcastPkts']; + $this_port['ifOutBroadcastPkts'] = $this_port['ifHCOutBroadcastPkts']; + $this_port['ifInMulticastPkts'] = $this_port['ifHCInMulticastPkts']; + $this_port['ifOutMulticastPkts'] = $this_port['ifHCOutMulticastPkts']; } - } + + ### Overwrite ifSpeed with ifHighSpeed if it's over 10G + if (is_numeric($this_port['ifHighSpeed']) && $this_port['ifSpeed'] > "1000000000") + { + echo("HighSpeed "); + $this_port['ifSpeed'] = $this_port['ifHighSpeed'] * 1000000; + } + + ### Overwrite ifDuplex with dot3StatsDuplexStatus if it exists + if (isset($this_port['dot3StatsDuplexStatus'])) + { + echo("dot3Duplex "); + $this_port['ifDuplex'] = $this_port['dot3StatsDuplexStatus']; + } + + ### Update IF-MIB data + foreach ($data_oids as $oid) + { + if ($port[$oid] != $this_port[$oid] && !isset($this_port[$oid])) + { + $update .= ", `$oid` = NULL"; + log_event($oid . ": ".$port[$oid]." -> NULL", $device['device_id'], 'interface', $port['interface_id']); + if ($debug) { echo($oid . ": ".$port[$oid]." -> NULL "); } else { echo($oid . " "); } + } elseif ($port[$oid] != $this_port[$oid] ) { + $update .= ", `$oid` = '".mres($this_port[$oid])."'"; + log_event($oid . ": ".$port[$oid]." -> " . $this_port[$oid], $device['device_id'], 'interface', $port['interface_id']); + if ($debug) { echo($oid . ": ".$port[$oid]." -> " . $this_port[$oid]." "); } else { echo($oid . " "); } + } + } + + /// Parse description (usually ifAlias) if config option set + + if (isset($config['port_descr_parser']) && is_file($config['install_dir'] . "/" . $config['port_descr_parser'])) + { + $port_attribs = array('type','descr','circuit','speed','notes'); + include($config['install_dir'] . "/" . $config['port_descr_parser']); + + foreach ($port_attribs as $attrib) + { + $attrib_key = "port_descr_".$attrib; + if ($port_ifAlias[$attrib] != $port[$attrib_key]) + { + $update .= ", `".$attrib_key."` = '".$port_ifAlias[$attrib]."'"; + log_event($attrib . ": ".$port[$attrib_key]." -> " . $port_ifAlias[$attrib], $device['device_id'], 'interface', $port['interface_id']); + } + } + } + + /// Ende parse ifAlias + + /// Update IF-MIB metrics + foreach ($stat_oids_db as $oid) + { + $update .= ", `$oid` = '".$this_port[$oid]."'"; + $update .= ", `".$oid."_prev` = '".$port[$oid]."'"; + $oid_prev = $oid . "_prev"; + if ($port[$oid]) + { + $oid_diff = $this_port[$oid] - $port[$oid]; + $oid_rate = $oid_diff / $polled_period; + if ($oid_rate < 0) { $oid_rate = "0"; } + $update .= ", `".$oid."_rate` = '".$oid_rate."'"; + $update .= ", `".$oid."_delta` = '".$oid_diff."'"; + if ($debug) {echo("\n $oid ($oid_diff B) $oid_rate Bps $polled_period secs\n"); } + } + } + + /// Update RRDs + $rrdfile = $host_rrd . "/port-" . safename($port['ifIndex'] . ".rrd"); + if (!is_file($rrdfile)) + { + rrdtool_create($rrdfile," --step 300 \ + DS:INOCTETS:DERIVE:600:0:12500000000 \ + DS:OUTOCTETS:DERIVE:600:0:12500000000 \ + DS:INERRORS:DERIVE:600:0:12500000000 \ + DS:OUTERRORS:DERIVE:600:0:12500000000 \ + DS:INUCASTPKTS:DERIVE:600:0:12500000000 \ + DS:OUTUCASTPKTS:DERIVE:600:0:12500000000 \ + DS:INNUCASTPKTS:DERIVE:600:0:12500000000 \ + DS:OUTNUCASTPKTS:DERIVE:600:0:12500000000 \ + DS:INDISCARDS:DERIVE:600:0:12500000000 \ + DS:OUTDISCARDS:DERIVE:600:0:12500000000 \ + DS:INUNKNOWNPROTOS:DERIVE:600:0:12500000000 \ + DS:INBROADCASTPKTS:DERIVE:600:0:12500000000 \ + DS:OUTBROADCASTPKTS:DERIVE:600:0:12500000000 \ + DS:INMULTICASTPKTS:DERIVE:600:0:12500000000 \ + DS:OUTMULTICASTPKTS:DERIVE:600:0:12500000000 \ + RRA:AVERAGE:0.5:1:600 \ + RRA:AVERAGE:0.5:6:700 \ + RRA:AVERAGE:0.5:24:775 \ + RRA:AVERAGE:0.5:288:797 \ + RRA:MAX:0.5:1:600 \ + RRA:MAX:0.5:6:700 \ + RRA:MAX:0.5:24:775 \ + RRA:MAX:0.5:288:797"); + } + + foreach ($stat_oids as $oid) + { /// Copy values from array to global variables and force numeric. + $$oid = $this_port[$oid]; + if (!is_numeric($$oid)) { $$oid = "0"; } + } + + $if_rrd_update = "$polled:$ifInOctets:$ifOutOctets:$ifInErrors:$ifOutErrors:$ifInUcastPkts:$ifOutUcastPkts:$ifInNUcastPkts:$ifOutNUcastPkts:$ifInDiscards:$ifOutDiscards:$ifInUnknownProtos"; + $if_rrd_update .= ":$ifInBroadcastPkts:$ifOutBroadcastPkts:$ifInMulticastPkts:$ifOutMulticastPkts"; + $ret = rrdtool_update("$rrdfile", $if_rrd_update); + + # if ($config['enable_ports_Xbcmc'] && $config['os'][$device['os']]['ifXmcbc']) { + # if (!is_file($ifx_rrd)) { shell_exec($ifx_rrd_cmd); } + # $ifx_rrd_update = "$polled:$ifHCInBroadcastPkts:$ifHCOutBroadcastPkts:$ifHCInMulticastPkts:$ifHCOutMulticastPkts"; + # $ret = rrdtool_update($ifx_rrd, $ifx_rrd_update); + # } + + /// End Update IF-MIB + + /// Update PAgP + if ($this_port['pagpOperationMode']) + { + foreach ($pagp_oids as $oid) + { // Loop the OIDs + if ($this_port[$oid] != $port[$oid] ) + { // If data has changed, build a query + $update .= ", `$oid` = '".mres($this_port[$oid])."'"; + echo("PAgP "); + log_event("$oid -> ".$this_port[$oid], $device['device_id'], 'interface', $port['interface_id']); + } + } + } + // End Update PAgP + + /// Do EtherLike-MIB + if ($config['enable_ports_etherlike']) { include("port-etherlike.inc.php"); } + + /// Do ADSL MIB + if ($config['enable_ports_adsl']) { include("port-adsl.inc.php"); } + + /// Do PoE MIBs + if ($config['enable_ports_poe']) { include("port-poe.inc.php"); } + + // Update MySQL + if ($update) + { + $update_query = "UPDATE `ports` SET ".$update." WHERE `interface_id` = '" . $port['interface_id'] . "'"; + @mysql_query($update_query); + if ($debug) {echo("\nMYSQL : [ $update_query ]"); } + } + // End Update MySQL + + unset($update_query); unset($update); + + // Send alerts for interface flaps. + if ($config['warn']['ifdown'] && ($port['ifOperStatus'] != $this_port['ifOperStatus']) && $port['ignore'] == 0) + { + if ($this_port['ifAlias']) + { + $falias = preg_replace('/^"/', '', $this_port['ifAlias']); $falias = preg_replace('/"$/', '', $falias); $full = $this_port['ifDescr'] . " (" . $falias . ")"; + } else { + $full = $this_port['ifDescr']; + } + switch ($this_port['ifOperStatus']) + { + case "up": + notify($device, "Interface UP - " . $device['hostname'] . " - " . $full, "Device: " . $device['hostname'] . "\nInterface: " . $full . "\nTimestamp: " . date($config['timestamp_format'])); + break; + case "down": + notify($device, "Interface DOWN - " . $device['hostname'] . " - " . $full, "Device: " . $device['hostname'] . "\nInterface: " . $full . "\nTimestamp: " . date($config['timestamp_format'])); + break; + } + } } - // End Update PAgP - - /// Do EtherLike-MIB - if ($config['enable_ports_etherlike']) { include("port-etherlike.inc.php"); } - - /// Do ADSL MIB - if ($config['enable_ports_adsl']) { include("port-adsl.inc.php"); } - - /// Do PoE MIBs - if ($config['enable_ports_poe']) { include("port-poe.inc.php"); } - - // Update MySQL - if ($update) + elseif ($port['disabled'] != "1") { - $update_query = "UPDATE `ports` SET ".$update." WHERE `interface_id` = '" . $port['interface_id'] . "'"; - @mysql_query($update_query); - if ($debug) {echo("\nMYSQL : [ $update_query ]"); } + echo("Port Deleted"); // Port missing from SNMP cache. + mysql_query("UPDATE `ports` SET `deleted` = '1' WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '".$this_port['ifIndex']."'"); + } else { + echo("Port Disabled."); } - // End Update MySQL - unset($update_query); unset($update); + echo("\n"); - // Send alerts for interface flaps. - if ($config['warn']['ifdown'] && ($port['ifOperStatus'] != $this_port['ifOperStatus']) && $port['ignore'] == 0) - { - if ($this_port['ifAlias']) - { - $falias = preg_replace('/^"/', '', $this_port['ifAlias']); $falias = preg_replace('/"$/', '', $falias); $full = $this_port['ifDescr'] . " (" . $falias . ")"; - } else { - $full = $this_port['ifDescr']; - } - switch ($this_port['ifOperStatus']) - { - case "up": - notify($device, "Interface UP - " . $device['hostname'] . " - " . $full, "Device: " . $device['hostname'] . "\nInterface: " . $full . "\nTimestamp: " . date($config['timestamp_format'])); - break; - case "down": - notify($device, "Interface DOWN - " . $device['hostname'] . " - " . $full, "Device: " . $device['hostname'] . "\nInterface: " . $full . "\nTimestamp: " . date($config['timestamp_format'])); - break; - } - } - } - elseif ($port['disabled'] != "1") - { - echo("Port Deleted"); // Port missing from SNMP cache. - mysql_query("UPDATE `ports` SET `deleted` = '1' WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '".$this_port['ifIndex']."'"); - } else { - echo("Port Disabled."); - } - - echo("\n"); - - #### Clear Per-Port Variables Here - unset($this_port); + #### Clear Per-Port Variables Here + unset($this_port); } diff --git a/includes/port-descr-parser.inc.php b/includes/port-descr-parser.inc.php index f72f017710..95116c5e62 100644 --- a/includes/port-descr-parser.inc.php +++ b/includes/port-descr-parser.inc.php @@ -15,19 +15,19 @@ $descr = trim($descr); if ($type && $descr) { - $type = strtolower($type); - $port_ifAlias['type'] = $type; - $port_ifAlias['descr'] = $descr; - $port_ifAlias['circuit'] = $circuit; - $port_ifAlias['speed'] = $speed; - $port_ifAlias['notes'] = $notes; + $type = strtolower($type); + $port_ifAlias['type'] = $type; + $port_ifAlias['descr'] = $descr; + $port_ifAlias['circuit'] = $circuit; + $port_ifAlias['speed'] = $speed; + $port_ifAlias['notes'] = $notes; - if ($debug) - { - print_r($port_ifAlias); - } + if ($debug) + { + print_r($port_ifAlias); + } } unset ($port_type, $port_descr, $port_circuit, $port_notes, $port_speed); -?> \ No newline at end of file +?> diff --git a/includes/rewrites.php b/includes/rewrites.php index 2e48036c6e..97e6e136bb 100644 --- a/includes/rewrites.php +++ b/includes/rewrites.php @@ -2,297 +2,297 @@ function formatMac($mac) { - $mac = preg_replace("/(..)(..)(..)(..)(..)(..)/", "\\1:\\2:\\3:\\4:\\5:\\6", $mac); - return $mac; + $mac = preg_replace("/(..)(..)(..)(..)(..)(..)/", "\\1:\\2:\\3:\\4:\\5:\\6", $mac); + return $mac; } function rewrite_entity_descr ($descr) { - $descr = str_replace("Distributed Forwarding Card", "DFC", $descr); - $descr = preg_replace("/7600 Series SPA Interface Processor-/", "7600 SIP-", $descr); - $descr = preg_replace("/Rev\.\ [0-9\.]+\ /", "", $descr); - $descr = preg_replace("/12000 Series Performance Route Processor/", "12000 PRP", $descr); - $descr = preg_replace("/^12000/", "", $descr); - $descr = preg_replace("/Gigabit Ethernet/", "GigE", $descr); - $descr = preg_replace("/^ASR1000\ /", "", $descr); - $descr = str_replace("Routing Processor", "RP", $descr); - $descr = str_replace("Route Processor", "RP", $descr); - $descr = str_replace("Switching Processor", "SP", $descr); - $descr = str_replace("Sub-Module", "Module ", $descr); - $descr = str_replace("DFC Card", "DFC", $descr); - $descr = str_replace("Centralized Forwarding Card", "CFC", $descr); - $descr = str_replace("Power Supply Module", "PSU ", $descr); - $descr = str_replace("/Voltage Sensor/", "Voltage", $descr); - $descr = preg_replace("/^temperatures /", "", $descr); - $descr = preg_replace("/^voltages /", "", $descr); + $descr = str_replace("Distributed Forwarding Card", "DFC", $descr); + $descr = preg_replace("/7600 Series SPA Interface Processor-/", "7600 SIP-", $descr); + $descr = preg_replace("/Rev\.\ [0-9\.]+\ /", "", $descr); + $descr = preg_replace("/12000 Series Performance Route Processor/", "12000 PRP", $descr); + $descr = preg_replace("/^12000/", "", $descr); + $descr = preg_replace("/Gigabit Ethernet/", "GigE", $descr); + $descr = preg_replace("/^ASR1000\ /", "", $descr); + $descr = str_replace("Routing Processor", "RP", $descr); + $descr = str_replace("Route Processor", "RP", $descr); + $descr = str_replace("Switching Processor", "SP", $descr); + $descr = str_replace("Sub-Module", "Module ", $descr); + $descr = str_replace("DFC Card", "DFC", $descr); + $descr = str_replace("Centralized Forwarding Card", "CFC", $descr); + $descr = str_replace("Power Supply Module", "PSU ", $descr); + $descr = str_replace("/Voltage Sensor/", "Voltage", $descr); + $descr = preg_replace("/^temperatures /", "", $descr); + $descr = preg_replace("/^voltages /", "", $descr); - return $descr; + return $descr; } function ifNameDescr($interface, $device = NULL) { - return ifLabel($interface, $device); + return ifLabel($interface, $device); } function ifLabel ($interface, $device = NULL) { - global $config; + global $config; - if (!$device) { $device = device_by_id_cache($interface['device_id']); } - $os = strtolower($device['os']); + if (!$device) { $device = device_by_id_cache($interface['device_id']); } + $os = strtolower($device['os']); - if (isset($config['os'][$os]['ifname'])) - { - $interface['label'] = $interface['ifName']; - } elseif (isset($config['os'][$os]['ifalias'])) - { - $interface['label'] = $interface['ifAlias']; - } else { - $interface['label'] = $interface['ifDescr']; - if (isset($config['os'][$os]['ifindex'])) + if (isset($config['os'][$os]['ifname'])) { - $interface['label'] = $interface['label'] . " " . $interface['ifIndex']; + $interface['label'] = $interface['ifName']; + } elseif (isset($config['os'][$os]['ifalias'])) + { + $interface['label'] = $interface['ifAlias']; + } else { + $interface['label'] = $interface['ifDescr']; + if (isset($config['os'][$os]['ifindex'])) + { + $interface['label'] = $interface['label'] . " " . $interface['ifIndex']; + } } - } - if ($device['os'] == "speedtouch") - { - list($interface['label']) = explode("thomson", $interface['label']); - } + if ($device['os'] == "speedtouch") + { + list($interface['label']) = explode("thomson", $interface['label']); + } - return $interface; + return $interface; } $rewrite_entSensorType = array ( - 'celsius' => 'C', - 'unknown' => '', - 'specialEnum' => 'C', - 'watts' => 'W', - 'truthvalue' => '', + 'celsius' => 'C', + 'unknown' => '', + 'specialEnum' => 'C', + 'watts' => 'W', + 'truthvalue' => '', ); $translate_ifOperStatus = array( - "1" => "up", - "2" => "down", - "3" => "testing", - "4" => "unknown", - "5" => "dormant", - "6" => "notPresent", - "7" => "lowerLayerDown", + "1" => "up", + "2" => "down", + "3" => "testing", + "4" => "unknown", + "5" => "dormant", + "6" => "notPresent", + "7" => "lowerLayerDown", ); function translate_ifOperStatus ($ifOperStatus) { - global $translate_ifOperStatus; + global $translate_ifOperStatus; - if ($translate_ifOperStatus['$ifOperStatus']) - { - $ifOperStatus = $translate_ifOperStatus['$ifOperStatus']; - } + if ($translate_ifOperStatus['$ifOperStatus']) + { + $ifOperStatus = $translate_ifOperStatus['$ifOperStatus']; + } - return $ifOperStatus; + return $ifOperStatus; } $translate_ifAdminStatus = array( - "1" => "up", - "2" => "down", - "3" => "testing", + "1" => "up", + "2" => "down", + "3" => "testing", ); function translate_ifAdminStatus ($ifAdminStatus) { - global $translate_ifAdminStatus; + global $translate_ifAdminStatus; - if ($translate_ifAdminStatus[$ifAdminStatus]) - { - $ifAdminStatus = $translate_ifAdminStatus[$ifAdminStatus]; - } + if ($translate_ifAdminStatus[$ifAdminStatus]) + { + $ifAdminStatus = $translate_ifAdminStatus[$ifAdminStatus]; + } - return $ifAdminStatus; + return $ifAdminStatus; } $rewrite_junose_hardware = array( - 'juniErx1400' => 'ERX-1400', - 'juniErx700' => 'ERX-700', - 'juniErx1440' => 'ERX-1440', - 'juniErx705' => 'ERX-705', - 'juniErx310' => 'ERX-310', - 'juniE320' => 'E320', - 'juniE120' => 'E120', - 'juniSsx1400' => 'SSX-1400', - 'juniSsx700' => 'SSX-700', - 'juniSsx1440' => 'SSX-1440', + 'juniErx1400' => 'ERX-1400', + 'juniErx700' => 'ERX-700', + 'juniErx1440' => 'ERX-1440', + 'juniErx705' => 'ERX-705', + 'juniErx310' => 'ERX-310', + 'juniE320' => 'E320', + 'juniE120' => 'E120', + 'juniSsx1400' => 'SSX-1400', + 'juniSsx700' => 'SSX-700', + 'juniSsx1440' => 'SSX-1440', ); $rewrite_ftos_hardware = array ( -'.1.3.6.1.4.1.6027.1.1.1'=> 'E1200', -'.1.3.6.1.4.1.6027.1.1.2'=> 'E600', -'.1.3.6.1.4.1.6027.1.1.3'=> 'E300', -'.1.3.6.1.4.1.6027.1.1.4'=> 'E610', -'.1.3.6.1.4.1.6027.1.1.5'=> 'E1200i', -'.1.3.6.1.4.1.6027.1.2.1'=> 'C300', -'.1.3.6.1.4.1.6027.1.2.2'=> 'C150', -'.1.3.6.1.4.1.6027.1.3.1'=> 'S50', -'.1.3.6.1.4.1.6027.1.3.2'=> 'S50E', -'.1.3.6.1.4.1.6027.1.3.3'=> 'S50V', -'.1.3.6.1.4.1.6027.1.3.4'=> 'S25P-AC', -'.1.3.6.1.4.1.6027.1.3.5'=> 'S2410CP', -'.1.3.6.1.4.1.6027.1.3.6'=> 'S2410P', -'.1.3.6.1.4.1.6027.1.3.7'=> 'S50N-AC', -'.1.3.6.1.4.1.6027.1.3.8'=> 'S50N-DC', -'.1.3.6.1.4.1.6027.1.3.9'=> 'S25P-DC', -'.1.3.6.1.4.1.6027.1.3.10'=> 'S25V', -'.1.3.6.1.4.1.6027.1.3.11'=> 'S25N' + '.1.3.6.1.4.1.6027.1.1.1'=> 'E1200', + '.1.3.6.1.4.1.6027.1.1.2'=> 'E600', + '.1.3.6.1.4.1.6027.1.1.3'=> 'E300', + '.1.3.6.1.4.1.6027.1.1.4'=> 'E610', + '.1.3.6.1.4.1.6027.1.1.5'=> 'E1200i', + '.1.3.6.1.4.1.6027.1.2.1'=> 'C300', + '.1.3.6.1.4.1.6027.1.2.2'=> 'C150', + '.1.3.6.1.4.1.6027.1.3.1'=> 'S50', + '.1.3.6.1.4.1.6027.1.3.2'=> 'S50E', + '.1.3.6.1.4.1.6027.1.3.3'=> 'S50V', + '.1.3.6.1.4.1.6027.1.3.4'=> 'S25P-AC', + '.1.3.6.1.4.1.6027.1.3.5'=> 'S2410CP', + '.1.3.6.1.4.1.6027.1.3.6'=> 'S2410P', + '.1.3.6.1.4.1.6027.1.3.7'=> 'S50N-AC', + '.1.3.6.1.4.1.6027.1.3.8'=> 'S50N-DC', + '.1.3.6.1.4.1.6027.1.3.9'=> 'S25P-DC', + '.1.3.6.1.4.1.6027.1.3.10'=> 'S25V', + '.1.3.6.1.4.1.6027.1.3.11'=> 'S25N' ); $rewrite_fortinet_hardware = array( -'.1.3.6.1.4.1.12356.102.1.1000' => 'FortiAnalyzer 100', -'.1.3.6.1.4.1.12356.102.1.10002' => 'FortiAnalyzer 1000B', -'.1.3.6.1.4.1.12356.102.1.1001' => 'FortiAnalyzer 100A', -'.1.3.6.1.4.1.12356.102.1.1002' => 'FortiAnalyzer 100B', -'.1.3.6.1.4.1.12356.102.1.20000' => 'FortiAnalyzer 2000', -'.1.3.6.1.4.1.12356.102.1.20001' => 'FortiAnalyzer 2000A', -'.1.3.6.1.4.1.12356.102.1.4000' => 'FortiAnalyzer 400', -'.1.3.6.1.4.1.12356.102.1.40000' => 'FortiAnalyzer 4000', -'.1.3.6.1.4.1.12356.102.1.40001' => 'FortiAnalyzer 4000A', -'.1.3.6.1.4.1.12356.102.1.4002' => 'FortiAnalyzer 400B', -'.1.3.6.1.4.1.12356.102.1.8000' => 'FortiAnalyzer 800', -'.1.3.6.1.4.1.12356.102.1.8002' => 'FortiAnalyzer 800B', -'.1.3.6.1.4.1.12356.101.1.1000' => 'FortiGate 100', -'.1.3.6.1.4.1.12356.101.1.10000' => 'FortiGate 1000', -'.1.3.6.1.4.1.12356.101.1.10001' => 'FortiGate 1000A', -'.1.3.6.1.4.1.12356.101.1.10002' => 'FortiGate 1000AFA2', -'.1.3.6.1.4.1.12356.101.1.10003' => 'FortiGate 1000ALENC', -'.1.3.6.1.4.1.12356.101.1.1001' => 'FortiGate 100A', -'.1.3.6.1.4.1.12356.101.1.1002' => 'FortiGate 110C', -'.1.3.6.1.4.1.12356.101.1.1003' => 'FortiGate 111C', -'.1.3.6.1.4.1.12356.101.1.2000' => 'FortiGate 200', -'.1.3.6.1.4.1.12356.101.1.20000' => 'FortiGate 2000', -'.1.3.6.1.4.1.12356.101.1.2001' => 'FortiGate 200A', -'.1.3.6.1.4.1.12356.101.1.2002' => 'FortiGate 224B', -'.1.3.6.1.4.1.12356.101.1.2003' => 'FortiGate 200A', -'.1.3.6.1.4.1.12356.101.1.3000' => 'FortiGate 300', -'.1.3.6.1.4.1.12356.101.1.30000' => 'FortiGate 3000', -'.1.3.6.1.4.1.12356.101.1.3001' => 'FortiGate 300A', -'.1.3.6.1.4.1.12356.101.1.30160' => 'FortiGate 3016B', -'.1.3.6.1.4.1.12356.101.1.302' => 'FortiGate 30B', -'.1.3.6.1.4.1.12356.101.1.3002' => 'FortiGate 310B', -'.1.3.6.1.4.1.12356.101.1.36000' => 'FortiGate 3600', -'.1.3.6.1.4.1.12356.101.1.36003' => 'FortiGate 3600A', -'.1.3.6.1.4.1.12356.101.1.38100' => 'FortiGate 3810A', -'.1.3.6.1.4.1.12356.101.1.4000' => 'FortiGate 400', -'.1.3.6.1.4.1.12356.101.1.40000' => 'FortiGate 4000', -'.1.3.6.1.4.1.12356.101.1.4001' => 'FortiGate 400A', -'.1.3.6.1.4.1.12356.101.1.5000' => 'FortiGate 500', -'.1.3.6.1.4.1.12356.101.1.50000' => 'FortiGate 5000', -'.1.3.6.1.4.1.12356.101.1.50010' => 'FortiGate 5001', -'.1.3.6.1.4.1.12356.101.1.50011' => 'FortiGate 5001A', -'.1.3.6.1.4.1.12356.101.1.50012' => 'FortiGate 5001FA2', -'.1.3.6.1.4.1.12356.101.1.50021' => 'FortiGate 5002A', -'.1.3.6.1.4.1.12356.101.1.50001' => 'FortiGate 5002FB2', -'.1.3.6.1.4.1.12356.101.1.50040' => 'FortiGate 5004', -'.1.3.6.1.4.1.12356.101.1.50050' => 'FortiGate 5005', -'.1.3.6.1.4.1.12356.101.1.50051' => 'FortiGate 5005FA2', -'.1.3.6.1.4.1.12356.101.1.5001' => 'FortiGate 500A', -'.1.3.6.1.4.1.12356.101.1.500' => 'FortiGate 50A', -'.1.3.6.1.4.1.12356.101.1.501' => 'FortiGate 50AM', -'.1.3.6.1.4.1.12356.101.1.502' => 'FortiGate 50B', -'.1.3.6.1.4.1.12356.101.1.504' => 'FortiGate 51B', -'.1.3.6.1.4.1.12356.101.1.600' => 'FortiGate 60', -'.1.3.6.1.4.1.12356.101.1.6201' => 'FortiGate 600D', -'.1.3.6.1.4.1.12356.101.1.602' => 'FortiGate 60ADSL', -'.1.3.6.1.4.1.12356.101.1.603' => 'FortiGate 60B', -'.1.3.6.1.4.1.12356.101.1.601' => 'FortiGate 60M', -'.1.3.6.1.4.1.12356.101.1.6200' => 'FortiGate 620B', -'.1.3.6.1.4.1.12356.101.1.8000' => 'FortiGate 800', -'.1.3.6.1.4.1.12356.101.1.8001' => 'FortiGate 800F', -'.1.3.6.1.4.1.12356.101.1.800' => 'FortiGate 80C', -'.1.3.6.1.4.1.12356.1688' => 'FortiMail 2000A', -'.1.3.6.1.4.1.12356.103.1.1000' => 'FortiManager 100', -'.1.3.6.1.4.1.12356.103.1.20000' => 'FortiManager 2000XL', -'.1.3.6.1.4.1.12356.103.1.30000' => 'FortiManager 3000', -'.1.3.6.1.4.1.12356.103.1.30002' => 'FortiManager 3000B', -'.1.3.6.1.4.1.12356.103.1.4000' => 'FortiManager 400', -'.1.3.6.1.4.1.12356.103.1.4001' => 'FortiManager 400A', -'.1.3.6.1.4.1.12356.106.1.50030' => 'FortiSwitch 5003A', -'.1.3.6.1.4.1.12356.101.1.510' => 'FortiWiFi 50B', -'.1.3.6.1.4.1.12356.101.1.610' => 'FortiWiFi 60', -'.1.3.6.1.4.1.12356.101.1.611' => 'FortiWiFi 60A', -'.1.3.6.1.4.1.12356.101.1.612' => 'FortiWiFi 60AM', -'.1.3.6.1.4.1.12356.101.1.613' => 'FortiWiFi 60B'); + '.1.3.6.1.4.1.12356.102.1.1000' => 'FortiAnalyzer 100', + '.1.3.6.1.4.1.12356.102.1.10002' => 'FortiAnalyzer 1000B', + '.1.3.6.1.4.1.12356.102.1.1001' => 'FortiAnalyzer 100A', + '.1.3.6.1.4.1.12356.102.1.1002' => 'FortiAnalyzer 100B', + '.1.3.6.1.4.1.12356.102.1.20000' => 'FortiAnalyzer 2000', + '.1.3.6.1.4.1.12356.102.1.20001' => 'FortiAnalyzer 2000A', + '.1.3.6.1.4.1.12356.102.1.4000' => 'FortiAnalyzer 400', + '.1.3.6.1.4.1.12356.102.1.40000' => 'FortiAnalyzer 4000', + '.1.3.6.1.4.1.12356.102.1.40001' => 'FortiAnalyzer 4000A', + '.1.3.6.1.4.1.12356.102.1.4002' => 'FortiAnalyzer 400B', + '.1.3.6.1.4.1.12356.102.1.8000' => 'FortiAnalyzer 800', + '.1.3.6.1.4.1.12356.102.1.8002' => 'FortiAnalyzer 800B', + '.1.3.6.1.4.1.12356.101.1.1000' => 'FortiGate 100', + '.1.3.6.1.4.1.12356.101.1.10000' => 'FortiGate 1000', + '.1.3.6.1.4.1.12356.101.1.10001' => 'FortiGate 1000A', + '.1.3.6.1.4.1.12356.101.1.10002' => 'FortiGate 1000AFA2', + '.1.3.6.1.4.1.12356.101.1.10003' => 'FortiGate 1000ALENC', + '.1.3.6.1.4.1.12356.101.1.1001' => 'FortiGate 100A', + '.1.3.6.1.4.1.12356.101.1.1002' => 'FortiGate 110C', + '.1.3.6.1.4.1.12356.101.1.1003' => 'FortiGate 111C', + '.1.3.6.1.4.1.12356.101.1.2000' => 'FortiGate 200', + '.1.3.6.1.4.1.12356.101.1.20000' => 'FortiGate 2000', + '.1.3.6.1.4.1.12356.101.1.2001' => 'FortiGate 200A', + '.1.3.6.1.4.1.12356.101.1.2002' => 'FortiGate 224B', + '.1.3.6.1.4.1.12356.101.1.2003' => 'FortiGate 200A', + '.1.3.6.1.4.1.12356.101.1.3000' => 'FortiGate 300', + '.1.3.6.1.4.1.12356.101.1.30000' => 'FortiGate 3000', + '.1.3.6.1.4.1.12356.101.1.3001' => 'FortiGate 300A', + '.1.3.6.1.4.1.12356.101.1.30160' => 'FortiGate 3016B', + '.1.3.6.1.4.1.12356.101.1.302' => 'FortiGate 30B', + '.1.3.6.1.4.1.12356.101.1.3002' => 'FortiGate 310B', + '.1.3.6.1.4.1.12356.101.1.36000' => 'FortiGate 3600', + '.1.3.6.1.4.1.12356.101.1.36003' => 'FortiGate 3600A', + '.1.3.6.1.4.1.12356.101.1.38100' => 'FortiGate 3810A', + '.1.3.6.1.4.1.12356.101.1.4000' => 'FortiGate 400', + '.1.3.6.1.4.1.12356.101.1.40000' => 'FortiGate 4000', + '.1.3.6.1.4.1.12356.101.1.4001' => 'FortiGate 400A', + '.1.3.6.1.4.1.12356.101.1.5000' => 'FortiGate 500', + '.1.3.6.1.4.1.12356.101.1.50000' => 'FortiGate 5000', + '.1.3.6.1.4.1.12356.101.1.50010' => 'FortiGate 5001', + '.1.3.6.1.4.1.12356.101.1.50011' => 'FortiGate 5001A', + '.1.3.6.1.4.1.12356.101.1.50012' => 'FortiGate 5001FA2', + '.1.3.6.1.4.1.12356.101.1.50021' => 'FortiGate 5002A', + '.1.3.6.1.4.1.12356.101.1.50001' => 'FortiGate 5002FB2', + '.1.3.6.1.4.1.12356.101.1.50040' => 'FortiGate 5004', + '.1.3.6.1.4.1.12356.101.1.50050' => 'FortiGate 5005', + '.1.3.6.1.4.1.12356.101.1.50051' => 'FortiGate 5005FA2', + '.1.3.6.1.4.1.12356.101.1.5001' => 'FortiGate 500A', + '.1.3.6.1.4.1.12356.101.1.500' => 'FortiGate 50A', + '.1.3.6.1.4.1.12356.101.1.501' => 'FortiGate 50AM', + '.1.3.6.1.4.1.12356.101.1.502' => 'FortiGate 50B', + '.1.3.6.1.4.1.12356.101.1.504' => 'FortiGate 51B', + '.1.3.6.1.4.1.12356.101.1.600' => 'FortiGate 60', + '.1.3.6.1.4.1.12356.101.1.6201' => 'FortiGate 600D', + '.1.3.6.1.4.1.12356.101.1.602' => 'FortiGate 60ADSL', + '.1.3.6.1.4.1.12356.101.1.603' => 'FortiGate 60B', + '.1.3.6.1.4.1.12356.101.1.601' => 'FortiGate 60M', + '.1.3.6.1.4.1.12356.101.1.6200' => 'FortiGate 620B', + '.1.3.6.1.4.1.12356.101.1.8000' => 'FortiGate 800', + '.1.3.6.1.4.1.12356.101.1.8001' => 'FortiGate 800F', + '.1.3.6.1.4.1.12356.101.1.800' => 'FortiGate 80C', + '.1.3.6.1.4.1.12356.1688' => 'FortiMail 2000A', + '.1.3.6.1.4.1.12356.103.1.1000' => 'FortiManager 100', + '.1.3.6.1.4.1.12356.103.1.20000' => 'FortiManager 2000XL', + '.1.3.6.1.4.1.12356.103.1.30000' => 'FortiManager 3000', + '.1.3.6.1.4.1.12356.103.1.30002' => 'FortiManager 3000B', + '.1.3.6.1.4.1.12356.103.1.4000' => 'FortiManager 400', + '.1.3.6.1.4.1.12356.103.1.4001' => 'FortiManager 400A', + '.1.3.6.1.4.1.12356.106.1.50030' => 'FortiSwitch 5003A', + '.1.3.6.1.4.1.12356.101.1.510' => 'FortiWiFi 50B', + '.1.3.6.1.4.1.12356.101.1.610' => 'FortiWiFi 60', + '.1.3.6.1.4.1.12356.101.1.611' => 'FortiWiFi 60A', + '.1.3.6.1.4.1.12356.101.1.612' => 'FortiWiFi 60AM', + '.1.3.6.1.4.1.12356.101.1.613' => 'FortiWiFi 60B'); $rewrite_extreme_hardware = array ( -'.1.3.6.1.4.1.1916.2.26' => 'Alpine 3802', -'.1.3.6.1.4.1.1916.2.20' => 'Alpine 3804', -'.1.3.6.1.4.1.1916.2.17' => 'Alpine 3808', -'.1.3.6.1.4.1.1916.2.86' => 'Altitude 300', -'.1.3.6.1.4.1.1916.2.75' => 'Altitude 350', -'.1.3.6.1.4.1.1916.2.56' => 'BlackDiamond 10808', -'.1.3.6.1.4.1.1916.2.85' => 'BlackDiamond 12802', -'.1.3.6.1.4.1.1916.2.77' => 'BlackDiamond 12804', -'.1.3.6.1.4.1.1916.2.8' => 'BlackDiamond 6800', -'.1.3.6.1.4.1.1916.2.27' => 'BlackDiamond 6804', -'.1.3.6.1.4.1.1916.2.11' => 'BlackDiamond 6808', -'.1.3.6.1.4.1.1916.2.24' => 'BlackDiamond 6816', -'.1.3.6.1.4.1.1916.2.74' => 'BlackDiamond 8806', -'.1.3.6.1.4.1.1916.2.62' => 'BlackDiamond 8810', -'.1.3.6.1.4.1.1916.2.23' => 'EnetSwitch 24Port', -'.1.3.6.1.4.1.1916.2.83' => 'Sentriant CE150', -'.1.3.6.1.4.1.1916.2.58' => 'Summit 400-48t', -'.1.3.6.1.4.1.1916.2.59' => 'Summit 400-48t', -'.1.3.6.1.4.1.1916.2.71' => 'Summit X450a-24t', -'.1.3.6.1.4.1.1916.2.81' => 'Summit X450a-24t', -'.1.3.6.1.4.1.1916.2.1' => 'Summit 1', -'.1.3.6.1.4.1.1916.2.19' => 'Summit 1iSX', -'.1.3.6.1.4.1.1916.2.14' => 'Summit 1iTX', -'.1.3.6.1.4.1.1916.2.2' => 'Summit 2', -'.1.3.6.1.4.1.1916.2.53' => 'Summit 200-24', -'.1.3.6.1.4.1.1916.2.70' => 'Summit 200-24fx', -'.1.3.6.1.4.1.1916.2.54' => 'Summit 200-48', -'.1.3.6.1.4.1.1916.2.7' => 'Summit 24', -'.1.3.6.1.4.1.1916.2.41' => 'Summit 24e2SX', -'.1.3.6.1.4.1.1916.2.40' => 'Summit 24e2TX', -'.1.3.6.1.4.1.1916.2.25' => 'Summit 24e3', -'.1.3.6.1.4.1.1916.2.3' => 'Summit 3', -'.1.3.6.1.4.1.1916.2.61' => 'Summit 300-24', -'.1.3.6.1.4.1.1916.2.55' => 'Summit 300-48', -'.1.3.6.1.4.1.1916.2.4' => 'Summit 4', -'.1.3.6.1.4.1.1916.2.58' => 'Summit 400-24', -'.1.3.6.1.4.1.1916.2.64' => 'Summit 400-24p', -'.1.3.6.1.4.1.1916.2.63' => 'Summit 400-24t', -'.1.3.6.1.4.1.1916.2.59' => 'Summit 400-24x', -'.1.3.6.1.4.1.1916.2.6' => 'Summit 48', -'.1.3.6.1.4.1.1916.2.16' => 'Summit 48i', -'.1.3.6.1.4.1.1916.2.28' => 'Summit 48i1u', -'.1.3.6.1.4.1.1916.2.5' => 'Summit 4FX', -'.1.3.6.1.4.1.1916.2.15' => 'Summit 5i', -'.1.3.6.1.4.1.1916.2.21' => 'Summit 5iLX', -'.1.3.6.1.4.1.1916.2.22' => 'Summit 5iTX', -'.1.3.6.1.4.1.1916.2.12' => 'Summit 7iSX', -'.1.3.6.1.4.1.1916.2.13' => 'Summit 7iTX', -'.1.3.6.1.4.1.1916.2.30' => 'Summit Px1', -'.1.3.6.1.4.1.1916.2.67' => 'SummitStack', -'.1.3.6.1.4.1.1916.2.93' => 'Summit Ver2Stack', -'.1.3.6.1.4.1.1916.2.68' => 'SummitWM 100', -'.1.3.6.1.4.1.1916.2.69' => 'SummitWM 1000', -'.1.3.6.1.4.1.1916.2.94' => 'SummitWM 200', -'.1.3.6.1.4.1.1916.2.95' => 'SummitWM 2000', -'.1.3.6.1.4.1.1916.2.89' => 'Summit X250-24p', -'.1.3.6.1.4.1.1916.2.88' => 'Summit X250-24t', -'.1.3.6.1.4.1.1916.2.90' => 'Summit X250-24x', -'.1.3.6.1.4.1.1916.2.92' => 'Summit X250-48p', -'.1.3.6.1.4.1.1916.2.91' => 'Summit X250-48t', -'.1.3.6.1.4.1.1916.2.93' => 'Summit X250e-24t (3-Stack)', -'.1.3.6.1.4.1.1916.2.88' => 'Summit X250e-24t (Single)', -'.1.3.6.1.4.1.1916.2.66' => 'Summit X450-24t', -'.1.3.6.1.4.1.1916.2.65' => 'Summit X450-24x', -'.1.3.6.1.4.1.1916.2.80' => 'Summit X450a-24tDC', -'.1.3.6.1.4.1.1916.2.84' => 'Summit X450a-24x', -'.1.3.6.1.4.1.1916.2.82' => 'Summit X450a-24xDC', -'.1.3.6.1.4.1.1916.2.76' => 'Summit X450a-48t', -'.1.3.6.1.4.1.1916.2.87' => 'Summit X450a-48tDC', -'.1.3.6.1.4.1.1916.2.72' => 'Summit X450e-24p', -'.1.3.6.1.4.1.1916.2.79' => 'Summit X450e-48p' + '.1.3.6.1.4.1.1916.2.26' => 'Alpine 3802', + '.1.3.6.1.4.1.1916.2.20' => 'Alpine 3804', + '.1.3.6.1.4.1.1916.2.17' => 'Alpine 3808', + '.1.3.6.1.4.1.1916.2.86' => 'Altitude 300', + '.1.3.6.1.4.1.1916.2.75' => 'Altitude 350', + '.1.3.6.1.4.1.1916.2.56' => 'BlackDiamond 10808', + '.1.3.6.1.4.1.1916.2.85' => 'BlackDiamond 12802', + '.1.3.6.1.4.1.1916.2.77' => 'BlackDiamond 12804', + '.1.3.6.1.4.1.1916.2.8' => 'BlackDiamond 6800', + '.1.3.6.1.4.1.1916.2.27' => 'BlackDiamond 6804', + '.1.3.6.1.4.1.1916.2.11' => 'BlackDiamond 6808', + '.1.3.6.1.4.1.1916.2.24' => 'BlackDiamond 6816', + '.1.3.6.1.4.1.1916.2.74' => 'BlackDiamond 8806', + '.1.3.6.1.4.1.1916.2.62' => 'BlackDiamond 8810', + '.1.3.6.1.4.1.1916.2.23' => 'EnetSwitch 24Port', + '.1.3.6.1.4.1.1916.2.83' => 'Sentriant CE150', + '.1.3.6.1.4.1.1916.2.58' => 'Summit 400-48t', + '.1.3.6.1.4.1.1916.2.59' => 'Summit 400-48t', + '.1.3.6.1.4.1.1916.2.71' => 'Summit X450a-24t', + '.1.3.6.1.4.1.1916.2.81' => 'Summit X450a-24t', + '.1.3.6.1.4.1.1916.2.1' => 'Summit 1', + '.1.3.6.1.4.1.1916.2.19' => 'Summit 1iSX', + '.1.3.6.1.4.1.1916.2.14' => 'Summit 1iTX', + '.1.3.6.1.4.1.1916.2.2' => 'Summit 2', + '.1.3.6.1.4.1.1916.2.53' => 'Summit 200-24', + '.1.3.6.1.4.1.1916.2.70' => 'Summit 200-24fx', + '.1.3.6.1.4.1.1916.2.54' => 'Summit 200-48', + '.1.3.6.1.4.1.1916.2.7' => 'Summit 24', + '.1.3.6.1.4.1.1916.2.41' => 'Summit 24e2SX', + '.1.3.6.1.4.1.1916.2.40' => 'Summit 24e2TX', + '.1.3.6.1.4.1.1916.2.25' => 'Summit 24e3', + '.1.3.6.1.4.1.1916.2.3' => 'Summit 3', + '.1.3.6.1.4.1.1916.2.61' => 'Summit 300-24', + '.1.3.6.1.4.1.1916.2.55' => 'Summit 300-48', + '.1.3.6.1.4.1.1916.2.4' => 'Summit 4', + '.1.3.6.1.4.1.1916.2.58' => 'Summit 400-24', + '.1.3.6.1.4.1.1916.2.64' => 'Summit 400-24p', + '.1.3.6.1.4.1.1916.2.63' => 'Summit 400-24t', + '.1.3.6.1.4.1.1916.2.59' => 'Summit 400-24x', + '.1.3.6.1.4.1.1916.2.6' => 'Summit 48', + '.1.3.6.1.4.1.1916.2.16' => 'Summit 48i', + '.1.3.6.1.4.1.1916.2.28' => 'Summit 48i1u', + '.1.3.6.1.4.1.1916.2.5' => 'Summit 4FX', + '.1.3.6.1.4.1.1916.2.15' => 'Summit 5i', + '.1.3.6.1.4.1.1916.2.21' => 'Summit 5iLX', + '.1.3.6.1.4.1.1916.2.22' => 'Summit 5iTX', + '.1.3.6.1.4.1.1916.2.12' => 'Summit 7iSX', + '.1.3.6.1.4.1.1916.2.13' => 'Summit 7iTX', + '.1.3.6.1.4.1.1916.2.30' => 'Summit Px1', + '.1.3.6.1.4.1.1916.2.67' => 'SummitStack', + '.1.3.6.1.4.1.1916.2.93' => 'Summit Ver2Stack', + '.1.3.6.1.4.1.1916.2.68' => 'SummitWM 100', + '.1.3.6.1.4.1.1916.2.69' => 'SummitWM 1000', + '.1.3.6.1.4.1.1916.2.94' => 'SummitWM 200', + '.1.3.6.1.4.1.1916.2.95' => 'SummitWM 2000', + '.1.3.6.1.4.1.1916.2.89' => 'Summit X250-24p', + '.1.3.6.1.4.1.1916.2.88' => 'Summit X250-24t', + '.1.3.6.1.4.1.1916.2.90' => 'Summit X250-24x', + '.1.3.6.1.4.1.1916.2.92' => 'Summit X250-48p', + '.1.3.6.1.4.1.1916.2.91' => 'Summit X250-48t', + '.1.3.6.1.4.1.1916.2.93' => 'Summit X250e-24t (3-Stack)', + '.1.3.6.1.4.1.1916.2.88' => 'Summit X250e-24t (Single)', + '.1.3.6.1.4.1.1916.2.66' => 'Summit X450-24t', + '.1.3.6.1.4.1.1916.2.65' => 'Summit X450-24x', + '.1.3.6.1.4.1.1916.2.80' => 'Summit X450a-24tDC', + '.1.3.6.1.4.1.1916.2.84' => 'Summit X450a-24x', + '.1.3.6.1.4.1.1916.2.82' => 'Summit X450a-24xDC', + '.1.3.6.1.4.1.1916.2.76' => 'Summit X450a-48t', + '.1.3.6.1.4.1.1916.2.87' => 'Summit X450a-48tDC', + '.1.3.6.1.4.1.1916.2.72' => 'Summit X450e-24p', + '.1.3.6.1.4.1.1916.2.79' => 'Summit X450e-48p' ); $rewrite_ironware_hardware = array( @@ -718,38 +718,38 @@ $rewrite_ironware_hardware = array( ); $rewrite_ios_features = array( - 'PK9S' => 'IP w/SSH LAN Only', - 'LANBASEK9' => 'Lan Base Crypto', - 'LANBASE' => 'Lan Base', - 'ADVENTERPRISEK9_IVS' => 'Advanced Enterprise Crypto Voice', - 'ADVENTERPRISEK9' => 'Advanced Enterprise Crypto', - 'ADVSECURITYK9' => 'Advanced Security Crypto', - 'K91P' => 'Provider Crypto', - 'K4P' => 'Provider Crypto', - 'ADVIPSERVICESK9' => 'Adv IP Services Crypto', - 'ADVIPSERVICES' => 'Adv IP Services', - 'IK9P' => 'IP Plus Crypto', - 'K9O3SY7' => 'IP ADSL FW IDS Plus IPSEC 3DES', - 'SPSERVICESK9' => 'SP Services Crypto', - 'PK9SV' => 'IP MPLS/IPV6 W/SSH + BGP', - 'IS' => 'IP Plus', - 'IPSERVICESK9' => 'IP Services Crypto', - 'BROADBAND' => 'Broadband', - 'IPBASE' => 'IP Base', - 'IPSERVICE' => 'IP Services', - 'P' => 'Service Provider', - 'P11' => 'Broadband Router', - 'G4P5' => 'NRP', - 'JK9S' => 'Enterprise Plus Crypto', - 'IK9S' => 'IP Plus Crypto', - 'JK' => 'Enterprise Plus', - 'I6Q4L2' => 'Layer 2', - 'I6K2L2Q4' => 'Layer 2 Crypto', - 'C3H2S' => 'Layer 2 SI/EI', - '_WAN' => ' + WAN', - ); + 'PK9S' => 'IP w/SSH LAN Only', + 'LANBASEK9' => 'Lan Base Crypto', + 'LANBASE' => 'Lan Base', + 'ADVENTERPRISEK9_IVS' => 'Advanced Enterprise Crypto Voice', + 'ADVENTERPRISEK9' => 'Advanced Enterprise Crypto', + 'ADVSECURITYK9' => 'Advanced Security Crypto', + 'K91P' => 'Provider Crypto', + 'K4P' => 'Provider Crypto', + 'ADVIPSERVICESK9' => 'Adv IP Services Crypto', + 'ADVIPSERVICES' => 'Adv IP Services', + 'IK9P' => 'IP Plus Crypto', + 'K9O3SY7' => 'IP ADSL FW IDS Plus IPSEC 3DES', + 'SPSERVICESK9' => 'SP Services Crypto', + 'PK9SV' => 'IP MPLS/IPV6 W/SSH + BGP', + 'IS' => 'IP Plus', + 'IPSERVICESK9' => 'IP Services Crypto', + 'BROADBAND' => 'Broadband', + 'IPBASE' => 'IP Base', + 'IPSERVICE' => 'IP Services', + 'P' => 'Service Provider', + 'P11' => 'Broadband Router', + 'G4P5' => 'NRP', + 'JK9S' => 'Enterprise Plus Crypto', + 'IK9S' => 'IP Plus Crypto', + 'JK' => 'Enterprise Plus', + 'I6Q4L2' => 'Layer 2', + 'I6K2L2Q4' => 'Layer 2 Crypto', + 'C3H2S' => 'Layer 2 SI/EI', + '_WAN' => ' + WAN', +); - $rewrite_shortif = array ( +$rewrite_shortif = array ( 'tengigabitethernet' => 'Te', 'gigabitethernet' => 'Gi', 'fastethernet' => 'Fa', @@ -764,9 +764,9 @@ $rewrite_ios_features = array( 'vlan' => 'Vlan', 'tunnel' => 'Tunnel', 'serviceinstance' => 'SI', - ); +); - $rewrite_iftype = array ( +$rewrite_iftype = array ( '/^frameRelay$/' => 'Frame Relay', '/^ethernetCsmacd$/' => 'Ethernet', '/^softwareLoopback$/' => 'Loopback', @@ -783,9 +783,9 @@ $rewrite_ios_features = array( '/^aal5$/' => 'ATM AAL5', '/^atmSubInterface$/' => 'ATM Subif', '/^propPointToPointSerial$/' => 'PtP Serial', - ); +); - $rewrite_ifname = array ( +$rewrite_ifname = array ( 'ether' => 'Ether', 'gig' => 'Gig', 'fast' => 'Fast', @@ -805,149 +805,149 @@ $rewrite_ios_features = array( 'hp procurve switch software loopback interface' => 'Loopback Interface', 'control plane interface' => 'Control Plane', 'loop' => 'Loop', - ); +); - $rewrite_hrDevice = array ( +$rewrite_hrDevice = array ( 'GenuineIntel:' => '', 'AuthenticAMD:' => '', 'Intel(R)' => '', 'CPU' => '', '(R)' => '', ' ' => ' ', - ); +); // Specific rewrite functions function makeshortif($if) { - global $rewrite_shortif; + global $rewrite_shortif; - $if = fixifName ($if); - $if = strtolower($if); - $if = array_str_replace($rewrite_shortif, $if); + $if = fixifName ($if); + $if = strtolower($if); + $if = array_str_replace($rewrite_shortif, $if); - return $if; + return $if; } function rewrite_ios_features ($features) { - global $rewrite_ios_features; + global $rewrite_ios_features; - $type = array_preg_replace($rewrite_ios_features, $features); + $type = array_preg_replace($rewrite_ios_features, $features); - return ($features); + return ($features); } function rewrite_fortinet_hardware ($hardware) { - global $rewrite_fortinet_hardware; + global $rewrite_fortinet_hardware; - $hardware = $rewrite_fortinet_hardware[$hardware]; + $hardware = $rewrite_fortinet_hardware[$hardware]; - return ($hardware); + return ($hardware); } function rewrite_extreme_hardware ($hardware) { - global $rewrite_extreme_hardware; + global $rewrite_extreme_hardware; - #$hardware = array_str_replace($rewrite_extreme_hardware, $hardware); - $hardware = $rewrite_extreme_hardware[$hardware]; + #$hardware = array_str_replace($rewrite_extreme_hardware, $hardware); + $hardware = $rewrite_extreme_hardware[$hardware]; - return ($hardware); + return ($hardware); } function rewrite_ftos_hardware ($hardware) { - global $rewrite_ftos_hardware; + global $rewrite_ftos_hardware; - $hardware = $rewrite_ftos_hardware[$hardware]; + $hardware = $rewrite_ftos_hardware[$hardware]; - return ($hardware); + return ($hardware); } function rewrite_ironware_hardware ($hardware) { - global $rewrite_ironware_hardware; + global $rewrite_ironware_hardware; - $hardware = array_str_replace($rewrite_ironware_hardware, $hardware); + $hardware = array_str_replace($rewrite_ironware_hardware, $hardware); - return ($hardware); + return ($hardware); } function rewrite_junose_hardware ($hardware) { - global $rewrite_junose_hardware; + global $rewrite_junose_hardware; - $hardware = array_str_replace($rewrite_junose_hardware, $hardware); + $hardware = array_str_replace($rewrite_junose_hardware, $hardware); - return ($hardware); + return ($hardware); } function fixiftype ($type) { - global $rewrite_iftype; + global $rewrite_iftype; - $type = array_preg_replace($rewrite_iftype, $type); + $type = array_preg_replace($rewrite_iftype, $type); - return ($type); + return ($type); } function fixifName ($inf) { - global $rewrite_ifname; + global $rewrite_ifname; - $inf = strtolower($inf); - $inf = array_str_replace($rewrite_ifname, $inf); + $inf = strtolower($inf); + $inf = array_str_replace($rewrite_ifname, $inf); - return $inf; + return $inf; } function short_hrDeviceDescr($dev) { - global $rewrite_hrDevice; + global $rewrite_hrDevice; - $dev = array_str_replace($rewrite_hrDevice, $dev); - $dev = preg_replace("/\ +/"," ", $dev); - $dev = trim($dev); + $dev = array_str_replace($rewrite_hrDevice, $dev); + $dev = preg_replace("/\ +/"," ", $dev); + $dev = trim($dev); - return $dev; + return $dev; } function short_port_descr ($desc) { - list($desc) = explode("(", $desc); - list($desc) = explode("[", $desc); - list($desc) = explode("{", $desc); - list($desc) = explode("|", $desc); - list($desc) = explode("<", $desc); - $desc = trim($desc); + list($desc) = explode("(", $desc); + list($desc) = explode("[", $desc); + list($desc) = explode("{", $desc); + list($desc) = explode("|", $desc); + list($desc) = explode("<", $desc); + $desc = trim($desc); - return $desc; + return $desc; } // Underlying rewrite functions function array_str_replace($array, $string) { - foreach ($array as $search => $replace) - { - $string = str_replace($search, $replace, $string); - } + foreach ($array as $search => $replace) + { + $string = str_replace($search, $replace, $string); + } - return $string; + return $string; } function array_preg_replace($array, $string) { - foreach ($array as $search => $replace) - { - $string = preg_replace($search, $replace, $string); - } + foreach ($array as $search => $replace) + { + $string = preg_replace($search, $replace, $string); + } - return $string; + return $string; } -?> \ No newline at end of file +?> diff --git a/includes/rrdtool.inc.php b/includes/rrdtool.inc.php index 1c37b7cf42..ffca9a43cb 100644 --- a/includes/rrdtool.inc.php +++ b/includes/rrdtool.inc.php @@ -2,53 +2,53 @@ function rrdtool_update($rrdfile, $rrdupdate) { - return rrdtool("update", $rrdfile, $rrdupdate); + return rrdtool("update", $rrdfile, $rrdupdate); } function rrdtool_create($rrdfile, $rrdupdate) { - global $config; global $debug; + global $config; global $debug; - $command = $config['rrdtool'] . " create $rrdfile $rrdupdate"; + $command = $config['rrdtool'] . " create $rrdfile $rrdupdate"; - if ($debug) { echo($command."\n"); } + if ($debug) { echo($command."\n"); } - return shell_exec($command); + return shell_exec($command); } function rrdtool_fetch($rrdfile, $rrdupdate) { - return rrdtool("fetch", $rrdfile, $rrdupdate); + return rrdtool("fetch", $rrdfile, $rrdupdate); } function rrdtool_graph($rrdfile, $rrdupdate) { - return rrdtool("graph", $rrdfile, $rrdupdate); + return rrdtool("graph", $rrdfile, $rrdupdate); } function rrdtool_last($rrdfile, $rrdupdate) { - return rrdtool("last", $rrdfile, $rrdupdate); + return rrdtool("last", $rrdfile, $rrdupdate); } function rrdtool_lastupdate($rrdfile, $rrdupdate) { - return rrdtool("lastupdate", $rrdfile, $rrdupdate); + return rrdtool("lastupdate", $rrdfile, $rrdupdate); } function rrdtool($command, $file, $options) { - global $config; global $debug; + global $config; global $debug; - $command = $config['rrdtool'] . " $command $file $options"; - if ($config['rrdcached']) - { - $command .= " --daemon " . $config['rrdcached']; - } + $command = $config['rrdtool'] . " $command $file $options"; + if ($config['rrdcached']) + { + $command .= " --daemon " . $config['rrdcached']; + } - if ($debug) { echo($command."\n"); } - return shell_exec($command); + if ($debug) { echo($command."\n"); } + return shell_exec($command); } ?> diff --git a/includes/services.inc.php b/includes/services.inc.php index 5ba02fdd80..41c90c6197 100644 --- a/includes/services.inc.php +++ b/includes/services.inc.php @@ -1,15 +1,15 @@ diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index f176395491..a7d7ee54f2 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -2,751 +2,751 @@ function snmp_get_multi($device, $oids, $options = "-OQUs", $mib = NULL, $mibdir = NULL) { - global $debug,$config,$runtime_stats,$mibs_loaded; + global $debug,$config,$runtime_stats,$mibs_loaded; - if (is_numeric($device['timeout']) && $device['timeout'] > 0) - { - $timeout = $device['timeout']; - } elseif (isset($config['snmp']['timeout'])) { - $timeout = $config['snmp']['timeout']; - } - - if (is_numeric($device['retries']) && $device['retries'] > 0) - { - $retries = $device['retries']; - } elseif (isset($config['snmp']['retries'])) { - $retries = $config['snmp']['retries']; - } - - if (!isset($device['transport'])) - { - $device['transport'] = "udp"; - } - - if ($config['snmp']['internal'] == true) - { - if ($mib && $mibdir && !$mibs_loaded[$mib]) + if (is_numeric($device['timeout']) && $device['timeout'] > 0) { - @snmp_read_mib($mibdir."/".$mib); - $mibs_loaded[$mib] = TRUE; + $timeout = $device['timeout']; + } elseif (isset($config['snmp']['timeout'])) { + $timeout = $config['snmp']['timeout']; } - snmp_set_quick_print(1); - $oids = explode(" ",trim($oids)); - // s->ms - php snmp extension requires the timeout in microseconds. - if (isset($timeout)) { $timeout = $timeout*1000*1000; } - - foreach ($oids as $oid) + if (is_numeric($device['retries']) && $device['retries'] > 0) { - if ($device['snmpver'] == "v2c") - { - $data = @snmp2_get($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries); - } - elseif ($device['snmpver'] == "v1") - { - $data = @snmpget($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries); - } - - list($oid, $index) = explode(".", $oid); - if ($data) { $array[$index][$oid] = $data; } - else { $array[$index][$oid] = null; } + $retries = $device['retries']; + } elseif (isset($config['snmp']['retries'])) { + $retries = $config['snmp']['retries']; } - } - else - { - $cmd = $config['snmpget'] . " -" . $device['snmpver'] . " -c " . $device['community'] . " "; - if ($options) { $cmd .= " " . $options; } - if ($mib) { $cmd .= " -m " . $mib; } - if ($mibdir) { $cmd .= " -M " . $mibdir; } else { $cmd .= " -M ".$config['mibdir']; } - if (isset($timeout)) { $cmd .= " -t " . $timeout; } - if (isset($retries)) { $cmd .= " -r " . $retries; } - - $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oids; - if (!$debug) { $cmd .= " 2>/dev/null"; } - if ($debug) { echo("$cmd\n"); } - $data = trim(shell_exec($cmd)); - $runtime_stats['snmpget']++; - if ($debug) { echo("$data\n"); } - foreach (explode("\n", $data) as $entry) + if (!isset($device['transport'])) { - list($oid,$value) = explode("=", $entry); - $oid = trim($oid); $value = trim($value); - list($oid, $index) = explode(".", $oid); - if (!strstr($value, "at this OID") && isset($oid) && isset($index)) - { - $array[$index][$oid] = $value; - } + $device['transport'] = "udp"; } - } - return $array; + + if ($config['snmp']['internal'] == true) + { + if ($mib && $mibdir && !$mibs_loaded[$mib]) + { + @snmp_read_mib($mibdir."/".$mib); + $mibs_loaded[$mib] = TRUE; + } + + snmp_set_quick_print(1); + $oids = explode(" ",trim($oids)); + // s->ms - php snmp extension requires the timeout in microseconds. + if (isset($timeout)) { $timeout = $timeout*1000*1000; } + + foreach ($oids as $oid) + { + if ($device['snmpver'] == "v2c") + { + $data = @snmp2_get($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries); + } + elseif ($device['snmpver'] == "v1") + { + $data = @snmpget($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries); + } + + list($oid, $index) = explode(".", $oid); + if ($data) { $array[$index][$oid] = $data; } + else { $array[$index][$oid] = null; } + } + } + else + { + $cmd = $config['snmpget'] . " -" . $device['snmpver'] . " -c " . $device['community'] . " "; + if ($options) { $cmd .= " " . $options; } + if ($mib) { $cmd .= " -m " . $mib; } + if ($mibdir) { $cmd .= " -M " . $mibdir; } else { $cmd .= " -M ".$config['mibdir']; } + + if (isset($timeout)) { $cmd .= " -t " . $timeout; } + if (isset($retries)) { $cmd .= " -r " . $retries; } + + $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oids; + if (!$debug) { $cmd .= " 2>/dev/null"; } + if ($debug) { echo("$cmd\n"); } + $data = trim(shell_exec($cmd)); + $runtime_stats['snmpget']++; + if ($debug) { echo("$data\n"); } + foreach (explode("\n", $data) as $entry) + { + list($oid,$value) = explode("=", $entry); + $oid = trim($oid); $value = trim($value); + list($oid, $index) = explode(".", $oid); + if (!strstr($value, "at this OID") && isset($oid) && isset($index)) + { + $array[$index][$oid] = $value; + } + } + } + return $array; } function snmp_get($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL) { - global $debug,$config,$runtime_stats,$mibs_loaded; + global $debug,$config,$runtime_stats,$mibs_loaded; - if (is_numeric($device['timeout']) && $device['timeout'] > 0) - { - $timeout = $device['timeout']; - } elseif (isset($config['snmp']['timeout'])) { - $timeout = $config['snmp']['timeout']; - } - - if (is_numeric($device['retries']) && $device['retries'] > 0) - { - $retries = $device['retries']; - } elseif (isset($config['snmp']['retries'])) { - $retries = $config['snmp']['retries']; - } - - if (!isset($device['transport'])) - { - $device['transport'] = "udp"; - } - - - if (strstr($oid,' ')) - { - echo "BUG: snmp_get called for multiple OIDs: $oid\n"; - echo "Please report this to the Observium team."; - } - - if ($config['snmp']['internal'] == true) - { - if ($mib && $mibdir && !$mibs_loaded[$mib]) + if (is_numeric($device['timeout']) && $device['timeout'] > 0) { - @snmp_read_mib($mibdir."/".$mib); - $mibs_loaded[$mib] = TRUE; + $timeout = $device['timeout']; + } elseif (isset($config['snmp']['timeout'])) { + $timeout = $config['snmp']['timeout']; } - snmp_set_quick_print(1); - // s->ms - php snmp extension requires the timeout in microseconds. - if (isset($timeout)) { $timeout = $timeout*1000*1000; } - if ($device['snmpver'] == "v2c") + + if (is_numeric($device['retries']) && $device['retries'] > 0) { - $data = @snmp2_get($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries); - } elseif ($device['snmpver'] == "v1") { - $data = @snmpget($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries); + $retries = $device['retries']; + } elseif (isset($config['snmp']['retries'])) { + $retries = $config['snmp']['retries']; } - if ($debug) { print "DEBUG: $oid: $data\nDEBUG: cmd: ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$device['community']." ".$oid." ".$timeout." ".$retries."\n"; } - } - else - { - $cmd = $config['snmpget'] . " -" . $device['snmpver'] . " -c " . $device['community'] . " "; - if ($options) { $cmd .= " " . $options; } - if ($mib) { $cmd .= " -m " . $mib; } - if ($mibdir) { $cmd .= " -M " . $mibdir; } else { $cmd .= " -M ".$config['mibdir']; } - if (isset($timeout)) { $cmd .= " -t " . $timeout; } - if (isset($retries)) { $cmd .= " -r " . $retries; } + if (!isset($device['transport'])) + { + $device['transport'] = "udp"; + } - $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid; - if (!$debug) { $cmd .= " 2>/dev/null"; } - if ($debug) { echo("$cmd\n"); } - $data = trim(shell_exec($cmd)); - if ($debug) { echo("$data\n"); } - } - $runtime_stats['snmpget']++; - if (is_string($data) && (preg_match("/No Such Instance/i", $data) || preg_match("/No Such Object/i", $data) || preg_match("/No more variables left/i", $data))) - { - return false; - } - elseif ($data) { return $data; } - else { return false; } + + if (strstr($oid,' ')) + { + echo "BUG: snmp_get called for multiple OIDs: $oid\n"; + echo "Please report this to the Observium team."; + } + + if ($config['snmp']['internal'] == true) + { + if ($mib && $mibdir && !$mibs_loaded[$mib]) + { + @snmp_read_mib($mibdir."/".$mib); + $mibs_loaded[$mib] = TRUE; + } + snmp_set_quick_print(1); + // s->ms - php snmp extension requires the timeout in microseconds. + if (isset($timeout)) { $timeout = $timeout*1000*1000; } + if ($device['snmpver'] == "v2c") + { + $data = @snmp2_get($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries); + } elseif ($device['snmpver'] == "v1") { + $data = @snmpget($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries); + } + if ($debug) { print "DEBUG: $oid: $data\nDEBUG: cmd: ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$device['community']." ".$oid." ".$timeout." ".$retries."\n"; } + } + else + { + $cmd = $config['snmpget'] . " -" . $device['snmpver'] . " -c " . $device['community'] . " "; + + if ($options) { $cmd .= " " . $options; } + if ($mib) { $cmd .= " -m " . $mib; } + if ($mibdir) { $cmd .= " -M " . $mibdir; } else { $cmd .= " -M ".$config['mibdir']; } + if (isset($timeout)) { $cmd .= " -t " . $timeout; } + if (isset($retries)) { $cmd .= " -r " . $retries; } + + $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid; + if (!$debug) { $cmd .= " 2>/dev/null"; } + if ($debug) { echo("$cmd\n"); } + $data = trim(shell_exec($cmd)); + if ($debug) { echo("$data\n"); } + } + $runtime_stats['snmpget']++; + if (is_string($data) && (preg_match("/No Such Instance/i", $data) || preg_match("/No Such Object/i", $data) || preg_match("/No more variables left/i", $data))) + { + return false; + } + elseif ($data) { return $data; } + else { return false; } } function snmp_walk($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL) { - global $debug,$config,$runtime_stats; + global $debug,$config,$runtime_stats; - if (is_numeric($device['timeout']) && $device['timeout'] > 0) - { - $timeout = $device['timeout']; - } elseif (isset($config['snmp']['timeout'])) - { - $timeout = $config['snmp']['timeout']; - } - - if (is_numeric($device['retries']) && $device['retries'] > 0) - { - $retries = $device['retries']; - } elseif (isset($config['snmp']['retries'])) { - $retries = $config['snmp']['retries']; - } - if (!isset($device['transport'])) - { - $device['transport'] = "udp"; - } - - - // php has no bulkwalk functionality, so use binary for this. - if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) - { - $snmpcommand = $config['snmpwalk']; - } - else - { - $snmpcommand = $config['snmpbulkwalk']; - } - - $cmd = $snmpcommand . " -" . $device['snmpver'] . " -c " . $device['community'] . " "; - if ($options) { $cmd .= " $options "; } - if ($mib) { $cmd .= " -m $mib"; } - if ($mibdir) { $cmd .= " -M " . $mibdir; } else { $cmd .= " -M ".$config['mibdir']; } - if (isset($timeout)) { $cmd .= " -t " . $timeout; } - if (isset($retries)) { $cmd .= " -r " . $retries; } - - $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid; - - if (!$debug) { $cmd .= " 2>/dev/null"; } - if ($debug) { echo("$cmd\n"); } - $data = trim(shell_exec($cmd)); - if ($debug) { echo("$data\n"); } - - if (is_string($data) && (preg_match("/No Such (Object|Instance)/i", $data))) - { - $data = false; - } - else - { - if (preg_match("/No more variables left in this MIB View \(It is past the end of the MIB tree\)$/",$data)) { - # Bit ugly :-( - $d_ex = explode("\n",$data); - unset($d_ex[count($d_ex)-1]); - $data = implode("\n",$d_ex); + if (is_numeric($device['timeout']) && $device['timeout'] > 0) + { + $timeout = $device['timeout']; + } elseif (isset($config['snmp']['timeout'])) + { + $timeout = $config['snmp']['timeout']; } - } - $runtime_stats['snmpwalk']++; - return $data; + if (is_numeric($device['retries']) && $device['retries'] > 0) + { + $retries = $device['retries']; + } elseif (isset($config['snmp']['retries'])) { + $retries = $config['snmp']['retries']; + } + if (!isset($device['transport'])) + { + $device['transport'] = "udp"; + } + + + // php has no bulkwalk functionality, so use binary for this. + if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) + { + $snmpcommand = $config['snmpwalk']; + } + else + { + $snmpcommand = $config['snmpbulkwalk']; + } + + $cmd = $snmpcommand . " -" . $device['snmpver'] . " -c " . $device['community'] . " "; + if ($options) { $cmd .= " $options "; } + if ($mib) { $cmd .= " -m $mib"; } + if ($mibdir) { $cmd .= " -M " . $mibdir; } else { $cmd .= " -M ".$config['mibdir']; } + if (isset($timeout)) { $cmd .= " -t " . $timeout; } + if (isset($retries)) { $cmd .= " -r " . $retries; } + + $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid; + + if (!$debug) { $cmd .= " 2>/dev/null"; } + if ($debug) { echo("$cmd\n"); } + $data = trim(shell_exec($cmd)); + if ($debug) { echo("$data\n"); } + + if (is_string($data) && (preg_match("/No Such (Object|Instance)/i", $data))) + { + $data = false; + } + else + { + if (preg_match("/No more variables left in this MIB View \(It is past the end of the MIB tree\)$/",$data)) { + # Bit ugly :-( + $d_ex = explode("\n",$data); + unset($d_ex[count($d_ex)-1]); + $data = implode("\n",$d_ex); + } + } + $runtime_stats['snmpwalk']++; + + return $data; } function snmpwalk_cache_cip($device, $oid, $array, $mib = 0) { - global $config; + global $config; - if (is_numeric($device['timeout']) && $device['timeout'] > 0) - { - $timeout = $device['timeout']; - } elseif (isset($config['snmp']['timeout'])) { - $timeout = $config['snmp']['timeout']; - } - - if (is_numeric($device['retries']) && $device['retries'] > 0) - { - $retries = $device['retries']; - } elseif (isset($config['snmp']['retries'])) { - $retries = $config['snmp']['retries']; - } - - if (!isset($device['transport'])) { $device['transport'] = "udp"; } - - if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) - { - $snmpcommand = $config['snmpwalk']; - } - else - { - $snmpcommand = $config['snmpbulkwalk']; - } - - $cmd = $snmpcommand . " -O snQ -" . $device['snmpver'] . " -c " . $device['community'] . " "; - if ($mib) { $cmd .= " -m $mib"; } - $cmd .= " -M ".$config['install_dir']."/mibs/"; - if (isset($timeout)) { $cmd .= " -t " . $timeout; } - if (isset($retries)) { $cmd .= " -r " . $retries; } - - $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid; - - if (!$debug) { $cmd .= " 2>/dev/null"; } - $data = trim(shell_exec($cmd)); - $device_id = $device['device_id']; - - #echo("Caching: $oid\n"); - foreach (explode("\n", $data) as $entry) - { - list ($this_oid, $this_value) = preg_split("/=/", $entry); - $this_oid = trim($this_oid); - $this_value = trim($this_value); - $this_oid = substr($this_oid, 30); - list($ifIndex,$dir,$a,$b,$c,$d,$e,$f) = explode(".", $this_oid); - $h_a = zeropad(dechex($a)); - $h_b = zeropad(dechex($b)); - $h_c = zeropad(dechex($c)); - $h_d = zeropad(dechex($d)); - $h_e = zeropad(dechex($e)); - $h_f = zeropad(dechex($f)); - $mac = "$h_a$h_b$h_c$h_d$h_e$h_f"; - if ($dir == "1") { $dir = "input"; } elseif ($dir == "2") { $dir = "output"; } - if ($mac && $dir) + if (is_numeric($device['timeout']) && $device['timeout'] > 0) { - $array[$ifIndex][$mac][$oid][$dir] = $this_value; + $timeout = $device['timeout']; + } elseif (isset($config['snmp']['timeout'])) { + $timeout = $config['snmp']['timeout']; } - return $array; - } + if (is_numeric($device['retries']) && $device['retries'] > 0) + { + $retries = $device['retries']; + } elseif (isset($config['snmp']['retries'])) { + $retries = $config['snmp']['retries']; + } + + if (!isset($device['transport'])) { $device['transport'] = "udp"; } + + if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) + { + $snmpcommand = $config['snmpwalk']; + } + else + { + $snmpcommand = $config['snmpbulkwalk']; + } + + $cmd = $snmpcommand . " -O snQ -" . $device['snmpver'] . " -c " . $device['community'] . " "; + if ($mib) { $cmd .= " -m $mib"; } + $cmd .= " -M ".$config['install_dir']."/mibs/"; + if (isset($timeout)) { $cmd .= " -t " . $timeout; } + if (isset($retries)) { $cmd .= " -r " . $retries; } + + $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid; + + if (!$debug) { $cmd .= " 2>/dev/null"; } + $data = trim(shell_exec($cmd)); + $device_id = $device['device_id']; + + #echo("Caching: $oid\n"); + foreach (explode("\n", $data) as $entry) + { + list ($this_oid, $this_value) = preg_split("/=/", $entry); + $this_oid = trim($this_oid); + $this_value = trim($this_value); + $this_oid = substr($this_oid, 30); + list($ifIndex,$dir,$a,$b,$c,$d,$e,$f) = explode(".", $this_oid); + $h_a = zeropad(dechex($a)); + $h_b = zeropad(dechex($b)); + $h_c = zeropad(dechex($c)); + $h_d = zeropad(dechex($d)); + $h_e = zeropad(dechex($e)); + $h_f = zeropad(dechex($f)); + $mac = "$h_a$h_b$h_c$h_d$h_e$h_f"; + if ($dir == "1") { $dir = "input"; } elseif ($dir == "2") { $dir = "output"; } + if ($mac && $dir) + { + $array[$ifIndex][$mac][$oid][$dir] = $this_value; + } + + return $array; + } } function snmp_cache_ifIndex($device) { - // FIXME: this has no internal version, and is not yet using our own snmp_* - global $config; + // FIXME: this has no internal version, and is not yet using our own snmp_* + global $config; - if (is_numeric($device['timeout']) && $device['timeout'] > 0) - { - $timeout = $device['timeout']; - } elseif (isset($config['snmp']['timeout'])) { - $timeout = $config['snmp']['timeout']; - } - - if (is_numeric($device['retries']) && $device['retries'] > 0) - { - $retries = $device['retries']; - } elseif (isset($config['snmp']['retries'])) { - $retries = $config['snmp']['retries']; - } - - if (!isset($device['transport'])) { $device['transport'] = "udp"; } - - if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) - { - $snmpcommand = $config['snmpwalk']; - } - else - { - $snmpcommand = $config['snmpbulkwalk']; - } - - $cmd = $snmpcommand . " -O Qs -" . $device['snmpver'] . " -c " . $device['community'] . " "; - $cmd .= " -M ".$config['install_dir']."/mibs/"; - $cmd .= " -m IF-MIB ifIndex"; - - if (isset($timeout)) { $cmd .= " -t " . $timeout; } - if (isset($retries)) { $cmd .= " -r " . $retries; } - if (!$debug) { $cmd .= " 2>/dev/null"; } - $data = trim(shell_exec($cmd)); - $device_id = $device['device_id']; - - foreach (explode("\n", $data) as $entry) - { - list ($this_oid, $this_value) = preg_split("/=/", $entry); - list ($this_oid, $this_index) = explode(".", $this_oid); - $this_index = trim($this_index); - $this_oid = trim($this_oid); - $this_value = trim($this_value); - if (!strstr($this_value, "at this OID") && $this_index) + if (is_numeric($device['timeout']) && $device['timeout'] > 0) { - $array[] = $this_value; + $timeout = $device['timeout']; + } elseif (isset($config['snmp']['timeout'])) { + $timeout = $config['snmp']['timeout']; } - } - return $array; + if (is_numeric($device['retries']) && $device['retries'] > 0) + { + $retries = $device['retries']; + } elseif (isset($config['snmp']['retries'])) { + $retries = $config['snmp']['retries']; + } + + if (!isset($device['transport'])) { $device['transport'] = "udp"; } + + if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) + { + $snmpcommand = $config['snmpwalk']; + } + else + { + $snmpcommand = $config['snmpbulkwalk']; + } + + $cmd = $snmpcommand . " -O Qs -" . $device['snmpver'] . " -c " . $device['community'] . " "; + $cmd .= " -M ".$config['install_dir']."/mibs/"; + $cmd .= " -m IF-MIB ifIndex"; + + if (isset($timeout)) { $cmd .= " -t " . $timeout; } + if (isset($retries)) { $cmd .= " -r " . $retries; } + if (!$debug) { $cmd .= " 2>/dev/null"; } + $data = trim(shell_exec($cmd)); + $device_id = $device['device_id']; + + foreach (explode("\n", $data) as $entry) + { + list ($this_oid, $this_value) = preg_split("/=/", $entry); + list ($this_oid, $this_index) = explode(".", $this_oid); + $this_index = trim($this_index); + $this_oid = trim($this_oid); + $this_value = trim($this_value); + if (!strstr($this_value, "at this OID") && $this_index) + { + $array[] = $this_value; + } + } + + return $array; } function snmpwalk_cache_oid($device, $oid, $array, $mib = NULL, $mibdir = NULL) { - $data = snmp_walk($device, $oid, "-OQUs", $mib, $mibdir); - foreach (explode("\n", $data) as $entry) - { - list($oid,$value) = explode("=", $entry); - $oid = trim($oid); $value = trim($value); - list($oid, $index) = explode(".", $oid); - if (!strstr($value, "at this OID") && isset($oid) && isset($index)) + $data = snmp_walk($device, $oid, "-OQUs", $mib, $mibdir); + foreach (explode("\n", $data) as $entry) { - $array[$index][$oid] = $value; + list($oid,$value) = explode("=", $entry); + $oid = trim($oid); $value = trim($value); + list($oid, $index) = explode(".", $oid); + if (!strstr($value, "at this OID") && isset($oid) && isset($index)) + { + $array[$index][$oid] = $value; + } } - } - return $array; + return $array; } function snmpwalk_cache_multi_oid($device, $oid, $array, $mib = NULL, $mibdir = NULL) { - global $cache; + global $cache; - if (!(is_array($cache['snmp'][$device['device_id']]) && array_key_exists($oid,$cache['snmp'][$device['device_id']]))) - { - $data = snmp_walk($device, $oid, "-OQUs", $mib, $mibdir); - foreach (explode("\n", $data) as $entry) + if (!(is_array($cache['snmp'][$device['device_id']]) && array_key_exists($oid,$cache['snmp'][$device['device_id']]))) { - list($r_oid,$value) = explode("=", $entry); - $r_oid = trim($r_oid); $value = trim($value); - $oid_parts = explode(".", $r_oid); - $r_oid = $oid_parts['0']; - $index = $oid_parts['1']; - if (isset($oid_parts['2'])) { $index .= ".".$oid_parts['2']; } - if (isset($oid_parts['3'])) { $index .= ".".$oid_parts['3']; } - if (isset($oid_parts['4'])) { $index .= ".".$oid_parts['4']; } - if (isset($oid_parts['5'])) { $index .= ".".$oid_parts['5']; } - if (isset($oid_parts['6'])) { $index .= ".".$oid_parts['6']; } - if (!strstr($value, "at this OID") && isset($r_oid) && isset($index)) - { - $array[$index][$r_oid] = $value; - } + $data = snmp_walk($device, $oid, "-OQUs", $mib, $mibdir); + foreach (explode("\n", $data) as $entry) + { + list($r_oid,$value) = explode("=", $entry); + $r_oid = trim($r_oid); $value = trim($value); + $oid_parts = explode(".", $r_oid); + $r_oid = $oid_parts['0']; + $index = $oid_parts['1']; + if (isset($oid_parts['2'])) { $index .= ".".$oid_parts['2']; } + if (isset($oid_parts['3'])) { $index .= ".".$oid_parts['3']; } + if (isset($oid_parts['4'])) { $index .= ".".$oid_parts['4']; } + if (isset($oid_parts['5'])) { $index .= ".".$oid_parts['5']; } + if (isset($oid_parts['6'])) { $index .= ".".$oid_parts['6']; } + if (!strstr($value, "at this OID") && isset($r_oid) && isset($index)) + { + $array[$index][$r_oid] = $value; + } + } + $cache['snmp'][$device['device_id']][$oid] = $array; } - $cache['snmp'][$device['device_id']][$oid] = $array; - } - return $cache['snmp'][$device['device_id']][$oid]; + return $cache['snmp'][$device['device_id']][$oid]; } function snmpwalk_cache_double_oid($device, $oid, $array, $mib = NULL, $mibdir = NULL) { - $data = snmp_walk($device, $oid, "-OQUs", $mib, $mibdir); + $data = snmp_walk($device, $oid, "-OQUs", $mib, $mibdir); - foreach (explode("\n", $data) as $entry) - { - list($oid,$value) = explode("=", $entry); - $oid = trim($oid); $value = trim($value); - list($oid, $first, $second) = explode(".", $oid); - if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) + foreach (explode("\n", $data) as $entry) { - $double = $first.".".$second; - $array[$double][$oid] = $value; + list($oid,$value) = explode("=", $entry); + $oid = trim($oid); $value = trim($value); + list($oid, $first, $second) = explode(".", $oid); + if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) + { + $double = $first.".".$second; + $array[$double][$oid] = $value; + } } - } - return $array; + return $array; } function snmpwalk_cache_triple_oid($device, $oid, $array, $mib = NULL, $mibdir = NULL) { - $data = snmp_walk($device, $oid, "-OQUs", $mib, $mibdir); + $data = snmp_walk($device, $oid, "-OQUs", $mib, $mibdir); - foreach (explode("\n", $data) as $entry) - { - list($oid,$value) = explode("=", $entry); - $oid = trim($oid); $value = trim($value); - list($oid, $first, $second, $third) = explode(".", $oid); - if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) + foreach (explode("\n", $data) as $entry) { - $index = $first.".".$second.".".$third; - $array[$index][$oid] = $value; + list($oid,$value) = explode("=", $entry); + $oid = trim($oid); $value = trim($value); + list($oid, $first, $second, $third) = explode(".", $oid); + if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) + { + $index = $first.".".$second.".".$third; + $array[$index][$oid] = $value; + } } - } - return $array; + return $array; } function snmpwalk_cache_twopart_oid($device, $oid, $array, $mib = 0) { - global $config; + global $config; - if (is_numeric($device['timeout']) && $device['timeout'] > 0) - { - $timeout = $device['timeout']; - } elseif (isset($config['snmp']['timeout'])) { - $timeout = $config['snmp']['timeout']; - } - - if (is_numeric($device['retries']) && $device['retries'] > 0) - { - $retries = $device['retries']; - } elseif (isset($config['snmp']['retries'])) { - $retries = $config['snmp']['retries']; - } - - if (!isset($device['transport'])) - { - $device['transport'] = "udp"; - } - - if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) - { - $snmpcommand = $config['snmpwalk']; - } - else - { - $snmpcommand = $config['snmpbulkwalk']; - } - $cmd = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " "; - $cmd .= " -M ".$config['install_dir']."/mibs/"; - if ($mib) { $cmd .= " -m $mib"; } - if (isset($timeout)) { $cmd .= " -t " . $timeout; } - if (isset($retries)) { $cmd .= " -r " . $retries; } - $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid; - if (!$debug) { $cmd .= " 2>/dev/null"; } - $data = trim(shell_exec($cmd)); - $device_id = $device['device_id']; - foreach (explode("\n", $data) as $entry) - { - list($oid,$value) = explode("=", $entry); - $oid = trim($oid); $value = trim($value); $value = str_replace("\"", "", $value); - list($oid, $first, $second) = explode(".", $oid); - if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) + if (is_numeric($device['timeout']) && $device['timeout'] > 0) { - $array[$first][$second][$oid] = $value; + $timeout = $device['timeout']; + } elseif (isset($config['snmp']['timeout'])) { + $timeout = $config['snmp']['timeout']; } - } - return $array; + if (is_numeric($device['retries']) && $device['retries'] > 0) + { + $retries = $device['retries']; + } elseif (isset($config['snmp']['retries'])) { + $retries = $config['snmp']['retries']; + } + + if (!isset($device['transport'])) + { + $device['transport'] = "udp"; + } + + if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) + { + $snmpcommand = $config['snmpwalk']; + } + else + { + $snmpcommand = $config['snmpbulkwalk']; + } + $cmd = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " "; + $cmd .= " -M ".$config['install_dir']."/mibs/"; + if ($mib) { $cmd .= " -m $mib"; } + if (isset($timeout)) { $cmd .= " -t " . $timeout; } + if (isset($retries)) { $cmd .= " -r " . $retries; } + $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid; + if (!$debug) { $cmd .= " 2>/dev/null"; } + $data = trim(shell_exec($cmd)); + $device_id = $device['device_id']; + foreach (explode("\n", $data) as $entry) + { + list($oid,$value) = explode("=", $entry); + $oid = trim($oid); $value = trim($value); $value = str_replace("\"", "", $value); + list($oid, $first, $second) = explode(".", $oid); + if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) + { + $array[$first][$second][$oid] = $value; + } + } + + return $array; } function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = 0) { - global $config, $debug; + global $config, $debug; - if (is_numeric($device['timeout']) && $device['timeout'] > 0) - { - $timeout = $device['timeout']; - } elseif (isset($config['snmp']['timeout'])) { - $timeout = $config['snmp']['timeout']; - } - - if (is_numeric($device['retries']) && $device['retries'] > 0) - { - $retries = $device['retries']; - } elseif (isset($config['snmp']['retries'])) { - $retries = $config['snmp']['retries']; - } - - if (!isset($device['transport'])) - { - $device['transport'] = "udp"; - } - - - if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) - { - $snmpcommand = $config['snmpwalk']; - } - else - { - $snmpcommand = $config['snmpbulkwalk']; - } - - $cmd = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " "; - $cmd .= " -M ".$config['install_dir']."/mibs/"; - if ($mib) { $cmd .= " -m $mib"; } - if (isset($timeout)) { $cmd .= " -t " . $timeout; } - if (isset($retries)) { $cmd .= " -r " . $retries; } - $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid; - if (!$debug) { $cmd .= " 2>/dev/null"; } - $data = trim(shell_exec($cmd)); - - $device_id = $device['device_id']; - foreach (explode("\n", $data) as $entry) - { - list($oid,$value) = explode("=", $entry); - $oid = trim($oid); $value = trim($value); $value = str_replace("\"", "", $value); - list($oid, $first, $second, $third) = explode(".", $oid); - if ($debug) {echo("$entry || $oid || $first || $second || $third\n"); } - if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second) && isset($third)) + if (is_numeric($device['timeout']) && $device['timeout'] > 0) { - $array[$first][$second][$third][$oid] = $value; + $timeout = $device['timeout']; + } elseif (isset($config['snmp']['timeout'])) { + $timeout = $config['snmp']['timeout']; } - } - return $array; + if (is_numeric($device['retries']) && $device['retries'] > 0) + { + $retries = $device['retries']; + } elseif (isset($config['snmp']['retries'])) { + $retries = $config['snmp']['retries']; + } + + if (!isset($device['transport'])) + { + $device['transport'] = "udp"; + } + + + if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) + { + $snmpcommand = $config['snmpwalk']; + } + else + { + $snmpcommand = $config['snmpbulkwalk']; + } + + $cmd = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " "; + $cmd .= " -M ".$config['install_dir']."/mibs/"; + if ($mib) { $cmd .= " -m $mib"; } + if (isset($timeout)) { $cmd .= " -t " . $timeout; } + if (isset($retries)) { $cmd .= " -r " . $retries; } + $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid; + if (!$debug) { $cmd .= " 2>/dev/null"; } + $data = trim(shell_exec($cmd)); + + $device_id = $device['device_id']; + foreach (explode("\n", $data) as $entry) + { + list($oid,$value) = explode("=", $entry); + $oid = trim($oid); $value = trim($value); $value = str_replace("\"", "", $value); + list($oid, $first, $second, $third) = explode(".", $oid); + if ($debug) {echo("$entry || $oid || $first || $second || $third\n"); } + if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second) && isset($third)) + { + $array[$first][$second][$third][$oid] = $value; + } + } + + return $array; } function snmp_cache_slotport_oid($oid, $device, $array, $mib = 0) { - global $config; + global $config; - if (is_numeric($device['timeout']) && $device['timeout'] > 0) - { - $timeout = $device['timeout']; - } elseif (isset($config['snmp']['timeout'])) { - $timeout = $config['snmp']['timeout']; - } - - if (is_numeric($device['retries']) && $device['retries'] > 0) - { - $retries = $device['retries']; - } elseif (isset($config['snmp']['retries'])) { - $retries = $config['snmp']['retries']; - } - - if (!isset($device['transport'])) - { - $device['transport'] = "udp"; - } - - if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) - { - $snmpcommand = $config['snmpwalk']; - } - else - { - $snmpcommand = $config['snmpbulkwalk']; - } - - $cmd = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " "; - if ($mib) { $cmd .= " -m $mib"; } - $cmd .= " -M ".$config['install_dir']."/mibs/"; - if (isset($timeout)) { $cmd .= " -t " . $timeout; } - if (isset($retries)) { $cmd .= " -r " . $retries; } - $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid; - if (!$debug) { $cmd .= " 2>/dev/null"; } - $data = trim(shell_exec($cmd)); - $device_id = $device['device_id']; - - foreach (explode("\n", $data) as $entry) - { - $entry = str_replace($oid.".", "", $entry); - list($slotport, $value) = explode("=", $entry); - $slotport = trim($slotport); $value = trim($value); - if ($array[$slotport]['ifIndex']) + if (is_numeric($device['timeout']) && $device['timeout'] > 0) { - $ifIndex = $array[$slotport]['ifIndex']; - $array[$ifIndex][$oid] = $value; + $timeout = $device['timeout']; + } elseif (isset($config['snmp']['timeout'])) { + $timeout = $config['snmp']['timeout']; } - } - return $array; + if (is_numeric($device['retries']) && $device['retries'] > 0) + { + $retries = $device['retries']; + } elseif (isset($config['snmp']['retries'])) { + $retries = $config['snmp']['retries']; + } + + if (!isset($device['transport'])) + { + $device['transport'] = "udp"; + } + + if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) + { + $snmpcommand = $config['snmpwalk']; + } + else + { + $snmpcommand = $config['snmpbulkwalk']; + } + + $cmd = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " "; + if ($mib) { $cmd .= " -m $mib"; } + $cmd .= " -M ".$config['install_dir']."/mibs/"; + if (isset($timeout)) { $cmd .= " -t " . $timeout; } + if (isset($retries)) { $cmd .= " -r " . $retries; } + $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid; + if (!$debug) { $cmd .= " 2>/dev/null"; } + $data = trim(shell_exec($cmd)); + $device_id = $device['device_id']; + + foreach (explode("\n", $data) as $entry) + { + $entry = str_replace($oid.".", "", $entry); + list($slotport, $value) = explode("=", $entry); + $slotport = trim($slotport); $value = trim($value); + if ($array[$slotport]['ifIndex']) + { + $ifIndex = $array[$slotport]['ifIndex']; + $array[$ifIndex][$oid] = $value; + } + } + + return $array; } function snmp_cache_oid($oid, $device, $array, $mib = 0) { - $array = snmpwalk_cache_oid($device, $oid, $array, $mib); - return $array; + $array = snmpwalk_cache_oid($device, $oid, $array, $mib); + return $array; } function snmp_cache_port_oids($oids, $port, $device, $array, $mib=0) { - global $config; + global $config; - if (is_numeric($device['timeout']) && $device['timeout'] > 0) - { - $timeout = $device['timeout']; - } elseif (isset($config['snmp']['timeout'])) { - $timeout = $config['snmp']['timeout']; - } - - if (is_numeric($device['retries']) && $device['retries'] > 0) - { - $retries = $device['retries']; - } elseif (isset($config['snmp']['retries'])) { - $retries = $config['snmp']['retries']; - } - - if (!isset($device['transport'])) - { - $device['transport'] = "udp"; - } - - foreach ($oids as $oid) - { - $string .= " $oid.$port"; - } - - $cmd = $config['snmpget'] . " -O vq -" . $device['snmpver'] . " -c " . $device['community'] . " "; - if (isset($timeout)) { $cmd .= " -t " . $timeout; } - if (isset($retries)) { $cmd .= " -r " . $retries; } - $cmd .= " -M ".$config['install_dir']."/mibs/"; - if ($mib) { $cmd .= " -m $mib"; } - $cmd .= " -t " . $timeout . " -r " . $retries; - $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$string; - if (!$debug) { $cmd .= " 2>/dev/null"; } - $data = trim(shell_exec($cmd)); - $x=0; - $values = explode("\n", $data); - #echo("Caching: ifIndex $port\n"); - foreach ($oids as $oid){ - if (!strstr($values[$x], "at this OID")) + if (is_numeric($device['timeout']) && $device['timeout'] > 0) { - $array[$port][$oid] = $values[$x]; + $timeout = $device['timeout']; + } elseif (isset($config['snmp']['timeout'])) { + $timeout = $config['snmp']['timeout']; } - $x++; - } - return $array; + if (is_numeric($device['retries']) && $device['retries'] > 0) + { + $retries = $device['retries']; + } elseif (isset($config['snmp']['retries'])) { + $retries = $config['snmp']['retries']; + } + + if (!isset($device['transport'])) + { + $device['transport'] = "udp"; + } + + foreach ($oids as $oid) + { + $string .= " $oid.$port"; + } + + $cmd = $config['snmpget'] . " -O vq -" . $device['snmpver'] . " -c " . $device['community'] . " "; + if (isset($timeout)) { $cmd .= " -t " . $timeout; } + if (isset($retries)) { $cmd .= " -r " . $retries; } + $cmd .= " -M ".$config['install_dir']."/mibs/"; + if ($mib) { $cmd .= " -m $mib"; } + $cmd .= " -t " . $timeout . " -r " . $retries; + $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$string; + if (!$debug) { $cmd .= " 2>/dev/null"; } + $data = trim(shell_exec($cmd)); + $x=0; + $values = explode("\n", $data); + #echo("Caching: ifIndex $port\n"); + foreach ($oids as $oid){ + if (!strstr($values[$x], "at this OID")) + { + $array[$port][$oid] = $values[$x]; + } + $x++; + } + + return $array; } function snmp_cache_portIfIndex($device, $array) { - global $config; + global $config; - if (is_numeric($device['timeout']) && $device['timeout'] > 0) - { - $timeout = $device['timeout']; - } elseif (isset($config['snmp']['timeout'])) { - $timeout = $config['snmp']['timeout']; - } - - if (is_numeric($device['retries']) && $device['retries'] > 0) - { - $retries = $device['retries']; - } elseif (isset($config['snmp']['retries'])) { - $retries = $config['snmp']['retries']; - } - - if (!isset($device['transport'])) - { - $device['transport'] = "udp"; - } - - $cmd = $config['snmpwalk'] . " -CI -m CISCO-STACK-MIB -O q -" . $device['snmpver'] . " -c " . $device['community'] . " "; - $cmd .= " -M ".$config['install_dir']."/mibs/"; - if (isset($timeout)) { $cmd .= " -t " . $timeout; } - if (isset($retries)) { $cmd .= " -r " . $retries; } - $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." portIfIndex"; - $output = trim(shell_exec($cmd)); - $device_id = $device['device_id']; - - foreach (explode("\n", $output) as $entry) - { - $entry = str_replace("CISCO-STACK-MIB::portIfIndex.", "", $entry); - list($slotport, $ifIndex) = explode(" ", $entry); - if ($slotport && $ifIndex){ - $array[$ifIndex]['portIfIndex'] = $slotport; - $array[$slotport]['ifIndex'] = $ifIndex; + if (is_numeric($device['timeout']) && $device['timeout'] > 0) + { + $timeout = $device['timeout']; + } elseif (isset($config['snmp']['timeout'])) { + $timeout = $config['snmp']['timeout']; } - } - return $array; + if (is_numeric($device['retries']) && $device['retries'] > 0) + { + $retries = $device['retries']; + } elseif (isset($config['snmp']['retries'])) { + $retries = $config['snmp']['retries']; + } + + if (!isset($device['transport'])) + { + $device['transport'] = "udp"; + } + + $cmd = $config['snmpwalk'] . " -CI -m CISCO-STACK-MIB -O q -" . $device['snmpver'] . " -c " . $device['community'] . " "; + $cmd .= " -M ".$config['install_dir']."/mibs/"; + if (isset($timeout)) { $cmd .= " -t " . $timeout; } + if (isset($retries)) { $cmd .= " -r " . $retries; } + $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." portIfIndex"; + $output = trim(shell_exec($cmd)); + $device_id = $device['device_id']; + + foreach (explode("\n", $output) as $entry) + { + $entry = str_replace("CISCO-STACK-MIB::portIfIndex.", "", $entry); + list($slotport, $ifIndex) = explode(" ", $entry); + if ($slotport && $ifIndex){ + $array[$ifIndex]['portIfIndex'] = $slotport; + $array[$slotport]['ifIndex'] = $ifIndex; + } + } + + return $array; } function snmp_cache_portName($device, $array) { - global $config; + global $config; - if (is_numeric($device['timeout']) && $device['timeout'] > 0) - { - $timeout = $device['timeout']; - } elseif (isset($config['snmp']['timeout'])) { - $timeout = $config['snmp']['timeout']; - } - - if (is_numeric($device['retries']) && $device['retries'] > 0) - { - $retries = $device['retries']; - } elseif (isset($config['snmp']['retries'])) { - $retries = $config['snmp']['retries']; - } - - if (!isset($device['transport'])) - { - $device['transport'] = "udp"; - } - - $cmd = $config['snmpwalk'] . " -CI -m CISCO-STACK-MIB -O Qs -" . $device['snmpver'] . " -c " . $device['community'] . " "; - $cmd .= " -M ".$config['install_dir']."/mibs/"; - if (isset($timeout)) { $cmd .= " -t " . $timeout; } - if (isset($retries)) { $cmd .= " -r " . $retries; } - $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." portName"; - $output = trim(shell_exec($cmd)); - $device_id = $device['device_id']; - #echo("Caching: portName\n"); - - foreach (explode("\n", $output) as $entry) - { - $entry = str_replace("portName.", "", $entry); - list($slotport, $portName) = explode("=", $entry); - $slotport = trim($slotport); $portName = trim($portName); - if ($array[$slotport]['ifIndex']) + if (is_numeric($device['timeout']) && $device['timeout'] > 0) { - $ifIndex = $array[$slotport]['ifIndex']; - $array[$slotport]['portName'] = $portName; - $array[$ifIndex]['portName'] = $portName; + $timeout = $device['timeout']; + } elseif (isset($config['snmp']['timeout'])) { + $timeout = $config['snmp']['timeout']; } - } - return $array; + if (is_numeric($device['retries']) && $device['retries'] > 0) + { + $retries = $device['retries']; + } elseif (isset($config['snmp']['retries'])) { + $retries = $config['snmp']['retries']; + } + + if (!isset($device['transport'])) + { + $device['transport'] = "udp"; + } + + $cmd = $config['snmpwalk'] . " -CI -m CISCO-STACK-MIB -O Qs -" . $device['snmpver'] . " -c " . $device['community'] . " "; + $cmd .= " -M ".$config['install_dir']."/mibs/"; + if (isset($timeout)) { $cmd .= " -t " . $timeout; } + if (isset($retries)) { $cmd .= " -r " . $retries; } + $cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." portName"; + $output = trim(shell_exec($cmd)); + $device_id = $device['device_id']; + #echo("Caching: portName\n"); + + foreach (explode("\n", $output) as $entry) + { + $entry = str_replace("portName.", "", $entry); + list($slotport, $portName) = explode("=", $entry); + $slotport = trim($slotport); $portName = trim($portName); + if ($array[$slotport]['ifIndex']) + { + $ifIndex = $array[$slotport]['ifIndex']; + $array[$slotport]['portName'] = $portName; + $array[$ifIndex]['portName'] = $portName; + } + } + + return $array; } ?> diff --git a/includes/snmptrap/linkDown.inc.php b/includes/snmptrap/linkDown.inc.php index ce2f505b21..a98a7049b1 100644 --- a/includes/snmptrap/linkDown.inc.php +++ b/includes/snmptrap/linkDown.inc.php @@ -15,8 +15,8 @@ log_event("SNMP Trap: linkDown " . $interface['ifDescr'], $device, "interface", #} if ($ifOperStatus != $interface['ifOperStatus']) { - log_event("Interface went Down : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['interface_id']); - mysql_query("UPDATE `ports` SET ifOperStatus = 'down' WHERE `interface_id` = '".$interface['interface_id']."'"); + log_event("Interface went Down : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['interface_id']); + mysql_query("UPDATE `ports` SET ifOperStatus = 'down' WHERE `interface_id` = '".$interface['interface_id']."'"); } -?> \ No newline at end of file +?> diff --git a/includes/snom-graphing.php b/includes/snom-graphing.php index ee3b0a99b6..a99b3d17bc 100644 --- a/includes/snom-graphing.php +++ b/includes/snom-graphing.php @@ -3,34 +3,34 @@ # FIXME not used, do we still need this? function callsgraphSNOM ($rrd, $graph, $from, $to, $width, $height, $title, $vertical) { - global $config; - $database = $config['rrd_dir'] . "/" . $rrd; - $imgfile = "graphs/" . "$graph"; - $optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical ,"--alt-autoscale-max", - "-l 0", - "-E", - "--title", $title, - "DEF:call=$database:CALLS:AVERAGE", - "CDEF:calls=call,360,*", - "LINE1.25:calls#FF9900:Calls", - "GPRINT:calls:LAST:Cu\: %2.0lf/min", - "GPRINT:calls:AVERAGE:Av\: %2.0lf/min", - "GPRINT:calls:MAX:Mx\: %2.0lf/min\\n"); - if($width <= "300") {$optsb = array("--font", "LEGEND:7:".$config['mono_font']."", - "--font", "AXIS:6:".$config['mono_font']."", - "--font-render-mode", "normal");} + global $config; + $database = $config['rrd_dir'] . "/" . $rrd; + $imgfile = "graphs/" . "$graph"; + $optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical ,"--alt-autoscale-max", + "-l 0", + "-E", + "--title", $title, + "DEF:call=$database:CALLS:AVERAGE", + "CDEF:calls=call,360,*", + "LINE1.25:calls#FF9900:Calls", + "GPRINT:calls:LAST:Cu\: %2.0lf/min", + "GPRINT:calls:AVERAGE:Av\: %2.0lf/min", + "GPRINT:calls:MAX:Mx\: %2.0lf/min\\n"); + if($width <= "300") {$optsb = array("--font", "LEGEND:7:".$config['mono_font']."", + "--font", "AXIS:6:".$config['mono_font']."", + "--font-render-mode", "normal");} - $opts = array_merge($config['rrdgraph_defaults'], $optsa, $optsb); + $opts = array_merge($config['rrdgraph_defaults'], $optsa, $optsb); - $ret = rrd_graph("$imgfile", $opts, count($opts)); + $ret = rrd_graph("$imgfile", $opts, count($opts)); - if( !is_array($ret) ) { - $err = rrd_error(); - echo("rrd_graph() ERROR: $err\n"); - return FALSE; - } else { - return $imgfile; - } + if( !is_array($ret) ) { + $err = rrd_error(); + echo("rrd_graph() ERROR: $err\n"); + return FALSE; + } else { + return $imgfile; + } } diff --git a/irc.php b/irc.php index 674009cbea..19aab14d71 100755 --- a/irc.php +++ b/irc.php @@ -10,36 +10,36 @@ include_once('Net/SmartIRC.php'); class observiumbot { - function device_info(&$irc, &$data) - { - $hostname = $data->messageex[1]; + function device_info(&$irc, &$data) + { + $hostname = $data->messageex[1]; - $device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE `hostname` = '".mres($hostname)."'")); + $device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE `hostname` = '".mres($hostname)."'")); - if ($device['status'] == 1) { $status = "Up " . formatUptime($device['uptime'] . " "); } else { $status = "Down "; } - if ($device['ignore']) { $status = "*Ignored*"; } - if ($device['disabled']) { $status = "*Disabled*"; } + if ($device['status'] == 1) { $status = "Up " . formatUptime($device['uptime'] . " "); } else { $status = "Down "; } + if ($device['ignore']) { $status = "*Ignored*"; } + if ($device['disabled']) { $status = "*Disabled*"; } - $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'id'.$device['device_id'] . " " . $device['os'] . " " . $device['version'] . " " . - $device['features'] . " " . $status); - } + $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'id'.$device['device_id'] . " " . $device['os'] . " " . $device['version'] . " " . + $device['features'] . " " . $status); + } - function port_info(&$irc, &$data) - { - $hostname = $data->messageex[1]; - $ifname = $data->messageex[2]; + function port_info(&$irc, &$data) + { + $hostname = $data->messageex[1]; + $ifname = $data->messageex[2]; - $device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE `hostname` = '".mres($hostname)."'")); - $port = mysql_fetch_Array(mysql_query("SELECT * FROM `ports` WHERE `ifName` = '".$ifname."' OR `ifDescr` = '".$ifname."' AND device_id = '".$device['device_id']."'")); + $device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE `hostname` = '".mres($hostname)."'")); + $port = mysql_fetch_Array(mysql_query("SELECT * FROM `ports` WHERE `ifName` = '".$ifname."' OR `ifDescr` = '".$ifname."' AND device_id = '".$device['device_id']."'")); - $bps_in = formatRates($port['ifInOctets_rate']); - $bps_out = formatRates($port['ifOutOctets_rate']); - $pps_in = format_bi($port['ifInUcastPkts_rate']); - $pps_out = format_bi($port['ifOutUcastPkts_rate']); + $bps_in = formatRates($port['ifInOctets_rate']); + $bps_out = formatRates($port['ifOutOctets_rate']); + $pps_in = format_bi($port['ifInUcastPkts_rate']); + $pps_out = format_bi($port['ifOutUcastPkts_rate']); - $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'id' . $port['interface_id'] . " " . $port['ifAdminStatus'] . "/" . $port['ifOperStatus'] . " " . - $bps_in. " > bps > " . $bps_out . " | " . $pps_in. "pps > PPS > " . $pps_out ."pps"); - } + $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'id' . $port['interface_id'] . " " . $port['ifAdminStatus'] . "/" . $port['ifOperStatus'] . " " . + $bps_in. " > bps > " . $bps_out . " | " . $pps_in. "pps > PPS > " . $pps_out ."pps"); + } } $host = "chat.eu.freenode.net"; @@ -60,4 +60,4 @@ $irc->join(array($chan)))); $irc->listen(); $irc->disconnect(); -?> \ No newline at end of file +?> diff --git a/poll-billing.php b/poll-billing.php index c4b4076060..c278072991 100644 --- a/poll-billing.php +++ b/poll-billing.php @@ -14,106 +14,106 @@ echo("Starting Polling Session ... \n\n"); $bill_query = mysql_query("select * from bills"); while ($bill_data = mysql_fetch_array($bill_query)) { - echo("Bill : ".$bill_data['bill_name']."\n"); - CollectData($bill_data['bill_id']); - $iter++; + echo("Bill : ".$bill_data['bill_name']."\n"); + CollectData($bill_data['bill_id']); + $iter++; } function CollectData($bill_id) { - $port_query = mysql_query("select * from bill_ports as P, ports as I, devices as D where P.bill_id='$bill_id' AND I.interface_id = P.port_id AND D.device_id = I.device_id"); + $port_query = mysql_query("select * from bill_ports as P, ports as I, devices as D where P.bill_id='$bill_id' AND I.interface_id = P.port_id AND D.device_id = I.device_id"); - while ($port_data = mysql_fetch_array($port_query)) - { - unset($port_in_measurement); - unset($port_in_delta); - unset($last_port_in_measurement); - unset($last_port_in_delta); - unset($port_out_measurement); - unset($port_out_delta); - unset($last_port_out_measurement); - unset($last_port_out_delta); + while ($port_data = mysql_fetch_array($port_query)) + { + unset($port_in_measurement); + unset($port_in_delta); + unset($last_port_in_measurement); + unset($last_port_in_delta); + unset($port_out_measurement); + unset($port_out_delta); + unset($last_port_out_measurement); + unset($last_port_out_delta); - $port_id = $port_data['port_id']; - $host = $port_data['hostname']; - $port = $port_data['port']; + $port_id = $port_data['port_id']; + $host = $port_data['hostname']; + $port = $port_data['port']; - echo("\nPolling ".$port_data['ifDescr']." on ".$port_data['hostname']."\n"); + echo("\nPolling ".$port_data['ifDescr']." on ".$port_data['hostname']."\n"); - $port_in_measurement = getValue($host, $port, $port_data['ifIndex'], "In"); - $port_out_measurement = getValue($host, $port, $port_data['ifIndex'], "Out"); + $port_in_measurement = getValue($host, $port, $port_data['ifIndex'], "In"); + $port_out_measurement = getValue($host, $port, $port_data['ifIndex'], "Out"); - $now = mysql_result(mysql_query("SELECT NOW()"), 0); + $now = mysql_result(mysql_query("SELECT NOW()"), 0); + + $last_data = getLastPortCounter($port_id,in); + if ($last_data[state] == "ok") + { + $last_port_in_measurement = $last_data[counter]; + $last_port_in_delta = $last_data[delta]; + if ($port_in_measurement > $last_port_in_measurement) + { + $port_in_delta = $port_in_measurement - $last_port_in_measurement; + } else { + $port_in_delta = $last_port_in_delta; + } + } else { + $port_in_delta = '0'; + } + $pim = "INSERT INTO port_in_measurements (port_id,timestamp,counter,delta) VALUES ($port_id, '$now', $port_in_measurement, $port_in_delta) "; + #echo("$pim \n"); + $pim_query = mysql_query($pim); + unset($last_data, $last_port_in_measurement, $last_port_in_delta); + + $last_data = getLastPortCounter($port_id,out); + if ($last_data[state] == "ok") + { + $last_port_out_measurement = $last_data[counter]; + $last_port_out_delta = $last_data[delta]; + if ($port_out_measurement > $last_port_out_measurement) + { + $port_out_delta = $port_out_measurement - $last_port_out_measurement; + } else { + $port_out_delta = $last_port_out_delta; + } + } else { + $port_out_delta = '0'; + } + $pom = "INSERT INTO port_out_measurements (port_id,timestamp,counter,delta) VALUES ($port_id, '$now', $port_out_measurement, $port_out_delta) "; + #echo("$pom \n"); + $pom_query = mysql_query($pom); + unset($last_data, $last_port_in_measurement, $last_port_in_delta); + + $delta = $delta + $port_in_delta + $port_out_delta; + $in_delta = $in_delta + $port_in_delta; + $out_delta = $out_delta + $port_out_delta; + unset($port_in_delta,$port_out_delta,$prev_delta,$prev_timestamp,$period); + + } + $last_data = getLastMeasurement($bill_id); - $last_data = getLastPortCounter($port_id,in); if ($last_data[state] == "ok") { - $last_port_in_measurement = $last_data[counter]; - $last_port_in_delta = $last_data[delta]; - if ($port_in_measurement > $last_port_in_measurement) - { - $port_in_delta = $port_in_measurement - $last_port_in_measurement; - } else { - $port_in_delta = $last_port_in_delta; - } + $prev_delta = $last_data[delta]; + $prev_in_delta = $last_data[in_delta]; + $prev_out_delta = $last_data[out_delta]; + $prev_timestamp = $last_data[timestamp]; + $period = mysql_result(mysql_query("SELECT UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - UNIX_TIMESTAMP('$prev_timestamp')"),0); } else { - $port_in_delta = '0'; + $prev_delta = '0'; + $period = '0'; + $prev_in_delta = '0'; + $prev_out_delta = '0'; } - $pim = "INSERT INTO port_in_measurements (port_id,timestamp,counter,delta) VALUES ($port_id, '$now', $port_in_measurement, $port_in_delta) "; - #echo("$pim \n"); - $pim_query = mysql_query($pim); - unset($last_data, $last_port_in_measurement, $last_port_in_delta); - $last_data = getLastPortCounter($port_id,out); - if ($last_data[state] == "ok") + if ($delta < '0' ) { - $last_port_out_measurement = $last_data[counter]; - $last_port_out_delta = $last_data[delta]; - if ($port_out_measurement > $last_port_out_measurement) - { - $port_out_delta = $port_out_measurement - $last_port_out_measurement; - } else { - $port_out_delta = $last_port_out_delta; - } - } else { - $port_out_delta = '0'; + $delta = $prev_delta; + $in_delta = $prev_in_delta; + $out_delta = $prev_out_delta; + } - $pom = "INSERT INTO port_out_measurements (port_id,timestamp,counter,delta) VALUES ($port_id, '$now', $port_out_measurement, $port_out_delta) "; - #echo("$pom \n"); - $pom_query = mysql_query($pom); - unset($last_data, $last_port_in_measurement, $last_port_in_delta); - - $delta = $delta + $port_in_delta + $port_out_delta; - $in_delta = $in_delta + $port_in_delta; - $out_delta = $out_delta + $port_out_delta; - unset($port_in_delta,$port_out_delta,$prev_delta,$prev_timestamp,$period); - - } - $last_data = getLastMeasurement($bill_id); - - if ($last_data[state] == "ok") - { - $prev_delta = $last_data[delta]; - $prev_in_delta = $last_data[in_delta]; - $prev_out_delta = $last_data[out_delta]; - $prev_timestamp = $last_data[timestamp]; - $period = mysql_result(mysql_query("SELECT UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - UNIX_TIMESTAMP('$prev_timestamp')"),0); - } else { - $prev_delta = '0'; - $period = '0'; - $prev_in_delta = '0'; - $prev_out_delta = '0'; - } - - if ($delta < '0' ) - { - $delta = $prev_delta; - $in_delta = $prev_in_delta; - $out_delta = $prev_out_delta; - - } - $insert_string = "INSERT INTO bill_data (bill_id,timestamp,period,delta,in_delta,out_delta) VALUES ('$bill_id','$now','$period','$delta','$in_delta','$out_delta')"; - $insert_measurement = mysql_query($insert_string); + $insert_string = "INSERT INTO bill_data (bill_id,timestamp,period,delta,in_delta,out_delta) VALUES ('$bill_id','$now','$period','$delta','$in_delta','$out_delta')"; + $insert_measurement = mysql_query($insert_string); } if ($argv[1]) { CollectData($argv[1]); } diff --git a/poll-reachability.php b/poll-reachability.php index e2138fabf0..dacf192f15 100755 --- a/poll-reachability.php +++ b/poll-reachability.php @@ -9,54 +9,54 @@ $device_query = mysql_query("SELECT * FROM `devices` WHERE `device_id` LIKE '%" while ($device = mysql_fetch_array($device_query)) { - $port = $device['port']; + $port = $device['port']; - echo($device['hostname']. " "); + echo($device['hostname']. " "); - if (isPingable($device['hostname'])) - { - $pos = snmp_get($device, "sysDescr.0", "-Oqv", "SNMPv2-MIB"); - echo($device['protocol'].":".$device['hostname'].":".$device['port']." - ".$device['community']." ".$device['snmpver'].": "); - if ($pos == '') + if (isPingable($device['hostname'])) { - $status='0'; + $pos = snmp_get($device, "sysDescr.0", "-Oqv", "SNMPv2-MIB"); + echo($device['protocol'].":".$device['hostname'].":".$device['port']." - ".$device['community']." ".$device['snmpver'].": "); + if ($pos == '') + { + $status='0'; + } else { + $status='1'; + } } else { - $status='1'; + $status='0'; } - } else { - $status='0'; - } - - if ($status == '1') - { - echo("Up\n"); - } else { - echo("Down\n"); - } - - if ($status != $device['status']) - { - mysql_query("UPDATE `devices` SET `status`= '$status' WHERE `device_id` = '" . $device['device_id'] . "'"); if ($status == '1') { - $stat = "Up"; - mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('0', '" . $device['device_id'] . "', 'Device is up\n')"); - if ($config['alerts']['email']['enable']) - { - notify($device, "Device Up: " . $device['hostname'], "Device Up: " . $device['hostname'] . " at " . date($config['timestamp_format'])); - } + echo("Up\n"); } else { - $stat = "Down"; - mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('9', '" . $device['device_id'] . "', 'Device is down\n')"); - if ($config['alerts']['email']['enable']) - { - notify($device, "Device Down: " . $device['hostname'], "Device Down: " . $device['hostname'] . " at " . date($config['timestamp_format'])); - } + echo("Down\n"); + } + + if ($status != $device['status']) + { + mysql_query("UPDATE `devices` SET `status`= '$status' WHERE `device_id` = '" . $device['device_id'] . "'"); + + if ($status == '1') + { + $stat = "Up"; + mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('0', '" . $device['device_id'] . "', 'Device is up\n')"); + if ($config['alerts']['email']['enable']) + { + notify($device, "Device Up: " . $device['hostname'], "Device Up: " . $device['hostname'] . " at " . date($config['timestamp_format'])); + } + } else { + $stat = "Down"; + mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('9', '" . $device['device_id'] . "', 'Device is down\n')"); + if ($config['alerts']['email']['enable']) + { + notify($device, "Device Down: " . $device['hostname'], "Device Down: " . $device['hostname'] . " at " . date($config['timestamp_format'])); + } + } + eventlog("Device status changed to $stat", $device['device_id']); + echo("Status Changed!\n"); } - eventlog("Device status changed to $stat", $device['device_id']); - echo("Status Changed!\n"); - } } -?> \ No newline at end of file +?> diff --git a/scripts/geshi-ios.php b/scripts/geshi-ios.php index 6e809e26ff..01ada56ba1 100755 --- a/scripts/geshi-ios.php +++ b/scripts/geshi-ios.php @@ -3,168 +3,168 @@ $language_data = array ( -'LANG_NAME' => 'IOS', -'COMMENT_SINGLE' => array(1 => '!'), -'CASE_KEYWORDS' => GESHI_CAPS_LOWER, -'OOLANG' => false, -'NUMBERS' => GESHI_NUMBER_OCT_PREFIX | GESHI_NUMBER_HEX_PREFIX, -'KEYWORDS' => array( - 1 => array( - 'no', 'shutdown' - ), -# 2 => array( -# 'router', 'interface', 'service', 'config-register', 'upgrade', 'version', 'hostname', 'boot-start-marker', 'boot', 'boot-end-marker', 'enable', 'aaa', 'clock', 'ip', -# 'logging', 'access-list', 'route-map', 'snmp-server', 'mpls', 'speed', 'media-type', 'negotiation', 'timestamps', 'prefix-list', 'network', 'mask', 'unsuppress-map', -# 'neighbor', 'remote-as', 'ebgp-multihop', 'update-source', 'description', 'peer-group', 'policy-map', 'class-map', 'class', 'match', 'access-group', 'bandwidth', 'username', -# 'password', 'send-community', 'next-hop-self', 'route-reflector-client', 'ldp', 'discovery', 'advertise-labels', 'label', 'protocol', 'login', 'debug', 'log', 'duplex', 'router-id', -# 'authentication', 'mode', 'maximum-paths', 'address-family', 'set', 'local-preference', 'community', 'trap-source', 'location', 'host', 'tacacs-server', 'session-id', -# 'flow-export', 'destination', 'source', 'in', 'out', 'permit', 'deny', 'control-plane', 'line', 'con' ,'aux', 'vty', 'access-class', 'ntp', 'server', 'end', 'source-interface', -# 'key', 'chain', 'key-string', 'redundancy', 'match-any', 'queue-limit', 'encapsulation', 'pvc', 'vbr-nrt', 'address', 'bundle-enable', 'atm', 'sonet', 'clns', 'route-cache', -# 'default-information', 'redistribute', 'log-adjacency-changes', 'metric', 'spf-interval', 'prc-interval', 'lsp-refresh-interval', 'max-lsp-lifetime', 'set-overload-bit', -# 'on-startup', 'wait-for-bgp', 'system', 'flash', 'timezone', 'subnet-zero', 'cef', 'flow-cache', 'timeout', 'active', 'domain', 'lookup', 'dhcp', 'use', 'vrf', 'hello', 'interval', -# 'priority', 'ilmi-keepalive', 'buffered', 'debugging', 'fpd', 'secret', 'accounting', 'exec', 'group', 'local', 'recurring', 'source-route', 'call', 'rsvp-sync', 'scripting', -# 'mtu', 'passive-interface', 'area' , 'distribute-list', 'metric-style', 'is-type', 'originate', 'activate', 'both', 'auto-summary', 'synchronization', 'aggregate-address', 'le', 'ge', -# 'bgp-community', 'route', 'exit-address-family', 'standard', 'file', 'verify', 'domain-name', 'domain-lookup', 'route-target', 'export', 'import', 'map', 'rd', 'mfib', 'vtp', 'mls', -# 'hardware-switching', 'replication-mode', 'ingress', 'flow', 'error', 'action', 'slb', 'purge', 'share-global', 'routing', 'traffic-eng', 'tunnels', 'propagate-ttl', 'switchport', 'vlan', -# 'portfast', 'counters', 'max', 'age', 'ethernet', 'evc', 'uni', 'count', 'oam', 'lmi', 'gmt', 'netflow', 'pseudowire-class', 'spanning-tree', 'name', 'circuit-type' -# ), -# 3 => array( -# 'isis', 'ospf', 'eigrp', 'rip', 'igrp', 'bgp', 'ipv4', 'unicast', 'multicast', 'ipv6', 'connected', 'static', 'subnets', 'tcl' -# ), -# 4 => array( -# 'point-to-point', 'aal5snap', 'rj45', 'auto', 'full', 'half', 'precedence', 'percent', 'datetime', 'msec', 'locatime', 'summer-time', 'md5', 'wait-for-bgp', 'wide', -# 'level-1', 'level-2', 'log-neighbor-changes', 'directed-request', 'password-encryption', 'common', 'origin-as', 'bgp-nexthop', 'random-detect', 'localtime', 'sso', 'stm-1', -# 'dot1q', 'isl', 'new-model', 'always', 'summary-only', 'freeze', 'global', 'forwarded', 'access', 'trunk', 'edge', 'transparent' -# ), -), - -'REGEXPS' => array ( - 1 => array( - GESHI_SEARCH => '(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})', - GESHI_REPLACE => '\\1', - GESHI_BEFORE => '', - ), - 2 => array( - GESHI_SEARCH => '(255\.\d{1,3}\.\d{1,3}\.\d{1,3})', - GESHI_REPLACE => '\\1', - GESHI_BEFORE => '', - ), - 3 => array( - GESHI_SEARCH => '(source|interface|update-source|router-id) ([A-Za-z0-9\/\:\-\.]+)', - GESHI_REPLACE => '\\2', - GESHI_BEFORE => '\\1 ', - ), - 4 => array( - GESHI_SEARCH => '(neighbor) ([\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}]+|[a-zA-Z0-9\-\_]+)', - GESHI_REPLACE => '\\2', - GESHI_BEFORE => '\\1 ', - ), - 5 => array( - GESHI_SEARCH => '(distribute-map|access-group|policy-map|class-map\ match-any|ip\ access-list\ extended|match\ community|community-list\ standard|community-list\ expanded|ip\ access-list\ standard|router\ bgp|remote-as|key\ chain|service-policy\ input|service-policy\ output|class|login\ authentication|authentication\ key-chain|username|import\ map|export\ map|domain-name|hostname|route-map|access-class|ip\ vrf\ forwarding|ip\ vrf|vtp\ domain|name|pseudowire-class|pw-class|prefix-list|vrf) ([A-Za-z0-9\-\_\.]+)', - GESHI_REPLACE => '\\2', - GESHI_BEFORE => '\\1 ', - ), - 6 => array( - GESHI_SEARCH => '(password|key-string|key) ([0-9]) (.+)', - GESHI_REPLACE => '\\2 \\3', - GESHI_BEFORE => '\\1 ', - ), - 7 => array( - GESHI_SEARCH => '(enable) ([a-z]+) ([0-9]) (.+)', - GESHI_REPLACE => '\\3 \\4', - GESHI_BEFORE => '\\1 \\2 ', - ), - 8 => array( - GESHI_SEARCH => '(description|location|contact|remark) (.+)', - GESHI_REPLACE => '\\2', - GESHI_BEFORE => '\\1 ', - ), - 9 => array( - GESHI_SEARCH => '([0-9\.\_\*]+\:[0-9\.\_\*]+)', - GESHI_REPLACE => '\\1', - ), - 10 => array( - GESHI_SEARCH => '(boot) ([a-z]+) (.+)', - GESHI_REPLACE => '\\3', - GESHI_BEFORE => '\\1 \\2 ' - ), - 11 => array( - GESHI_SEARCH => '(net) ([0-9a-z\.]+)', - GESHI_REPLACE => '\\2', - GESHI_BEFORE => '\\1 ' - ), - 12 => array( - GESHI_SEARCH => '(access-list|RO|RW) ([0-9]+)', - GESHI_REPLACE => '\\2', - GESHI_BEFORE => '\\1 ' - ), - 13 => array( - GESHI_SEARCH => '(vlan) ([0-9]+)', - GESHI_REPLACE => '\\2', - GESHI_BEFORE => '\\1 ' - ), - 14 => array( - GESHI_SEARCH => '(encapsulation|speed|duplex|mtu|metric|media-type|negotiation|transport\ input|bgp-community|set\ as-path\ prepend|maximum-prefix|version|local-preference|continue|redistribute|cluster-id|vtp\ mode|label\ protocol|spanning-tree\ mode) (.+)', - GESHI_REPLACE => '\\2', - GESHI_BEFORE => '\\1 ' - ), - -), - -'STYLES' => array( - 'REGEXPS' => array( - 0 => 'color: #ff0000;', - 1 => 'color: #0000cc;', # x.x.x.x - 2 => 'color: #000099; font-style: italic', # 255.x.x.x - 3 => 'color: #000000; font-weight: bold; font-style: italic;', # interface xxx - 4 => 'color: #ff0000;', # neighbor x.x.x.x - 5 => 'color: #000099;', # variable names - 6 => 'color: #cc0000;', - 7 => 'color: #cc0000;', # passwords - 8 => 'color: #555555;', # description - 9 => 'color: #990099;', # communities - 10 => 'color: #cc0000; font-style: italic;', # no/shut - 11 => 'color: #000099;', # net numbers - 12 => 'color: #000099;', # acls - 13 => 'color: #000099;', # acls - 14 => 'color: #990099;', # warnings - ), + 'LANG_NAME' => 'IOS', + 'COMMENT_SINGLE' => array(1 => '!'), + 'CASE_KEYWORDS' => GESHI_CAPS_LOWER, + 'OOLANG' => false, + 'NUMBERS' => GESHI_NUMBER_OCT_PREFIX | GESHI_NUMBER_HEX_PREFIX, 'KEYWORDS' => array( - 1 => 'color: #cc0000; font-weight: bold;', # no/shut - 2 => 'color: #000000;', # commands - 3 => 'color: #000000; font-weight: bold;', # proto/service - 4 => 'color: #000000;', # options - 5 => 'color: #ff0000;' + 1 => array( + 'no', 'shutdown' ), - 'COMMENTS' => array( - 1 => 'color: #808080; font-style: italic;' + # 2 => array( + # 'router', 'interface', 'service', 'config-register', 'upgrade', 'version', 'hostname', 'boot-start-marker', 'boot', 'boot-end-marker', 'enable', 'aaa', 'clock', 'ip', + # 'logging', 'access-list', 'route-map', 'snmp-server', 'mpls', 'speed', 'media-type', 'negotiation', 'timestamps', 'prefix-list', 'network', 'mask', 'unsuppress-map', + # 'neighbor', 'remote-as', 'ebgp-multihop', 'update-source', 'description', 'peer-group', 'policy-map', 'class-map', 'class', 'match', 'access-group', 'bandwidth', 'username', + # 'password', 'send-community', 'next-hop-self', 'route-reflector-client', 'ldp', 'discovery', 'advertise-labels', 'label', 'protocol', 'login', 'debug', 'log', 'duplex', 'router-id', + # 'authentication', 'mode', 'maximum-paths', 'address-family', 'set', 'local-preference', 'community', 'trap-source', 'location', 'host', 'tacacs-server', 'session-id', + # 'flow-export', 'destination', 'source', 'in', 'out', 'permit', 'deny', 'control-plane', 'line', 'con' ,'aux', 'vty', 'access-class', 'ntp', 'server', 'end', 'source-interface', + # 'key', 'chain', 'key-string', 'redundancy', 'match-any', 'queue-limit', 'encapsulation', 'pvc', 'vbr-nrt', 'address', 'bundle-enable', 'atm', 'sonet', 'clns', 'route-cache', + # 'default-information', 'redistribute', 'log-adjacency-changes', 'metric', 'spf-interval', 'prc-interval', 'lsp-refresh-interval', 'max-lsp-lifetime', 'set-overload-bit', + # 'on-startup', 'wait-for-bgp', 'system', 'flash', 'timezone', 'subnet-zero', 'cef', 'flow-cache', 'timeout', 'active', 'domain', 'lookup', 'dhcp', 'use', 'vrf', 'hello', 'interval', + # 'priority', 'ilmi-keepalive', 'buffered', 'debugging', 'fpd', 'secret', 'accounting', 'exec', 'group', 'local', 'recurring', 'source-route', 'call', 'rsvp-sync', 'scripting', + # 'mtu', 'passive-interface', 'area' , 'distribute-list', 'metric-style', 'is-type', 'originate', 'activate', 'both', 'auto-summary', 'synchronization', 'aggregate-address', 'le', 'ge', + # 'bgp-community', 'route', 'exit-address-family', 'standard', 'file', 'verify', 'domain-name', 'domain-lookup', 'route-target', 'export', 'import', 'map', 'rd', 'mfib', 'vtp', 'mls', + # 'hardware-switching', 'replication-mode', 'ingress', 'flow', 'error', 'action', 'slb', 'purge', 'share-global', 'routing', 'traffic-eng', 'tunnels', 'propagate-ttl', 'switchport', 'vlan', + # 'portfast', 'counters', 'max', 'age', 'ethernet', 'evc', 'uni', 'count', 'oam', 'lmi', 'gmt', 'netflow', 'pseudowire-class', 'spanning-tree', 'name', 'circuit-type' + # ), + # 3 => array( + # 'isis', 'ospf', 'eigrp', 'rip', 'igrp', 'bgp', 'ipv4', 'unicast', 'multicast', 'ipv6', 'connected', 'static', 'subnets', 'tcl' + # ), + # 4 => array( + # 'point-to-point', 'aal5snap', 'rj45', 'auto', 'full', 'half', 'precedence', 'percent', 'datetime', 'msec', 'locatime', 'summer-time', 'md5', 'wait-for-bgp', 'wide', + # 'level-1', 'level-2', 'log-neighbor-changes', 'directed-request', 'password-encryption', 'common', 'origin-as', 'bgp-nexthop', 'random-detect', 'localtime', 'sso', 'stm-1', + # 'dot1q', 'isl', 'new-model', 'always', 'summary-only', 'freeze', 'global', 'forwarded', 'access', 'trunk', 'edge', 'transparent' + # ), + ), + + 'REGEXPS' => array ( + 1 => array( + GESHI_SEARCH => '(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})', + GESHI_REPLACE => '\\1', + GESHI_BEFORE => '', ), - 'ESCAPE_CHAR' => array( - 0 => 'color: #000099; font-weight: bold;' + 2 => array( + GESHI_SEARCH => '(255\.\d{1,3}\.\d{1,3}\.\d{1,3})', + GESHI_REPLACE => '\\1', + GESHI_BEFORE => '', ), - 'BRACKETS' => array( - 0 => 'color: #66cc66;' + 3 => array( + GESHI_SEARCH => '(source|interface|update-source|router-id) ([A-Za-z0-9\/\:\-\.]+)', + GESHI_REPLACE => '\\2', + GESHI_BEFORE => '\\1 ', ), - 'STRINGS' => array( - 0 => 'color: #ff0000;' + 4 => array( + GESHI_SEARCH => '(neighbor) ([\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}]+|[a-zA-Z0-9\-\_]+)', + GESHI_REPLACE => '\\2', + GESHI_BEFORE => '\\1 ', ), - 'NUMBERS' => array( - 0 => 'color: #cc0000;' + 5 => array( + GESHI_SEARCH => '(distribute-map|access-group|policy-map|class-map\ match-any|ip\ access-list\ extended|match\ community|community-list\ standard|community-list\ expanded|ip\ access-list\ standard|router\ bgp|remote-as|key\ chain|service-policy\ input|service-policy\ output|class|login\ authentication|authentication\ key-chain|username|import\ map|export\ map|domain-name|hostname|route-map|access-class|ip\ vrf\ forwarding|ip\ vrf|vtp\ domain|name|pseudowire-class|pw-class|prefix-list|vrf) ([A-Za-z0-9\-\_\.]+)', + GESHI_REPLACE => '\\2', + GESHI_BEFORE => '\\1 ', ), - 'METHODS' => array( - 0 => 'color: #006600;' + 6 => array( + GESHI_SEARCH => '(password|key-string|key) ([0-9]) (.+)', + GESHI_REPLACE => '\\2 \\3', + GESHI_BEFORE => '\\1 ', ), - 'SYMBOLS' => array( - 0 => 'color: #66cc66;' + 7 => array( + GESHI_SEARCH => '(enable) ([a-z]+) ([0-9]) (.+)', + GESHI_REPLACE => '\\3 \\4', + GESHI_BEFORE => '\\1 \\2 ', ), - 'SCRIPT' => array( - 0 => '', - 1 => '', - 2 => '', - 3 => '' + 8 => array( + GESHI_SEARCH => '(description|location|contact|remark) (.+)', + GESHI_REPLACE => '\\2', + GESHI_BEFORE => '\\1 ', + ), + 9 => array( + GESHI_SEARCH => '([0-9\.\_\*]+\:[0-9\.\_\*]+)', + GESHI_REPLACE => '\\1', + ), + 10 => array( + GESHI_SEARCH => '(boot) ([a-z]+) (.+)', + GESHI_REPLACE => '\\3', + GESHI_BEFORE => '\\1 \\2 ' + ), + 11 => array( + GESHI_SEARCH => '(net) ([0-9a-z\.]+)', + GESHI_REPLACE => '\\2', + GESHI_BEFORE => '\\1 ' + ), + 12 => array( + GESHI_SEARCH => '(access-list|RO|RW) ([0-9]+)', + GESHI_REPLACE => '\\2', + GESHI_BEFORE => '\\1 ' + ), + 13 => array( + GESHI_SEARCH => '(vlan) ([0-9]+)', + GESHI_REPLACE => '\\2', + GESHI_BEFORE => '\\1 ' + ), + 14 => array( + GESHI_SEARCH => '(encapsulation|speed|duplex|mtu|metric|media-type|negotiation|transport\ input|bgp-community|set\ as-path\ prepend|maximum-prefix|version|local-preference|continue|redistribute|cluster-id|vtp\ mode|label\ protocol|spanning-tree\ mode) (.+)', + GESHI_REPLACE => '\\2', + GESHI_BEFORE => '\\1 ' + ), + + ), + + 'STYLES' => array( + 'REGEXPS' => array( + 0 => 'color: #ff0000;', + 1 => 'color: #0000cc;', # x.x.x.x + 2 => 'color: #000099; font-style: italic', # 255.x.x.x + 3 => 'color: #000000; font-weight: bold; font-style: italic;', # interface xxx + 4 => 'color: #ff0000;', # neighbor x.x.x.x + 5 => 'color: #000099;', # variable names + 6 => 'color: #cc0000;', + 7 => 'color: #cc0000;', # passwords + 8 => 'color: #555555;', # description + 9 => 'color: #990099;', # communities + 10 => 'color: #cc0000; font-style: italic;', # no/shut + 11 => 'color: #000099;', # net numbers + 12 => 'color: #000099;', # acls + 13 => 'color: #000099;', # acls + 14 => 'color: #990099;', # warnings + ), + 'KEYWORDS' => array( + 1 => 'color: #cc0000; font-weight: bold;', # no/shut + 2 => 'color: #000000;', # commands + 3 => 'color: #000000; font-weight: bold;', # proto/service + 4 => 'color: #000000;', # options + 5 => 'color: #ff0000;' + ), + 'COMMENTS' => array( + 1 => 'color: #808080; font-style: italic;' + ), + 'ESCAPE_CHAR' => array( + 0 => 'color: #000099; font-weight: bold;' + ), + 'BRACKETS' => array( + 0 => 'color: #66cc66;' + ), + 'STRINGS' => array( + 0 => 'color: #ff0000;' + ), + 'NUMBERS' => array( + 0 => 'color: #cc0000;' + ), + 'METHODS' => array( + 0 => 'color: #006600;' + ), + 'SYMBOLS' => array( + 0 => 'color: #66cc66;' + ), + 'SCRIPT' => array( + 0 => '', + 1 => '', + 2 => '', + 3 => '' ) - -) + + ) );