New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Tidy up sensor discovery #5550
Merged
Merged
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
32453ac
refactor: Tidy up sensor discovery
laf 05f9ac4
more files
laf e9557a6
removed uneeded files
laf b570a8b
updated array check
laf 8dc2a13
updates for linux/supermicro
laf f4612e3
small changes
laf b7ebc5a
Update linux.inc.php
laf 3b2ed8b
Add supermicro temps back to linux.inc.php
murrant c258dc9
Merge branch 'sensor-discovery-tidyup' of github.com:laf/librenms int…
laf b68f406
rebased
laf a61c4f2
No need for is_file on rfc1628.inc.php, it exists
murrant 762102c
Revert rfc1628 change
murrant 07bf39d
Fix whitespace...
murrant 3b89601
Merge branch 'master' of github.com:librenms/librenms into sensor-dis…
laf 0cbb5f0
rebased
laf 6654b6f
Merge branch 'sensor-discovery-tidyup' of github.com:laf/librenms int…
laf 824b8c7
fixed $valid data not being passed to new sensors() function
laf File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,45 @@ | ||
<?php | ||
|
||
if ($device['os'] == 'apc') { | ||
$oids = snmp_get($device, '.1.3.6.1.4.1.318.1.1.1.2.3.1.0', '-OsqnU', ''); | ||
$oids = snmp_get($device, '.1.3.6.1.4.1.318.1.1.1.2.3.1.0', '-OsqnU'); | ||
d_echo($oids."\n"); | ||
|
||
// Try High-Precision First | ||
if (!empty($oids)) { | ||
echo 'APC UPS Battery Charge High Precision'; | ||
$type = 'apc'; | ||
list($oid,$current) = explode(' ', $oids); | ||
|
||
$precision = 10; | ||
$sensorType = 'apc'; | ||
$current_oid = '.1.3.6.1.4.1.318.1.1.1.2.3.1.0'; | ||
$index = 0; | ||
$current_val = ($current / $precision); | ||
$limit = 100; | ||
$lowlimit = 0; | ||
$warnlimit = 10; | ||
$descr = 'Battery Charge'; | ||
|
||
discover_sensor($valid['sensor'], 'charge', $device, $current_oid, $index, $sensorType, $descr, $precision, '1', $lowlimit, $warnlimit, null, $limit, $current_val); | ||
} else { | ||
// Try to just get capacity | ||
$oids = snmp_get($device, '.1.3.6.1.4.1.318.1.1.1.2.2.1.0', '-OsqnU'); | ||
d_echo($oids."\n"); | ||
|
||
// Try High-Precision First | ||
if (!empty($oids)) { | ||
echo 'APC UPS Battery Charge High Precision'; | ||
echo 'APC UPS Battery Charge'; | ||
$type = 'apc'; | ||
list($oid,$current) = explode(' ', $oids); | ||
|
||
$precision = 10; | ||
$precision = 1; | ||
$sensorType = 'apc'; | ||
$current_oid = '.1.3.6.1.4.1.318.1.1.1.2.3.1.0'; | ||
$current_oid = '.1.3.6.1.4.1.318.1.1.1.2.2.1.0'; | ||
$index = 0; | ||
$current_val = ($current / $precision); | ||
$current_val = $current; | ||
$limit = 100; | ||
$lowlimit = 0; | ||
$warnlimit = 10; | ||
$descr = 'Battery Charge'; | ||
|
||
discover_sensor($valid['sensor'], 'charge', $device, $current_oid, $index, $sensorType, $descr, $precision, '1', $lowlimit, $warnlimit, null, $limit, $current_val); | ||
} else { | ||
// Try to just get capacity | ||
$oids = snmp_get($device, '.1.3.6.1.4.1.318.1.1.1.2.2.1.0', '-OsqnU', ''); | ||
d_echo($oids."\n"); | ||
|
||
if (!empty($oids)) { | ||
echo 'APC UPS Battery Charge'; | ||
$type = 'apc'; | ||
list($oid,$current) = explode(' ', $oids); | ||
|
||
$precision = 1; | ||
$sensorType = 'apc'; | ||
$current_oid = '.1.3.6.1.4.1.318.1.1.1.2.2.1.0'; | ||
$index = 0; | ||
$current_val = $current; | ||
$limit = 100; | ||
$lowlimit = 0; | ||
$warnlimit = 10; | ||
$descr = 'Battery Charge'; | ||
|
||
discover_sensor($valid['sensor'], 'charge', $device, $current_oid, $index, $sensorType, $descr, $precision, '1', $lowlimit, $warnlimit, null, $limit, $current_val); | ||
} | ||
}//end if | ||
} | ||
}//end if |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
<?php | ||
|
||
// RFC1628 UPS | ||
if (isset($config['modules_compat']['rfc1628'][$device['os']]) && $config['modules_compat']['rfc1628'][$device['os']]) { | ||
echo 'RFC1628 '; | ||
echo 'RFC1628 '; | ||
|
||
$oids = snmp_walk($device, '.1.3.6.1.2.1.33.1.2.4', '-Osqn', 'UPS-MIB'); | ||
d_echo($oids."\n"); | ||
$oids = snmp_walk($device, '.1.3.6.1.2.1.33.1.2.4', '-Osqn', 'UPS-MIB'); | ||
d_echo($oids."\n"); | ||
|
||
$oids = trim($oids); | ||
foreach (explode("\n", $oids) as $data) { | ||
$data = trim($data); | ||
if ($data) { | ||
list($oid,$descr) = explode(' ', $data, 2); | ||
$split_oid = explode('.', $oid); | ||
$current_id = $split_oid[(count($split_oid) - 1)]; | ||
$current_oid = ".1.3.6.1.2.1.33.1.2.4.$current_id"; | ||
$current = snmp_get($device, $current_oid, '-O vq'); | ||
$descr = 'Battery charge remaining'.(count(explode("\n", $oids)) == 1 ? '' : ' '.($current_id + 1)); | ||
$type = 'rfc1628'; | ||
$index = (500 + $current_id); | ||
$oids = trim($oids); | ||
foreach (explode("\n", $oids) as $data) { | ||
$data = trim($data); | ||
if ($data) { | ||
list($oid,$descr) = explode(' ', $data, 2); | ||
$split_oid = explode('.', $oid); | ||
$current_id = $split_oid[(count($split_oid) - 1)]; | ||
$current_oid = ".1.3.6.1.2.1.33.1.2.4.$current_id"; | ||
$current = snmp_get($device, $current_oid, '-O vq'); | ||
$descr = 'Battery charge remaining'.(count(explode("\n", $oids)) == 1 ? '' : ' '.($current_id + 1)); | ||
$type = 'rfc1628'; | ||
$index = (500 + $current_id); | ||
|
||
discover_sensor($valid['sensor'], 'charge', $device, $current_oid, $index, $type, $descr, '1', '1', null, null, null, null, $current); | ||
} | ||
discover_sensor($valid['sensor'], 'charge', $device, $current_oid, $index, $type, $descr, '1', '1', null, null, null, null, $current); | ||
} | ||
}//end if | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can avoid the is_array check by casting $types to array
foreach ((array)$types as $type)