From 502f207291e972255e4ac050c918bc2f7221cf78 Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Mon, 9 Apr 2012 10:53:55 +0000 Subject: [PATCH] only poll cisco CEF and cisco mac accounting on cisco devices + some small fixes git-svn-id: http://www.observium.org/svn/observer/trunk@2999 61d68cd4-352d-0410-923a-c4978735b2b8 --- html/includes/print-menubar.php | 4 +- html/index.php | 2 +- includes/defaults.inc.php | 2 +- includes/discovery/entity-sensor.inc.php | 2 +- .../discovery/temperatures/lm-sensors.inc.php | 2 +- includes/polling/cisco-cef.inc.php | 189 +++++++++--------- includes/polling/cisco-mac-accounting.inc.php | 171 ++++++++-------- includes/polling/os/airport.inc.php | 2 +- 8 files changed, 190 insertions(+), 184 deletions(-) diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 89301fd6a..0aaa14b97 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -346,7 +346,7 @@ foreach (array('fanspeed','humidity','temperature') as $item) { if ($menu_sensors[$item]) { - echo('
  • '.ucfirst($item).'
  • '); + echo('
  • '.nicecase($item).'
  • '); unset($menu_sensors[$item]);$sep++; } } @@ -361,7 +361,7 @@ foreach (array('current','frequency','power','voltage') as $item) { if ($menu_sensors[$item]) { - echo('
  • '.ucfirst($item).'
  • '); + echo('
  • '.nicecase($item).'
  • '); unset($menu_sensors[$item]);$sep++; } } diff --git a/html/index.php b/html/index.php index 304d3e467..4e7ecb7d1 100755 --- a/html/index.php +++ b/html/index.php @@ -134,7 +134,7 @@ if (isset($config['branding']) && is_array($config['branding'])) "); } +if ($config['page_refresh']) { echo(' ' . "\n"); } ?> diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index aec9dd693..a977de659 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -69,7 +69,7 @@ $config['stylesheet'] = "css/styles.css"; $config['mono_font'] = "DejaVuSansMono"; $config['favicon'] = "images/observium-icon.png"; $config['header_color'] = "#1F334E"; -$config['page_refresh'] = "300"; ## Refresh the page every xx seconds +$config['page_refresh'] = "300"; ## Refresh the page every xx seconds, 0 to disable $config['front_page'] = "pages/front/default.php"; $config['page_title'] = "Observium :: Network Observation and Monitoring"; $config['timestamp_format'] = 'd-m-Y H:i:s'; diff --git a/includes/discovery/entity-sensor.inc.php b/includes/discovery/entity-sensor.inc.php index 33c022ccc..811f74623 100644 --- a/includes/discovery/entity-sensor.inc.php +++ b/includes/discovery/entity-sensor.inc.php @@ -1,6 +1,6 @@ $afis) + + if ($debug) { print_r($cefs); } + + if (is_array($cefs)) { - $entity_name = $entity_array[$entity]['entPhysicalName'] ." - ".$entity_array[$entity]['entPhysicalModelName']; - echo("\n$entity $entity_name\n"); - foreach ($afis as $afi => $paths) + if (!is_array($entity_array)) { - echo(" |- $afi\n"); - foreach ($paths as $path => $cef_stat) + echo("Caching OIDs: "); + $entity_array = array(); + echo(" entPhysicalDescr"); + $entity_array = snmpwalk_cache_multi_oid($device, "entPhysicalDescr", $entity_array, "ENTITY-MIB"); + echo(" entPhysicalName"); + $entity_array = snmpwalk_cache_multi_oid($device, "entPhysicalName", $entity_array, "ENTITY-MIB"); + echo(" entPhysicalModelName"); + $entity_array = snmpwalk_cache_multi_oid($device, "entPhysicalModelName", $entity_array, "ENTITY-MIB"); + } + foreach ($cefs as $entity => $afis) + { + $entity_name = $entity_array[$entity]['entPhysicalName'] ." - ".$entity_array[$entity]['entPhysicalModelName']; + echo("\n$entity $entity_name\n"); + foreach ($afis as $afi => $paths) { - echo(" | |-".$path.": ".$cef_stat['cefSwitchingPath']); - - $cef_id = $device['device_id']."-".$entity."-".$afi."-".$path; - -# if (dbFetchCell("SELECT COUNT(*) FROM `cef_switching` WHERE `device_id` = ? AND `entPhysicalIndex` = ? AND `afi` = ? AND `cef_index` = ?", array($device['device_id'], $entity, $afi, $path)) != "1") - if (!isset($cefs_db[$cef_id])) + echo(" |- $afi\n"); + foreach ($paths as $path => $cef_stat) { - dbInsert(array('device_id' => $device['device_id'], 'entPhysicalIndex' => $entity, 'afi' => $afi, 'cef_index' => $path, 'cef_path' => $cef_stat['cefSwitchingPath']), 'cef_switching'); - echo("+"); + echo(" | |-".$path.": ".$cef_stat['cefSwitchingPath']); + + $cef_id = $device['device_id']."-".$entity."-".$afi."-".$path; + + # if (dbFetchCell("SELECT COUNT(*) FROM `cef_switching` WHERE `device_id` = ? AND `entPhysicalIndex` = ? AND `afi` = ? AND `cef_index` = ?", array($device['device_id'], $entity, $afi, $path)) != "1") + if (!isset($cefs_db[$cef_id])) + { + dbInsert(array('device_id' => $device['device_id'], 'entPhysicalIndex' => $entity, 'afi' => $afi, 'cef_index' => $path, 'cef_path' => $cef_stat['cefSwitchingPath']), 'cef_switching'); + echo("+"); + } + unset($cefs_db[$cef_id]); + + $cef_entry = dbFetchRow("SELECT * FROM `cef_switching` WHERE `device_id` = ? AND `entPhysicalIndex = ? AND `afi` = ? AND `cef_index` = ?", array($device['device_id'], $entity, $afi, $path)); + + $filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("cefswitching-".$entity."-".$afi."-".$path.".rrd"); + + if (!is_file($filename)) + { + rrdtool_create($filename, "--step 300 \ + DS:drop:DERIVE:600:0:1000000 \ + DS:punt:DERIVE:600:0:1000000 \ + DS:hostpunt:DERIVE:600:0:1000000 \ + 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:MIN:0.5:1:600 RRA:MIN:0.5:6:700 RRA:MIN:0.5:24:775 RRA:MIN: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 \ + RRA:LAST:0.5:1:600 RRA:LAST:0.5:6:700 RRA:LAST:0.5:24:775 RRA:LAST:0.5:288:797"); + } + + ### Copy HC to non-HC if they exist + if (is_numeric($cef_stat['cefSwitchingHCDrop'])) { $cef_stat['cefSwitchingDrop'] = $cef_stat['cefSwitchingHCDrop']; } + if (is_numeric($cef_stat['cefSwitchingHCPunt'])) { $cef_stat['cefSwitchingPunt'] = $cef_stat['cefSwitchingHCPunt']; } + if (is_numeric($cef_stat['cefSwitchingHCPunt2Host'])) { $cef_stat['cefSwitchingPunt2Host'] = $cef_stat['cefSwitchingHCPunt2Host']; } + + $cef_stat['update']['drop'] = $cef_stat['cefSwitchingDrop']; + $cef_stat['update']['punt'] = $cef_stat['cefSwitchingPunt']; + $cef_stat['update']['punt2host'] = $cef_stat['cefSwitchingPunt2Host']; + $cef_stat['update']['drop_prev'] = $cef_entry['drop']; + $cef_stat['update']['punt_prev'] = $cef_entry['punt']; + $cef_stat['update']['punt2host_prev'] = $cef_entry['punt2host']; + $cef_stat['update']['updated'] = $polled; + $cef_stat['update']['updated_prev'] = $cef_entry['updated']; + + dbUpdate($cef_stat['update'], 'cef_switching', '`device_id` = ? AND `entPhysicalIndex` = ? AND `afi` = ? AND `cef_index` = ?', array($device['device_id'], $entity, $afi, $path)); + + $rrd_update = "N:".$cef_stat['cefSwitchingDrop'].":".$cef_stat['cefSwitchingPunt'].":".$cef_stat['cefSwitchingPunt2Host']; + $ret = rrdtool_update("$filename", $rrd_update); + + if ($debug) { echo(" Values: ".$cef_stat['cefSwitchingDrop'].":".$cef_stat['cefSwitchingPunt'].":".$cef_stat['cefSwitchingPunt2Host']); } + + echo("\n"); + } - unset($cefs_db[$cef_id]); - - $cef_entry = dbFetchRow("SELECT * FROM `cef_switching` WHERE `device_id` = ? AND `entPhysicalIndex = ? AND `afi` = ? AND `cef_index` = ?", array($device['device_id'], $entity, $afi, $path)); - - $filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("cefswitching-".$entity."-".$afi."-".$path.".rrd"); - - if (!is_file($filename)) - { - rrdtool_create($filename, "--step 300 \ - DS:drop:DERIVE:600:0:1000000 \ - DS:punt:DERIVE:600:0:1000000 \ - DS:hostpunt:DERIVE:600:0:1000000 \ - 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:MIN:0.5:1:600 RRA:MIN:0.5:6:700 RRA:MIN:0.5:24:775 RRA:MIN: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 \ - RRA:LAST:0.5:1:600 RRA:LAST:0.5:6:700 RRA:LAST:0.5:24:775 RRA:LAST:0.5:288:797"); - } - - ### Copy HC to non-HC if they exist - if (is_numeric($cef_stat['cefSwitchingHCDrop'])) { $cef_stat['cefSwitchingDrop'] = $cef_stat['cefSwitchingHCDrop']; } - if (is_numeric($cef_stat['cefSwitchingHCPunt'])) { $cef_stat['cefSwitchingPunt'] = $cef_stat['cefSwitchingHCPunt']; } - if (is_numeric($cef_stat['cefSwitchingHCPunt2Host'])) { $cef_stat['cefSwitchingPunt2Host'] = $cef_stat['cefSwitchingHCPunt2Host']; } - - $cef_stat['update']['drop'] = $cef_stat['cefSwitchingDrop']; - $cef_stat['update']['punt'] = $cef_stat['cefSwitchingPunt']; - $cef_stat['update']['punt2host'] = $cef_stat['cefSwitchingPunt2Host']; - $cef_stat['update']['drop_prev'] = $cef_entry['drop']; - $cef_stat['update']['punt_prev'] = $cef_entry['punt']; - $cef_stat['update']['punt2host_prev'] = $cef_entry['punt2host']; - $cef_stat['update']['updated'] = $polled; - $cef_stat['update']['updated_prev'] = $cef_entry['updated']; - - dbUpdate($cef_stat['update'], 'cef_switching', '`device_id` = ? AND `entPhysicalIndex` = ? AND `afi` = ? AND `cef_index` = ?', array($device['device_id'], $entity, $afi, $path)); - - $rrd_update = "N:".$cef_stat['cefSwitchingDrop'].":".$cef_stat['cefSwitchingPunt'].":".$cef_stat['cefSwitchingPunt2Host']; - $ret = rrdtool_update("$filename", $rrd_update); - - if ($debug) { echo(" Values: ".$cef_stat['cefSwitchingDrop'].":".$cef_stat['cefSwitchingPunt'].":".$cef_stat['cefSwitchingPunt2Host']); } - - echo("\n"); - } } } -} - -## FIXME - need to delete old ones. FIXME REALLY. - -print_r($cefs_db); - -foreach ($cefs_db as $cef_switching_id) -{ - dbDelete("cef_switching", "`cef_switching_id` = ?", array($cef_switching_id)); - echo("-"); -} - -echo("\n"); + + ## FIXME - need to delete old ones. FIXME REALLY. + + print_r($cefs_db); + + foreach ($cefs_db as $cef_switching_id) + { + dbDelete("cef_switching", "`cef_switching_id` = ?", array($cef_switching_id)); + echo("-"); + } + echo("\n"); +} # os_group = cisco + ?> diff --git a/includes/polling/cisco-mac-accounting.inc.php b/includes/polling/cisco-mac-accounting.inc.php index a298250ea..53b9a1f96 100755 --- a/includes/polling/cisco-mac-accounting.inc.php +++ b/includes/polling/cisco-mac-accounting.inc.php @@ -2,98 +2,101 @@ ## FIXME -- we're walking, so we can discover here too. -$cip_oids = array('cipMacHCSwitchedBytes', 'cipMacHCSwitchedPkts'); -echo("Cisco MAC - Caching OID: "); -$cip_array = array(); - -foreach ($cip_oids as $oid) +if ($device['os_group'] == "cisco") { - echo("$oid "); - $cip_array = snmpwalk_cache_cip($device, $oid, $cip_array, "CISCO-IP-STAT-MIB"); -} - -$polled = time(); - -$mac_entries = 0; - -$acc_rows = dbFetchRows("SELECT *, A.poll_time AS poll_time FROM `mac_accounting` as A, `ports` AS I where A.interface_id = I.interface_id AND I.device_id = ?", array($device['device_id'])); - -foreach ($acc_rows as $acc) -{ - $device_id = $acc['device_id']; - $ifIndex = $acc['ifIndex']; - $mac = $acc['mac']; - - $polled_period = $polled - $acc['poll_time']; - - if ($cip_array[$ifIndex][$mac]) + $cip_oids = array('cipMacHCSwitchedBytes', 'cipMacHCSwitchedPkts'); + echo("Cisco MAC - Caching OID: "); + $cip_array = array(); + + foreach ($cip_oids as $oid) { - $acc['update']['poll_time'] = $polled; - $acc['update']['poll_prev'] = $acc['poll_time']; - $acc['update']['poll_period'] = $polled_period; - - $mac_entries++; - - $b_in = $cip_array[$ifIndex][$mac]['cipMacHCSwitchedBytes']['input']; - $b_out = $cip_array[$ifIndex][$mac]['cipMacHCSwitchedBytes']['output']; - $p_in = $cip_array[$ifIndex][$mac]['cipMacHCSwitchedPkts']['input']; - $p_out = $cip_array[$ifIndex][$mac]['cipMacHCSwitchedPkts']['output']; - - $this_ma = &$cip_array[$ifIndex][$mac]; - - /// Update metrics - foreach ($cip_oids as $oid) + echo("$oid "); + $cip_array = snmpwalk_cache_cip($device, $oid, $cip_array, "CISCO-IP-STAT-MIB"); + } + + $polled = time(); + + $mac_entries = 0; + + $acc_rows = dbFetchRows("SELECT *, A.poll_time AS poll_time FROM `mac_accounting` as A, `ports` AS I where A.interface_id = I.interface_id AND I.device_id = ?", array($device['device_id'])); + + foreach ($acc_rows as $acc) + { + $device_id = $acc['device_id']; + $ifIndex = $acc['ifIndex']; + $mac = $acc['mac']; + + $polled_period = $polled - $acc['poll_time']; + + if ($cip_array[$ifIndex][$mac]) { - foreach (array('input','output') as $dir) + $acc['update']['poll_time'] = $polled; + $acc['update']['poll_prev'] = $acc['poll_time']; + $acc['update']['poll_period'] = $polled_period; + + $mac_entries++; + + $b_in = $cip_array[$ifIndex][$mac]['cipMacHCSwitchedBytes']['input']; + $b_out = $cip_array[$ifIndex][$mac]['cipMacHCSwitchedBytes']['output']; + $p_in = $cip_array[$ifIndex][$mac]['cipMacHCSwitchedPkts']['input']; + $p_out = $cip_array[$ifIndex][$mac]['cipMacHCSwitchedPkts']['output']; + + $this_ma = &$cip_array[$ifIndex][$mac]; + + /// Update metrics + foreach ($cip_oids as $oid) { - $oid_dir = $oid . "_" . $dir; - $acc['update'][$oid_dir] = $this_ma[$oid][$dir]; - $acc['update'][$oid_dir.'_prev'] = $acc[$oid_dir]; - $oid_prev = $oid_dir . "_prev"; - if ($this_ma[$oid][$dir]) + foreach (array('input','output') as $dir) { - $oid_diff = $this_ma[$oid][$dir] - $acc[$oid_dir]; - $oid_rate = $oid_diff / $polled_period; - $acc['update'][$oid_dir.'_rate'] = $oid_rate; - $acc['update'][$oid_dir.'_delta'] = $oid_diff; - if ($debug) { echo("\n $oid_dir ($oid_diff B) $oid_rate Bps $polled_period secs\n"); } + $oid_dir = $oid . "_" . $dir; + $acc['update'][$oid_dir] = $this_ma[$oid][$dir]; + $acc['update'][$oid_dir.'_prev'] = $acc[$oid_dir]; + $oid_prev = $oid_dir . "_prev"; + if ($this_ma[$oid][$dir]) + { + $oid_diff = $this_ma[$oid][$dir] - $acc[$oid_dir]; + $oid_rate = $oid_diff / $polled_period; + $acc['update'][$oid_dir.'_rate'] = $oid_rate; + $acc['update'][$oid_dir.'_delta'] = $oid_diff; + if ($debug) { echo("\n $oid_dir ($oid_diff B) $oid_rate Bps $polled_period secs\n"); } + } } } + + if ($debug) { echo("\n" . $acc['hostname']." ".$acc['ifDescr'] . " $mac -> $b_in:$b_out:$p_in:$p_out "); } + + $rrdfile = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd"); + + if (!is_file($rrdfile)) + { + rrdtool_create($rrdfile,"DS:IN:COUNTER:600:0:12500000000 \ + DS:OUT:COUNTER:600:0:12500000000 \ + DS:PIN:COUNTER:600:0:12500000000 \ + DS:POUT:COUNTER: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"); + } + $woo = "N:".($b_in+0).":".($b_out+0).":".($p_in+0).":".($p_out+0); + $ret = rrdtool_update("$rrdfile", $woo); + + if ($acc['update']) + { /// Do Updates + dbUpdate($acc['update'], 'mac_accounting', '`ma_id` = ?', array($acc['ma_id'])); + } /// End Updates } - - if ($debug) { echo("\n" . $acc['hostname']." ".$acc['ifDescr'] . " $mac -> $b_in:$b_out:$p_in:$p_out "); } - - $rrdfile = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd"); - - if (!is_file($rrdfile)) - { - rrdtool_create($rrdfile,"DS:IN:COUNTER:600:0:12500000000 \ - DS:OUT:COUNTER:600:0:12500000000 \ - DS:PIN:COUNTER:600:0:12500000000 \ - DS:POUT:COUNTER: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"); - } - $woo = "N:".($b_in+0).":".($b_out+0).":".($p_in+0).":".($p_out+0); - $ret = rrdtool_update("$rrdfile", $woo); - - if ($acc['update']) - { /// Do Updates - dbUpdate($acc['update'], 'mac_accounting', '`ma_id` = ?', array($acc['ma_id'])); - } /// End Updates } + + unset($cip_array); + + if ($mac_entries) { echo(" $mac_entries MAC accounting entries\n"); } + + echo("\n"); } - -unset($cip_array); - -if ($mac_entries) { echo(" $mac_entries MAC accounting entries\n"); } - -echo("\n"); - + ?> diff --git a/includes/polling/os/airport.inc.php b/includes/polling/os/airport.inc.php index fd1e214d1..365d25483 100644 --- a/includes/polling/os/airport.inc.php +++ b/includes/polling/os/airport.inc.php @@ -1,5 +1,5 @@ \ No newline at end of file