device: Updated F5 Discovery and Polling (#8481)

* updated discovery method

* added LF at EOF

* changed discovery data gather to an array loop

* updated per murrant's suggestions

* updated to only poll attribues if objects exist
This commit is contained in:
dnapper
2018-04-07 20:14:09 +01:00
committed by Neil Lathwood
parent a3f822b7a3
commit e534608668
+102 -39
View File
@@ -44,29 +44,87 @@ $components = $keep;
// Begin our master array, all other values will be processed into this array.
$tblBigIP = array();
// Let's gather some data..
$ltmVirtualServEntry = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.2.10.1.2.1', 0);
$ltmVsStatusEntry = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.2.10.13.2.1', 0);
$ltmPoolEntry = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.2.5.1.2.1', 0);
$ltmPoolMemberEntry = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.2.5.3.2.1', 0);
$ltmPoolMbrStatusEntry = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.2.5.6.2.1', 0);
// Virtual Server Data
$ltmVirtualServOID = array(
ip => '1.3.6.1.4.1.3375.2.2.10.1.2.1.3',
port => '1.3.6.1.4.1.3375.2.2.10.1.2.1.6',
defaultpool => '1.3.6.1.4.1.3375.2.2.10.1.2.1.19',
state => '1.3.6.1.4.1.3375.2.2.10.13.2.1.2',
errorcode => '1.3.6.1.4.1.3375.2.2.10.13.2.1.5',
);
$ltmVirtualServEntry = [];
//Check for Virtual Server Enries
$ltmVirtualServEntry[name] = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.2.10.1.2.1.1', 0);
//If no Virtual Servers are found don't look for statistics
if (!empty($ltmVirtualServEntry[name])) {
foreach ($ltmVirtualServOID as $key => $value) {
$ltmVirtualServEntry[$key] = snmpwalk_array_num($device, $value, 0);
}
} else {
d_echo("No Virtual Servers Found\n");
}
// Pool Data
$ltmPoolEntryOID = array(
mode => '1.3.6.1.4.1.3375.2.2.5.1.2.1.2',
minup => '1.3.6.1.4.1.3375.2.2.5.1.2.1.4',
minupstatus => '1.3.6.1.4.1.3375.2.2.5.1.2.1.5',
minupaction => '1.3.6.1.4.1.3375.2.2.5.1.2.1.6',
currentup => '1.3.6.1.4.1.3375.2.2.5.1.2.1.8',
monitor => '1.3.6.1.4.1.3375.2.2.5.1.2.1.17',
);
// Pool Member Data
$ltmPoolMemberEntryOID = array(
ip => '1.3.6.1.4.1.3375.2.2.5.3.2.1.3',
port => '1.3.6.1.4.1.3375.2.2.5.3.2.1.4',
ratio => '1.3.6.1.4.1.3375.2.2.5.3.2.1.6',
weight => '1.3.6.1.4.1.3375.2.2.5.3.2.1.7',
priority => '1.3.6.1.4.1.3375.2.2.5.3.2.1.8',
state => '1.3.6.1.4.1.3375.2.2.5.6.2.1.5',
available => '1.3.6.1.4.1.3375.2.2.5.6.2.1.6',
errorcode => '1.3.6.1.4.1.3375.2.2.5.6.2.1.8',
);
//Check for Pool Enries
$ltmPoolEntry = [];
$ltmPoolMemberEntry = [];
$ltmPoolEntry[name] = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.2.5.1.2.1.1', 0);
//If no Pools are found don't look for statistics or pool members
if (!empty($ltmPoolEntry[name])) {
// If there are pools gather Pool Member Data
foreach ($ltmPoolEntryOID as $key => $value) {
$ltmPoolEntry[$key] = snmpwalk_array_num($device, $value, 0);
}
// Gather Pool Member Data if pool members found
$ltmPoolMemberEntry[name] = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.2.5.3.2.1.1', 0);
if (!empty($ltmPoolMemberEntry[name])) {
foreach ($ltmPoolMemberEntryOID as $key => $value) {
$ltmPoolMemberEntry[$key] = snmpwalk_array_num($device, $value, 0);
}
}
} else {
d_echo("No Pools Found\n");
}
/*
* False == no object found - this is not an error, OID doesn't exist.
* null == timeout or something else that caused an error, OID may exist but we couldn't get it.
*/
if (!is_null($ltmVirtualServEntry) || !is_null($ltmVsStatusEntry) || !is_null($ltmPoolEntry) || !is_null($ltmPoolMemberEntry) || !is_null($ltmPoolMbrStatusEntry)) {
if (!empty($ltmVirtualServEntry) || !empty($ltmPoolEntry) || !empty($ltmPoolMemberEntry)) {
// No Nulls, lets go....
d_echo("Objects Found:\n");
// Process the Virtual Servers
if (is_array($ltmVsStatusEntry)) {
foreach ($ltmVsStatusEntry as $oid => $value) {
if (is_array($ltmVirtualServEntry[name])) {
foreach ($ltmVirtualServEntry[name] as $oid => $value) {
$result = array();
// Find all Virtual server names and UID's, then we can find everything else we need.
if (strpos($oid, '1.3.6.1.4.1.3375.2.2.10.13.2.1.1.') !== false) {
list($null, $index) = explode('1.3.6.1.4.1.3375.2.2.10.13.2.1.1.', $oid);
if (strpos($oid, '1.3.6.1.4.1.3375.2.2.10.1.2.1.1.') !== false) {
list($null, $index) = explode('1.3.6.1.4.1.3375.2.2.10.1.2.1.1.', $oid);
$result['type'] = 'f5-ltm-vs';
$result['UID'] = (string)$index;
$result['label'] = $value;
@@ -74,25 +132,25 @@ if (!is_null($ltmVirtualServEntry) || !is_null($ltmVsStatusEntry) || !is_null($l
$result['hash'] = hash('crc32', $result['UID']);
// Trim IPv4 response to remove route domain ID
if (strlen($ltmVirtualServEntry['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index]) == 23) {
$ltmVirtualServEntry['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index] = substr($ltmVirtualServEntry['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index], 0, 11);
if (strlen($ltmVirtualServEntry[ip]['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index]) == 23) {
$ltmVirtualServEntry[ip]['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index] = substr($ltmVirtualServEntry[ip]['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index], 0, 11);
}
// Now that we have our UID we can pull all the other data we need.
$result['IP'] = IP::fromHexString($ltmVirtualServEntry['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index], true);
$result['port'] = $ltmVirtualServEntry['1.3.6.1.4.1.3375.2.2.10.1.2.1.6.'.$index];
$result['pool'] = $ltmVirtualServEntry['1.3.6.1.4.1.3375.2.2.10.1.2.1.19.'.$index];
$result['IP'] = IP::fromHexString($ltmVirtualServEntry[ip]['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index], true);
$result['port'] = $ltmVirtualServEntry[port]['1.3.6.1.4.1.3375.2.2.10.1.2.1.6.'.$index];
$result['pool'] = $ltmVirtualServEntry[defaultpool]['1.3.6.1.4.1.3375.2.2.10.1.2.1.19.'.$index];
// 0 = None, 1 = Green, 2 = Yellow, 3 = Red, 4 = Blue
$result['state'] = $ltmVsStatusEntry['1.3.6.1.4.1.3375.2.2.10.13.2.1.2.'.$index];
$result['state'] = $ltmVirtualServEntry[state]['1.3.6.1.4.1.3375.2.2.10.13.2.1.2.'.$index];
if ($result['state'] == 2) {
// Looks like one of the VS Pool members is down.
$result['status'] = 1;
$result['error'] = $ltmVsStatusEntry['1.3.6.1.4.1.3375.2.2.10.13.2.1.5.'.$index];
$result['error'] = $ltmVirtualServEntry[errorcode]['1.3.6.1.4.1.3375.2.2.10.13.2.1.5.'.$index];
} elseif ($result['state'] == 3) {
// Looks like ALL of the VS Pool members is down.
$result['status'] = 2;
$result['error'] = $ltmVsStatusEntry['1.3.6.1.4.1.3375.2.2.10.13.2.1.5.'.$index];
$result['error'] = $ltmVirtualServEntry[errorcode]['1.3.6.1.4.1.3375.2.2.10.13.2.1.5.'.$index];
} else {
// All is good.
$result['status'] = 0;
@@ -114,8 +172,8 @@ if (!is_null($ltmVirtualServEntry) || !is_null($ltmVsStatusEntry) || !is_null($l
}
// Process the Pools
if (is_array($ltmPoolEntry)) {
foreach ($ltmPoolEntry as $oid => $value) {
if (is_array($ltmPoolEntry[name])) {
foreach ($ltmPoolEntry[name] as $oid => $value) {
$result = array ();
// Find all Pool names and UID's, then we can find everything else we need.
@@ -128,12 +186,12 @@ if (!is_null($ltmVirtualServEntry) || !is_null($ltmVsStatusEntry) || !is_null($l
$result['hash'] = hash('crc32', $result['UID']);
// Now that we have our UID we can pull all the other data we need.
$result['mode'] = $ltmPoolEntry['1.3.6.1.4.1.3375.2.2.5.1.2.1.2.'.$index];
$result['minup'] = $ltmPoolEntry['1.3.6.1.4.1.3375.2.2.5.1.2.1.4.'.$index];
$result['minupstatus'] = $ltmPoolEntry['1.3.6.1.4.1.3375.2.2.5.1.2.1.5.'.$index];
$result['currentup'] = $ltmPoolEntry['1.3.6.1.4.1.3375.2.2.5.1.2.1.8.'.$index];
$result['minupaction'] = $ltmPoolEntry['1.3.6.1.4.1.3375.2.2.5.1.2.1.6.'.$index];
$result['monitor'] = $ltmPoolEntry['1.3.6.1.4.1.3375.2.2.5.1.2.1.17.'.$index];
$result['mode'] = $ltmPoolEntry[mode]['1.3.6.1.4.1.3375.2.2.5.1.2.1.2.'.$index];
$result['minup'] = $ltmPoolEntry[minup]['1.3.6.1.4.1.3375.2.2.5.1.2.1.4.'.$index];
$result['minupstatus'] = $ltmPoolEntry[minupstatus]['1.3.6.1.4.1.3375.2.2.5.1.2.1.5.'.$index];
$result['currentup'] = $ltmPoolEntry[currentup]['1.3.6.1.4.1.3375.2.2.5.1.2.1.8.'.$index];
$result['minupaction'] = $ltmPoolEntry[minupaction]['1.3.6.1.4.1.3375.2.2.5.1.2.1.6.'.$index];
$result['monitor'] = $ltmPoolEntry[monitor]['1.3.6.1.4.1.3375.2.2.5.1.2.1.17.'.$index];
// If we have less pool members than the minimum, we should error.
if ($result['currentup'] < $result['minup']) {
@@ -161,34 +219,39 @@ if (!is_null($ltmVirtualServEntry) || !is_null($ltmVsStatusEntry) || !is_null($l
}
// Process the Pool Members
if (is_array($ltmPoolMemberEntry)) {
foreach ($ltmPoolMemberEntry as $oid => $value) {
if (is_array($ltmPoolMemberEntry[name])) {
foreach ($ltmPoolMemberEntry[name] as $oid => $value) {
$result = array ();
// Find all Pool member names and UID's, then we can find everything else we need.
if (strpos($oid, '1.3.6.1.4.1.3375.2.2.5.3.2.1.19.') !== false) {
list($null, $index) = explode('1.3.6.1.4.1.3375.2.2.5.3.2.1.19.', $oid);
if (strpos($oid, '1.3.6.1.4.1.3375.2.2.5.3.2.1.1.') !== false) {
list($null, $index) = explode('1.3.6.1.4.1.3375.2.2.5.3.2.1.1.', $oid);
$result['type'] = 'f5-ltm-poolmember';
$result['UID'] = (string)$index;
$result['label'] = $value;
// The UID is far too long to have in a RRD filename, use a hash of it instead.
$result['hash'] = hash('crc32', $result['UID']);
//Remove route domain ID from v4 IPs
if (strlen($ltmPoolMemberEntry[ip]['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.'.$index]) == 23) {
$ltmPoolMemberEntry[ip]['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.'.$index] = substr($ltmPoolMemberEntry[ip]['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.'.$index], 0, 11);
}
// Now that we have our UID we can pull all the other data we need.
$result['IP'] = IP::fromHexString($ltmPoolMemberEntry['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.'.$index], true);
$result['port'] = $ltmPoolMemberEntry['1.3.6.1.4.1.3375.2.2.5.3.2.1.4.'.$index];
$result['ratio'] = $ltmPoolMemberEntry['1.3.6.1.4.1.3375.2.2.5.3.2.1.6.'.$index];
$result['weight'] = $ltmPoolMemberEntry['1.3.6.1.4.1.3375.2.2.5.3.2.1.7.'.$index];
$result['priority'] = $ltmPoolMemberEntry['1.3.6.1.4.1.3375.2.2.5.3.2.1.8.'.$index];
$result['state'] = $ltmPoolMbrStatusEntry['1.3.6.1.4.1.3375.2.2.5.6.2.1.5.'.$index];
$result['available'] = $ltmPoolMbrStatusEntry['1.3.6.1.4.1.3375.2.2.5.6.2.1.6.'.$index];
$result['IP'] = IP::fromHexString($ltmPoolMemberEntry[ip]['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.'.$index], true);
$result['port'] = $ltmPoolMemberEntry[port]['1.3.6.1.4.1.3375.2.2.5.3.2.1.4.'.$index];
$result['ratio'] = $ltmPoolMemberEntry[ratio]['1.3.6.1.4.1.3375.2.2.5.3.2.1.6.'.$index];
$result['weight'] = $ltmPoolMemberEntry[weight]['1.3.6.1.4.1.3375.2.2.5.3.2.1.7.'.$index];
$result['priority'] = $ltmPoolMemberEntry[priority]['1.3.6.1.4.1.3375.2.2.5.3.2.1.8.'.$index];
$result['state'] = $ltmPoolMemberEntry[state]['1.3.6.1.4.1.3375.2.2.5.6.2.1.5.'.$index];
$result['available'] = $ltmPoolMemberEntry[available]['1.3.6.1.4.1.3375.2.2.5.6.2.1.6.'.$index];
// If available and bad state
// 0 = None, 1 = Green, 2 = Yellow, 3 = Red, 4 = Blue
if (($result['available'] == 1) && ($result['state'] == 3)) {
// Warning Alarm, the pool member is down.
$result['status'] = 1;
$result['error'] = "Pool Member is Down: ".$ltmPoolMbrStatusEntry['1.3.6.1.4.1.3375.2.2.5.6.2.1.8.'.$index];
$result['error'] = "Pool Member is Down: ".$ltmPoolMemberEntry[errorcode]['1.3.6.1.4.1.3375.2.2.5.6.2.1.8.'.$index];
} else {
// All is good.
$result['status'] = 0;