2016-01-21 12:04:20 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* LibreNMS module to capture Cisco OTV Details
|
|
|
|
*
|
|
|
|
* Copyright (c) 2015 Aaron Daniels <aaron@daniels.id.au>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version. Please see LICENSE.txt at the top level of
|
|
|
|
* the source code distribution for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ($device['os_group'] == 'cisco') {
|
|
|
|
// Define some error messages
|
2020-09-21 13:40:17 +00:00
|
|
|
$error_vpn = [];
|
2020-09-21 13:59:34 +00:00
|
|
|
$error_vpn[0] = 'Other';
|
|
|
|
$error_vpn[1] = 'Configuration changed';
|
|
|
|
$error_vpn[2] = 'Control Group information is unavailable';
|
|
|
|
$error_vpn[3] = 'Data Group range information is unavailable';
|
|
|
|
$error_vpn[4] = 'Join or Source interface information is unavailable';
|
|
|
|
$error_vpn[5] = 'VPN name is unavailable';
|
|
|
|
$error_vpn[6] = 'IP address is missing for Join Interface';
|
|
|
|
$error_vpn[7] = 'Join Interface is down';
|
|
|
|
$error_vpn[8] = 'Overlay is administratively shutdown';
|
|
|
|
$error_vpn[9] = 'Overlay is in delete hold down phase';
|
|
|
|
$error_vpn[10] = 'VPN is reinitializing';
|
|
|
|
$error_vpn[11] = 'Site ID information is unavailable';
|
|
|
|
$error_vpn[12] = 'Site ID mismatch has occurred';
|
|
|
|
$error_vpn[13] = 'IP address is missing for Source Interface';
|
|
|
|
$error_vpn[14] = 'Source interface is down';
|
|
|
|
$error_vpn[15] = 'Changing site identifier';
|
|
|
|
$error_vpn[16] = 'Changing control group';
|
|
|
|
$error_vpn[17] = 'Device ID information is unavailable';
|
|
|
|
$error_vpn[18] = 'Changing device ID';
|
|
|
|
$error_vpn[19] = 'Cleanup in progress';
|
2016-01-27 21:04:12 +00:00
|
|
|
|
2020-09-21 13:40:17 +00:00
|
|
|
$error_aed = [];
|
2020-09-21 13:59:34 +00:00
|
|
|
$error_aed[0] = 'Other';
|
|
|
|
$error_aed[1] = 'Overlay is Down';
|
|
|
|
$error_aed[2] = 'Site ID is not configured';
|
|
|
|
$error_aed[3] = 'Site ID mismatch';
|
|
|
|
$error_aed[4] = 'Version mismatch';
|
|
|
|
$error_aed[5] = 'Site VLAN is Down';
|
|
|
|
$error_aed[6] = 'No extended VLAN is operationally up';
|
|
|
|
$error_aed[7] = 'No Overlay Adjacency is up';
|
|
|
|
$error_aed[8] = 'LSPDB sync incomplete';
|
|
|
|
$error_aed[9] = 'Overlay state down event in progress';
|
|
|
|
$error_aed[10] = 'ISIS control group sync pending';
|
2016-01-27 21:04:12 +00:00
|
|
|
|
2020-09-21 13:40:17 +00:00
|
|
|
$error_overlay = [];
|
2020-09-21 13:59:34 +00:00
|
|
|
$error_overlay[1] = 'active';
|
|
|
|
$error_overlay[2] = 'notInService';
|
|
|
|
$error_overlay[3] = 'notReady';
|
|
|
|
$error_overlay[4] = 'createAndGo';
|
|
|
|
$error_overlay[5] = 'createAndWait';
|
|
|
|
$error_overlay[6] = 'destroy';
|
2016-01-27 21:04:12 +00:00
|
|
|
|
|
|
|
$module = 'Cisco-OTV';
|
2016-01-21 12:04:20 +00:00
|
|
|
|
2016-08-21 13:07:14 +00:00
|
|
|
$component = new LibreNMS\Component();
|
2020-09-21 13:40:17 +00:00
|
|
|
$components = $component->getComponents($device['device_id'], ['type'=>$module]);
|
2016-01-21 12:04:20 +00:00
|
|
|
|
|
|
|
// We only care about our device id.
|
2016-01-27 21:04:12 +00:00
|
|
|
$components = $components[$device['device_id']];
|
2016-01-21 12:04:20 +00:00
|
|
|
|
|
|
|
// Begin our master array, all other values will be processed into this array.
|
2020-09-21 13:40:17 +00:00
|
|
|
$tblOTV = [];
|
|
|
|
$tblEndpoints = [];
|
2016-01-21 12:04:20 +00:00
|
|
|
|
|
|
|
// Let's gather some data..
|
|
|
|
$tblOverlayEntry = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.810.1.2.1.1');
|
|
|
|
$tblAdjacencyDatabaseEntry = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.810.1.3.1.1', 0);
|
|
|
|
$tblAdjacentDevName = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.810.1.3.1.1.4', 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* False == no object found - this is not an error, there is no QOS configured
|
|
|
|
* null == timeout or something else that caused an error, there may be QOS configured but we couldn't get it.
|
|
|
|
*/
|
2016-08-28 17:32:58 +00:00
|
|
|
if (is_null($tblOverlayEntry) || is_null($tblAdjacencyDatabaseEntry) || is_null($tblAdjacentDevName)) {
|
2016-01-21 12:04:20 +00:00
|
|
|
// We have to error here or we will end up deleting all our components.
|
|
|
|
echo "Error\n";
|
2016-08-28 17:32:58 +00:00
|
|
|
} else {
|
2016-01-21 12:04:20 +00:00
|
|
|
// No Error, lets process things.
|
|
|
|
|
|
|
|
// Add each overlay to the array.
|
2020-09-21 13:40:17 +00:00
|
|
|
foreach ((array) $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.2'] as $index => $name) {
|
|
|
|
$result = [];
|
2016-01-21 12:04:20 +00:00
|
|
|
$message = false;
|
2016-01-27 21:04:12 +00:00
|
|
|
$result['index'] = $index;
|
|
|
|
$result['label'] = $name;
|
2016-01-21 12:04:20 +00:00
|
|
|
if ($tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.15'][$index] == 1) {
|
2016-01-27 21:04:12 +00:00
|
|
|
$result['transport'] = 'Multicast';
|
2016-08-28 17:32:58 +00:00
|
|
|
} else {
|
2016-01-27 21:04:12 +00:00
|
|
|
$result['transport'] = 'Unicast';
|
2016-01-21 12:04:20 +00:00
|
|
|
}
|
2016-01-27 21:04:12 +00:00
|
|
|
$result['otvtype'] = 'overlay';
|
2020-09-21 13:59:34 +00:00
|
|
|
$result['UID'] = $result['otvtype'] . '-' . $result['index'];
|
2016-01-27 21:04:12 +00:00
|
|
|
$result['vpn_state'] = $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.3'][$index];
|
|
|
|
if ($result['vpn_state'] != 2) {
|
2020-09-21 13:59:34 +00:00
|
|
|
$message .= 'VPN Down: ' . $error_vpn[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.4'][$index]] . "\n";
|
2016-01-21 12:04:20 +00:00
|
|
|
}
|
2016-01-27 21:04:12 +00:00
|
|
|
$result['aed_state'] = $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.13'][$index];
|
|
|
|
if ($result['aed_state'] == 2) {
|
2020-09-21 13:59:34 +00:00
|
|
|
$message .= 'AED Down: ' . $error_aed[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.14'][$index]] . "\n";
|
2016-01-21 12:04:20 +00:00
|
|
|
}
|
2016-01-27 21:04:12 +00:00
|
|
|
$result['overlay_state'] = $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.23'][$index];
|
|
|
|
if ($result['overlay_state'] == 2) {
|
2020-09-21 13:59:34 +00:00
|
|
|
$message .= 'Overlay Down: ' . $error_overlay[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.24'][$index]] . "\n";
|
2016-01-21 12:04:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we have set a message, we have an error, activate alert.
|
|
|
|
if ($message !== false) {
|
2016-01-27 21:04:12 +00:00
|
|
|
$result['error'] = $message;
|
2016-03-10 07:30:32 +00:00
|
|
|
$result['status'] = 2;
|
2016-08-28 17:32:58 +00:00
|
|
|
} else {
|
2020-09-21 13:59:34 +00:00
|
|
|
$result['error'] = '';
|
2016-03-10 07:30:32 +00:00
|
|
|
$result['status'] = 0;
|
2016-01-21 12:04:20 +00:00
|
|
|
}
|
|
|
|
|
2016-01-28 08:40:05 +00:00
|
|
|
// Let's log some debugging
|
2020-09-21 13:40:17 +00:00
|
|
|
d_echo("\n\nOverlay: " . $result['label'] . "\n");
|
2020-09-21 13:59:34 +00:00
|
|
|
d_echo(' Index: ' . $result['index'] . "\n");
|
|
|
|
d_echo(' UID: ' . $result['UID'] . "\n");
|
|
|
|
d_echo(' Transport: ' . $result['transport'] . "\n");
|
|
|
|
d_echo(' Type: ' . $result['otvtype'] . "\n");
|
|
|
|
d_echo(' Status: ' . $result['status'] . "\n");
|
|
|
|
d_echo(' Message: ' . $result['error'] . "\n");
|
2016-01-28 08:40:05 +00:00
|
|
|
|
2016-01-21 12:04:20 +00:00
|
|
|
// Add the result to the parent array.
|
2016-01-27 21:04:12 +00:00
|
|
|
$tblOTV[] = $result;
|
2016-01-21 12:04:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add each adjacency to the array.
|
2019-03-15 12:28:01 +00:00
|
|
|
if ($tblAdjacentDevName) {
|
2020-09-21 13:40:17 +00:00
|
|
|
foreach ((array) $tblAdjacentDevName as $key => $value) {
|
2019-03-15 12:28:01 +00:00
|
|
|
preg_match('/^1.3.6.1.4.1.9.9.810.1.3.1.1.4.(\d+).1.4.(\d+.\d+.\d+.\d+)$/', $key, $matches);
|
2020-09-21 13:40:17 +00:00
|
|
|
$result = [];
|
2019-03-15 12:28:01 +00:00
|
|
|
$result['index'] = $matches[1];
|
|
|
|
$result['endpoint'] = $matches[2];
|
|
|
|
$tblEndpoints[$value] = true;
|
|
|
|
$result['otvtype'] = 'adjacency';
|
2020-09-21 13:59:34 +00:00
|
|
|
$result['UID'] = $result['otvtype'] . '-' . $result['index'] . '-' . str_replace(' ', '', $tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.3.' . $result['index'] . '.1.4.' . $result['endpoint']]);
|
2020-09-21 13:40:17 +00:00
|
|
|
$result['uptime'] = $tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.6.' . $result['index'] . '.1.4.' . $result['endpoint']];
|
2019-03-15 12:28:01 +00:00
|
|
|
$message = false;
|
2020-09-21 13:40:17 +00:00
|
|
|
if ($tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.5.' . $result['index'] . '.1.4.' . $result['endpoint']] != 1) {
|
2019-03-15 12:28:01 +00:00
|
|
|
$message .= "Adjacency is Down\n";
|
|
|
|
}
|
2016-01-21 12:04:20 +00:00
|
|
|
|
2019-03-15 12:28:01 +00:00
|
|
|
// If we have set a message, we have an error, activate alert.
|
|
|
|
if ($message !== false) {
|
|
|
|
$result['error'] = $message;
|
|
|
|
$result['status'] = 1;
|
|
|
|
} else {
|
2020-09-21 13:59:34 +00:00
|
|
|
$result['error'] = '';
|
2019-03-15 12:28:01 +00:00
|
|
|
$result['status'] = 0;
|
|
|
|
}
|
2016-01-21 12:04:20 +00:00
|
|
|
|
2019-03-15 12:28:01 +00:00
|
|
|
// Set a default name, if for some unknown reason we cant find the parent VPN.
|
2020-09-21 13:59:34 +00:00
|
|
|
$result['label'] = 'Unknown (' . $result['index'] . ') - ' . $value;
|
2019-03-15 12:28:01 +00:00
|
|
|
// We need to search the existing array to build the name
|
|
|
|
foreach ($tblOTV as $item) {
|
|
|
|
if (($item['otvtype'] == 'overlay') && ($item['index'] == $result['index'])) {
|
2020-09-21 13:59:34 +00:00
|
|
|
$result['label'] = $item['label'] . ' - ' . $value;
|
2019-03-15 12:28:01 +00:00
|
|
|
}
|
2016-01-21 12:04:20 +00:00
|
|
|
}
|
|
|
|
|
2019-03-15 12:28:01 +00:00
|
|
|
// Let's log some debugging
|
2020-09-21 13:40:17 +00:00
|
|
|
d_echo("\n\nAdjacency: " . $result['label'] . "\n");
|
2020-09-21 13:59:34 +00:00
|
|
|
d_echo(' Endpoint: ' . $result['endpoint'] . "\n");
|
|
|
|
d_echo(' Index: ' . $result['index'] . "\n");
|
|
|
|
d_echo(' UID: ' . $result['UID'] . "\n");
|
|
|
|
d_echo(' Status: ' . $result['status'] . "\n");
|
|
|
|
d_echo(' Message: ' . $result['error'] . "\n");
|
2016-01-28 08:40:05 +00:00
|
|
|
|
2019-03-15 12:28:01 +00:00
|
|
|
// Add the result to the parent array.
|
|
|
|
$tblOTV[] = $result;
|
|
|
|
}
|
2016-01-21 12:04:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We retain a list of all endpoints to tie the RRD to.
|
2016-01-27 21:04:12 +00:00
|
|
|
foreach ($tblEndpoints as $k => $v) {
|
2020-09-21 13:59:34 +00:00
|
|
|
$result['label'] = 'Endpoint: ' . $k;
|
2016-01-27 21:04:12 +00:00
|
|
|
$result['otvtype'] = 'endpoint';
|
|
|
|
$result['endpoint'] = $k;
|
2020-09-21 13:59:34 +00:00
|
|
|
$result['UID'] = $result['otvtype'] . '-' . $k;
|
2016-01-21 12:04:20 +00:00
|
|
|
|
2016-01-28 08:40:05 +00:00
|
|
|
// Let's log some debugging
|
2020-09-21 13:40:17 +00:00
|
|
|
d_echo("\n\nEndpoint: " . $result['label'] . "\n");
|
2020-09-21 13:59:34 +00:00
|
|
|
d_echo(' UID: ' . $result['UID'] . "\n");
|
|
|
|
d_echo(' Type: ' . $result['otvtype'] . "\n");
|
2016-01-28 08:40:05 +00:00
|
|
|
|
2016-01-21 12:04:20 +00:00
|
|
|
// Add the result to the parent array.
|
2016-01-27 21:04:12 +00:00
|
|
|
$tblOTV[] = $result;
|
2016-01-21 12:04:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ok, we have our 2 array's (Components and SNMP) now we need
|
|
|
|
* to compare and see what needs to be added/updated.
|
|
|
|
*
|
|
|
|
* Let's loop over the SNMP data to see if we need to ADD or UPDATE any components.
|
|
|
|
*/
|
|
|
|
foreach ($tblOTV as $key => $array) {
|
2016-01-27 21:04:12 +00:00
|
|
|
$component_key = false;
|
2016-01-21 12:04:20 +00:00
|
|
|
|
|
|
|
// Loop over our components to determine if the component exists, or we need to add it.
|
2020-09-21 13:40:17 +00:00
|
|
|
foreach ((array) $components as $compid => $child) {
|
2016-01-27 21:04:12 +00:00
|
|
|
if ($child['UID'] === $array['UID']) {
|
|
|
|
$component_key = $compid;
|
2016-01-21 12:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-21 13:40:17 +00:00
|
|
|
if (! $component_key) {
|
2016-01-21 12:04:20 +00:00
|
|
|
// The component doesn't exist, we need to ADD it - ADD.
|
2016-08-28 17:32:58 +00:00
|
|
|
$new_component = $component->createComponent($device['device_id'], $module);
|
2016-01-27 21:04:12 +00:00
|
|
|
$component_key = key($new_component);
|
|
|
|
$components[$component_key] = array_merge($new_component[$component_key], $array);
|
2020-09-21 13:59:34 +00:00
|
|
|
echo '+';
|
2016-08-28 17:32:58 +00:00
|
|
|
} else {
|
2016-01-21 12:04:20 +00:00
|
|
|
// The component does exist, merge the details in - UPDATE.
|
2016-01-27 21:04:12 +00:00
|
|
|
$components[$component_key] = array_merge($components[$component_key], $array);
|
2020-09-21 13:59:34 +00:00
|
|
|
echo '.';
|
2016-01-21 12:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop over the Component data to see if we need to DELETE any components.
|
|
|
|
*/
|
2020-09-21 13:40:17 +00:00
|
|
|
foreach ((array) $components as $key => $array) {
|
2016-01-21 12:04:20 +00:00
|
|
|
// Guilty until proven innocent
|
2016-01-27 21:04:12 +00:00
|
|
|
$found = false;
|
2016-01-21 12:04:20 +00:00
|
|
|
|
|
|
|
foreach ($tblOTV as $k => $v) {
|
|
|
|
if ($array['UID'] == $v['UID']) {
|
|
|
|
// Yay, we found it...
|
2016-01-27 21:04:12 +00:00
|
|
|
$found = true;
|
2016-01-21 12:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-27 21:04:12 +00:00
|
|
|
if ($found === false) {
|
2016-01-21 12:04:20 +00:00
|
|
|
// The component has not been found. we should delete it.
|
2020-09-21 13:59:34 +00:00
|
|
|
echo '-';
|
2016-01-27 21:04:12 +00:00
|
|
|
$component->deleteComponent($key);
|
2016-01-21 12:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the Components back to the DB.
|
2016-08-28 17:32:58 +00:00
|
|
|
$component->setComponentPrefs($device['device_id'], $components);
|
2016-01-21 12:04:20 +00:00
|
|
|
echo "\n";
|
|
|
|
} // End if not error
|
|
|
|
}
|