Issues (2963)

includes/discovery/entity-physical/cimc.inc.php (2 issues)

1
<?php
2
/*
3
 * LibreNMS module to discover hardware components in a Cisco Integrated Management Controller
4
 *
5
 * Copyright (c) 2016 Aaron Daniels <[email protected]>
6
 *
7
 * This program is free software: you can redistribute it and/or modify it
8
 * under the terms of the GNU General Public License as published by the
9
 * Free Software Foundation, either version 3 of the License, or (at your
10
 * option) any later version.  Please see LICENSE.txt at the top level of
11
 * the source code distribution for details.
12
 */
13
14
$comp_module = 'Cisco-CIMC';
15
$component = new LibreNMS\Component();
16
$components = $component->getComponents($device['device_id'], ['type'=>$comp_module]);
17
18
// We only care about our device id.
19
$components = $components[$device['device_id']];
20
21
// Begin our master array, all other values will be processed into this array.
22
$tblCIMC = [];
23
24
// Let's gather some data..
25
$tblUCSObjects = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.719.1', 2);
26
27
/*
28
 * False == no object found - this is not an error, there is no QOS configured
29
 * null  == timeout or something else that caused an error, the OID's may be present but we couldn't get them.
30
 */
31
if (is_null($tblUCSObjects)) {
0 ignored issues
show
The condition is_null($tblUCSObjects) is always false.
Loading history...
32
    // We have to error here or we will end up deleting all our components.
33
} else {
34
    // No Error, lets process things.
35
    echo 'CIMC Hardware Found: ';
36
37
    // Make sure we have an array before we try to iterate over it
38
    if (is_array($tblUCSObjects)) {
0 ignored issues
show
The condition is_array($tblUCSObjects) is always true.
Loading history...
39
        // Gather entPhysical data
40
        $entmax = 0;
41
        $entphysical = [];
42
        $dbentphysical = $entries = dbFetchRows('SELECT * FROM entPhysical WHERE device_id=?', [$device['device_id']]);
43
        foreach ($dbentphysical as $array) {
44
            $entphysical[$array['entPhysicalVendorType']] = $array;
45
            if ($array['entPhysicalIndex'] > $entmax) {
46
                $entmax = $array['entPhysicalIndex'];
47
            }
48
        }
49
50
        // Let's extract any active faults, we will use them later.
51
        $faults = [];
52
        foreach ($tblUCSObjects['1.3.6.1.4.1.9.9.719.1.1.1.1'][5] as $fid => $fobj) {
53
            $fobj = preg_replace('/^\/?sys\//', '', $fobj);
54
            $faults[$fobj] = $tblUCSObjects['1.3.6.1.4.1.9.9.719.1.1.1.1'][3][$fid] . ' - ' . $tblUCSObjects['1.3.6.1.4.1.9.9.719.1.1.1.1'][11][$fid];
55
        }
56
57
        // Unset the faults and stats array so it isn't reported as an error later.
58
        unset(
59
            $tblUCSObjects['1.3.6.1.4.1.9.9.719.1.1.1.1'],
60
            $tblUCSObjects['1.3.6.1.4.1.9.9.719.1.9.14.1'],
61
            $tblUCSObjects['1.3.6.1.4.1.9.9.719.1.9.44.1'],
62
            $tblUCSObjects['1.3.6.1.4.1.9.9.719.1.30.12.1'],
63
            $tblUCSObjects['1.3.6.1.4.1.9.9.719.1.41.2.1'],
64
            $tblUCSObjects['1.3.6.1.4.1.9.9.719.1.45.36.1']
65
        );
66
67
        foreach ($tblUCSObjects as $tbl => $array) {
68
            // Remove the leading /sys/
69
            foreach ($array[2] as &$label) {
70
                $label = preg_replace('/^\/?sys\//', '', $label);
71
            }
72
73
            // Lets Set some defaults.
74
            $entPhysicalData = [
75
                'entPhysicalHardwareRev'    => '',
76
                'entPhysicalFirmwareRev'    => '',
77
                'entPhysicalSoftwareRev'    => '',
78
                'entPhysicalIsFRU'          => 'FALSE',
79
            ];
80
81
            switch ($tbl) {
82
                // Chassis - rack-unit-1
83
                case '1.3.6.1.4.1.9.9.719.1.9.35.1':
84
                    foreach ($array[3] as $key => $item) {
85
                        $result = [];
86
                        $result['hwtype'] = 'chassis';
87
                        $result['id'] = $array[27][$key];
88
                        $result['label'] = $array[2][$key];
89
                        $result['serial'] = $array[47][$key];
90
                        $result['string'] = $array[32][$key] . ' - ' . ($array[49][$key] / 1024) . 'G Mem, ' . $array[36][$key] . ' CPU, ' . $array[35][$key] . ' core';
91
                        $result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.9.35.1.43.' . $key;
92
93
                        // What is the Operability, 1 is good, everything else is bad.
94
                        if ($array[43][$key] != 1) {
95
                            // Yes, report an error
96
                            $result['status'] = 2;
97
                            $result['error'] = 'Error Operability Code: ' . $array[43][$key] . "\n";
98
                        } else {
99
                            // No, unset any errors that may exist.
100
                            $result['status'] = 0;
101
                            $result['error'] = '';
102
                        }
103
104
                        // See if there are any errors on this chassis.
105
                        foreach ($faults as $id => $value) {
106
                            if (strpos($id, $result['label']) !== false) {
107
                                // The fault is on this chassis.
108
                                $result['status'] = 2;
109
                                $result['error'] .= $value . "\n";
110
                            }
111
                        }
112
113
                        // Add the ent Physical entry
114
                        $entPhysicalData['entPhysicalClass'] = 'chassis';
115
                        $entPhysicalData['entPhysicalModelName'] = $array[32][$key];
116
                        $entPhysicalData['entPhysicalName'] = 'Chassis';
117
                        $entPhysicalData['entPhysicalDescr'] = $result['string'];
118
                        $entPhysicalData['entPhysicalSerialNum'] = $array[47][$key];
119
                        [$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
120
                        $valid[$entPhysicalData['entPhysicalIndex']] = 1;
121
122
                        // Add the result to the array.
123
                        d_echo('Chassis (' . $tbl . '): ' . print_r($result, true) . "\n");
124
                        $tblCIMC[] = $result;
125
                    }
126
                    break;
127
128
                // System Board - rack-unit-1/board
129
                case '1.3.6.1.4.1.9.9.719.1.9.6.1':
130
                    foreach ($array[3] as $key => $item) {
131
                        $result = [];
132
                        $result['hwtype'] = 'board';
133
                        $result['id'] = $array[5][$key];
134
                        $result['label'] = $array[2][$key];
135
                        $result['serial'] = $array[14][$key];
136
                        $result['string'] = $array[6][$key];
137
                        $result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.9.6.1.9.' . $key;
138
139
                        // What is the Operability, 1 is good, everything else is bad.
140
                        if ($array[9][$key] != 1) {
141
                            // Yes, report an error
142
                            $result['status'] = 2;
143
                            $result['error'] = 'Error Operability Code: ' . $array[9][$key];
144
                        } else {
145
                            // No, unset any errors that may exist.
146
                            $result['status'] = 0;
147
                            $result['error'] = '';
148
                        }
149
150
                        // Add the ent Physical entry
151
                        $entPhysicalData['entPhysicalClass'] = 'backplane';
152
                        $entPhysicalData['entPhysicalName'] = 'System Board';
153
                        $entPhysicalData['entPhysicalDescr'] = $result['string'];
154
                        $entPhysicalData['entPhysicalSerialNum'] = $array[14][$key];
155
                        [$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
156
                        $valid[$entPhysicalData['entPhysicalIndex']] = 1;
157
158
                        // Add the result to the array.
159
                        d_echo('System Board (' . $tbl . '): ' . print_r($result, true) . "\n");
160
                        $tblCIMC[] = $result;
161
                    }
162
                    break;
163
164
                // Memory Modules - rack-unit-1/board/memarray-1/mem-0
165
                case '1.3.6.1.4.1.9.9.719.1.30.11.1':
166
                    foreach ($array[3] as $key => $item) {
167
                        $result = [];
168
                        // If there is no memory module present, continue.
169
                        if ($array[17][$key] != 10) {
170
                            continue;
171
                        }
172
173
                        $result['hwtype'] = 'memory';
174
                        $result['id'] = substr($array[3][$key], 4);
175
                        $result['label'] = $array[2][$key];
176
                        $result['serial'] = $array[19][$key];
177
                        $result['string'] = $array[11][$key] . ' - ' . ($array[6][$key] / 1024) . 'G, ' . $array[27][$key] . ' Bit, ' . $array[7][$key] . ' Mhz, ' . $array[21][$key] . ' MT/s';
178
                        $result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.30.11.1.14.' . $key;
179
180
                        // What is the Operability, 1 is good, everything else is bad.
181
                        if ($array[14][$key] != 1) {
182
                            // Yes, report an error
183
                            $result['status'] = 2;
184
                            $result['error'] = 'Error Operability Code: ' . $array[14][$key];
185
                        } else {
186
                            // No, unset any errors that may exist.
187
                            $result['status'] = 0;
188
                            $result['error'] = '';
189
                        }
190
191
                        // Add the ent Physical entry
192
                        $entPhysicalData['entPhysicalClass'] = 'module';
193
                        $entPhysicalData['entPhysicalModelName'] = $array[11][$key];
194
                        $entPhysicalData['entPhysicalName'] = 'Memory';
195
                        $entPhysicalData['entPhysicalDescr'] = $result['string'];
196
                        $entPhysicalData['entPhysicalSerialNum'] = $array[19][$key];
197
                        [$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
198
                        $valid[$entPhysicalData['entPhysicalIndex']] = 1;
199
200
                        // Add the result to the array.
201
                        d_echo('Memory (' . $tbl . '): ' . print_r($result, true) . "\n");
202
                        $tblCIMC[] = $result;
203
                    }
204
                    break;
205
206
                // CPU's - rack-unit-1/board/cpu-1
207
                case '1.3.6.1.4.1.9.9.719.1.41.9.1':
208
                    foreach ($array[3] as $key => $item) {
209
                        $result = [];
210
                        // If there is no cpu present, continue.
211
                        if ($array[13][$key] != 10) {
212
                            continue;
213
                        }
214
215
                        $result['hwtype'] = 'cpu';
216
                        $result['id'] = substr($array[3][$key], 4);
217
                        $result['label'] = $array[2][$key];
218
                        $result['serial'] = $array[15][$key];
219
                        $result['string'] = $array[8][$key] . ' - ' . $array[5][$key] . ' Cores, ' . $array[20][$key] . ' Threads';
220
                        $result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.41.9.1.10.' . $key;
221
222
                        // What is the Operability, 1 is good, everything else is bad.
223
                        if ($array[10][$key] != 1) {
224
                            // Yes, report an error
225
                            $result['status'] = 2;
226
                            $result['error'] = 'Error Operability Code: ' . $array[10][$key];
227
                        } else {
228
                            // No, unset any errors that may exist.
229
                            $result['status'] = 0;
230
                            $result['error'] = '';
231
                        }
232
233
                        // Add the ent Physical entry
234
                        $entPhysicalData['entPhysicalClass'] = 'cpu';
235
                        $entPhysicalData['entPhysicalModelName'] = $array[8][$key];
236
                        $entPhysicalData['entPhysicalName'] = 'Processor';
237
                        $entPhysicalData['entPhysicalDescr'] = $result['string'];
238
                        $entPhysicalData['entPhysicalSerialNum'] = $array[15][$key];
239
                        [$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
240
                        $valid[$entPhysicalData['entPhysicalIndex']] = 1;
241
242
                        // Add the result to the array.
243
                        d_echo('CPU (' . $tbl . '): ' . print_r($result, true) . "\n");
244
                        $tblCIMC[] = $result;
245
                    }
246
                    break;
247
248
                // SAS Storage Module - rack-unit-1/board/storage-SAS-2
249
                case '1.3.6.1.4.1.9.9.719.1.45.1.1':
250
                    foreach ($array[3] as $key => $item) {
251
                        $result = [];
252
                        $result['hwtype'] = 'sas-controller';
253
                        $result['id'] = substr($array[3][$key], 12);
254
                        $result['label'] = $array[2][$key];
255
                        $result['serial'] = $array[14][$key];
256
                        $result['string'] = $array[5][$key] . ' - Rev: ' . $array[13][$key] . ', ' . $array[9][$key] . ', RAID Types: ' . $array[19][$key];
257
                        $result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.45.1.1.7.' . $key;
258
259
                        // What is the Operability, 1 is good, everything else is bad.
260
                        if ($array[7][$key] != 1) {
261
                            // Yes, report an error
262
                            $result['status'] = 2;
263
                            $result['error'] = 'Error Operability Code: ' . $array[7][$key];
264
                        } else {
265
                            // No, unset any errors that may exist.
266
                            $result['status'] = 0;
267
                            $result['error'] = '';
268
                        }
269
270
                        // Add the ent Physical entry
271
                        $entPhysicalData['entPhysicalClass'] = 'module';
272
                        $entPhysicalData['entPhysicalModelName'] = $array[5][$key];
273
                        $entPhysicalData['entPhysicalName'] = 'Storage Module';
274
                        $entPhysicalData['entPhysicalDescr'] = $result['string'];
275
                        $entPhysicalData['entPhysicalSerialNum'] = $array[14][$key];
276
                        [$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
277
                        $valid[$entPhysicalData['entPhysicalIndex']] = 1;
278
279
                        // Add the result to the array.
280
                        d_echo('SAS Module (' . $tbl . '): ' . print_r($result, true) . "\n");
281
                        $tblCIMC[] = $result;
282
                    }
283
                    break;
284
285
                // SAS Disks - rack-unit-1/board/storage-SAS-2/disk-1
286
                case '1.3.6.1.4.1.9.9.719.1.45.4.1':
287
                    foreach ($array[3] as $key => $item) {
288
                        $result = [];
289
                        $result['hwtype'] = 'sas-disk';
290
                        $result['id'] = substr($array[3][$key], 5);
291
                        $result['label'] = $array[2][$key];
292
                        $result['serial'] = $array[12][$key];
293
                        $result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.45.4.1.9.' . $key;
294
295
                        // Old Firmware returns 4294967296 as 1 MB.
296
                        // The if below assumes we will never have < 1 Gb on old firmware or > 4 Pb on new firmware
297
                        if (($array[13][$key]) > 4294967296000) {
298
                            // Old Firmware
299
                            $result['string'] = $array[14][$key] . ' ' . $array[7][$key] . ', Rev: ' . $array[11][$key] . ', Size: ' . round($array[13][$key] / 4294967296000, 2) . ' GB';
300
                            d_echo('Disk: ' . $array[2][$key] . ', Raw Size: ' . $array[13][$key] . ', converted (old FW): ' . round($array[13][$key] / 4294967296000, 2) . "GB\n");
301
                        } else {
302
                            // New Firmware
303
                            $result['string'] = $array[14][$key] . ' ' . $array[7][$key] . ', Rev: ' . $array[11][$key] . ', Size: ' . round($array[13][$key] / 1000, 2) . ' GB';
304
                            d_echo('Disk: ' . $array[2][$key] . ', Raw Size: ' . $array[13][$key] . ', converted (New FW): ' . round($array[13][$key] / 1000, 2) . "GB\n");
305
                        }
306
307
                        // What is the Operability, 1 is good, everything else is bad.
308
                        if ($array[9][$key] != 1) {
309
                            // Yes, report an error
310
                            $result['status'] = 2;
311
                            $result['error'] = 'Error Operability Code: ' . $array[9][$key];
312
                        } else {
313
                            // No, unset any errors that may exist.
314
                            $result['status'] = 0;
315
                            $result['error'] = '';
316
                        }
317
318
                        // Add the ent Physical entry
319
                        $entPhysicalData['entPhysicalClass'] = 'module';
320
                        $entPhysicalData['entPhysicalModelName'] = $array[14][$key];
321
                        $entPhysicalData['entPhysicalName'] = 'Disk';
322
                        $entPhysicalData['entPhysicalDescr'] = $result['string'];
323
                        $entPhysicalData['entPhysicalSerialNum'] = $array[12][$key];
324
                        [$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
325
                        $valid[$entPhysicalData['entPhysicalIndex']] = 1;
326
327
                        // Add the result to the array.
328
                        d_echo('SAS Disk (' . $tbl . '): ' . print_r($result, true) . "\n");
329
                        $tblCIMC[] = $result;
330
                    }
331
                    break;
332
333
                // LUN's - rack-unit-1/board/storage-SAS-2/lun-0
334
                case '1.3.6.1.4.1.9.9.719.1.45.8.1':
335
                    foreach ($array[3] as $key => $item) {
336
                        $result = [];
337
                        $result['hwtype'] = 'lun';
338
                        $result['id'] = substr($array[3][$key], 4);
339
                        $result['label'] = $array[2][$key];
340
                        $result['serial'] = 'N/A';
341
                        $result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.45.8.1.9.' . $key;
342
343
                        // Old Firmware returns 4294967296 as 1 MB.
344
                        // The if below assumes we will never have < 1 Gb on old firmware or > 4 Pb on new firmware
345
                        if (($array[13][$key]) > 4294967296000) {
346
                            // Old Firmware
347
                            $result['string'] = $array[3][$key] . ', Size: ' . round($array[13][$key] / 4294967296000, 2) . ' GB';
348
                            d_echo('LUN: ' . $array[2][$key] . ', Raw Size: ' . $array[13][$key] . ', converted (Old FW): ' . round($array[13][$key] / 4294967296000, 2) . "GB\n");
349
                        } else {
350
                            // New Firmware
351
                            $result['string'] = $array[3][$key] . ', Size: ' . round($array[13][$key] / 1000, 2) . ' GB';
352
                            d_echo('LUN: ' . $array[2][$key] . ', Raw Size: ' . $array[13][$key] . ', converted (New FW): ' . round($array[13][$key] / 1000, 2) . "GB\n");
353
                        }
354
355
                        // What is the Operability, 1 is good, everything else is bad.
356
                        if ($array[9][$key] != 1) {
357
                            // Yes, report an error
358
                            $result['status'] = 2;
359
                            $result['error'] = 'Error Operability Code: ' . $array[9][$key];
360
                        } else {
361
                            // No, unset any errors that may exist.
362
                            $result['status'] = 0;
363
                            $result['error'] = '';
364
                        }
365
366
                        // Add the ent Physical entry
367
                        $entPhysicalData['entPhysicalClass'] = 'module';
368
                        $entPhysicalData['entPhysicalModelName'] = $array[3][$key];
369
                        $entPhysicalData['entPhysicalName'] = 'LUN';
370
                        $entPhysicalData['entPhysicalDescr'] = $result['string'];
371
                        $entPhysicalData['entPhysicalSerialNum'] = '';
372
                        [$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
373
                        $valid[$entPhysicalData['entPhysicalIndex']] = 1;
374
375
                        // Add the result to the array.
376
                        d_echo('LUN (' . $tbl . '): ' . print_r($result, true) . "\n");
377
                        $tblCIMC[] = $result;
378
                    }
379
                    break;
380
381
                // RAID Battery - rack-unit-1/board/storage-SAS-2/raid-battery
382
                case '1.3.6.1.4.1.9.9.719.1.45.11.1':
383
                    foreach ($array[3] as $key => $item) {
384
                        $result = [];
385
                        $result['hwtype'] = 'raid-battery';
386
                        $result['id'] = $array[3][$key];
387
                        $result['label'] = $array[2][$key];
388
                        $result['serial'] = 'N/A';
389
                        $result['string'] = $array[3][$key] . ' - ' . $array[7][$key];
390
                        $result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.45.11.1.9.' . $key;
391
392
                        // What is the Operability, 1 is good, everything else is bad.
393
                        if ($array[9][$key] != 1) {
394
                            // Yes, report an error
395
                            $result['status'] = 2;
396
                            $result['error'] = 'Error Operability Code: ' . $array[9][$key];
397
                        } else {
398
                            // No, unset any errors that may exist.
399
                            $result['status'] = 0;
400
                            $result['error'] = '';
401
                        }
402
403
                        // Add the ent Physical entry
404
                        $entPhysicalData['entPhysicalClass'] = 'module';
405
                        $entPhysicalData['entPhysicalModelName'] = $array[3][$key];
406
                        $entPhysicalData['entPhysicalName'] = 'RAID Battery';
407
                        $entPhysicalData['entPhysicalDescr'] = $result['string'];
408
                        $entPhysicalData['entPhysicalSerialNum'] = '';
409
                        [$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
410
                        $valid[$entPhysicalData['entPhysicalIndex']] = 1;
411
412
                        // Add the result to the array.
413
                        d_echo('RAID Battery (' . $tbl . '): ' . print_r($result, true) . "\n");
414
                        $tblCIMC[] = $result;
415
                    }
416
                    break;
417
418
                // Fan's - rack-unit-1/fan-module-1-1/fan-1
419
                case '1.3.6.1.4.1.9.9.719.1.15.12.1':
420
                    foreach ($array[3] as $key => $item) {
421
                        $result = [];
422
                        $result['hwtype'] = 'fan';
423
                        $result['id'] = $array[8][$key] . '-' . substr($array[3][$key], 4);
424
                        $result['label'] = $array[2][$key];
425
                        $result['serial'] = 'N/A';
426
                        $result['string'] = $array[7][$key];
427
                        $result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.15.12.1.10.' . $key;
428
429
                        // What is the Operability, 1 is good, everything else is bad.
430
                        if ($array[10][$key] != 1) {
431
                            // Yes, report an error
432
                            $result['status'] = 2;
433
                            $result['error'] = 'Error Operability Code: ' . $array[10][$key];
434
                        } else {
435
                            // No, unset any errors that may exist.
436
                            $result['status'] = 0;
437
                            $result['error'] = '';
438
                        }
439
440
                        // Add the ent Physical entry
441
                        $entPhysicalData['entPhysicalClass'] = 'fan';
442
                        $entPhysicalData['entPhysicalModelName'] = $array[7][$key];
443
                        $entPhysicalData['entPhysicalName'] = 'FAN';
444
                        $entPhysicalData['entPhysicalDescr'] = $result['string'];
445
                        $entPhysicalData['entPhysicalSerialNum'] = '';
446
                        [$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
447
                        $valid[$entPhysicalData['entPhysicalIndex']] = 1;
448
449
                        // Add the result to the array.
450
                        d_echo('Fan (' . $tbl . '): ' . print_r($result, true) . "\n");
451
                        $tblCIMC[] = $result;
452
                    }
453
                    break;
454
455
                // PSU's - rack-unit-1/psu-1
456
                case '1.3.6.1.4.1.9.9.719.1.15.56.1':
457
                    foreach ($array[3] as $key => $item) {
458
                        $result = [];
459
                        $result['hwtype'] = 'psu';
460
                        $result['id'] = substr($array[3][$key], 4);
461
                        $result['label'] = $array[2][$key];
462
                        $result['serial'] = $array[13][$key];
463
                        $result['string'] = $array[6][$key] . ' - Rev: ' . $array[12][$key];
464
                        $result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.15.56.1.8.' . $key;
465
466
                        // What is the Operability, 1 is good, everything else is bad.
467
                        if ($array[8][$key] != 1) {
468
                            // Yes, report an error
469
                            $result['status'] = 2;
470
                            $result['error'] = 'Error Operability Code: ' . $array[8][$key];
471
                        } else {
472
                            // No, unset any errors that may exist.
473
                            $result['status'] = 0;
474
                            $result['error'] = '';
475
                        }
476
477
                        // Add the ent Physical entry
478
                        $entPhysicalData['entPhysicalClass'] = 'powerSupply';
479
                        $entPhysicalData['entPhysicalModelName'] = $array[6][$key];
480
                        $entPhysicalData['entPhysicalName'] = 'PSU';
481
                        $entPhysicalData['entPhysicalDescr'] = $result['string'];
482
                        $entPhysicalData['entPhysicalSerialNum'] = $array[13][$key];
483
                        [$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
484
                        $valid[$entPhysicalData['entPhysicalIndex']] = 1;
485
486
                        // Add the result to the array.
487
                        d_echo('PSU (' . $tbl . '): ' . print_r($result, true) . "\n");
488
                        $tblCIMC[] = $result;
489
                    }
490
                    break;
491
492
                // Adaptors - rack-unit-1/adaptor-1
493
                case '1.3.6.1.4.1.9.9.719.1.3.85.1':
494
                    foreach ($array[3] as $key => $item) {
495
                        $result = [];
496
                        $result['hwtype'] = 'adaptor';
497
                        $result['id'] = substr($array[3][$key], 8);
498
                        $result['label'] = $array[2][$key];
499
                        $result['serial'] = $array[21][$key];
500
                        $result['string'] = $array[11][$key] . ' - Rev: ' . $array[20][$key] . ' - Part-No: ' . $array[26][$key];
501
                        $result['statusoid'] = '1.3.6.1.4.1.9.9.719.1.3.85.1.13.' . $key;
502
503
                        // What is the Operability, 1 is good, everything else is bad.
504
                        if ($array[13][$key] != 1) {
505
                            // Yes, report an error
506
                            $result['status'] = 2;
507
                            $result['error'] = 'Error Operability Code: ' . $array[13][$key];
508
                        } else {
509
                            // No, unset any errors that may exist.
510
                            $result['status'] = 0;
511
                            $result['error'] = '';
512
                        }
513
514
                        // Add the ent Physical entry
515
                        $entPhysicalData['entPhysicalClass'] = 'module';
516
                        $entPhysicalData['entPhysicalModelName'] = $array[11][$key];
517
                        $entPhysicalData['entPhysicalName'] = 'Adaptor';
518
                        $entPhysicalData['entPhysicalDescr'] = $result['string'];
519
                        $entPhysicalData['entPhysicalSerialNum'] = $array[21][$key];
520
                        [$result['entPhysical'],$entPhysicalData['entPhysicalIndex']] = setCIMCentPhysical($result['label'], $entPhysicalData, $entphysical, $entmax);
521
                        $valid[$entPhysicalData['entPhysicalIndex']] = 1;
522
523
                        // Add the result to the array.
524
                        d_echo('Adaptor (' . $tbl . '): ' . print_r($result, true) . "\n");
525
                        $tblCIMC[] = $result;
526
                    }
527
                    break;
528
529
                // Unknown Table, ask the user to log an issue so this can be identified.
530
                default:
531
                    d_echo("Cisco-CIMC Error...\n");
532
                    d_echo("Please log an issue on github with the following information:\n");
533
                    d_echo("-----------------------------------------------\n");
534
                    d_echo('Subject: CIMC Unknown Table: ' . $tbl . "\n");
535
                    d_echo("Description: The entity-physical module discovered an unknown CIMC table.\nA dump of its contents is below:\n");
536
                    d_echo($array);
537
                    d_echo("-----------------------------------------------\n\n");
538
                    break;
539
            } // End Switch
540
        } // End foreach tblUCSObjects
541
    } // End is_array
542
543
    /*
544
     * Ok, we have our 2 array's (Components and SNMP) now we need
545
     * to compare and see what needs to be added/updated.
546
     *
547
     * Let's loop over the SNMP data to see if we need to ADD or UPDATE any components.
548
     */
549
    foreach ($tblCIMC as $key => $array) {
550
        $component_key = false;
551
552
        // Loop over our components to determine if the component exists, or we need to add it.
553
        foreach ($components as $compid => $child) {
554
            if ($child['label'] === $array['label']) {
555
                $component_key = $compid;
556
            }
557
        }
558
559
        if (! $component_key) {
560
            // The component doesn't exist, we need to ADD it - ADD.
561
            $new_component = $component->createComponent($device['device_id'], $comp_module);
562
            $component_key = key($new_component);
563
            $components[$component_key] = array_merge($new_component[$component_key], $array);
564
            echo '+';
565
        } else {
566
            // The component does exist, merge the details in - UPDATE.
567
            $components[$component_key] = array_merge($components[$component_key], $array);
568
            echo '.';
569
        }
570
    }
571
572
    /*
573
     * Loop over the Component data to see if we need to DELETE any components.
574
     */
575
    foreach ($components as $key => $array) {
576
        // Guilty until proven innocent
577
        $found = false;
578
579
        foreach ($tblCIMC as $k => $v) {
580
            if ($array['label'] == $v['label']) {
581
                // Yay, we found it...
582
                $found = true;
583
            }
584
        }
585
586
        if ($found === false) {
587
            // The component has not been found. we should delete it and it's entPhysical entry
588
            echo '-';
589
            dbDelete('entPhysical', '`entPhysical_id` = ?', [$array['entPhysical']]);
590
            $component->deleteComponent($key);
591
        }
592
    }
593
    if (is_array($components)) {
594
        // Write the Components back to the DB.
595
        $component->setComponentPrefs($device['device_id'], $components);
596
        echo "\n";
597
    }
598
} // End if not error
599