initial commit; version 22.5.12042

This commit is contained in:
2022-12-12 23:28:25 -05:00
commit af1b03d79f
17653 changed files with 22692970 additions and 0 deletions

View File

@ -0,0 +1,163 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$mib = "CISCO-IETF-PW-MIB";
echo("$mib ");
$pws = snmpwalk_cache_oid($device, "cpwVcID", array(), $mib, mib_dirs('cisco'));
if ($GLOBALS['snmp_status'] === FALSE)
{
return;
}
$pws = snmpwalk_cache_oid($device, "cpwVcRowStatus", $pws, $mib);
$pws = snmpwalk_cache_oid($device, "cpwVcName", $pws, $mib);
$pws = snmpwalk_cache_oid($device, "cpwVcType", $pws, $mib);
$pws = snmpwalk_cache_oid($device, "cpwVcDescr", $pws, $mib);
$pws = snmpwalk_cache_oid($device, "cpwVcPsnType", $pws, $mib);
$pws = snmpwalk_cache_oid($device, "cpwVcPeerAddrType", $pws, $mib);
$pws = snmpwalk_cache_oid($device, "cpwVcPeerAddr", $pws, $mib, NULL, OBS_SNMP_ALL_HEX);
$pws = snmpwalk_cache_oid($device, "cpwVcOutboundVcLabel", $pws, $mib);
$pws = snmpwalk_cache_oid($device, "cpwVcInboundVcLabel", $pws, $mib);
$pws = snmpwalk_cache_oid($device, "cpwVcRemoteIfString", $pws, $mib);
// For MPLS pseudowires
$pws = snmpwalk_cache_oid($device, "cpwVcMplsLocalLdpID", $pws, "CISCO-IETF-PW-MPLS-MIB");
$pws = snmpwalk_cache_oid($device, "cpwVcMplsPeerLdpID", $pws, "CISCO-IETF-PW-MPLS-MIB");
//echo("PWS_WALK: ".count($pws)."\n"); var_dump($pws);
$peer_where = generate_query_values($device['device_id'], 'device_id', '!='); // Additional filter for exclude self IPs
foreach ($pws as $pw_id => $pw)
{
$peer_addr = hex2ip($pw['cpwVcPeerAddr']);
$peer_addr_type = $pw['cpwVcPeerAddrType'];
if (!get_ip_version($peer_addr) && $pw['cpwVcMplsPeerLdpID'])
{
// Sometime return wrong peer addr (not hex string):
// cpwVcPeerAddr.8 = "\\<h&"
$peer_addr = preg_replace('/:\d+$/', '', $pw['cpwVcMplsPeerLdpID']);
}
$peer_addr_version = get_ip_version($peer_addr);
if ($peer_addr_version)
{
$peer_addr_type = 'ipv' . $peer_addr_version; // Override address type, because snmp sometime return incorrect
$peer_rdns = gethostbyaddr6($peer_addr); // PTR name
// Fetch all devices with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('device', $peer_addr, $peer_where))
{
$remote_device = $ids[0];
if (count($ids) > 1)
{
// If multiple same IPs found, get first NOT disabled or down
foreach ($ids as $id)
{
$tmp_device = device_by_id_cache($id);
if (!$tmp_device['disabled'] && $tmp_device['status'])
{
$remote_device = $id;
break;
}
}
}
}
} else {
$peer_addr = ''; // Unset peer address
print_debug("Not found correct peer address. See snmpwalk for 'cpwVcPeerAddr' and 'cpwVcMplsPeerLdpID'.");
}
if (empty($remote_device)) { $remote_device = array('NULL'); }
$if_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `ifDescr` = ? AND `device_id` = ? LIMIT 1;', array($pw['cpwVcName'], $device['device_id']));
if (!is_numeric($if_id) && strpos($pw['cpwVcName'], '_'))
{
// IOS-XR some time use '_' instead '/'. http://jira.observium.org/browse/OBSERVIUM-246
// cpwVcName.3221225526 = TenGigE0_3_0_6.438
// ifDescr.84 = TenGigE0/3/0/6.438
$if_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `ifDescr` = ? AND `device_id` = ? LIMIT 1;', array(str_replace('_', '/', $pw['cpwVcName']), $device['device_id']));
}
if (!is_numeric($if_id) && strpos($pw['cpwVcMplsLocalLdpID'], ':'))
{
// Last (know) way for detect local port by MPLS LocalLdpID,
// because IOS-XR some time use Remote IP instead ifDescr in cpwVcName
// cpwVcName.3221225473 = STRING: 82.209.169.153,3055
// cpwVcMplsLocalLdpID.3221225473 = STRING: 82.209.169.129:0
list($local_addr) = explode(':', $pw['cpwVcMplsLocalLdpID']);
$local_where = generate_query_values($device['device_id'], 'device_id'); // Filter by self IPs
if ($ids = get_entity_ids_ip_by_network('port', $local_addr, $local_where))
{
$if_id = $ids[0];
}
}
// Note, Cisco experimental 'cpwVc' oid prefix converted to 'pw' prefix as in rfc PW-STD-MIB
$pws_new = array(
'device_id' => $device['device_id'],
'mib' => $mib,
'port_id' => $if_id,
'peer_device_id' => $remote_device,
'peer_addr' => $peer_addr,
'peer_rdns' => $peer_rdns,
'pwIndex' => $pw_id,
'pwType' => $pw['cpwVcType'],
'pwID' => $pw['cpwVcID'],
'pwOutboundLabel' => $pw['cpwVcOutboundVcLabel'],
'pwInboundLabel' => $pw['cpwVcInboundVcLabel'],
//'pwMplsPeerLdpID' => $pw['cpwVcMplsPeerLdpID'],
'pwPsnType' => $pw['cpwVcPsnType'],
//'pwLocalIfMtu' => $pw['cpwVcLocalIfMtu'],
//'pwRemoteIfMtu' => $pw['cpwVcRemoteIfMtu'],
'pwDescr' => $pw['cpwVcDescr'],
'pwRemoteIfString' => $pw['cpwVcRemoteIfString'],
'pwRowStatus' => $pw['cpwVcRowStatus'],
);
if (!empty($pws_cache['pws_db'][$mib][$pw_id]))
{
$pws_old = $pws_cache['pws_db'][$mib][$pw_id];
$pseudowire_id = $pws_old['pseudowire_id'];
if (empty($pws_old['peer_device_id']))
{
$pws_old['peer_device_id'] = array('NULL');
}
$update_array = array();
//var_dump(array_keys($pws_new));
foreach (array_keys($pws_new) as $column)
{
if ($pws_new[$column] != $pws_old[$column])
{
$update_array[$column] = $pws_new[$column];
}
}
if (count($update_array) > 0)
{
dbUpdate($update_array, 'pseudowires', '`pseudowire_id` = ?', array($pseudowire_id));
$GLOBALS['module_stats'][$module]['updated']++; //echo("U");
} else {
$GLOBALS['module_stats'][$module]['unchanged']++; //echo(".");
}
} else {
$pseudowire_id = dbInsert($pws_new, 'pseudowires');
$GLOBALS['module_stats'][$module]['added']++; //echo("+");
}
$valid['pseudowires'][$mib][$pseudowire_id] = $pseudowire_id;
}
// Clean
unset($pws, $pw, $update_array, $remote_device);
// EOF

