diff --git a/doc/Extensions/Component.md b/doc/Extensions/Component.md index 40331981d3..5fcf3838ff 100644 --- a/doc/Extensions/Component.md +++ b/doc/Extensions/Component.md @@ -307,11 +307,11 @@ To see an example of how the component module can used, please see the following - Cisco CBQoS - includes/discovery/cisco-cbqos.inc.php - - includes/poller/cisco-cbqos.inc.php + - includes/polling/cisco-cbqos.inc.php - html/includes/graphs/device/cbqos_traffic.inc.php - Cisco OTV - includes/discovery/cisco-otv.inc.php - - includes/poller/applications/cisco-otv.inc.php + - includes/polling/cisco-otv.inc.php - html/includes/graphs/device/cisco-otv-mac.inc.php - - html/pages/device/apps/cisco-otv.inc.php + - html/pages/routing/cisco-otv.inc.php diff --git a/doc/Installation/Installation-(Debian-Ubuntu).md b/doc/Installation/Installation-(Debian-Ubuntu).md index e07ac9bd2c..dea55fb1fb 100644 --- a/doc/Installation/Installation-(Debian-Ubuntu).md +++ b/doc/Installation/Installation-(Debian-Ubuntu).md @@ -73,7 +73,7 @@ Adding the above line to `/etc/snmp/snmpd.conf` and running `service snmpd resta In `/etc/php5/apache2/php.ini` and `/etc/php5/cli/php.ini`, ensure date.timezone is set to your preferred time zone. See http://php.net/manual/en/timezones.php for a list of supported timezones. Valid examples are: "America/New York", "Australia/Brisbane", "Etc/UTC". -Please also ensure that allow_url_fopen is enabled. +Please also ensure that `allow_url_fopen` is enabled. Other functions needed for LibreNMS include `exec,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,popen`. ### Adding the librenms-user ### diff --git a/doc/Installation/Installation-(RHEL-CentOS).md b/doc/Installation/Installation-(RHEL-CentOS).md index 46100d0781..d60fe96af6 100644 --- a/doc/Installation/Installation-(RHEL-CentOS).md +++ b/doc/Installation/Installation-(RHEL-CentOS).md @@ -135,7 +135,8 @@ You need to configure snmpd appropriately if you have not already done so. An a Adding the above line to `/etc/snmp/snmpd.conf` and running `service snmpd restart` will activate this config. In `/etc/php.ini`, ensure date.timezone is set to your preferred time zone. See http://php.net/manual/en/timezones.php for a list of supported timezones. Valid -examples are: "America/New York", "Australia/Brisbane", "Etc/UTC". Please also ensure that allow_url_fopen is enabled. +examples are: "America/New York", "Australia/Brisbane", "Etc/UTC". +Please also ensure that `allow_url_fopen` is enabled. Other functions needed for LibreNMS include `exec,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,popen`. Next, add the following to `/etc/httpd/conf.d/librenms.conf` diff --git a/doc/Support/FAQ.md b/doc/Support/FAQ.md index 8f9147e88c..bdcfc73cae 100644 --- a/doc/Support/FAQ.md +++ b/doc/Support/FAQ.md @@ -73,6 +73,8 @@ If the page you are trying to load has a substantial amount of data in it then i This is usually due to there being blank spaces outside of the `` php tags within config.php. Remove these and retry. It's also worth removing the final `?>` at the end of config.php as this is not required. +Another reason why it might not be working is if you disabled functions needed by LibreNMS, which include `allow_url_fopen` +and `exec,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,popen`. #### How do I debug pages not loading correctly? diff --git a/html/ajax_setresolution.php b/html/ajax_setresolution.php index b72bd748ee..413832fb7d 100644 --- a/html/ajax_setresolution.php +++ b/html/ajax_setresolution.php @@ -4,5 +4,6 @@ if(isset($_REQUEST['width']) AND isset($_REQUEST['height'])) { $_SESSION['screen_width'] = $_REQUEST['width']; $_SESSION['screen_height'] = $_REQUEST['height']; } +header('Content-type: text/plain'); echo $_SESSION['screen_width']; echo $_SESSION['screen_height']; diff --git a/html/includes/graphs/device/cisco-otv-mac.inc.php b/html/includes/graphs/device/cisco-otv-mac.inc.php new file mode 100644 index 0000000000..691bfd10d8 --- /dev/null +++ b/html/includes/graphs/device/cisco-otv-mac.inc.php @@ -0,0 +1,62 @@ + + * + * 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. + */ + +require_once "../includes/component.php"; +$component = new component(); +$options['filter']['type'] = array('=','Cisco-OTV'); +$components = $component->getComponents($device['device_id'],$options); + +// We only care about our device id. +$components = $components[$device['device_id']]; + +include "includes/graphs/common.inc.php"; +$rrd_options .= " -l 0 -E "; +$rrd_options .= " COMMENT:'MAC Addresses Now Min Max\\n'"; +$rrd_additions = ""; + +$count = 0; +foreach ($components as $id => $array) { + if ($array['otvtype'] == 'endpoint') { + $rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename("cisco-otv-".$array['endpoint']."-mac.rrd"); + + if (file_exists($rrd_filename)) { + // Stack the area on the second and subsequent DS's + $stack = ""; + if ($count != 0) { + $stack = ":STACK "; + } + + // Grab a color from the array. + if ( isset($config['graph_colours']['mixed'][$count]) ) { + $color = $config['graph_colours']['mixed'][$count]; + } + else { + $color = $config['graph_colours']['oranges'][$count-7]; + } + + $rrd_additions .= " DEF:DS" . $count . "=" . $rrd_filename . ":count:AVERAGE "; + $rrd_additions .= " AREA:DS" . $count . "#" . $color . ":'" . str_pad(substr($components[$id]['endpoint'],0,15),15) . "'" . $stack; + $rrd_additions .= " GPRINT:DS" . $count . ":LAST:%4.0lf%s "; + $rrd_additions .= " GPRINT:DS" . $count . ":MIN:%4.0lf%s "; + $rrd_additions .= " GPRINT:DS" . $count . ":MAX:%4.0lf%s\\\l "; + $count++; + } + } +} + +if ($rrd_additions == "") { + // We didn't add any data points. +} +else { + $rrd_options .= $rrd_additions; +} diff --git a/html/includes/graphs/device/cisco-otv-vlan.inc.php b/html/includes/graphs/device/cisco-otv-vlan.inc.php new file mode 100644 index 0000000000..1116e056c6 --- /dev/null +++ b/html/includes/graphs/device/cisco-otv-vlan.inc.php @@ -0,0 +1,62 @@ + + * + * 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. + */ + +require_once "../includes/component.php"; +$component = new component(); +$options['filter']['type'] = array('=','Cisco-OTV'); +$components = $component->getComponents($device['device_id'],$options); + +// We only care about our device id. +$components = $components[$device['device_id']]; + +include "includes/graphs/common.inc.php"; +$rrd_options .= " -l 0 -E "; +$rrd_options .= " COMMENT:'VLANs Now Min Max\\n'"; +$rrd_additions = ""; + +$count = 0; +foreach ($components as $id => $array) { + if ($array['otvtype'] == 'overlay') { + $rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename("cisco-otv-".$array['label']."-vlan.rrd"); + + if (file_exists($rrd_filename)) { + // Stack the area on the second and subsequent DS's + $stack = ""; + if ($count != 0) { + $stack = ":STACK "; + } + + // Grab a color from the array. + if ( isset($config['graph_colours']['mixed'][$count]) ) { + $color = $config['graph_colours']['mixed'][$count]; + } + else { + $color = $config['graph_colours']['oranges'][$count-7]; + } + + $rrd_additions .= " DEF:DS" . $count . "=" . $rrd_filename . ":count:AVERAGE "; + $rrd_additions .= " AREA:DS" . $count . "#" . $color . ":'" . str_pad(substr($components[$id]['label'],0,15),15) . "'" . $stack; + $rrd_additions .= " GPRINT:DS" . $count . ":LAST:%4.0lf%s "; + $rrd_additions .= " GPRINT:DS" . $count . ":MIN:%4.0lf%s "; + $rrd_additions .= " GPRINT:DS" . $count . ":MAX:%4.0lf%s\\\l "; + $count++; + } + } +} + +if ($rrd_additions == "") { + // We didn't add any data points. +} +else { + $rrd_options .= $rrd_additions; +} diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 74ae6f7a14..4c22ad08ba 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -420,7 +420,13 @@ $routing_count['ospf'] = dbFetchCell("SELECT COUNT(ospf_instance_id) FROM `ospf_ $routing_count['cef'] = dbFetchCell("SELECT COUNT(cef_switching_id) from `cef_switching`"); $routing_count['vrf'] = dbFetchCell("SELECT COUNT(vrf_id) from `vrfs`"); -if ($_SESSION['userlevel'] >= '5' && ($routing_count['bgp']+$routing_count['ospf']+$routing_count['cef']+$routing_count['vrf']) > "0") { +require_once "../includes/component.php"; +$component = new component(); +$options['type'] = 'Cisco-OTV'; +$otv = $component->getComponents(null,$options); +$routing_count['cisco-otv'] = count($otv); + +if ($_SESSION['userlevel'] >= '5' && ($routing_count['bgp']+$routing_count['ospf']+$routing_count['cef']+$routing_count['vrf']+$routing_count['cisco-otv']) > "0") { ?> '); + $separator = 0; + } + echo('
  • Cisco OTV
  • '); + $separator++; + } + // BGP Sessions if ($_SESSION['userlevel'] >= '5' && $routing_count['bgp']) { if ($separator) { diff --git a/html/js/librenms.js b/html/js/librenms.js index b910907618..f103ea29b0 100644 --- a/html/js/librenms.js +++ b/html/js/librenms.js @@ -223,3 +223,24 @@ $(document).on("click", '.collapse-neighbors', function(event) list.toggle(); continued.toggle(); }); + + +$(document).ready(function() { + var lines = 'on'; + $("#linenumbers").button().click(function() { + if (lines == 'on') { + $($('.config').find('ol').get().reverse()).each(function(){ + $(this).replaceWith($('')) + lines = 'off'; + $('#linenumbers').val('Show line numbers'); + }); + } + else { + $($('.config').find('ul').get().reverse()).each(function(){ + $(this).replaceWith($('
      '+$(this).html()+'
    ')); + lines = 'on'; + $('#linenumbers').val('Hide line numbers'); + }); + } + }); +}); diff --git a/html/pages/device.inc.php b/html/pages/device.inc.php index 54fe3f0933..9517dd96cf 100644 --- a/html/pages/device.inc.php +++ b/html/pages/device.inc.php @@ -210,6 +210,16 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) { $routing_tabs[] = 'vrf'; } + require_once "../includes/component.php"; + $component = new component(); + $options['type'] = 'Cisco-OTV'; + $options['filter']['device_id'] = array('=',$device['device_id']); + $otv = $component->getComponents(null,$options); + $device_routing_count['cisco-otv'] = count($otv); + if ($device_routing_count['cisco-otv'] > 0) { + $routing_tabs[] = 'cisco-otv'; + } + if (is_array($routing_tabs)) { echo '
  • @@ -388,19 +398,25 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) { } - echo '
  • https
  • -
  • ssh
  • -
  • telnet
  • '; - - if (is_admin()) { - echo '
  • + echo ''; echo ''; + }//end if if (device_permitted($device['device_id']) || $check_device == $vars['device']) { diff --git a/html/pages/device/routing.inc.php b/html/pages/device/routing.inc.php index e4be546178..c58fe17a8d 100644 --- a/html/pages/device/routing.inc.php +++ b/html/pages/device/routing.inc.php @@ -20,6 +20,7 @@ $type_text['bgp'] = 'BGP'; $type_text['cef'] = 'CEF'; $type_text['ospf'] = 'OSPF'; $type_text['vrf'] = 'VRFs'; +$type_text['cisco-otv'] = 'OTV'; print_optionbar_start(); diff --git a/html/pages/device/routing/cisco-otv.inc.php b/html/pages/device/routing/cisco-otv.inc.php new file mode 100644 index 0000000000..602f67abd8 --- /dev/null +++ b/html/pages/device/routing/cisco-otv.inc.php @@ -0,0 +1,94 @@ +getComponents($device['device_id'],$options); +$components = $components[$device['device_id']]; + +global $config; +?> +
    +
    +

    Overlay's & Adjacencies

    +
    +
    + $overlay) { + if ($overlay['otvtype'] == 'overlay') { + if ($overlay['status'] == 1) { + $overlay_status = "Normal"; + $gli = ""; + } + else { + $overlay_status = "".$overlay['error']." - Alert"; + $gli = "list-group-item-danger"; + } +?> + - + + +
    +
    + +
    +
    +

    AED Enabled VLAN's

    +
    +
    + +
    +
    + +
    +
    +

    MAC Addresses

    +
    +
    + +
    +
    diff --git a/html/pages/device/showconfig.inc.php b/html/pages/device/showconfig.inc.php index 2efa9cfeed..dd8af7cc2e 100644 --- a/html/pages/device/showconfig.inc.php +++ b/html/pages/device/showconfig.inc.php @@ -241,7 +241,10 @@ if (is_admin()) { // $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); $geshi->set_overall_style('color: black;'); // $geshi->set_line_style('color: #999999'); + echo '
    '; + echo ''; echo $geshi->parse_code(); + echo '
    '; } }//end if diff --git a/html/pages/routing.inc.php b/html/pages/routing.inc.php index 0a7fcb3355..848c655e2b 100644 --- a/html/pages/routing.inc.php +++ b/html/pages/routing.inc.php @@ -16,6 +16,7 @@ $type_text['bgp'] = 'BGP'; $type_text['cef'] = 'CEF'; $type_text['ospf'] = 'OSPF'; $type_text['vrf'] = 'VRFs'; +$type_text['cisco-otv'] = 'OTV'; print_optionbar_start(); @@ -53,6 +54,7 @@ switch ($vars['protocol']) { case 'vrf': case 'cef': case 'ospf': + case 'cisco-otv': include 'pages/routing/'.$vars['protocol'].'.inc.php'; break; diff --git a/html/pages/routing/cisco-otv.inc.php b/html/pages/routing/cisco-otv.inc.php new file mode 100644 index 0000000000..00ca33bdd8 --- /dev/null +++ b/html/pages/routing/cisco-otv.inc.php @@ -0,0 +1,58 @@ +getComponents(null,$options); + +foreach ($COMPONENTS as $DEVICE_ID => $COMP) { + $LINK = generate_url(array('page' => 'device', 'device' => $DEVICE_ID, 'tab' => 'routing', 'proto' => 'cisco-otv')); +?> +
    + +
    + $OVERLAY) { + if ($OVERLAY['otvtype'] == 'overlay') { + if ($OVERLAY['status'] == 1) { + $OVERLAY_STATUS = "Normal"; + $GLI = ""; + } + else { + $OVERLAY_STATUS = "".$OVERLAY['error']." - Alert"; + $GLI = "list-group-item-danger"; + } + ?> + - + + +
    +
    + 'From name', 'type' => 'text', ), + array('name' => 'email_from', + 'descr' => 'From email address', + 'type' => 'text', + ), array('name' => 'email_sendmail_path', 'descr' => 'Sendmail path', 'type' => 'text', diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index bed0b577dc..744846cb86 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -712,6 +712,7 @@ $config['poller_modules']['mib'] = 0; $config['poller_modules']['cisco-voice'] = 1; $config['poller_modules']['cisco-cbqos'] = 1; $config['poller_modules']['stp'] = 1; +$config['poller_modules']['cisco-otv'] = 1; // List of discovery modules. Need to be in this array to be // considered for execution. @@ -745,6 +746,7 @@ $config['discovery_modules']['services'] = 1; $config['discovery_modules']['charge'] = 1; $config['discovery_modules']['cisco-cbqos'] = 0; $config['discovery_modules']['stp'] = 1; +$config['discovery_modules']['cisco-otv'] = 1; $config['modules_compat']['rfc1628']['liebert'] = 1; $config['modules_compat']['rfc1628']['netmanplus'] = 1; diff --git a/includes/discovery/cisco-otv.inc.php b/includes/discovery/cisco-otv.inc.php new file mode 100644 index 0000000000..864786577d --- /dev/null +++ b/includes/discovery/cisco-otv.inc.php @@ -0,0 +1,260 @@ + + * + * 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 + $error_vpn = array(); + $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"; + + $error_aed = array(); + $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"; + + $error_overlay = array(); + $error_overlay[1] = "active"; + $error_overlay[2] = "notInService"; + $error_overlay[3] = "notReady"; + $error_overlay[4] = "createAndGo"; + $error_overlay[5] = "createAndWait"; + $error_overlay[6] = "destroy"; + + $module = 'Cisco-OTV'; + echo $module.': '; + + require_once 'includes/component.php'; + $component = new component(); + $components = $component->getComponents($device['device_id'],array('type'=>$module)); + + // We only care about our device id. + $components = $components[$device['device_id']]; + + // Begin our master array, all other values will be processed into this array. + $tblOTV = array(); + $tblEndpoints = array(); + + // 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. + */ + if ( is_null($tblOverlayEntry) || is_null($tblAdjacencyDatabaseEntry) || is_null($tblAdjacentDevName) ) { + // We have to error here or we will end up deleting all our components. + echo "Error\n"; + } + else { + // No Error, lets process things. + + // Add each overlay to the array. + foreach ($tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.2'] as $index => $name) { + $result = array(); + $message = false; + $result['index'] = $index; + $result['label'] = $name; + if ($tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.15'][$index] == 1) { + $result['transport'] = 'Multicast'; + } + else { + $result['transport'] = 'Unicast'; + } + $result['otvtype'] = 'overlay'; + $result['UID'] = $result['otvtype']."-".$result['index']; + $result['vpn_state'] = $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.3'][$index]; + if ($result['vpn_state'] != 2) { + $message .= "VPN Down: ".$error_vpn[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.4'][$index]]."\n"; + } + $result['aed_state'] = $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.13'][$index]; + if ($result['aed_state'] == 2) { + $message .= "AED Down: ".$error_aed[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.14'][$index]]."\n"; + } + $result['overlay_state'] = $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.23'][$index]; + if ($result['overlay_state'] == 2) { + $message .= "Overlay Down: ".$error_overlay[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.24'][$index]]."\n"; + } + + // If we have set a message, we have an error, activate alert. + if ($message !== false) { + $result['error'] = $message; + $result['status'] = 0; + } + else { + $result['error'] = ""; + $result['status'] = 1; + } + + // Let's log some debugging + d_echo("\n\nOverlay: ".$result['label']."\n"); + 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"); + + // Add the result to the parent array. + $tblOTV[] = $result; + } + + // Add each adjacency to the array. + foreach ($tblAdjacentDevName as $key => $value) { + 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); + $result = array(); + $result['index'] = $matches[1]; + $result['endpoint'] = $matches[2]; + $tblEndpoints[$value] = true; + $result['otvtype'] = 'adjacency'; + $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']]); + $result['uptime'] = $tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.6.'.$result['index'].'.1.4.'.$result['endpoint']]; + $message = false; + if ($tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.5.'.$result['index'].'.1.4.'.$result['endpoint']] != 1) { + $message .= "Adjacency is Down\n"; + } + + // If we have set a message, we have an error, activate alert. + if ($message !== false) { + $result['error'] = $message; + $result['status'] = 0; + } + else { + $result['error'] = ""; + $result['status'] = 1; + } + + // Set a default name, if for some unknown reason we cant find the parent VPN. + $result['label'] = "Unknown (".$result['index'].") - ".$value; + // We need to search the existing array to build the name + foreach ($tblOTV as $item) { + if (($item['otvtype'] == 'overlay') && ($item['index'] == $result['index'])) { + $result['label'] = $item['label']." - ".$value; + } + } + + // Let's log some debugging + d_echo("\n\nAdjacency: ".$result['label']."\n"); + 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"); + + // Add the result to the parent array. + $tblOTV[] = $result; + } + + // We retain a list of all endpoints to tie the RRD to. + foreach ($tblEndpoints as $k => $v) { + $result['label'] = "Endpoint: ".$k; + $result['otvtype'] = 'endpoint'; + $result['endpoint'] = $k; + $result['UID'] = $result['otvtype']."-".$k; + + // Let's log some debugging + d_echo("\n\nEndpoint: ".$result['label']."\n"); + d_echo(" UID: ".$result['UID']."\n"); + d_echo(" Type: ".$result['otvtype']."\n"); + + // Add the result to the parent array. + $tblOTV[] = $result; + } + + /* + * 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) { + $component_key = false; + + // Loop over our components to determine if the component exists, or we need to add it. + foreach ($components as $compid => $child) { + if ($child['UID'] === $array['UID']) { + $component_key = $compid; + } + } + + if (!$component_key) { + // The component doesn't exist, we need to ADD it - ADD. + $new_component = $component->createComponent($device['device_id'],$module); + $component_key = key($new_component); + $components[$component_key] = array_merge($new_component[$component_key], $array); + echo "+"; + } + else { + // The component does exist, merge the details in - UPDATE. + $components[$component_key] = array_merge($components[$component_key], $array); + echo "."; + } + + } + + /* + * Loop over the Component data to see if we need to DELETE any components. + */ + foreach ($components as $key => $array) { + // Guilty until proven innocent + $found = false; + + foreach ($tblOTV as $k => $v) { + if ($array['UID'] == $v['UID']) { + // Yay, we found it... + $found = true; + } + } + + if ($found === false) { + // The component has not been found. we should delete it. + echo "-"; + $component->deleteComponent($key); + } + } + + // Write the Components back to the DB. + $component->setComponentPrefs($device['device_id'],$components); + echo "\n"; + + } // End if not error + +} diff --git a/includes/polling/bgp-peers.inc.php b/includes/polling/bgp-peers.inc.php index eb91eb935c..9b7c9b5e2a 100644 --- a/includes/polling/bgp-peers.inc.php +++ b/includes/polling/bgp-peers.inc.php @@ -1,310 +1,318 @@ 0) { - $peer2 = true; - } + $peers = dbFetchRows('SELECT * FROM bgpPeers WHERE device_id = ?', array($device['device_id'])); - if ($peer2 === true) { - if (strstr($peer['bgpPeerIdentifier'], ':')) { - $bgp_peer_ident = ipv62snmp($peer['bgpPeerIdentifier']); - } - else { - $bgp_peer_ident = $peer['bgpPeerIdentifier']; + if (!empty($peers)) { + + if ($device['os'] != 'junos') { + $peer_data_check = snmpwalk_cache_oid($device, 'cbgpPeer2RemoteAs', array(), 'CISCO-BGP4-MIB', $config['mibdir']); + } + + foreach ($peers as $peer) { + // Poll BGP Peer + $peer2 = false; + echo 'Checking BGP peer '.$peer['bgpPeerIdentifier'].' '; + + if (!empty($peer['bgpPeerIdentifier'])) { + if (!strstr($peer['bgpPeerIdentifier'], ':') || $device['os'] != 'junos') { + // v4 BGP4 MIB + if (count($peer_data_check) > 0) { + $peer2 = true; } - if (strstr($peer['bgpPeerIdentifier'], ':')) { - $ip_type = 2; - $ip_len = 16; - $ip_ver = 'ipv6'; - } - else { - $ip_type = 1; - $ip_len = 4; - $ip_ver = 'ipv4'; - } - - $peer_identifier = $ip_type.'.'.$ip_len.'.'.$bgp_peer_ident; - $peer_data_tmp = snmp_get_multi( - $device, - ' cbgpPeer2State.'.$peer_identifier.' cbgpPeer2AdminStatus.'.$peer_identifier.' cbgpPeer2InUpdates.'.$peer_identifier.' cbgpPeer2OutUpdates.'.$peer_identifier.' cbgpPeer2InTotalMessages.'.$peer_identifier.' cbgpPeer2OutTotalMessages.'.$peer_identifier.' cbgpPeer2FsmEstablishedTime.'.$peer_identifier.' cbgpPeer2InUpdateElapsedTime.'.$peer_identifier.' cbgpPeer2LocalAddr.'.$peer_identifier, - '-OQUs', - 'CISCO-BGP4-MIB', - $config['mibdir'] - ); - $ident = "$ip_ver.\"".$bgp_peer_ident.'"'; - unset($peer_data); - $ident_key = array_keys($peer_data_tmp); - foreach ($peer_data_tmp[$ident_key[0]] as $k => $v) { - if (strstr($k, 'cbgpPeer2LocalAddr')) { - if ($ip_ver == 'ipv6') { - $v = str_replace('"', '', $v); - $v = rtrim($v); - $v = preg_replace('/(\S+\s+\S+)\s/', '$1:', $v); - $v = strtolower($v); - } - else { - $v = hex_to_ip($v); - } + if ($peer2 === true) { + if (strstr($peer['bgpPeerIdentifier'], ':')) { + $bgp_peer_ident = ipv62snmp($peer['bgpPeerIdentifier']); + } + else { + $bgp_peer_ident = $peer['bgpPeerIdentifier']; } - $peer_data .= "$v\n"; - } - } - else { - $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m BGP4-MIB -OUvq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'].' '; - $peer_cmd .= 'bgpPeerState.'.$peer['bgpPeerIdentifier'].' bgpPeerAdminStatus.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerOutUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerInTotalMessages.'.$peer['bgpPeerIdentifier'].' '; - $peer_cmd .= 'bgpPeerOutTotalMessages.'.$peer['bgpPeerIdentifier'].' bgpPeerFsmEstablishedTime.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdateElapsedTime.'.$peer['bgpPeerIdentifier'].' '; - $peer_cmd .= 'bgpPeerLocalAddr.'.$peer['bgpPeerIdentifier'].''; - $peer_data = trim(`$peer_cmd`); - }//end if - list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); - $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); - } - else if ($device['os'] == 'junos') { - // v6 for JunOS via Juniper MIB - $peer_ip = ipv62snmp($peer['bgpPeerIdentifier']); + if (strstr($peer['bgpPeerIdentifier'], ':')) { + $ip_type = 2; + $ip_len = 16; + $ip_ver = 'ipv6'; + } + else { + $ip_type = 1; + $ip_len = 4; + $ip_ver = 'ipv4'; + } - if (!isset($junos_v6)) { - echo "\nCaching Oids..."; - // FIXME - needs moved to function - $peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; - $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6'; - foreach (explode("\n", trim(`$peer_cmd`)) as $oid) { - list($peer_oid) = explode(' ', $oid); - $peer_id = explode('.', $peer_oid); - $junos_v6[implode('.', array_slice($peer_id, 35))] = implode('.', array_slice($peer_id, 18)); - } - } - - // FIXME - move to function (and clean up, wtf?) - $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUvq '.snmp_gen_auth($device); - $peer_cmd .= ' -M"'.$config['install_dir'].'/mibs/junos"'; - $peer_cmd .= ' '.$device['hostname'].':'.$device['port']; - $peer_cmd .= ' jnxBgpM2PeerState.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6.'.$junos_v6[$peer_ip]; - // Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented? - $peer_cmd .= ' jnxBgpM2PeerInUpdates.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerOutUpdates.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerInTotalMessages.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerOutTotalMessages.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerFsmEstablishedTime.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerLocalAddr.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= '|grep -v "No Such Instance"'; - d_echo("\n$peer_cmd\n"); - - $peer_data = trim(`$peer_cmd`); - list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); - - d_echo("State = $bgpPeerState - AdminStatus: $bgpPeerAdminStatus\n"); - - $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); - if ($bgpLocalAddr == '00000000000000000000000000000000') { - $bgpLocalAddr = ''; - // Unknown? - } - else { - $bgpLocalAddr = strtolower($bgpLocalAddr); - for ($i = 0; $i < 32; $i += 4) { - $bgpLocalAddr6[] = substr($bgpLocalAddr, $i, 4); - } - - $bgpLocalAddr = Net_IPv6::compress(implode(':', $bgpLocalAddr6)); - unset($bgpLocalAddr6); - } - }//end if - }//end if - - if ($bgpPeerFsmEstablishedTime) { - if (!(is_array($config['alerts']['bgp']['whitelist']) && !in_array($peer['bgpPeerRemoteAs'], $config['alerts']['bgp']['whitelist'])) && ($bgpPeerFsmEstablishedTime < $peer['bgpPeerFsmEstablishedTime'] || $bgpPeerState != $peer['bgpPeerState'])) { - if ($peer['bgpPeerState'] == $bgpPeerState) { - log_event('BGP Session Flap: '.$peer['bgpPeerIdentifier'].' (AS'.$peer['bgpPeerRemoteAs'].')', $device, 'bgpPeer', $bgpPeer_id); - } - else if ($bgpPeerState == 'established') { - log_event('BGP Session Up: '.$peer['bgpPeerIdentifier'].' (AS'.$peer['bgpPeerRemoteAs'].')', $device, 'bgpPeer', $bgpPeer_id); - } - else if ($peer['bgpPeerState'] == 'established') { - log_event('BGP Session Down: '.$peer['bgpPeerIdentifier'].' (AS'.$peer['bgpPeerRemoteAs'].')', $device, 'bgpPeer', $bgpPeer_id); - } - } - } - - $peerrrd = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('bgp-'.$peer['bgpPeerIdentifier'].'.rrd'); - if (!is_file($peerrrd)) { - $create_rrd = 'DS:bgpPeerOutUpdates:COUNTER:600:U:100000000000 - DS:bgpPeerInUpdates:COUNTER:600:U:100000000000 - DS:bgpPeerOutTotal:COUNTER:600:U:100000000000 - DS:bgpPeerInTotal:COUNTER:600:U:100000000000 - DS:bgpPeerEstablished:GAUGE:600:0:U '.$config['rrd_rra']; - - rrdtool_create($peerrrd, $create_rrd); - } - - $fields = array( - 'bgpPeerOutUpdates' => $bgpPeerOutUpdates, - 'bgpPeerInUpdates' => $bgpPeerInUpdates, - 'bgpPeerOutTotal' => $bgpPeerOutTotalMessages, - 'bgpPeerInTotal' => $bgpPeerInTotalMessages, - 'bgpPeerEstablished' => $bgpPeerFsmEstablishedTime, - ); - rrdtool_update("$peerrrd", $fields); - - $tags = array('bgpPeerIdentifier' => $peer['bgpPeerIdentifier']); - influx_update($device,'bgp',$tags,$fields); - - $peer['update']['bgpPeerState'] = $bgpPeerState; - $peer['update']['bgpPeerAdminStatus'] = $bgpPeerAdminStatus; - $peer['update']['bgpPeerFsmEstablishedTime'] = $bgpPeerFsmEstablishedTime; - $peer['update']['bgpPeerInUpdates'] = $bgpPeerInUpdates; - $peer['update']['bgpLocalAddr'] = $bgpLocalAddr; - $peer['update']['bgpPeerOutUpdates'] = $bgpPeerOutUpdates; - - dbUpdate($peer['update'], 'bgpPeers', '`device_id` = ? AND `bgpPeerIdentifier` = ?', array($device['device_id'], $peer['bgpPeerIdentifier'])); - - if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') { - // Poll each AFI/SAFI for this peer (using CISCO-BGP4-MIB or BGP4-V2-JUNIPER MIB) - $peer_afis = dbFetchRows('SELECT * FROM bgpPeers_cbgp WHERE `device_id` = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['bgpPeerIdentifier'])); - foreach ($peer_afis as $peer_afi) { - $afi = $peer_afi['afi']; - $safi = $peer_afi['safi']; - d_echo("$afi $safi\n"); - - if ($device['os_group'] == 'cisco') { - $bgp_peer_ident = ipv62snmp($peer['bgpPeerIdentifier']); - if (strstr($peer['bgpPeerIdentifier'], ':')) { - $ip_type = 2; - $ip_len = 16; - $ip_ver = 'ipv6'; - } - else { - $ip_type = 1; - $ip_len = 4; - $ip_ver = 'ipv4'; - } - - $ip_cast = 1; - if ($peer_afi['safi'] == 'multicast') { - $ip_cast = 2; - } - else if ($peer_afi['safi'] == 'unicastAndMulticast') { - $ip_cast = 3; - } - else if ($peer_afi['safi'] == 'vpn') { - $ip_cast = 128; - } - - $check = snmp_get($device, 'cbgpPeer2AcceptedPrefixes.'.$ip_type.'.'.$ip_len.'.'.$bgp_peer_ident.'.'.$ip_type.'.'.$ip_cast, '', 'CISCO-BGP4-MIB', $config['mibdir']); - - if (!empty($check)) { - $cgp_peer_identifier = $ip_type.'.'.$ip_len.'.'.$bgp_peer_ident.'.'.$ip_type.'.'.$ip_cast; - $cbgp_data_tmp = snmp_get_multi( + $peer_identifier = $ip_type.'.'.$ip_len.'.'.$bgp_peer_ident; + $peer_data_tmp = snmp_get_multi( $device, - ' cbgpPeer2AcceptedPrefixes.'.$cgp_peer_identifier.' cbgpPeer2DeniedPrefixes.'.$cgp_peer_identifier.' cbgpPeer2PrefixAdminLimit.'.$cgp_peer_identifier.' cbgpPeer2PrefixThreshold.'.$cgp_peer_identifier.' cbgpPeer2PrefixClearThreshold.'.$cgp_peer_identifier.' cbgpPeer2AdvertisedPrefixes.'.$cgp_peer_identifier.' cbgpPeer2SuppressedPrefixes.'.$cgp_peer_identifier.' cbgpPeer2WithdrawnPrefixes.'.$cgp_peer_identifier, + ' cbgpPeer2State.'.$peer_identifier.' cbgpPeer2AdminStatus.'.$peer_identifier.' cbgpPeer2InUpdates.'.$peer_identifier.' cbgpPeer2OutUpdates.'.$peer_identifier.' cbgpPeer2InTotalMessages.'.$peer_identifier.' cbgpPeer2OutTotalMessages.'.$peer_identifier.' cbgpPeer2FsmEstablishedTime.'.$peer_identifier.' cbgpPeer2InUpdateElapsedTime.'.$peer_identifier.' cbgpPeer2LocalAddr.'.$peer_identifier, '-OQUs', 'CISCO-BGP4-MIB', $config['mibdir'] ); - $ident = "$ip_ver.\"".$peer['bgpPeerIdentifier'].'"'.'.'.$ip_type.'.'.$ip_cast; - unset($cbgp_data); - $temp_keys = array_keys($cbgp_data_tmp); - unset($temp_data); - $temp_data['cbgpPeer2AcceptedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2AcceptedPrefixes']; - $temp_data['cbgpPeer2DeniedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2DeniedPrefixes']; - $temp_data['cbgpPeer2PrefixAdminLimit'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2PrefixAdminLimit']; - $temp_data['cbgpPeer2PrefixThreshold'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2PrefixThreshold']; - $temp_data['cbgpPeer2PrefixClearThreshold'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2PrefixClearThreshold']; - $temp_data['cbgpPeer2AdvertisedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2AdvertisedPrefixes']; - $temp_data['cbgpPeer2SuppressedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2SuppressedPrefixes']; - $temp_data['cbgpPeer2WithdrawnPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2WithdrawnPrefixes']; - foreach ($temp_data as $k => $v) { - $cbgp_data .= "$v\n"; - } + $ident = "$ip_ver.\"".$bgp_peer_ident.'"'; + unset($peer_data); + $ident_key = array_keys($peer_data_tmp); + foreach ($peer_data_tmp[$ident_key[0]] as $k => $v) { + if (strstr($k, 'cbgpPeer2LocalAddr')) { + if ($ip_ver == 'ipv6') { + $v = str_replace('"', '', $v); + $v = rtrim($v); + $v = preg_replace('/(\S+\s+\S+)\s/', '$1:', $v); + $v = strtolower($v); + } + else { + $v = hex_to_ip($v); + } + } - d_echo("$cbgp_data\n"); + $peer_data .= "$v\n"; + } } else { - // FIXME - move to function - $cbgp_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m CISCO-BGP4-MIB -Ovq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; - $cbgp_cmd .= ' cbgpPeerAcceptedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerDeniedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixAdminLimit.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixClearThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerAdvertisedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerSuppressedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerWithdrawnPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - - d_echo("$cbgp_cmd\n"); - - $cbgp_data = preg_replace('/^OID.*$/', '', trim(`$cbgp_cmd`)); - $cbgp_data = preg_replace('/No Such Instance currently exists at this OID/', '0', $cbgp_data); - d_echo("$cbgp_data\n"); + $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m BGP4-MIB -OUvq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'].' '; + $peer_cmd .= 'bgpPeerState.'.$peer['bgpPeerIdentifier'].' bgpPeerAdminStatus.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerOutUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerInTotalMessages.'.$peer['bgpPeerIdentifier'].' '; + $peer_cmd .= 'bgpPeerOutTotalMessages.'.$peer['bgpPeerIdentifier'].' bgpPeerFsmEstablishedTime.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdateElapsedTime.'.$peer['bgpPeerIdentifier'].' '; + $peer_cmd .= 'bgpPeerLocalAddr.'.$peer['bgpPeerIdentifier'].''; + $peer_data = trim(`$peer_cmd`); }//end if - list($cbgpPeerAcceptedPrefixes,$cbgpPeerDeniedPrefixes,$cbgpPeerPrefixAdminLimit,$cbgpPeerPrefixThreshold,$cbgpPeerPrefixClearThreshold,$cbgpPeerAdvertisedPrefixes,$cbgpPeerSuppressedPrefixes,$cbgpPeerWithdrawnPrefixes) = explode("\n", $cbgp_data); + list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); + $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); + } + else if ($device['os'] == 'junos') { + // v6 for JunOS via Juniper MIB + $peer_ip = ipv62snmp($peer['bgpPeerIdentifier']); + + if (!isset($junos_v6)) { + echo "\nCaching Oids..."; + // FIXME - needs moved to function + $peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; + $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6'; + foreach (explode("\n", trim(`$peer_cmd`)) as $oid) { + list($peer_oid) = explode(' ', $oid); + $peer_id = explode('.', $peer_oid); + $junos_v6[implode('.', array_slice($peer_id, 35))] = implode('.', array_slice($peer_id, 18)); + } + } + + // FIXME - move to function (and clean up, wtf?) + $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUvq '.snmp_gen_auth($device); + $peer_cmd .= ' -M"'.$config['install_dir'].'/mibs/junos"'; + $peer_cmd .= ' '.$device['hostname'].':'.$device['port']; + $peer_cmd .= ' jnxBgpM2PeerState.0.ipv6.'.$junos_v6[$peer_ip]; + $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6.'.$junos_v6[$peer_ip]; + // Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented? + $peer_cmd .= ' jnxBgpM2PeerInUpdates.0.ipv6.'.$junos_v6[$peer_ip]; + $peer_cmd .= ' jnxBgpM2PeerOutUpdates.0.ipv6.'.$junos_v6[$peer_ip]; + $peer_cmd .= ' jnxBgpM2PeerInTotalMessages.0.ipv6.'.$junos_v6[$peer_ip]; + $peer_cmd .= ' jnxBgpM2PeerOutTotalMessages.0.ipv6.'.$junos_v6[$peer_ip]; + $peer_cmd .= ' jnxBgpM2PeerFsmEstablishedTime.0.ipv6.'.$junos_v6[$peer_ip]; + $peer_cmd .= ' jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6.'.$junos_v6[$peer_ip]; + $peer_cmd .= ' jnxBgpM2PeerLocalAddr.0.ipv6.'.$junos_v6[$peer_ip]; + $peer_cmd .= '|grep -v "No Such Instance"'; + d_echo("\n$peer_cmd\n"); + + $peer_data = trim(`$peer_cmd`); + list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); + + d_echo("State = $bgpPeerState - AdminStatus: $bgpPeerAdminStatus\n"); + + $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); + if ($bgpLocalAddr == '00000000000000000000000000000000') { + $bgpLocalAddr = ''; + // Unknown? + } + else { + $bgpLocalAddr = strtolower($bgpLocalAddr); + for ($i = 0; $i < 32; $i += 4) { + $bgpLocalAddr6[] = substr($bgpLocalAddr, $i, 4); + } + + $bgpLocalAddr = Net_IPv6::compress(implode(':', $bgpLocalAddr6)); + unset($bgpLocalAddr6); + } }//end if + }//end if - // FIXME THESE FIELDS DO NOT EXIST IN THE DATABASE! - $update = 'UPDATE bgpPeers_cbgp SET'; - $peer['c_update']['AcceptedPrefixes'] = $cbgpPeerAcceptedPrefixes; - $peer['c_update']['DeniedPrefixes'] = $cbgpPeerDeniedPrefixes; - $peer['c_update']['PrefixAdminLimit'] = $cbgpPeerAdminLimit; - $peer['c_update']['PrefixThreshold'] = $cbgpPeerPrefixThreshold; - $peer['c_update']['PrefixClearThreshold'] = $cbgpPeerPrefixClearThreshold; - $peer['c_update']['AdvertisedPrefixes'] = $cbgpPeerAdvertisedPrefixes; - $peer['c_update']['SuppressedPrefixes'] = $cbgpPeerSuppressedPrefixes; - $peer['c_update']['WithdrawnPrefixes'] = $cbgpPeerWithdrawnPrefixes; - - - $oids = array( - 'AcceptedPrefixes', - 'DeniedPrefixes', - 'AdvertisedPrefixes', - 'SuppressedPrefixes', - 'WithdrawnPrefixes', - ); - - foreach ($oids as $oid) { - $peer['c_update'][$oid.'_delta'] = $peer['c_update'][$oid] - $peer_afi[$oid]; - $peer['c_update'][$oid.'_prev'] = $peer_afi[$oid]; + if ($bgpPeerFsmEstablishedTime) { + if (!(is_array($config['alerts']['bgp']['whitelist']) && !in_array($peer['bgpPeerRemoteAs'], $config['alerts']['bgp']['whitelist'])) && ($bgpPeerFsmEstablishedTime < $peer['bgpPeerFsmEstablishedTime'] || $bgpPeerState != $peer['bgpPeerState'])) { + if ($peer['bgpPeerState'] == $bgpPeerState) { + log_event('BGP Session Flap: '.$peer['bgpPeerIdentifier'].' (AS'.$peer['bgpPeerRemoteAs'].')', $device, 'bgpPeer', $bgpPeer_id); + } + else if ($bgpPeerState == 'established') { + log_event('BGP Session Up: '.$peer['bgpPeerIdentifier'].' (AS'.$peer['bgpPeerRemoteAs'].')', $device, 'bgpPeer', $bgpPeer_id); + } + else if ($peer['bgpPeerState'] == 'established') { + log_event('BGP Session Down: '.$peer['bgpPeerIdentifier'].' (AS'.$peer['bgpPeerRemoteAs'].')', $device, 'bgpPeer', $bgpPeer_id); + } } + } - dbUpdate($peer['c_update'], 'bgpPeers_cbgp', '`device_id` = ? AND bgpPeerIdentifier = ? AND afi = ? AND safi = ?', array($device['device_id'], $peer['bgpPeerIdentifier'], $afi, $safi)); + $peerrrd = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('bgp-'.$peer['bgpPeerIdentifier'].'.rrd'); + if (!is_file($peerrrd)) { + $create_rrd = 'DS:bgpPeerOutUpdates:COUNTER:600:U:100000000000 + DS:bgpPeerInUpdates:COUNTER:600:U:100000000000 + DS:bgpPeerOutTotal:COUNTER:600:U:100000000000 + DS:bgpPeerInTotal:COUNTER:600:U:100000000000 + DS:bgpPeerEstablished:GAUGE:600:0:U '.$config['rrd_rra']; - $cbgp_rrd = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('cbgp-'.$peer['bgpPeerIdentifier'].".$afi.$safi.rrd"); - if (!is_file($cbgp_rrd)) { - $rrd_create = 'DS:AcceptedPrefixes:GAUGE:600:U:100000000000 - DS:DeniedPrefixes:GAUGE:600:U:100000000000 - DS:AdvertisedPrefixes:GAUGE:600:U:100000000000 - DS:SuppressedPrefixes:GAUGE:600:U:100000000000 - DS:WithdrawnPrefixes:GAUGE:600:U:100000000000 '.$config['rrd_rra']; - rrdtool_create($cbgp_rrd, $rrd_create); - } + rrdtool_create($peerrrd, $create_rrd); + } - $fields = array( - 'AcceptedPrefixes' => $cbgpPeerAcceptedPrefixes, - 'DeniedPrefixes' => $cbgpPeerDeniedPrefixes, - 'AdvertisedPrefixes' => $cbgpPeerAdvertisedPrefixes, - 'SuppressedPrefixes' => $cbgpPeerSuppressedPrefixes, - 'WithdrawnPrefixes' => $cbgpPeerWithdrawnPrefixes, - ); - rrdtool_update("$cbgp_rrd", $fields); + $fields = array( + 'bgpPeerOutUpdates' => $bgpPeerOutUpdates, + 'bgpPeerInUpdates' => $bgpPeerInUpdates, + 'bgpPeerOutTotal' => $bgpPeerOutTotalMessages, + 'bgpPeerInTotal' => $bgpPeerInTotalMessages, + 'bgpPeerEstablished' => $bgpPeerFsmEstablishedTime, + ); + rrdtool_update("$peerrrd", $fields); - $tags = array('bgpPeerIdentifier' => $peer['bgpPeerIdentifier'], 'afi' => $afi, 'safi' => $safi); - influx_update($device,'cbgp',$tags,$fields); + $tags = array('bgpPeerIdentifier' => $peer['bgpPeerIdentifier']); + influx_update($device,'bgp',$tags,$fields); - } //end foreach - } //end if - echo "\n"; - } //end foreach + $peer['update']['bgpPeerState'] = $bgpPeerState; + $peer['update']['bgpPeerAdminStatus'] = $bgpPeerAdminStatus; + $peer['update']['bgpPeerFsmEstablishedTime'] = $bgpPeerFsmEstablishedTime; + $peer['update']['bgpPeerInUpdates'] = $bgpPeerInUpdates; + $peer['update']['bgpLocalAddr'] = $bgpLocalAddr; + $peer['update']['bgpPeerOutUpdates'] = $bgpPeerOutUpdates; + + dbUpdate($peer['update'], 'bgpPeers', '`device_id` = ? AND `bgpPeerIdentifier` = ?', array($device['device_id'], $peer['bgpPeerIdentifier'])); + + if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') { + // Poll each AFI/SAFI for this peer (using CISCO-BGP4-MIB or BGP4-V2-JUNIPER MIB) + $peer_afis = dbFetchRows('SELECT * FROM bgpPeers_cbgp WHERE `device_id` = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['bgpPeerIdentifier'])); + foreach ($peer_afis as $peer_afi) { + $afi = $peer_afi['afi']; + $safi = $peer_afi['safi']; + d_echo("$afi $safi\n"); + + if ($device['os_group'] == 'cisco') { + $bgp_peer_ident = ipv62snmp($peer['bgpPeerIdentifier']); + if (strstr($peer['bgpPeerIdentifier'], ':')) { + $ip_type = 2; + $ip_len = 16; + $ip_ver = 'ipv6'; + } + else { + $ip_type = 1; + $ip_len = 4; + $ip_ver = 'ipv4'; + } + + $ip_cast = 1; + if ($peer_afi['safi'] == 'multicast') { + $ip_cast = 2; + } + else if ($peer_afi['safi'] == 'unicastAndMulticast') { + $ip_cast = 3; + } + else if ($peer_afi['safi'] == 'vpn') { + $ip_cast = 128; + } + + $check = snmp_get($device, 'cbgpPeer2AcceptedPrefixes.'.$ip_type.'.'.$ip_len.'.'.$bgp_peer_ident.'.'.$ip_type.'.'.$ip_cast, '', 'CISCO-BGP4-MIB', $config['mibdir']); + + if (!empty($check)) { + $cgp_peer_identifier = $ip_type.'.'.$ip_len.'.'.$bgp_peer_ident.'.'.$ip_type.'.'.$ip_cast; + $cbgp_data_tmp = snmp_get_multi( + $device, + ' cbgpPeer2AcceptedPrefixes.'.$cgp_peer_identifier.' cbgpPeer2DeniedPrefixes.'.$cgp_peer_identifier.' cbgpPeer2PrefixAdminLimit.'.$cgp_peer_identifier.' cbgpPeer2PrefixThreshold.'.$cgp_peer_identifier.' cbgpPeer2PrefixClearThreshold.'.$cgp_peer_identifier.' cbgpPeer2AdvertisedPrefixes.'.$cgp_peer_identifier.' cbgpPeer2SuppressedPrefixes.'.$cgp_peer_identifier.' cbgpPeer2WithdrawnPrefixes.'.$cgp_peer_identifier, + '-OQUs', + 'CISCO-BGP4-MIB', + $config['mibdir'] + ); + $ident = "$ip_ver.\"".$peer['bgpPeerIdentifier'].'"'.'.'.$ip_type.'.'.$ip_cast; + unset($cbgp_data); + $temp_keys = array_keys($cbgp_data_tmp); + unset($temp_data); + $temp_data['cbgpPeer2AcceptedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2AcceptedPrefixes']; + $temp_data['cbgpPeer2DeniedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2DeniedPrefixes']; + $temp_data['cbgpPeer2PrefixAdminLimit'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2PrefixAdminLimit']; + $temp_data['cbgpPeer2PrefixThreshold'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2PrefixThreshold']; + $temp_data['cbgpPeer2PrefixClearThreshold'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2PrefixClearThreshold']; + $temp_data['cbgpPeer2AdvertisedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2AdvertisedPrefixes']; + $temp_data['cbgpPeer2SuppressedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2SuppressedPrefixes']; + $temp_data['cbgpPeer2WithdrawnPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2WithdrawnPrefixes']; + foreach ($temp_data as $k => $v) { + $cbgp_data .= "$v\n"; + } + + d_echo("$cbgp_data\n"); + } + else { + // FIXME - move to function + $cbgp_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m CISCO-BGP4-MIB -Ovq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; + $cbgp_cmd .= ' cbgpPeerAcceptedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; + $cbgp_cmd .= ' cbgpPeerDeniedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; + $cbgp_cmd .= ' cbgpPeerPrefixAdminLimit.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; + $cbgp_cmd .= ' cbgpPeerPrefixThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; + $cbgp_cmd .= ' cbgpPeerPrefixClearThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; + $cbgp_cmd .= ' cbgpPeerAdvertisedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; + $cbgp_cmd .= ' cbgpPeerSuppressedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; + $cbgp_cmd .= ' cbgpPeerWithdrawnPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; + + d_echo("$cbgp_cmd\n"); + + $cbgp_data = preg_replace('/^OID.*$/', '', trim(`$cbgp_cmd`)); + $cbgp_data = preg_replace('/No Such Instance currently exists at this OID/', '0', $cbgp_data); + d_echo("$cbgp_data\n"); + }//end if + list($cbgpPeerAcceptedPrefixes,$cbgpPeerDeniedPrefixes,$cbgpPeerPrefixAdminLimit,$cbgpPeerPrefixThreshold,$cbgpPeerPrefixClearThreshold,$cbgpPeerAdvertisedPrefixes,$cbgpPeerSuppressedPrefixes,$cbgpPeerWithdrawnPrefixes) = explode("\n", $cbgp_data); + }//end if + + // FIXME THESE FIELDS DO NOT EXIST IN THE DATABASE! + $update = 'UPDATE bgpPeers_cbgp SET'; + $peer['c_update']['AcceptedPrefixes'] = $cbgpPeerAcceptedPrefixes; + $peer['c_update']['DeniedPrefixes'] = $cbgpPeerDeniedPrefixes; + $peer['c_update']['PrefixAdminLimit'] = $cbgpPeerAdminLimit; + $peer['c_update']['PrefixThreshold'] = $cbgpPeerPrefixThreshold; + $peer['c_update']['PrefixClearThreshold'] = $cbgpPeerPrefixClearThreshold; + $peer['c_update']['AdvertisedPrefixes'] = $cbgpPeerAdvertisedPrefixes; + $peer['c_update']['SuppressedPrefixes'] = $cbgpPeerSuppressedPrefixes; + $peer['c_update']['WithdrawnPrefixes'] = $cbgpPeerWithdrawnPrefixes; + + + $oids = array( + 'AcceptedPrefixes', + 'DeniedPrefixes', + 'AdvertisedPrefixes', + 'SuppressedPrefixes', + 'WithdrawnPrefixes', + ); + + foreach ($oids as $oid) { + $peer['c_update'][$oid.'_delta'] = $peer['c_update'][$oid] - $peer_afi[$oid]; + $peer['c_update'][$oid.'_prev'] = $peer_afi[$oid]; + } + + dbUpdate($peer['c_update'], 'bgpPeers_cbgp', '`device_id` = ? AND bgpPeerIdentifier = ? AND afi = ? AND safi = ?', array($device['device_id'], $peer['bgpPeerIdentifier'], $afi, $safi)); + + $cbgp_rrd = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('cbgp-'.$peer['bgpPeerIdentifier'].".$afi.$safi.rrd"); + if (!is_file($cbgp_rrd)) { + $rrd_create = 'DS:AcceptedPrefixes:GAUGE:600:U:100000000000 + DS:DeniedPrefixes:GAUGE:600:U:100000000000 + DS:AdvertisedPrefixes:GAUGE:600:U:100000000000 + DS:SuppressedPrefixes:GAUGE:600:U:100000000000 + DS:WithdrawnPrefixes:GAUGE:600:U:100000000000 '.$config['rrd_rra']; + rrdtool_create($cbgp_rrd, $rrd_create); + } + + $fields = array( + 'AcceptedPrefixes' => $cbgpPeerAcceptedPrefixes, + 'DeniedPrefixes' => $cbgpPeerDeniedPrefixes, + 'AdvertisedPrefixes' => $cbgpPeerAdvertisedPrefixes, + 'SuppressedPrefixes' => $cbgpPeerSuppressedPrefixes, + 'WithdrawnPrefixes' => $cbgpPeerWithdrawnPrefixes, + ); + rrdtool_update("$cbgp_rrd", $fields); + + $tags = array('bgpPeerIdentifier' => $peer['bgpPeerIdentifier'], 'afi' => $afi, 'safi' => $safi); + influx_update($device,'cbgp',$tags,$fields); + + } //end foreach + } //end if + echo "\n"; + } //end foreach + } //end if } //end if diff --git a/includes/polling/cisco-otv.inc.php b/includes/polling/cisco-otv.inc.php new file mode 100644 index 0000000000..1c1fa4aa14 --- /dev/null +++ b/includes/polling/cisco-otv.inc.php @@ -0,0 +1,206 @@ + + * + * 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 + $error_vpn = array(); + $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"; + + $error_aed = array(); + $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"; + + $error_overlay = array(); + $error_overlay[1] = "active"; + $error_overlay[2] = "notInService"; + $error_overlay[3] = "notReady"; + $error_overlay[4] = "createAndGo"; + $error_overlay[5] = "createAndWait"; + $error_overlay[6] = "destroy"; + + $module = 'Cisco-OTV'; + + require_once 'includes/component.php'; + $component = new component(); + $options['filter']['type'] = array('=',$module); + $options['filter']['disabled'] = array('=',0); + $components = $component->getComponents($device['device_id'],$options); + + // We only care about our device id. + $components = $components[$device['device_id']]; + + // Only collect SNMP data if we have enabled components + if (count($components > 0)) { + // Let's gather the stats.. + $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); + $tblRouteNextHopAddr = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.810.1.5.1.1.8', 0); + $tblVlanEdgeDevIsAed = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.810.1.2.2.1.6', 2); + + // Let's create an array of each remote OTV endpoint and the count of MAC addresses that are reachable via. + $count_mac = array(); + foreach ($tblRouteNextHopAddr as $k => $v) { + $count_mac[$v]++; + } + // Let's log some debugging + d_echo("\n\nMAC Addresses: ".print_r($count_mac,TRUE)); + + // Loop through the components and extract the data. + foreach ($components as $key => &$array) { + + if ($array['otvtype'] == 'overlay') { + // Let's check the various status' of the overlay + $message = false; + $vpn_state = $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.3'][$array['index']]; + if ($vpn_state != 2) { + $message .= "VPN Down: ".$error_vpn[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.4'][$array['index']]]; + } + $aed_state = $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.13'][$array['index']]; + if ($aed_state == 2) { + $message .= "AED Down: ".$error_aed[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.14'][$array['index']]]; + } + $overlay_state = $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.23'][$array['index']]; + if ($overlay_state == 2) { + $message .= "Overlay Down: ".$error_overlay[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.24'][$array['index']]]; + } + + // If we have set a message, we have an error, activate alert. + if ($message !== false) { + $array['error'] = $message; + $array['status'] = 0; + } + else { + $array['error'] = ""; + $array['status'] = 1; + } + + // Time to graph the count of the active VLAN's on this overlay. + $count_vlan = 0; + foreach ($tblVlanEdgeDevIsAed['1.3.6.1.4.1.9.9.810.1.2.2.1.6'][$array['index']] as $v) { + if ($v == 1) { + $count_vlan++; + } + } + + // Let's log some debugging + d_echo("\n\nOverlay Component: ".$key."\n"); + d_echo(" Label: ".$array['label']."\n"); + d_echo(" Index: ".$array['index']."\n"); + d_echo(" Status: ".$array['status']."\n"); + d_echo(" Message: ".$array['error']."\n"); + d_echo(" VLAN Count: ".$count_vlan."\n"); + + $filename = "cisco-otv-".$array['label']."-vlan.rrd"; + $rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename ($filename); + + if (!file_exists ($rrd_filename)) { + rrdtool_create ($rrd_filename, " DS:count:GAUGE:600:0:U" . $config['rrd_rra']); + } + $rrd['count'] = $count_vlan; + + // Update RRD + rrdtool_update ($rrd_filename, $rrd); + + } + elseif ($array['otvtype'] == 'adjacency') { + $array['uptime'] = $tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.6.'.$array['index'].'.1.4.'.$array['endpoint']]; + $message = false; + if ($tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.5.'.$array['index'].'.1.4.'.$array['endpoint']] != 1) { + $message .= "Adjacency is Down\n"; + } + if ($tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.6.'.$array['index'].'.1.4.'.$array['endpoint']] < $array['uptime']) { + $message .= "Adjacency has been reset\n"; + } + + // If we have set a message, we have an error, activate alert. + if ($message !== false) { + $array['error'] = $message; + $array['status'] = 0; + } + else { + $array['error'] = ""; + $array['status'] = 1; + } + + // Let's log some debugging + d_echo("\n\nAdjacency Component: ".$key."\n"); + d_echo(" Label: ".$array['label']."\n"); + d_echo(" Index: ".$array['index']."\n"); + d_echo(" Status: ".$array['status']."\n"); + d_echo(" Message: ".$array['error']."\n"); + } + elseif ($array['otvtype'] == 'endpoint') { + if (isset($count_mac[$array['endpoint']])) { + $rrd['count'] = $count_mac[$array['endpoint']]; + } + else { + $rrd['count'] = "0"; + } + + // Let's log some debugging + d_echo("\n\nEndpoint Component: ".$key."\n"); + d_echo(" Label: ".$array['label']."\n"); + d_echo(" MAC Count: ".$rrd['count']."\n"); + + $filename = "cisco-otv-".$array['endpoint']."-mac.rrd"; + $rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename ($filename); + + if (!file_exists ($rrd_filename)) { + rrdtool_create ($rrd_filename, " DS:count:GAUGE:600:0:U" . $config['rrd_rra']); + } + + // Update RRD + rrdtool_update ($rrd_filename, $rrd); + + } // End If + + } // End foreach components + + // Write the Components back to the DB. + $component->setComponentPrefs($device['device_id'],$components); + + echo $module." "; + } // end if count components + + // Clean-up after yourself! + unset($components, $component, $module); +} \ No newline at end of file diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index fdd9aa3d73..69ad9b0278 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -203,7 +203,6 @@ function poll_device($device, $options) { $poll_separator = ', '; dbUpdate(array('status' => $status, 'status_reason' => $response['status_reason']), 'devices', 'device_id=?', array($device['device_id'])); - dbInsert(array('importance' => '0', 'device_id' => $device['device_id'], 'message' => 'Device is '.($status == '1' ? 'up' : 'down')), 'alerts'); log_event('Device status changed to '.($status == '1' ? 'Up' : 'Down'), $device, ($status == '1' ? 'up' : 'down')); } diff --git a/includes/polling/os/windows.inc.php b/includes/polling/os/windows.inc.php index c31e1741ef..637aff1a2c 100644 --- a/includes/polling/os/windows.inc.php +++ b/includes/polling/os/windows.inc.php @@ -28,7 +28,7 @@ if (strstr($poll_device['sysDescr'], 'Intel64')) { $hardware = 'Intel x64'; } -if ($poll_device['sysObjectID'] == '.1.3.6.1.4.1.311.1.1.3.1.1') { +if ($poll_device['sysObjectID'] == 'enterprises.311.1.1.3.1.1') { if (strstr($poll_device['sysDescr'], 'Build Number: 1057')) { $version = 'NT 3.51 Workstation'; } @@ -81,6 +81,10 @@ if ($poll_device['sysObjectID'] == '.1.3.6.1.4.1.311.1.1.3.1.1') { $version = '8.1 SP1 (NT 6.2)'; } + if (strstr($poll_device['sysDescr'], 'Version 6.3 (Build 10')) { + $version = '10 (NT 6.3)'; + } + } else if ($poll_device['sysObjectID'] == '.1.3.6.1.4.1.311.1.1.3.1.2') { if (strstr($poll_device['sysDescr'], 'Build Number: 1057')) { diff --git a/validate.php b/validate.php index f2fe619e32..f16178d3b0 100755 --- a/validate.php +++ b/validate.php @@ -79,7 +79,6 @@ echo "MySQL: ".$versions['mysql_ver']."\n"; echo "RRDTool: ".$versions['rrdtool_ver']."\n"; echo "SNMP: ".$versions['netsnmp_ver']."\n"; - // Check php modules we use to make sure they are loaded $extensions = array('pcre','curl','session','snmp','mcrypt'); foreach ($extensions as $extension) { @@ -161,6 +160,10 @@ if (!$config['rrdcached']) { } } +if (isset($config['rrdcached'])) { + check_rrdcached(); +} + // Disk space and permission checks if (substr(sprintf('%o', fileperms($config['temp_dir'])), -3) != 777) { print_warn('Your tmp directory ('.$config['temp_dir'].") is not set to 777 so graphs most likely won't be generated"); @@ -176,13 +179,25 @@ if ($space_check < 1) { } // Check programs -$bins = array('fping'); +$bins = array('fping','rrdtool','snmpwalk','snmpget','snmpbulkwalk'); foreach ($bins as $bin) { if (!is_file($config[$bin])) { print_fail("$bin location is incorrect or bin not installed"); } - else { - print_ok("$bin has been found"); +} + +$disabled_functions = explode(',', ini_get('disable_functions')); +$required_functions = array('exec','passthru','shell_exec','escapeshellarg','escapeshellcmd','proc_close','proc_open','popen'); +foreach ($required_functions as $function) { + if (in_array($function, $disabled_functions)) { + print_fail("$function is disabled in php.ini"); + } +} + +if (!function_exists('openssl_random_pseudo_bytes')) { + print_warn("openssl_random_pseudo_bytes is not being used for user password hashing. This is a recommended function (https://secure.php.net/openssl_random_pseudo_bytes)"); + if (!is_readable('/dev/urandom')) { + print_warn("It also looks like we can't use /dev/urandom for user password hashing. We will fall back to generating our own hash - be warned"); } } @@ -257,15 +272,7 @@ foreach ($modules as $module) { print_fail('You have not configured $config[\'rrd_dir\']'); } else { - list($host,$port) = explode(':',$config['rrdcached']); - $connection = @fsockopen($host, $port); - if (is_resource($connection)) { - fclose($connection); - print_ok('Connection to rrdcached is ok'); - } - else { - print_fail('Cannot connect to rrdcached instance'); - } + check_rrdcached(); } } break; @@ -317,17 +324,34 @@ foreach ($modules as $module) { function print_ok($msg) { echo "[OK] $msg\n"; - }//end print_ok() function print_fail($msg) { echo "[FAIL] $msg\n"; - }//end print_fail() function print_warn($msg) { echo "[WARN] $msg\n"; - }//end print_warn() + +function check_rrdcached() { + global $config; + list($host,$port) = explode(':',$config['rrdcached']); + if ($host == 'unix') { + // Using socket, check that file exists + if (!file_exists($port)) { + print_fail("$port doesn't appear to exist, rrdcached test failed"); + } + } + else { + $connection = @fsockopen($host, $port); + if (is_resource($connection)) { + fclose($connection); + } + else { + print_fail('Cannot connect to rrdcached instance'); + } + } +}//end check_rrdcached