1<?php 2 3/** 4 * Observium 5 * 6 * This file is part of Observium. 7 * 8 * @package observium 9 * @subpackage poller 10 * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited 11 * 12 */ 13 14if (is_device_mib($device, 'CISCO-CEF-MIB')) 15{ 16 echo('Cisco CEF Switching Path: '); 17 18 $cefs_query = dbFetchRows('SELECT * FROM `cef_switching` WHERE `device_id` = ?', array($device['device_id'])); 19 foreach ($cefs_query as $ceftmp) 20 { 21 $cef_id = $device['device_id'].'-'.$ceftmp['entPhysicalIndex'].'-'.$ceftmp['afi'].'-'.$ceftmp['cef_index']; 22 $cefs_db[$cef_id] = $ceftmp['cef_switching_id']; 23 } 24 $cef_pfxs_query = dbFetchRows('SELECT * FROM `cef_prefix` WHERE `device_id` = ?', array($device['device_id'])); 25 foreach ($cef_pfxs_query as $pfx) 26 { 27 $cef_pfxs_db[$pfx['entPhysicalIndex']][$pfx['afi']] = $pfx['cef_pfx_id']; 28 } 29 unset($cefs_query, $cef_pfxs_query); 30 31 $device_context = $device; 32 if (!count($cefs_db)) 33 { 34 // Set retries to 0 for speedup first walking, only if previously polling also empty (DB empty) 35 $device_context['snmp_retries'] = 0; 36 } 37 $cefs = snmpwalk_cache_threepart_oid($device_context, 'cefSwitchingStatsEntry', array(), 'CISCO-CEF-MIB'); 38 unset($device_context); 39 if ($GLOBALS['snmp_status']) 40 { 41 $cef_pfxs = snmpwalk_cache_twopart_oid($device, 'cefFIBSummaryEntry', array(), 'CISCO-CEF-MIB'); 42 if (!is_array($entity_array)) 43 { 44 echo('Caching OIDs: '); 45 $entity_array = array(); 46 echo(' entPhysicalDescr'); 47 $entity_array = snmpwalk_cache_multi_oid($device, 'entPhysicalDescr', $entity_array, 'ENTITY-MIB'); 48 echo(' entPhysicalName'); 49 $entity_array = snmpwalk_cache_multi_oid($device, 'entPhysicalName', $entity_array, 'ENTITY-MIB'); 50 echo(' entPhysicalModelName'); 51 $entity_array = snmpwalk_cache_multi_oid($device, 'entPhysicalModelName', $entity_array, 'ENTITY-MIB'); 52 } 53 $polled = time(); 54 } 55 if (OBS_DEBUG > 1 && count($cefs)) { print_vars($cefs); } 56 57 foreach ($cefs as $entity => $afis) 58 { 59 $entity_name = $entity_array[$entity]['entPhysicalName'] .' - '.$entity_array[$entity]['entPhysicalModelName']; 60 echo("\n$entity $entity_name\n"); 61 foreach ($afis as $afi => $paths) 62 { 63 echo(" |- $afi "); 64 65 // Do Per-AFI entity summary 66 67 // FIXME -- memory tables 68 69 if (!isset($cef_pfxs_db[$entity][$afi])) 70 { 71 dbInsert(array('device_id' => $device['device_id'], 'entPhysicalIndex' => $entity, 'afi' => $afi), 'cef_prefix'); 72 echo('+'); 73 } 74 unset($cef_pfxs_db[$entity][$afi]); 75 76 $cef_pfx['update']['cef_pfx'] = $cef_pfxs[$entity][$afi]['cefFIBSummaryFwdPrefixes']; 77 dbUpdate($cef_pfx['update'], 'cef_prefix', '`device_id` = ? AND `entPhysicalIndex` = ? AND `afi` = ?', array($device['device_id'], $entity, $afi)); 78 79 rrdtool_update_ng($device, 'cisco-cef-pfx', array('pfx' => $cef_pfxs[$entity][$afi]['cefFIBSummaryFwdPrefixes']), "$entity-$afi"); 80 81 //print_vars($cef_pfxs[$entity][$afi]); 82 83 // Do Per-path statistics 84 foreach ($paths as $path => $cef_stat) 85 { 86 echo(' | |-'.$path.': '.$cef_stat['cefSwitchingPath']); 87 88 $cef_id = $device['device_id'].'-'.$entity.'-'.$afi.'-'.$path; 89 90 #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') 91 if (!isset($cefs_db[$cef_id])) 92 { 93 dbInsert(array('device_id' => $device['device_id'], 'entPhysicalIndex' => $entity, 'afi' => $afi, 'cef_index' => $path, 'cef_path' => $cef_stat['cefSwitchingPath']), 'cef_switching'); 94 echo('+'); 95 } 96 unset($cefs_db[$cef_id]); 97 98 $cef_entry = dbFetchRow('SELECT * FROM `cef_switching` WHERE `device_id` = ? AND `entPhysicalIndex` = ? AND `afi` = ? AND `cef_index` = ?', array($device['device_id'], $entity, $afi, $path)); 99 100 // Copy HC to non-HC if they exist 101 if (is_numeric($cef_stat['cefSwitchingHCDrop'])) { $cef_stat['cefSwitchingDrop'] = $cef_stat['cefSwitchingHCDrop']; } 102 if (is_numeric($cef_stat['cefSwitchingHCPunt'])) { $cef_stat['cefSwitchingPunt'] = $cef_stat['cefSwitchingHCPunt']; } 103 if (is_numeric($cef_stat['cefSwitchingHCPunt2Host'])) { $cef_stat['cefSwitchingPunt2Host'] = $cef_stat['cefSwitchingHCPunt2Host']; } 104 105 // FIXME -- memory tables 106 107 $cef_stat['update']['drop'] = $cef_stat['cefSwitchingDrop']; 108 $cef_stat['update']['punt'] = $cef_stat['cefSwitchingPunt']; 109 $cef_stat['update']['punt2host'] = $cef_stat['cefSwitchingPunt2Host']; 110 $cef_stat['update']['drop_prev'] = $cef_entry['drop']; 111 $cef_stat['update']['punt_prev'] = $cef_entry['punt']; 112 $cef_stat['update']['punt2host_prev'] = $cef_entry['punt2host']; 113 $cef_stat['update']['updated'] = $polled; 114 $cef_stat['update']['updated_prev'] = $cef_entry['updated']; 115 116 dbUpdate($cef_stat['update'], 'cef_switching', '`device_id` = ? AND `entPhysicalIndex` = ? AND `afi` = ? AND `cef_index` = ?', array($device['device_id'], $entity, $afi, $path)); 117 118 rrdtool_update_ng($device, 'cisco-cef-switching', array( 119 'drop' => $cef_stat['cefSwitchingDrop'], 120 'punt' => $cef_stat['cefSwitchingPunt'], 121 'hostpunt' => $cef_stat['cefSwitchingPunt2Host'], 122 ), "$entity-$afi-$path"); 123 124 echo(PHP_EOL); 125 } 126 } 127 } 128 129 //print_vars($cefs_db); 130 131 foreach ($cefs_db as $cef_switching_id) 132 { 133 dbDelete('cef_switching', '`cef_switching_id` = ?', array($cef_switching_id)); 134 echo('-'); 135 } 136 foreach ($cef_pfxs_db as $afis) 137 { 138 foreach ($afis as $pfx_id) 139 { 140 dbDelete('cef_prefix', '`cef_pfx_id` = ?', array($pfx_id)); 141 echo('-'); 142 } 143 } 144 145 echo(PHP_EOL); 146} # os_group = cisco 147 148// EOF 149