mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
@@ -5,6 +5,9 @@ use LibreNMS\RRD\RrdDefinition;
|
||||
foreach (dbFetchRows('SELECT * FROM `customoids` WHERE `customoid_passed` = 1 AND `device_id` = ?', [$device['device_id']]) as $customoid) {
|
||||
d_echo($customoid);
|
||||
|
||||
$descr = $customoid['customoid_descr'];
|
||||
$unit = $customoid['customoid_unit'];
|
||||
|
||||
$prev_oid_value = $customoid['customoid_current'];
|
||||
|
||||
$rawdata = snmp_get($device, $customoid['customoid_oid'], '-Oqv');
|
||||
@@ -19,12 +22,12 @@ foreach (dbFetchRows('SELECT * FROM `customoids` WHERE `customoid_passed` = 1 AN
|
||||
$os->enableGraph('customoid');
|
||||
$oid_value = $rawdata;
|
||||
} elseif (
|
||||
$customoid['customoid_unit'] &&
|
||||
str_i_contains($rawdata, $customoid['customoid_unit']) &&
|
||||
is_numeric(trim(str_replace($customoid['customoid_unit'], '', $rawdata)))
|
||||
$unit &&
|
||||
str_i_contains($rawdata, $unit) &&
|
||||
is_numeric(trim(str_replace($unit, '', $rawdata)))
|
||||
) {
|
||||
$os->enableGraph('customoid');
|
||||
$oid_value = trim(str_replace($customoid['customoid_unit'], '', $rawdata));
|
||||
$oid_value = trim(str_replace($unit, '', $rawdata));
|
||||
} elseif (is_numeric(string_to_float($rawdata))) {
|
||||
$os->enableGraph('customoid');
|
||||
$oid_value = string_to_float($rawdata);
|
||||
@@ -44,14 +47,14 @@ foreach (dbFetchRows('SELECT * FROM `customoids` WHERE `customoid_passed` = 1 AN
|
||||
$oid_value = $customoid['user_func']($oid_value);
|
||||
}
|
||||
|
||||
echo 'Custom OID ' . $customoid['customoid_descr'] . ': ';
|
||||
echo $oid_value . ' ' . $customoid['customoid_unit'] . "\n";
|
||||
echo 'Custom OID ' . $descr . ': ';
|
||||
echo $oid_value . ' ' . $unit . "\n";
|
||||
|
||||
$fields = [
|
||||
'oid_value' => $oid_value,
|
||||
];
|
||||
|
||||
$rrd_name = ['customoid', $customoid['customoid_descr']];
|
||||
$rrd_name = ['customoid', $descr];
|
||||
if ($customoid['customoid_datatype'] == 'COUNTER') {
|
||||
$datatype = $customoid['customoid_datatype'];
|
||||
} else {
|
||||
@@ -60,7 +63,7 @@ foreach (dbFetchRows('SELECT * FROM `customoids` WHERE `customoid_passed` = 1 AN
|
||||
$rrd_def = RrdDefinition::make()
|
||||
->addDataset('oid_value', $datatype);
|
||||
|
||||
$tags = compact('rrd_name', 'rrd_def');
|
||||
$tags = compact('descr', 'unit', 'rrd_name', 'rrd_def');
|
||||
|
||||
data_update($device, 'customoid', $tags, $fields);
|
||||
dbUpdate(['customoid_current' => $oid_value, 'lastupdate' => ['NOW()'], 'customoid_prev' => $prev_oid_value], 'customoids', '`customoid_id` = ?', [$customoid['customoid_id']]);
|
||||
|
Reference in New Issue
Block a user