View File

@ -0,0 +1,157 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$flags = OBS_SNMP_ALL ^ OBS_QUOTES_STRIP;
$pws = snmpwalk_cache_threepart_oid($device, "jnxVpnPwRowStatus", array(), 'JUNIPER-VPN-MIB', NULL, $flags);
if ($GLOBALS['snmp_status'] === FALSE)
{
return;
}
$pws = snmpwalk_cache_threepart_oid($device, 'jnxVpnPwAssociatedInterface', $pws, 'JUNIPER-VPN-MIB', NULL, $flags);
$pws = snmpwalk_cache_threepart_oid($device, 'jnxVpnPwLocalSiteId', $pws, 'JUNIPER-VPN-MIB', NULL, $flags); // pwID
$pws = snmpwalk_cache_threepart_oid($device, 'jnxVpnPwTunnelName', $pws, 'JUNIPER-VPN-MIB', NULL, $flags); // pwDescr
$pws = snmpwalk_cache_threepart_oid($device, 'jnxVpnPwTunnelType', $pws, 'JUNIPER-VPN-MIB', NULL, $flags); // pwPsnType
$pws = snmpwalk_cache_threepart_oid($device, 'jnxVpnRemotePeIdAddrType', $pws, 'JUNIPER-VPN-MIB', NULL, $flags); // pwPeerAddrType
$pws = snmpwalk_cache_threepart_oid($device, 'jnxVpnRemotePeIdAddress', $pws, 'JUNIPER-VPN-MIB', NULL, OBS_SNMP_ALL_HEX ^ OBS_QUOTES_STRIP); // pwPeerAddr
//$pws = snmpwalk_cache_oid($device, 'pwLocalIfMtu', $pws, 'JUNIPER-VPN-MIB');
//$pws = snmpwalk_cache_oid($device, 'pwRemoteIfMtu', $pws, 'JUNIPER-VPN-MIB');
$pws = snmpwalk_cache_threepart_oid($device, 'jnxVpnPwRemoteSiteId', $pws, 'JUNIPER-VPN-MIB', NULL, $flags); // pwMplsPeerLdpID
if (OBS_DEBUG > 1)
{
echo('PWS_WALK: '.count($pws)."\n"); print_vars($pws);
}
$peer_where = generate_query_values($device['device_id'], 'device_id', '!='); // Additional filter for exclude self IPs
foreach ($pws as $pw_type => $entry)
{
foreach ($entry as $pw_name => $entry2)
{
foreach ($entry2 as $pw_ifIndex => $pw)
{
//if (strlen($pw['jnxVpnPwRowStatus']) && $pw['jnxVpnPwRowStatus'] != 'active') { continue; } // Skip inactive (active, notinService, notReady, createAndGo, createAndWait, destroy)
// Get full index
$pw_index = snmp_translate('jnxVpnPwRowStatus.'.$pw_type.'."'.$pw_name.'".'.$pw_ifIndex, 'JUNIPER-VPN-MIB');
$pw_index = str_replace('.1.3.6.1.4.1.2636.3.26.1.4.1.4.', '', $pw_index);
$peer_addr = hex2ip($pw['jnxVpnRemotePeIdAddress']);
$peer_addr_version = get_ip_version($peer_addr);
$peer_addr_type = $pw['jnxVpnRemotePeIdAddrType'];
if ($peer_addr_version)
{
$peer_addr_type = 'ipv' . $peer_addr_version; // Override address type, because snmp sometime return incorrect
$peer_rdns = gethostbyaddr6($peer_addr); // PTR name
// Fetch all devices with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('device', $peer_addr, $peer_where))
{
$remote_device = $ids[0];
if (count($ids) > 1)
{
// If multiple same IPs found, get first NOT disabled or down
foreach ($ids as $id)
{
$tmp_device = device_by_id_cache($id);
if (!$tmp_device['disabled'] && $tmp_device['status'])
{
$remote_device = $id;
break;
}
}
}
}
} else {
$peer_rdns = '';
$peer_addr = ''; // Unset peer address
print_debug("Not found correct peer address. See snmpwalk for 'jnxVpnRemotePeIdAddress'.");
}
if (empty($remote_device)) { $remote_device = array('NULL'); }
if (!is_numeric($pw['jnxVpnPwAssociatedInterface']) || $pw['jnxVpnPwAssociatedInterface'] <= 0)
{
$pw['jnxVpnPwAssociatedInterface'] = $pw_ifIndex;
}
$port = get_port_by_index_cache($device, $pw['jnxVpnPwAssociatedInterface']);
if (is_numeric($port['port_id']))
{
$if_id = $port['port_id'];
} else {
$if_id = get_port_id_by_ifDescr($device['device_id'], $pw_name);
}
$pws_new = array(
'device_id' => $device['device_id'],
'mib' => 'JUNIPER-VPN-MIB',
'port_id' => $if_id,
'peer_device_id' => $remote_device,
'peer_addr' => $peer_addr,
'peer_rdns' => $peer_rdns,
'pwIndex' => $pw_index,
'pwType' => $pw_type,
'pwID' => $pw['jnxVpnPwLocalSiteId'],
'pwOutboundLabel' => $pw['jnxVpnPwLocalSiteId'],
'pwInboundLabel' => $pw['jnxVpnPwRemoteSiteId'],
'pwPsnType' => ($pw['jnxVpnPwTunnelType'] ? $pw['jnxVpnPwTunnelType'] : 'unknown'),
//'pwLocalIfMtu' => $pw['pwLocalIfMtu'],
//'pwRemoteIfMtu' => $pw['pwRemoteIfMtu'],
'pwDescr' => ($pw['jnxVpnPwTunnelName'] ? $pw['jnxVpnPwTunnelName'] : $pw_name),
//'pwRemoteIfString' => '',
'pwRowStatus' => $pw['jnxVpnPwRowStatus'],
);
if (OBS_DEBUG > 1) { print_vars($pws_new); }
if (!empty($pws_cache['pws_db']['JUNIPER-VPN-MIB'][$pw_index]))
{
$pws_old = $pws_cache['pws_db']['JUNIPER-VPN-MIB'][$pw_index];
$pseudowire_id = $pws_old['pseudowire_id'];
if (empty($pws_old['peer_device_id']))
{
$pws_old['peer_device_id'] = array('NULL');
}
$update_array = array();
//var_dump(array_keys($pws_new));
foreach (array_keys($pws_new) as $column)
{
if ($pws_new[$column] != $pws_old[$column])
{
$update_array[$column] = $pws_new[$column];
}
}
if (count($update_array) > 0)
{
dbUpdate($update_array, 'pseudowires', '`pseudowire_id` = ?', array($pseudowire_id));
$GLOBALS['module_stats'][$module]['updated']++; //echo("U");
} else {
$GLOBALS['module_stats'][$module]['unchanged']++; //echo(".");
}
} else {
$pseudowire_id = dbInsert($pws_new, 'pseudowires');
$GLOBALS['module_stats'][$module]['added']++; //echo("+");
}
$valid['pseudowires']['JUNIPER-VPN-MIB'][$pseudowire_id] = $pseudowire_id;
}
}
}
// Clean
unset($pws, $pw, $update_array, $remote_device, $flags);
// EOF

