1 | <?php |
||
2 | |||
3 | use LibreNMS\Config; |
||
4 | use LibreNMS\RRD\RrdDefinition; |
||
5 | |||
6 | $ipmi_rows = dbFetchRows("SELECT * FROM sensors WHERE device_id = ? AND poller_type='ipmi'", [$device['device_id']]); |
||
7 | |||
8 | if (is_array($ipmi_rows)) { |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
9 | d_echo($ipmi_rows); |
||
10 | |||
11 | if ($ipmi['host'] = $attribs['ipmi_hostname']) { |
||
12 | $ipmi['port'] = filter_var($attribs['ipmi_port'], FILTER_VALIDATE_INT) ? $attribs['ipmi_port'] : '623'; |
||
13 | $ipmi['user'] = $attribs['ipmi_username']; |
||
14 | $ipmi['password'] = $attribs['ipmi_password']; |
||
15 | $ipmi['type'] = $attribs['ipmi_type']; |
||
16 | |||
17 | echo 'Fetching IPMI sensor data...'; |
||
18 | |||
19 | $cmd = [Config::get('ipmitool', 'ipmitool')]; |
||
20 | if (Config::get('own_hostname') != $device['hostname'] || $ipmi['host'] != 'localhost') { |
||
21 | array_push($cmd, '-H', $ipmi['host'], '-U', $ipmi['user'], '-P', $ipmi['password'], '-L', 'USER', '-p', $ipmi['port']); |
||
22 | } |
||
23 | |||
24 | // Check to see if we know which IPMI interface to use |
||
25 | // so we dont use wrong arguments for ipmitool |
||
26 | if ($ipmi['type'] != '') { |
||
27 | array_push($cmd, '-I', $ipmi['type'], '-c', 'sdr'); |
||
28 | $results = external_exec($cmd); |
||
29 | d_echo($results); |
||
30 | echo " done.\n"; |
||
31 | } else { |
||
32 | echo " type not yet discovered.\n"; |
||
33 | } |
||
34 | |||
35 | foreach (explode("\n", $results) as $row) { |
||
36 | [$desc, $value, $type, $status] = explode(',', $row); |
||
37 | $desc = trim($desc, ' '); |
||
38 | $ipmi_unit_type = Config::get("ipmi_unit.$type"); |
||
39 | |||
40 | // SDR records can include hexadecimal values, identified by an h |
||
41 | // suffix (like "93h" for 0x93). Convert them to decimal. |
||
42 | if (preg_match('/^([0-9A-Fa-f]+)h$/', $value, $matches)) { |
||
43 | $value = hexdec($matches[1]); |
||
44 | } |
||
45 | |||
46 | $ipmi_sensor[$desc][$ipmi_unit_type]['value'] = $value; |
||
47 | $ipmi_sensor[$desc][$ipmi_unit_type]['unit'] = $type; |
||
48 | } |
||
49 | |||
50 | foreach ($ipmi_rows as $ipmisensors) { |
||
51 | echo 'Updating IPMI sensor ' . $ipmisensors['sensor_descr'] . '... '; |
||
52 | |||
53 | $sensor_value = $ipmi_sensor[$ipmisensors['sensor_descr']][$ipmisensors['sensor_class']]['value']; |
||
54 | $unit = $ipmi_sensor[$ipmisensors['sensor_descr']][$ipmisensors['sensor_class']]['unit']; |
||
55 | |||
56 | echo "$sensor_value $unit\n"; |
||
57 | |||
58 | $rrd_name = get_sensor_rrd_name($device, $ipmisensors); |
||
59 | $rrd_def = RrdDefinition::make()->addDataset('sensor', 'GAUGE', -20000, 20000); |
||
60 | |||
61 | $fields = [ |
||
62 | 'sensor' => $sensor_value, |
||
63 | ]; |
||
64 | |||
65 | $tags = [ |
||
66 | 'sensor_class' => $ipmisensors['sensor_class'], |
||
67 | 'sensor_type' => $ipmisensors['sensor_type'], |
||
68 | 'sensor_descr' => $ipmisensors['sensor_descr'], |
||
69 | 'sensor_index' => $ipmisensors['sensor_index'], |
||
70 | 'rrd_name' => $rrd_name, |
||
71 | 'rrd_def' => $rrd_def, |
||
72 | ]; |
||
73 | data_update($device, 'ipmi', $tags, $fields); |
||
74 | |||
75 | // FIXME warnings in event & mail not done here yet! |
||
76 | dbUpdate( |
||
77 | ['sensor_current' => $sensor_value, |
||
78 | 'lastupdate' => ['NOW()'], ], |
||
79 | 'sensors', |
||
80 | 'poller_type = ? AND sensor_class = ? AND sensor_id = ?', |
||
81 | ['ipmi', $ipmisensors['sensor_class'], $ipmisensors['sensor_id']] |
||
82 | ); |
||
83 | } |
||
84 | |||
85 | unset($ipmi_sensor); |
||
86 | } |
||
87 | } |
||
88 |