|
209 | 209 | } |
210 | 210 | } |
211 | 211 |
|
212 | | -echo 'Caching Oids: '; |
| 212 | +$fetched_data_string = 'Fetched data '; |
213 | 213 | $port_stats = []; |
214 | 214 |
|
215 | 215 | if ($device['os'] === 'f5' && (version_compare($device['version'], '11.2.0', '>=') && version_compare($device['version'], '11.7', '<'))) { |
|
219 | 219 | } else { |
220 | 220 | $selected_attrib = DeviceCache::get($device['device_id'] ?? null)->getAttrib('selected_ports'); |
221 | 221 | if ($selected_attrib !== null ? $selected_attrib == 'true' : Config::getOsSetting($device['os'], 'polling.selected_ports')) { |
222 | | - echo 'Selected ports polling '; |
| 222 | + $fetched_data_string .= '(Selected ports polling): '; |
223 | 223 |
|
224 | 224 | // remove the deleted and disabled ports and mark them skipped |
225 | 225 | $polled_ports = array_filter($ports, function ($port) use ($ports) { |
|
237 | 237 | $walk_base = $total_port_count - $polled_port_count < 5 || $polled_port_count / $total_port_count > 0.9; |
238 | 238 |
|
239 | 239 | if ($walk_base) { |
240 | | - echo "Not enough ports for selected port polling, walking base OIDs instead\n"; |
| 240 | + Log::info('Not enough ports for selected port polling, walking base OIDs instead'); |
241 | 241 | foreach ($table_base_oids as $oid) { |
242 | 242 | $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, 'IF-MIB'); |
243 | 243 | } |
|
288 | 288 | } |
289 | 289 | } |
290 | 290 | } else { |
291 | | - echo 'Full ports polling '; |
| 291 | + $fetched_data_string .= '(Full ports polling): '; |
292 | 292 | // For devices that are on the bad_ifXentry list, try fetching ifAlias to have nice interface descriptions. |
293 | 293 |
|
294 | 294 | if (! in_array(strtolower($device['hardware'] ?? ''), array_map('strtolower', (array) Config::getOsSetting($device['os'], 'bad_ifXEntry', [])))) { |
|
308 | 308 | } else { |
309 | 309 | // For devices with ifXentry data, only specific ifEntry keys are fetched to reduce SNMP load |
310 | 310 | foreach ($ifmib_oids as $oid) { |
311 | | - echo "$oid "; |
| 311 | + $fetched_data_string .= "$oid "; |
312 | 312 | $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, 'IF-MIB', null, '-OQUst'); |
313 | 313 | } |
314 | 314 | } |
315 | 315 | if ($device['os'] != 'asa') { |
316 | | - echo 'dot3StatsDuplexStatus'; |
| 316 | + $fetched_data_string .= 'dot3StatsDuplexStatus '; |
317 | 317 | if (Config::get('enable_ports_poe') || Config::get('enable_ports_etherlike')) { |
318 | 318 | $port_stats = snmpwalk_cache_oid($device, 'dot3StatsIndex', $port_stats, 'EtherLike-MIB'); |
319 | 319 | } |
|
336 | 336 | // Code by OS device |
337 | 337 |
|
338 | 338 | if ($device['os'] == 'ios' || $device['os'] == 'iosxe') { |
339 | | - echo 'cpeExtPsePortEntry'; |
340 | | - $port_stats_poe = snmpwalk_cache_oid($device, 'cpeExtPsePortEntry', [], 'CISCO-POWER-ETHERNET-EXT-MIB'); |
| 339 | + $fetched_data_string .= 'cpeExtPsePortTable '; |
| 340 | + $port_stats_poe = snmpwalk_cache_oid($device, 'cpeExtPsePortTable', [], 'CISCO-POWER-ETHERNET-EXT-MIB'); |
341 | 341 | $port_ent_to_if = snmpwalk_cache_oid($device, 'portIfIndex', [], 'CISCO-STACK-MIB'); |
342 | 342 |
|
343 | 343 | if (! $port_ent_to_if) { |
|
363 | 363 | } |
364 | 364 | } |
365 | 365 | } elseif ($device['os'] == 'vrp') { |
366 | | - echo 'HwPoePortEntry'; |
| 366 | + $fetched_data_string .= 'HwPoePortTable '; |
367 | 367 |
|
368 | 368 | $vrp_poe_oids = [ |
369 | 369 | 'hwPoePortReferencePower', |
|
377 | 377 | $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, 'HUAWEI-POE-MIB'); |
378 | 378 | } |
379 | 379 | } elseif ($device['os'] == 'linksys-ss') { |
380 | | - echo 'rlPethPsePort'; |
| 380 | + $fetched_data_string .= 'rlPethPsePort '; |
381 | 381 |
|
382 | 382 | $linksys_poe_oids = [ |
383 | 383 | 'pethPsePortAdminEnable', |
|
394 | 394 | $port_stats[$if_id] = array_merge($port_stats[$if_id], $value); |
395 | 395 | } |
396 | 396 | } elseif ($device['os'] == 'jetstream') { |
397 | | - echo 'tpPoePortConfigEntry'; |
398 | | - $port_stats_poe = snmpwalk_cache_oid($device, 'tpPoePortConfigEntry', [], 'TPLINK-POWER-OVER-ETHERNET-MIB'); |
| 397 | + $fetched_data_string .= 'tpPoePortConfigTable '; |
| 398 | + $port_stats_poe = snmpwalk_cache_oid($device, 'tpPoePortConfigTable', [], 'TPLINK-POWER-OVER-ETHERNET-MIB'); |
399 | 399 | $ifTable_ifDescr = snmpwalk_cache_oid($device, 'ifDescr', [], 'IF-MIB'); |
400 | 400 |
|
401 | 401 | $port_ent_to_if = []; |
|
444 | 444 | } |
445 | 445 | } |
446 | 446 |
|
| 447 | +Log::info($fetched_data_string); |
| 448 | + |
447 | 449 | $polled = time(); |
448 | 450 |
|
449 | 451 | // End Building SNMP Cache Array |
|
503 | 505 | $port_id = dbInsert(['device_id' => $device['device_id'], 'ifIndex' => $ifIndex, 'ifName' => $ifName], 'ports'); |
504 | 506 | dbInsert(['port_id' => $port_id], 'ports_statistics'); |
505 | 507 | $ports[$port_id] = dbFetchRow('SELECT * FROM `ports` WHERE `port_id` = ?', [$port_id]); |
506 | | - echo 'Adding: ' . $ifName . '(' . $ifIndex . ')(' . $port_id . ')'; |
| 508 | + Log::info('Adding: ' . $ifName . '(' . $ifIndex . ')(' . $port_id . ')'); |
507 | 509 | } elseif ($ports[$port_id]['deleted'] == 1) { |
508 | 510 | // Port re-discovered after previous deletion? |
509 | 511 | dbUpdate(['deleted' => '0'], 'ports', '`port_id` = ?', [$port_id]); |
|
535 | 537 | } |
536 | 538 | } // End new interface detection |
537 | 539 |
|
538 | | -echo "\n"; |
539 | | - |
540 | 540 | // get last poll time to optimize poll_time, poll_prev and poll_period in table db |
541 | 541 | $prev_poll_times = array_filter(array_column($ports, 'poll_time')); |
542 | 542 | $max_poll_time_prev = empty($prev_poll_times) ? null : max($prev_poll_times); |
|
557 | 557 |
|
558 | 558 | /* We don't care for disabled ports, go on */ |
559 | 559 | if ($port['disabled'] == 1) { |
560 | | - echo "{$port_info_string}disabled.\n"; |
| 560 | + Log::info("{$port_info_string}disabled."); |
561 | 561 | continue; |
562 | 562 | } |
563 | 563 |
|
|
568 | 568 | if (! in_array($port_id, $ports_found)) { |
569 | 569 | if ($port['deleted'] != '1') { |
570 | 570 | dbUpdate(['deleted' => '1'], 'ports', '`device_id` = ? AND `port_id` = ?', [$device['device_id'], $port_id]); |
571 | | - echo "{$port_info_string}deleted.\n"; |
| 571 | + Log::info("{$port_info_string}deleted."); |
572 | 572 | } |
573 | 573 | continue; |
574 | 574 | } |
575 | 575 |
|
576 | | - echo $port_info_string; |
577 | 576 | if ($port_stats[$ifIndex]) { |
578 | 577 | // Check to make sure Port data is cached. |
579 | 578 | $this_port = &$port_stats[$ifIndex]; |
|
627 | 626 |
|
628 | 627 | // Overwrite ifDuplex with dot3StatsDuplexStatus if it exists |
629 | 628 | if (isset($this_port['dot3StatsDuplexStatus'])) { |
630 | | - echo 'dot3Duplex '; |
| 629 | + $port_info_string .= 'dot3Duplex '; |
631 | 630 | $this_port['ifDuplex'] = $this_port['dot3StatsDuplexStatus']; |
632 | 631 | } |
633 | 632 |
|
|
663 | 662 | } |
664 | 663 |
|
665 | 664 | // FIXME use $q_bridge_mib[$this_port['ifIndex']] to see if it is a trunk (>1 array count) |
666 | | - echo 'VLAN = ' . ($this_port['ifVlan'] ?? '?') . ' '; |
| 665 | + $port_info_string .= ' VLAN = ' . ($this_port['ifVlan'] ?? '?') . ' '; |
667 | 666 |
|
668 | 667 | // attempt to fill missing fields |
669 | 668 | port_fill_missing_and_trim($this_port, $device); |
|
727 | 726 | if (Debug::isEnabled()) { |
728 | 727 | d_echo($oid . ': ' . $old . ' -> ' . $new . ' '); |
729 | 728 | } else { |
730 | | - echo $oid . ' '; |
| 729 | + $port_info_string .= $oid . ' '; |
731 | 730 | } |
732 | 731 | } else { |
733 | 732 | if (in_array($oid, ['ifOperStatus', 'ifAdminStatus', 'ifSpeed'])) { |
|
798 | 797 | if ($oid_rate < 0) { |
799 | 798 | $oid_rate = '0'; |
800 | 799 | $oid_diff = '0'; |
801 | | - echo "negative $oid"; |
| 800 | + $port_info_string .= "negative $oid "; |
802 | 801 | } |
803 | 802 |
|
804 | 803 | $current_port_stats[$oid . '_rate'] = $oid_rate; |
|
814 | 813 | $port_debug = $port['port_id'] . '|' . $polled . '|' . $polled_period . '|' . $this_port['ifHCInOctets'] . '|' . $this_port['ifHCOutOctets']; |
815 | 814 | $port_debug .= '|' . $current_port_stats['ifInOctets_rate'] . '|' . $current_port_stats['ifOutOctets_rate'] . "\n"; |
816 | 815 | file_put_contents('/tmp/port_debug.txt', $port_debug, FILE_APPEND); |
817 | | - echo 'Wrote port debugging data'; |
| 816 | + Log::info('debug_port enabled, wrote port debugging data to /tmp/port_debug.txt'); |
818 | 817 | } |
819 | 818 |
|
820 | 819 | $current_port_stats['ifInBits_rate'] = round($current_port_stats['ifInOctets_rate'] * 8); |
|
826 | 825 | $current_port_stats['ifOutBits_perc'] = Number::calculatePercent($current_port_stats['ifOutBits_rate'], $this_port['ifSpeed'], 0); |
827 | 826 | } |
828 | 827 |
|
829 | | - echo 'bps(' . Number::formatSi($current_port_stats['ifInBits_rate'], 2, 3, 'bps') . '/' . Number::formatSi($current_port_stats['ifOutBits_rate'], 2, 0, 'bps') . ')'; |
830 | | - echo 'bytes(' . Number::formatBi($current_port_stats['ifInOctets_diff'] ?? 0) . '/' . Number::formatBi($current_port_stats['ifOutOctets_diff'] ?? 0) . ')'; |
831 | | - echo 'pkts(' . Number::formatSi($current_port_stats['ifInUcastPkts_rate'] ?? 0, 2, 3, 'pps') . '/' . Number::formatSi($current_port_stats['ifOutUcastPkts_rate'] ?? 0, 2, 0, 'pps') . ')'; |
| 828 | + $port_info_string .= 'bps(' . Number::formatSi($current_port_stats['ifInBits_rate'], 2, 3, 'bps') . '/' . Number::formatSi($current_port_stats['ifOutBits_rate'], 2, 0, 'bps') . ') '; |
| 829 | + $port_info_string .= 'bytes(' . Number::formatBi($current_port_stats['ifInOctets_diff'] ?? 0) . '/' . Number::formatBi($current_port_stats['ifOutOctets_diff'] ?? 0) . ') '; |
| 830 | + $port_info_string .= 'pkts(' . Number::formatSi($current_port_stats['ifInUcastPkts_rate'] ?? 0, 2, 3, 'pps') . '/' . Number::formatSi($current_port_stats['ifOutUcastPkts_rate'] ?? 0, 2, 0, 'pps') . ') '; |
832 | 831 |
|
833 | 832 | // Update data stores |
834 | 833 | $rrd_name = Rrd::portName($port_id, ''); |
|
903 | 902 | if ($current_oid != $port[$oid]) { |
904 | 903 | // If data has changed, build a query |
905 | 904 | $port['update'][$oid] = $current_oid; |
906 | | - echo 'PAgP '; |
| 905 | + $port_info_string .= 'PAgP '; |
907 | 906 | Eventlog::log("$oid -> " . $current_oid, $device['device_id'], 'interface', Severity::Notice, $port['port_id']); |
908 | 907 | } |
909 | 908 | } |
|
944 | 943 | // End Update Database |
945 | 944 | } |
946 | 945 |
|
947 | | - echo "\n"; |
| 946 | + Log::info($port_info_string); |
948 | 947 |
|
949 | 948 | // Clear Per-Port Variables Here |
950 | 949 | unset($this_port, $port); |
|
0 commit comments