Issues (2963)

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

1
<?php
2
/*
3
 * LibreNMS module to poll 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
$component = new LibreNMS\Component();
15
$components = $component->getComponents($device['device_id'], ['type'=>'Cisco-CIMC']);
16
17
// We only care about our device id.
18
$components = $components[$device['device_id']];
19
20
// Only collect SNMP data if we have enabled components
21
if (count($components > 0)) {
0 ignored issues
show
$components > 0 of type boolean is incompatible with the type Countable|array expected by parameter $value of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

21
if (count(/** @scrutinizer ignore-type */ $components > 0)) {
Loading history...
22
    // Let's gather some data..
23
    $tblUCSObjects = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.719.1', 0);
24
25
    // Make sure we have an array of data before we try to iterate over it
26
    if (is_array($tblUCSObjects)) {
0 ignored issues
show
The condition is_array($tblUCSObjects) is always true.
Loading history...
27
        // First, let's extract any active faults, we will use them later.
28
        $faults = [];
29
        foreach ($tblUCSObjects as $oid => $data) {
30
            if (strstr($oid, '1.3.6.1.4.1.9.9.719.1.1.1.1.5.')) {
31
                $id = substr($oid, 30);
32
                $fobj = $tblUCSObjects['1.3.6.1.4.1.9.9.719.1.1.1.1.5.' . $id];
33
                $fobj = preg_replace('/^sys/', '/sys', $fobj);
34
                $faults[$fobj] = $tblUCSObjects['1.3.6.1.4.1.9.9.719.1.1.1.1.11.' . $id];
35
            }
36
        }
37
38
        foreach ($components as &$array) {
39
            /*
40
             * Because our discovery module was nice and stored the OID we need to
41
             * poll for status, this is quite straight forward.
42
             *
43
             * Was the status oid found in the list?
44
             */
45
            if (isset($tblUCSObjects[$array['statusoid']])) {
46
                if ($tblUCSObjects[$array['statusoid']] != 1) {
47
                    // Yes, report an error
48
                    $array['status'] = 2;
49
                    $array['error'] = 'Error Operability Code: ' . $tblUCSObjects[$array['statusoid']] . "\n";
50
                } else {
51
                    // No, unset any errors that may exist.
52
                    $array['status'] = 0;
53
                    $array['error'] = '';
54
                }
55
            }
56
57
            // if the type is chassis, we may have to add generic chassis faults
58
            if ($array['hwtype'] == 'chassis') {
59
                // See if there are any errors on this chassis.
60
                foreach ($faults as $key => $value) {
61
                    if (strstr($key, $array['label'])) {
62
                        // The fault is on this chassis.
63
                        $array['status'] = 2;
64
                        $array['error'] .= $value . "\n";
65
                    }
66
                }
67
            }
68
69
            // Print some debugging
70
            if ($array['status'] == 0) {
71
                d_echo($array['label'] . " - Ok\n");
72
            } else {
73
                d_echo($array['label'] . ' - ' . $array['error'] . "\n");
74
            }
75
        } // End foreach components
76
        // Write the Components back to the DB.
77
        $component->setComponentPrefs($device['device_id'], $components);
78
    } // End is_array
79
    echo "\n";
80
} // End if not error
81