1 | <?php |
||
2 | /* |
||
3 | * LibreNMS module to display F5 GTM Wide IP Details |
||
4 | * |
||
5 | * Adapted from F5 LTM module by Darren Napper |
||
6 | * Copyright (c) 2016 Aaron Daniels <[email protected]> |
||
7 | * |
||
8 | * This program is free software: you can redistribute it and/or modify it |
||
9 | * under the terms of the GNU General Public License as published by the |
||
10 | * Free Software Foundation, either version 3 of the License, or (at your |
||
11 | * option) any later version. Please see LICENSE.txt at the top level of |
||
12 | * the source code distribution for details. |
||
13 | */ |
||
14 | |||
15 | // Define some error messages |
||
16 | use LibreNMS\Util\IP; |
||
17 | |||
18 | $error_poolaction = []; |
||
19 | $error_poolaction[0] = 'Unused'; |
||
20 | $error_poolaction[1] = 'Reboot'; |
||
21 | $error_poolaction[2] = 'Restart'; |
||
22 | $error_poolaction[3] = 'Failover'; |
||
23 | $error_poolaction[4] = 'Failover and Restart'; |
||
24 | $error_poolaction[5] = 'Go Active'; |
||
25 | $error_poolaction[6] = 'None'; |
||
26 | |||
27 | $component = new LibreNMS\Component(); |
||
28 | $components = $component->getComponents($device['device_id']); |
||
29 | |||
30 | // We only care about our device id. |
||
31 | $components = $components[$device['device_id']]; |
||
32 | |||
33 | // We extracted all the components for this device, now lets only get the LTM ones. |
||
34 | $keep = []; |
||
35 | $types = [$module, 'bigip', 'f5-gtm-wide', 'f5-gtm-pool']; |
||
36 | foreach ($components as $k => $v) { |
||
37 | foreach ($types as $type) { |
||
38 | if ($v['type'] == $type) { |
||
39 | $keep[$k] = $v; |
||
40 | } |
||
41 | } |
||
42 | } |
||
43 | $components = $keep; |
||
44 | |||
45 | // Begin our master array, all other values will be processed into this array. |
||
46 | $tblBigIP = []; |
||
47 | |||
48 | if ((snmp_get($device, 'sysModuleAllocationProvisionLevel.3.103.116.109', '-Ovqs', 'F5-BIGIP-SYSTEM-MIB')) != false) { |
||
49 | $gtmWideIPEntry = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.3.12.1.2.1', 0); |
||
50 | if (! is_null($gtmWideIPEntry)) { |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
51 | $gtmWideStatusEntry = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.3.12.3.2.1', 0); |
||
52 | $gtmPoolEntry = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.3.6.2.3.1.1', 0); |
||
53 | } |
||
54 | } |
||
55 | |||
56 | /* |
||
57 | * False == no object found - this is not an error, OID doesn't exist. |
||
58 | * null == timeout or something else that caused an error, OID may exist but we couldn't get it. |
||
59 | */ |
||
60 | |||
61 | if (! is_null($gtmWideIPEntry) || ! is_null($gtmWideStatusEntry) || ! is_null($gtmPoolEntry)) { |
||
62 | // No Nulls, lets go.... |
||
63 | d_echo("Objects Found:\n"); |
||
64 | |||
65 | // Process the Virtual Servers |
||
66 | if (is_array($gtmWideStatusEntry)) { |
||
67 | foreach ($gtmWideStatusEntry as $oid => $value) { |
||
68 | $result = []; |
||
69 | |||
70 | // Find all Virtual server names and UID's, then we can find everything else we need. |
||
71 | if (strpos($oid, '1.3.6.1.4.1.3375.2.3.12.3.2.1.1.') !== false) { |
||
72 | [$null, $index] = explode('1.3.6.1.4.1.3375.2.3.12.3.2.1.1.', $oid); |
||
73 | $result['type'] = 'f5-gtm-wide'; |
||
74 | $result['UID'] = (string) $index; |
||
75 | $result['label'] = $value; |
||
76 | // The UID is far too long to have in a RRD filename, use a hash of it instead. |
||
77 | $result['hash'] = hash('crc32', $result['UID']); |
||
78 | |||
79 | // Now that we have our UID we can pull all the other data we need. |
||
80 | // 0 = None, 1 = Green, 2 = Yellow, 3 = Red, 4 = Blue |
||
81 | $result['state'] = $gtmWideStatusEntry['1.3.6.1.4.1.3375.2.3.12.3.2.1.2.' . $index]; |
||
82 | if ($result['state'] == 2) { |
||
83 | // Looks like one of the VS Pool members is down. |
||
84 | $result['status'] = 1; |
||
85 | $result['error'] = $gtmWideStatusEntry['1.3.6.1.4.1.3375.2.3.12.3.2.1.5.' . $index]; |
||
86 | } elseif ($result['state'] == 3) { |
||
87 | // Looks like ALL of the VS Pool members is down. |
||
88 | $result['status'] = 2; |
||
89 | $result['error'] = $gtmWideStatusEntry['1.3.6.1.4.1.3375.2.3.12.3.2.1.5.' . $index]; |
||
90 | } else { |
||
91 | // All is good. |
||
92 | $result['status'] = 0; |
||
93 | $result['error'] = $gtmWideStatusEntry['1.3.6.1.4.1.3375.2.3.12.3.2.1.5.' . $index]; |
||
94 | } |
||
95 | } |
||
96 | |||
97 | // Do we have any results |
||
98 | if (count($result) > 0) { |
||
99 | // Let's log some debugging |
||
100 | d_echo("\n\n" . $result['type'] . ': ' . $result['label'] . "\n"); |
||
101 | d_echo(' Status: ' . $result['status'] . "\n"); |
||
102 | d_echo(' Message: ' . $result['error'] . "\n"); |
||
103 | |||
104 | // Add this result to the master array. |
||
105 | $tblBigIP[] = $result; |
||
106 | } |
||
107 | } |
||
108 | } |
||
109 | |||
110 | // Process the Pools |
||
111 | if (is_array($gtmPoolEntry)) { |
||
112 | foreach ($gtmPoolEntry as $oid => $value) { |
||
113 | $result = []; |
||
114 | |||
115 | // Find all Pool names and UID's, then we can find everything else we need. |
||
116 | if (strpos($oid, '1.3.6.1.4.1.3375.2.3.6.2.3.1.1.') !== false) { |
||
117 | [$null, $index] = explode('1.3.6.1.4.1.3375.2.3.6.2.3.1.1.', $oid); |
||
118 | $result['type'] = 'f5-gtm-pool'; |
||
119 | $result['UID'] = (string) $index; |
||
120 | $result['label'] = $value; |
||
121 | // The UID is far too long to have in a RRD filename, use a hash of it instead. |
||
122 | $result['hash'] = hash('crc32', $result['UID']); |
||
123 | } |
||
124 | |||
125 | // Do we have any results |
||
126 | if (count($result) > 0) { |
||
127 | // Let's log some debugging |
||
128 | d_echo("\n\n" . $result['type'] . ': ' . $result['label'] . "\n"); |
||
129 | |||
130 | // Add this result to the master array. |
||
131 | $tblBigIP[] = $result; |
||
132 | } |
||
133 | } |
||
134 | } |
||
135 | /* |
||
136 | * Ok, we have our 2 array's (Components and SNMP) now we need |
||
137 | * to compare and see what needs to be added/updated. |
||
138 | * |
||
139 | * Let's loop over the SNMP data to see if we need to ADD or UPDATE any components. |
||
140 | */ |
||
141 | foreach ($tblBigIP as $key => $array) { |
||
142 | $component_key = false; |
||
143 | |||
144 | // Loop over our components to determine if the component exists, or we need to add it. |
||
145 | foreach ($components as $compid => $child) { |
||
146 | if (($child['UID'] === $array['UID']) && ($child['type'] === $array['type'])) { |
||
147 | $component_key = $compid; |
||
148 | } |
||
149 | } |
||
150 | |||
151 | if (! $component_key) { |
||
152 | // The component doesn't exist, we need to ADD it - ADD. |
||
153 | $new_component = $component->createComponent($device['device_id'], $array['type']); |
||
154 | $component_key = key($new_component); |
||
155 | $components[$component_key] = array_merge($new_component[$component_key], $array); |
||
156 | echo '+'; |
||
157 | } else { |
||
158 | // The component does exist, merge the details in - UPDATE. |
||
159 | $components[$component_key] = array_merge($components[$component_key], $array); |
||
160 | echo '.'; |
||
161 | } |
||
162 | } |
||
163 | |||
164 | /* |
||
165 | * Loop over the Component data to see if we need to DELETE any components. |
||
166 | */ |
||
167 | foreach ($components as $key => $array) { |
||
168 | // Guilty until proven innocent |
||
169 | $found = false; |
||
170 | |||
171 | foreach ($tblBigIP as $k => $v) { |
||
172 | if (($array['UID'] == $v['UID']) && ($array['type'] == $v['type'])) { |
||
173 | // Yay, we found it... |
||
174 | $found = true; |
||
175 | } |
||
176 | } |
||
177 | |||
178 | if ($found === false) { |
||
179 | // The component has not been found. we should delete it. |
||
180 | echo '-'; |
||
181 | $component->deleteComponent($key); |
||
182 | } |
||
183 | } |
||
184 | |||
185 | // Write the Components back to the DB. |
||
186 | $component->setComponentPrefs($device['device_id'], $components); |
||
187 | echo "\n"; |
||
188 | } // End if not error |
||
189 |