Files
librenms-librenms/includes/polling/ipmi.inc.php
Tony Murray cb005210d2 Resubmit #9608 (#9941)
* Reorganize trap tests

* Testing db DRIVER to prevent .env from interfering

* New code to detect if Laravel is booted.  Hopefully more reliable.

* WIP external test process

* revert module test helper

* Use .env in Eloquent::boot()

* Fix test database settings loading

* fix undefined classes
(didn't find the one I needed)

* Fix incorrect Config usages
And RrdDefinition return type

* fix .env loading

* use the right DB

* slightly more accurate isConnected

* Move db_name to DBSetupTest specifically

* restore $_SERVER in AuthSSOTest

* missed item

* WIP

* tear down in the correct order.

* some testing cleanups

* remove check for duplicate event listener, it's not working right

* Don't need this change anymore

* Implement Log::event to replace legacy function log_event()

* fix port tests

* fix up tests

* remove pointless TrapTestCase class

* fix style

* Fix db config not being merged...

* skip env check for tests

* defer database operations until after Laravel is booted.

* don't include dbFaciale...

* redundant use
2019-03-12 23:59:03 -05:00

79 lines
2.9 KiB
PHP

<?php
use LibreNMS\Config;
use LibreNMS\RRD\RrdDefinition;
$ipmi_rows = dbFetchRows("SELECT * FROM sensors WHERE device_id = ? AND poller_type='ipmi'", array($device['device_id']));
if (is_array($ipmi_rows)) {
d_echo($ipmi_rows);
if ($ipmi['host'] = $attribs['ipmi_hostname']) {
$ipmi['user'] = $attribs['ipmi_username'];
$ipmi['password'] = $attribs['ipmi_password'];
$ipmi['type'] = $attribs['ipmi_type'];
echo 'Fetching IPMI sensor data...';
$cmd = [Config::get('ipmitool', 'ipmitool')];
if ($config['own_hostname'] != $device['hostname'] || $ipmi['host'] != 'localhost') {
array_push($cmd, '-H', $ipmi['host'], '-U', $ipmi['user'], '-P', $ipmi['password'], '-L', 'USER');
}
// Check to see if we know which IPMI interface to use
// so we dont use wrong arguments for ipmitool
if ($ipmi['type'] != '') {
array_push($cmd, '-I', $ipmi['type'], '-c', 'sdr');
$results = external_exec($cmd);
d_echo($results);
echo " done.\n";
} else {
echo " type not yet discovered.\n";
}
foreach (explode("\n", $results) as $row) {
list($desc, $value, $type, $status) = explode(',', $row);
$desc = trim($desc, ' ');
$ipmi_sensor[$desc][$config['ipmi_unit'][$type]]['value'] = $value;
$ipmi_sensor[$desc][$config['ipmi_unit'][$type]]['unit'] = $type;
}
foreach ($ipmi_rows as $ipmisensors) {
echo 'Updating IPMI sensor ' . $ipmisensors['sensor_descr'] . '... ';
$sensor_value = $ipmi_sensor[$ipmisensors['sensor_descr']][$ipmisensors['sensor_class']]['value'];
$unit = $ipmi_sensor[$ipmisensors['sensor_descr']][$ipmisensors['sensor_class']]['unit'];
echo "$sensor_value $unit\n";
$rrd_name = get_sensor_rrd_name($device, $ipmisensors);
$rrd_def = RrdDefinition::make()->addDataset('sensor', 'GAUGE', -20000, 20000);
$fields = array(
'sensor' => $sensor_value,
);
$tags = array(
'sensor_class' => $ipmisensors['sensor_class'],
'sensor_type' => $ipmisensors['sensor_type'],
'sensor_descr' => $ipmisensors['sensor_descr'],
'sensor_index' => $ipmisensors['sensor_index'],
'rrd_name' => $rrd_name,
'rrd_def' => $rrd_def
);
data_update($device, 'ipmi', $tags, $fields);
// FIXME warnings in event & mail not done here yet!
dbUpdate(
array('sensor_current' => $sensor_value,
'lastupdate' => array('NOW()')),
'sensors',
'poller_type = ? AND sensor_class = ? AND sensor_id = ?',
array('ipmi', $ipmisensors['sensor_class'], $ipmisensors['sensor_id'])
);
}
unset($ipmi_sensor);
}
}