Skip to content
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

Update raspberrypi sensor discovery to check for sensor existance #5114

Merged
merged 1 commit into from Dec 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion includes/discovery/sensors/frequencies/linux.inc.php
Expand Up @@ -19,6 +19,8 @@
break;
}
$value = snmp_get($device, $oid.$freq, '-Oqve');
discover_sensor($valid['sensor'], 'frequency', $device, $oid.$freq, $freq, $sensor_type, $descr, 1, 1, null, null, null, null, $value);
if (is_numeric($value)) {
discover_sensor($valid['sensor'], 'frequency', $device, $oid.$freq, $freq, $sensor_type, $descr, 1, 1, null, null, null, null, $value);
}
}
}
6 changes: 3 additions & 3 deletions includes/discovery/sensors/states/linux.inc.php
Expand Up @@ -31,7 +31,7 @@
}
$value = snmp_get($device, $oid.$codec, '-Oqv');

if (!empty($value)) {
if (stripos($value, 'abled') !== false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What output is this trying to match out of interest?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laf The options are "enabled" or "disabled" for the codec:

ra:~% dash raspberry.sh 
47.2
1.2000
1.2000
1.2000
1.2250
600062000
250000000
enabled
disabled
disabled
enabled
enabled
disabled

That's the full output of a "normal" raspberry.sh snmp extension. That's the "stock" output on a RPI which hasn't had any of the extra codec's purchased. It's a headless system so they aren't needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can also modify the stipos() if statement to if ($value = 'enabled' || $value = 'disabled') if the goal was to have some tighter checking on the line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I'm fine with it as is :)

$state_index_id = create_state_index($state);
if ($state_index_id) {
$states = array(
Expand All @@ -50,8 +50,8 @@
);
dbInsert($insert, 'state_translations');
}
discover_sensor($valid['sensor'], 'state', $device, $oid.$codec, $codec, $state, $descr, '1', '1', null, null, null, null, $value, 'snmp', $codec);
create_sensor_to_state_index($device, $state, $codec);
}
discover_sensor($valid['sensor'], 'state', $device, $oid.$codec, $codec, $state, $descr, '1', '1', null, null, null, null, $value, 'snmp', $codec);
create_sensor_to_state_index($device, $state, $codec);
}
}
2 changes: 1 addition & 1 deletion includes/discovery/sensors/temperatures/linux.inc.php
Expand Up @@ -11,7 +11,7 @@
$sensor_oid = ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.1";
$descr = "CPU Temp";
$value = snmp_get($device, $sensor_oid, '-Oqve');
if ($value > 0) {
if (is_numeric($value)) {
discover_sensor($valid['sensor'], 'temperature', $device, $sensor_oid, 1, $sensor_type, $descr, 1, 1, null, null, null, null, $value);
}
}
4 changes: 3 additions & 1 deletion includes/discovery/sensors/voltages/linux.inc.php
Expand Up @@ -23,7 +23,9 @@
break;
}
$value = snmp_get($device, $oid.$volt, '-Oqv');
discover_sensor($valid['sensor'], 'voltage', $device, $oid.$volt, $volt, $sensor_type, $descr, '1', '1', null, null, null, null, $value);
if (is_numeric($value)) {
discover_sensor($valid['sensor'], 'voltage', $device, $oid.$volt, $volt, $sensor_type, $descr, '1', '1', null, null, null, null, $value);
}
}
/*
* other linux os
Expand Down