mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-27 00:25:06 +02:00
more fixes and updates from sid3windr
git-svn-id: http://www.observium.org/svn/observer/trunk@579 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
### Discover BGP peers on Cisco devices
|
||||
### Discover BGP peers on Cisco and Juniper devices
|
||||
|
||||
echo("BGP Sessions : ");
|
||||
|
||||
@@ -34,10 +34,11 @@
|
||||
echo("+");
|
||||
} else {
|
||||
$update = mysql_query("UPDATE `bgpPeers` SET astext = '$astext' WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '$peer_ip'");
|
||||
echo(".");
|
||||
}
|
||||
|
||||
## Get afi/safi and populate cbgp on cisco ios (xe/xr)
|
||||
if($device['os_type'] == "ios") {
|
||||
if($device['os'] == "ios") {
|
||||
unset($af_list);
|
||||
$af_cmd = $config['snmpwalk'] . " -CI -m CISCO-BGP4-MIB -OsQ -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port'] . " ";
|
||||
$af_cmd .= "cbgpPeerAddrFamilyName." . $peer_ip;
|
||||
@@ -61,7 +62,39 @@
|
||||
mysql_query("DELETE FROM `bgpPeers_cbgp` WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '$peer_ip' AND afi = '$afi' AND safi = '$safi'");
|
||||
}
|
||||
} # AF list
|
||||
} # if os_type = ios
|
||||
} # if os = ios
|
||||
} # If Peer
|
||||
} # Foreach
|
||||
|
||||
if ($device['os'] == "junos")
|
||||
## Juniper BGP4-V2 MIB, ipv6 only for now, because v4 should be covered in BGP4-MIB above
|
||||
$peers_cmd = $config['snmpwalk'] . " -m BGP4-V2-MIB-JUNIPER -CI -Onq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port'] . " ";
|
||||
$peers_cmd .= "jnxBgpM2PeerRemoteAs.0.ipv6"; # FIXME: is .0 the only possible value here?
|
||||
$peers = trim(str_replace(".1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.0.","", `$peers_cmd`));
|
||||
foreach (explode("\n", $peers) as $peer) {
|
||||
list($peer_ip_snmp, $peer_as) = split(" ", $peer);
|
||||
$peer_ip_ex = explode('.',$peer_ip_snmp);
|
||||
$peer_ip_ex = array_slice($peer_ip_ex,count($peer_ip_ex)-16);
|
||||
for ($i = 0;$i <= 15;$i++) { $peer_ip_ex[$i] = dechex($peer_ip_ex[$i]); if (strlen($peer_ip_ex[$i]) < 2) $peer_ip_ex[$i] = '0' . $peer_ip_ex[$i]; }
|
||||
for ($i = 0;$i <= 15;$i+=2) { $peer_ip_ex2[] = $peer_ip_ex[$i] . $peer_ip_ex[$i+1]; }
|
||||
$peer_ip = implode(':',$peer_ip_ex2); unset($peer_ip_ex2);
|
||||
$peer_ip = Net_IPv6::compress($peer_ip);
|
||||
|
||||
if($peer) {
|
||||
|
||||
$peerlist[] = $device['device_id'] ." $peer_ip";
|
||||
|
||||
$astext = trim(str_replace("\"", "", shell_exec("/usr/bin/dig +short AS$peer_as.asn.cymru.com TXT | cut -d '|' -f 5 | sed s/\\\"//g")));
|
||||
|
||||
#echo("$peer_ip AS$peer_as ");
|
||||
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `bgpPeers` WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '$peer_ip'"),0) < '1') {
|
||||
$add = mysql_query("INSERT INTO bgpPeers (`device_id`, `bgpPeerIdentifier`, `bgpPeerRemoteAS`) VALUES ('".$device['device_id']."','$peer_ip','$peer_as')");
|
||||
echo("+");
|
||||
} else {
|
||||
$update = mysql_query("UPDATE `bgpPeers` SET astext = '$astext' WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '$peer_ip'");
|
||||
echo(".");
|
||||
}
|
||||
|
||||
} # If Peer
|
||||
} # Foreach
|
||||
} else {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
echo("CISCO-PROCESS-MIB : ");
|
||||
|
||||
## Cisco Processors
|
||||
if($device['os_type'] == "ios") {
|
||||
if($device['os'] == "ios") {
|
||||
$oids = shell_exec($config['snmpwalk'] . " -m CISCO-PROCESS-MIB -".$device['snmpver']." -CI -Osqn -c ".$community." ".$hostname.":".$port." .1.3.6.1.4.1.9.9.109.1.1.1.1.2 | sed s/.1.3.6.1.4.1.9.9.109.1.1.1.1.2.//g");
|
||||
$oids = trim($oids);
|
||||
foreach(explode("\n", $oids) as $data) {
|
||||
|
||||
@@ -119,7 +119,7 @@
|
||||
} ## End Supermicro Temperatures
|
||||
|
||||
## Cisco Temperatures
|
||||
if($device['os_type'] == "ios") {
|
||||
if($device['os'] == "ios") {
|
||||
echo("Cisco ");
|
||||
$oids = shell_exec($config['snmpwalk'] . " -m CISCO-ENVMON-MIB -$snmpver -CI -Osqn -c $community $hostname:$port .1.3.6.1.4.1.9.9.13.1.3.1.2 | sed s/.1.3.6.1.4.1.9.9.13.1.3.1.2.//g");
|
||||
$oids = trim($oids);
|
||||
|
||||
@@ -12,12 +12,65 @@ while($peer = mysql_fetch_array($peers)) {
|
||||
|
||||
echo("Checking ".$peer['bgpPeerIdentifier']." ");
|
||||
|
||||
if (!strstr($peer['bgpPeerIdentifier'],':'))
|
||||
{
|
||||
# v4 BGP4 MIB
|
||||
$peer_cmd = $config['snmpget'] . " -m BGP4-MIB -Ovq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $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`);
|
||||
list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data);
|
||||
}
|
||||
else
|
||||
if ($device['os'] == "junos")
|
||||
{
|
||||
# v6 for JunOS via Juniper MIB
|
||||
$peer_ip_ex = explode(':',Net_IPv6::uncompress($peer['bgpPeerIdentifier']));
|
||||
for ($i = 0;$i < 8;$i++) { while (strlen($peer_ip_ex[$i]) < 4) $peer_ip_ex[$i] = "0" . $peer_ip_ex[$i]; } # Pad zeroes back
|
||||
$peer_ip = implode('',$peer_ip_ex);
|
||||
for ($i = 0;$i < 16;$i+=2) $peer_ip_split[] = hexdec(substr($peer_ip,$i,2));
|
||||
$peer_ip = implode($peer_ip_split,'.'); unset($peer_ip_split); # Now in JunOS SNMP format
|
||||
|
||||
if (!isset($junos_v6))
|
||||
{
|
||||
echo "\nCaching Oids...";
|
||||
$peer_cmd = $config['snmpwalk'] . " -m BGP4-V2-MIB-JUNIPER -Onq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port'];
|
||||
$peer_cmd .= " jnxBgpM2PeerStatus.0.ipv6";
|
||||
foreach (explode("\n",trim(`$peer_cmd`)) as $oid)
|
||||
{
|
||||
list($peer_oid) = split(' ',$oid);
|
||||
$peer_id = explode('.',$peer_oid);
|
||||
$junos_v6[implode('.',array_slice($peer_id,35,8))] = implode('.',array_slice($peer_id,18));
|
||||
}
|
||||
}
|
||||
|
||||
$peer_cmd = $config['snmpget'] . " -m BGP4-V2-MIB-JUNIPER -Ovq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port'];
|
||||
$peer_cmd .= " jnxBgpM2PeerState.0.ipv6." . $junos_v6[$peer_ip];
|
||||
$peer_cmd .= " jnxBgpM2PeerStatus.0.ipv6." . $junos_v6[$peer_ip];
|
||||
$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_data = trim(`$peer_cmd`);
|
||||
list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data);
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
$peerrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/bgp-" . $peer['bgpPeerIdentifier'] . ".rrd";
|
||||
if(!is_file($peerrrd)) {
|
||||
|
||||
Reference in New Issue
Block a user