librenms/includes/discovery/cisco-pw.inc.php
Tony Murray eeb3d58f5b Improved Logging and Debugging (#8870)
Use Log facility when Laravel is booted.
Update init.php so we can easily boot Laravel for CLI scripts. (and just Eloquent, but that may go away)
Move all debug setup into set_debug() function and use that across all scripts.
Log Laravel database queries.
Send debug output to librenms log file when enabling debug in the webui.
Allow for colorized Log CLI output. (currently will leave % tags in log file output)

** Needs testing and perhaps tweaking still.

DO NOT DELETE THIS TEXT

#### Please note

> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.

- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)

#### Testers

If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
2018-07-13 23:08:00 +01:00

61 lines
2.6 KiB
PHP

<?php
use LibreNMS\Config;
if (Config::get('enable_pseudowires') && $device['os_group'] == 'cisco') {
$pws_db = [];
// Pre-cache the existing state of pseudowires for this device from the database
$pws_db_raw = dbFetchRows('SELECT * FROM `pseudowires` WHERE `device_id` = ?', array($device['device_id']));
foreach ($pws_db_raw as $pw_db) {
$pws_db[$pw_db['cpwVcID']] = $pw_db['pseudowire_id'];
}
$pws = snmpwalk_cache_oid($device, 'cpwVcID', array(), 'CISCO-IETF-PW-MPLS-MIB');
$pws = snmpwalk_cache_oid($device, 'cpwVcName', $pws, 'CISCO-IETF-PW-MPLS-MIB');
$pws = snmpwalk_cache_oid($device, 'cpwVcType', $pws, 'CISCO-IETF-PW-MPLS-MIB');
$pws = snmpwalk_cache_oid($device, 'cpwVcPsnType', $pws, 'CISCO-IETF-PW-MPLS-MIB');
$pws = snmpwalk_cache_oid($device, 'cpwVcDescr', $pws, 'CISCO-IETF-PW-MPLS-MIB');
// For MPLS pseudowires
$pws = snmpwalk_cache_oid($device, 'cpwVcMplsPeerLdpID', $pws, 'CISCO-IETF-PW-MPLS-MIB');
foreach ($pws as $pw_id => $pw) {
list($cpw_remote_id) = explode(':', $pw['cpwVcMplsPeerLdpID']);
$cpw_remote_device = dbFetchCell('SELECT device_id from ipv4_addresses AS A, ports AS I WHERE A.ipv4_address=? AND A.port_id=I.port_id', array($cpw_remote_id));
$if_id = dbFetchCell('SELECT port_id from ports WHERE `ifDescr`=? AND `device_id`=?', array($pw['cpwVcName'], $device['device_id']));
if (!empty($pws_db[$pw['cpwVcID']])) {
$pseudowire_id = $pws_db[$pw['cpwVcID']];
echo '.';
} else {
$pseudowire_id = dbInsert(
array(
'device_id' => $device['device_id'],
'port_id' => $if_id,
'peer_device_id' => $cpw_remote_device,
'peer_ldp_id' => $cpw_remote_id,
'cpwVcID' => $pw['cpwVcID'],
'cpwOid' => $pw_id,
'pw_type' => $pw['cpwVcType'],
'pw_descr' => $pw['cpwVcDescr'],
'pw_psntype' => $pw['cpwVcPsnType'],
),
'pseudowires'
);
echo '+';
}
$device['pws'][$pw['cpwVcID']] = $pseudowire_id;
}//end foreach
// Cycle the list of pseudowires we cached earlier and make sure we saw them again.
foreach ($pws_db as $pw_id => $pseudowire_id) {
if (empty($device['pws'][$pw_id])) {
dbDelete('pseudowires', '`pseudowire_id` = ?', array($pseudowire_id));
}
}
echo "\n";
} //end if
unset($pws_db, $pws_db_raw, $pw_db);