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
This commit is contained in:
Tom Laermans
2012-04-09 10:53:55 +00:00
parent e826fc4b99
commit 502f207291
8 changed files with 190 additions and 184 deletions

View File

@@ -346,7 +346,7 @@ foreach (array('fanspeed','humidity','temperature') as $item)
{
if ($menu_sensors[$item])
{
echo('<li><a href="health/metric='.$item.'/"><img src="images/icons/'.$item.'.png" border="0" align="absmiddle" /> '.ucfirst($item).'</a></li>');
echo('<li><a href="health/metric='.$item.'/"><img src="images/icons/'.$item.'.png" border="0" align="absmiddle" /> '.nicecase($item).'</a></li>');
unset($menu_sensors[$item]);$sep++;
}
}
@@ -361,7 +361,7 @@ foreach (array('current','frequency','power','voltage') as $item)
{
if ($menu_sensors[$item])
{
echo('<li><a href="health/metric='.$item.'/"><img src="images/icons/'.$item.'.png" border="0" align="absmiddle" /> '.ucfirst($item).'</a></li>');
echo('<li><a href="health/metric='.$item.'/"><img src="images/icons/'.$item.'.png" border="0" align="absmiddle" /> '.nicecase($item).'</a></li>');
unset($menu_sensors[$item]);$sep++;
}
}

View File

@@ -134,7 +134,7 @@ if (isset($config['branding']) && is_array($config['branding']))
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="content-language" content="en-us" />
<?php
if ($config['page_refresh']) { echo("<meta http-equiv='refresh' content='".$config['page_refresh']."'>"); }
if ($config['page_refresh']) { echo(' <meta http-equiv="refresh" content="'.$config['page_refresh'].'" />' . "\n"); }
?>
<link href="<?php echo($config['stylesheet']); ?>" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="<?php echo($config['favicon']); ?>" />

View File

@@ -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';

View File

@@ -1,6 +1,6 @@
<?php
echo(" ENTITY-SENSOR ");
echo(" ENTITY-SENSOR: ");
echo("\nCaching OIDs:");

View File

@@ -5,7 +5,7 @@ if ($device['os'] == "linux")
$oids = snmp_walk($device, "lmTempSensorsDevice", "-Osqn", "LM-SENSORS-MIB");
if ($debug) { echo($oids."\n"); }
$oids = trim($oids);
if ($oids) echo("LM-SENSORS-MIB ");
if ($oids) echo("LM-SENSORS-MIB: ");
foreach (explode("\n", $oids) as $data)
{
$data = trim($data);

View File

@@ -1,108 +1,111 @@
<?php
echo("Cisco CEF Switching Path: ");
$cefs = array();
$cefs = snmpwalk_cache_threepart_oid($device, "CISCO-CEF-MIB::cefSwitchingStatsEntry", $cefs, "CISCO-CEF-MIB");
$polled = time();
$cefs_query = dbFetchRows("SELECT * FROM `cef_switching` WHERE `device_id` = ?", array($device['device_id']));
foreach ($cefs_query as $ceftmp)
if ($device['os_group'] == "cisco")
{
$cef_id = $device['device_id']."-".$ceftmp['entPhysicalIndex']."-".$ceftmp['afi']."-".$ceftmp['cef_index'];
$cefs_db[$cef_id] = $ceftmp['cef_switching_id'];
}
if ($debug) { print_r($cefs); }
if (is_array($cefs))
{
if (!is_array($entity_array))
echo("Cisco CEF Switching Path: ");
$cefs = array();
$cefs = snmpwalk_cache_threepart_oid($device, "CISCO-CEF-MIB::cefSwitchingStatsEntry", $cefs, "CISCO-CEF-MIB");
$polled = time();
$cefs_query = dbFetchRows("SELECT * FROM `cef_switching` WHERE `device_id` = ?", array($device['device_id']));
foreach ($cefs_query as $ceftmp)
{
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");
$cef_id = $device['device_id']."-".$ceftmp['entPhysicalIndex']."-".$ceftmp['afi']."-".$ceftmp['cef_index'];
$cefs_db[$cef_id] = $ceftmp['cef_switching_id'];
}
foreach ($cefs as $entity => $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
?>

View File

@@ -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");
?>

View File

@@ -1,5 +1,5 @@
<?php
$version = snmp_get($device, "sysConfFirmwareVersion.0 ", "-Ovq", "AIRPORT-BASESTATION-3-MIB");
$version = snmp_get($device, "sysConfFirmwareVersion.0", "-Ovq", "AIRPORT-BASESTATION-3-MIB");
?>