View File

@ -0,0 +1,167 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
*
*/
$pws = snmpwalk_cache_oid($device, "pwID", array(), 'PW-STD-MIB');
if ($GLOBALS['snmp_status'] === FALSE)
{
return;
}
$pws = snmpwalk_cache_oid($device, "pwRowStatus", $pws, 'PW-STD-MIB');
$pws = snmpwalk_cache_oid($device, "pwName", $pws, 'PW-STD-MIB');
$pws = snmpwalk_cache_oid($device, "pwType", $pws, 'PW-STD-MIB');
$pws = snmpwalk_cache_oid($device, "pwDescr", $pws, 'PW-STD-MIB');
$pws = snmpwalk_cache_oid($device, "pwPsnType", $pws, 'PW-STD-MIB');
$pws = snmpwalk_cache_oid($device, "pwPeerAddrType", $pws, 'PW-STD-MIB');
$pws = snmpwalk_cache_oid($device, "pwPeerAddr", $pws, 'PW-STD-MIB', NULL, OBS_SNMP_ALL_HEX);
$pws = snmpwalk_cache_oid($device, "pwOutboundLabel", $pws, 'PW-STD-MIB');
$pws = snmpwalk_cache_oid($device, "pwInboundLabel", $pws, 'PW-STD-MIB');
$pws = snmpwalk_cache_oid($device, "pwRemoteIfString", $pws, 'PW-STD-MIB');
// For MPLS pseudowires
$pws = snmpwalk_cache_oid($device, "pwMplsLocalLdpID", $pws, "PW-MPLS-STD-MIB");
$pws = snmpwalk_cache_oid($device, "pwMplsPeerLdpID", $pws, "PW-MPLS-STD-MIB");
//echo("PWS_WALK: ".count($pws)."\n"); var_dump($pws);
$peer_where = generate_query_values($device['device_id'], 'device_id', '!='); // Additional filter for exclude self IPs
foreach ($pws as $pw_id => $pw)
{
$peer_addr_type = $pw['pwPeerAddrType'];
if ($peer_addr_type == "ipv4" || $peer_addr_type == "ipv6")
{
$peer_addr = hex2ip($pw['pwPeerAddr']);
}
if (!get_ip_version($peer_addr) && $pw['pwMplsPeerLdpID'])
{
// Sometime return wrong peer addr (not hex string):
// pwPeerAddr.8 = "\\<h&"
$peer_addr = preg_replace('/:\d+$/', '', $pw['pwMplsPeerLdpID']);
}
if (get_ip_version($peer_addr))
{
$peer_rdns = gethostbyaddr6($peer_addr); // PTR name
// Fetch all devices with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('device', $peer_addr, $peer_where))
{
$remote_device = $ids[0];
if (count($ids) > 1)
{
// If multiple same IPs found, get first NOT disabled or down
foreach ($ids as $id)
{
$tmp_device = device_by_id_cache($id);
if (!$tmp_device['disabled'] && $tmp_device['status'])
{
$remote_device = $id;
break;
}
}
}
}
} else {
$peer_addr = ''; // Unset peer address
print_debug("Not found correct peer address. See snmpwalk for 'pwPeerAddr' and 'pwMplsPeerLdpID'.");
}
if (empty($remote_device)) { $remote_device = array('NULL'); }
// Clean some entries on Extreme devices, ie:
// pwName.10001 = V_AKN_POP001....................
// pwDescr.10001 = ................................
// pwRemoteIfString.10001 = ................................
$pw['pwName'] = rtrim($pw['pwName'], ". \t\n\r\0\x0B");
$pw['pwDescr'] = rtrim($pw['pwDescr'], ". \t\n\r\0\x0B");
$pw['pwRemoteIfString'] = rtrim($pw['pwRemoteIfString'], ". \t\n\r\0\x0B");
$if_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `ifDescr` = ? AND `device_id` = ? LIMIT 1;', array($pw['pwName'], $device['device_id']));
if (!is_numeric($if_id) && strpos($pw['pwName'], '_'))
{
// IOS-XR some time use '_' instead '/'. http://jira.observium.org/browse/OBSERVIUM-246
// pwName.3221225526 = TenGigE0_3_0_6.438
// ifDescr.84 = TenGigE0/3/0/6.438
$if_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `ifDescr` = ? AND `device_id` = ? LIMIT 1;', array(str_replace('_', '/', $pw['pwName']), $device['device_id']));
}
if (!is_numeric($if_id) && strpos($pw['pwMplsLocalLdpID'], ':'))
{
// Last (know) way for detect local port by MPLS LocalLdpID,
// because IOS-XR some time use Remote IP instead ifDescr in pwName
// pwName.3221225473 = STRING: 82.209.169.153,3055
// pwMplsLocalLdpID.3221225473 = STRING: 82.209.169.129:0
list($local_addr) = explode(':', $pw['pwMplsLocalLdpID']);
$local_where = generate_query_values($device['device_id'], 'device_id'); // Filter by self IPs
if ($ids = get_entity_ids_ip_by_network('port', $local_addr, $local_where))
{
$if_id = $ids[0];
}
}
$pws_new = array(
'device_id' => $device['device_id'],
'mib' => 'PW-STD-MIB',
'port_id' => $if_id,
'peer_device_id' => $remote_device,
'peer_addr' => $peer_addr,
'peer_rdns' => $peer_rdns,
'pwIndex' => $pw_id,
'pwType' => $pw['pwType'],
'pwID' => $pw['pwID'],
'pwOutboundLabel' => $pw['pwOutboundLabel'],
'pwInboundLabel' => $pw['pwInboundLabel'],
//'pwMplsPeerLdpID' => $pw['pwMplsPeerLdpID'],
'pwPsnType' => $pw['pwPsnType'],
//'pwLocalIfMtu' => $pw['pwLocalIfMtu'],
//'pwRemoteIfMtu' => $pw['pwRemoteIfMtu'],
'pwDescr' => $pw['pwDescr'],
'pwRemoteIfString' => $pw['pwRemoteIfString'],
'pwRowStatus' => $pw['pwRowStatus'],
);
if (!empty($pws_cache['pws_db']['PW-STD-MIB'][$pw_id]))
{
$pws_old = $pws_cache['pws_db']['PW-STD-MIB'][$pw_id];
$pseudowire_id = $pws_old['pseudowire_id'];
if (empty($pws_old['peer_device_id']))
{
$pws_old['peer_device_id'] = array('NULL');
}
$update_array = array();
//var_dump(array_keys($pws_new));
foreach (array_keys($pws_new) as $column)
{
if ($pws_new[$column] != $pws_old[$column])
{
$update_array[$column] = $pws_new[$column];
}
}
if (count($update_array) > 0)
{
dbUpdate($update_array, 'pseudowires', '`pseudowire_id` = ?', array($pseudowire_id));
$GLOBALS['module_stats'][$module]['updated']++; //echo("U");
} else {
$GLOBALS['module_stats'][$module]['unchanged']++; //echo(".");
}
} else {
$pseudowire_id = dbInsert($pws_new, 'pseudowires');
$GLOBALS['module_stats'][$module]['added']++; //echo("+");
}
$valid['pseudowires']['PW-STD-MIB'][$pseudowire_id] = $pseudowire_id;
}
// Clean
unset($pws, $pw, $update_array, $remote_device);
// EOF