lmsensors 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,38 @@
1
+ # lib/lmsensors/features/alarm.rb
2
+
3
+ # Make sure to include the constants
4
+ require_relative "../lm_constants"
5
+ require_relative "./abs_feature"
6
+
7
+ # :nodoc: Append to the main module
8
+ module LmSensors
9
+ # :nodoc: Append to the Feature module
10
+ module Feature
11
+ ##
12
+ # Default formatting proc for ALARM types
13
+ FMT_ALARM = lambda do |feature|
14
+ # Formatted structure
15
+ unit = feature.unit
16
+ out = feature.feature
17
+ # Don't need to return unit, as it is proc for this feature type
18
+ out.delete(:unit)
19
+
20
+ # Format the outputs
21
+ feature.subfs.map do |k, v|
22
+ # Only check is alarm is enabled.
23
+ # The other option SSF_INTRUDE_BEEP
24
+ # is not formatted in the normal sensor program
25
+ if v[:subtype] == SSF_INTRUDE_ALARM then
26
+ out[k] = unit.call(v[:value]) end
27
+ end # End value mapper for alarm
28
+ out
29
+ end # End default alarm formatter
30
+
31
+ ##
32
+ # The Alarm class is appended to the LmSensors module
33
+ # to handle analytic post-processing of the FEATURE_INTRUSION type.
34
+ class Alarm < LmSensors::Feature::GenFeature
35
+ def def_fmt() @default_formatter = LmSensors::Feature::FMT_ALARM end
36
+ end # End Alarm class
37
+ end # End Feature append
38
+ end # End LmSensors inclusion
@@ -0,0 +1,33 @@
1
+ # lib/lmsensors/features/beep.rb
2
+
3
+ # Make sure to include the constants
4
+ require_relative "../lm_constants"
5
+ require_relative "./abs_feature"
6
+
7
+ # :nodoc: Append to the main module
8
+ module LmSensors
9
+ # :nodoc: Append to the Feature module
10
+ module Feature
11
+ ##
12
+ # Default formatting proc for BEEP types
13
+ FMT_BEEP = lambda do |feature|
14
+ unit = feature.unit
15
+ out = feature.feature
16
+ # Don't need to return unit, as it is proc for this feature type
17
+ out.delete(:unit)
18
+
19
+ # Format the outputs
20
+ feature.subfs.map do |k, v|
21
+ out[k] = unit.call(v[:value])
22
+ end # End value mapper for beep
23
+ out
24
+ end # End default beep formatter
25
+
26
+ ##
27
+ # The Beep class is appended to the LmSensors module
28
+ # to handle analytic post-processing of the FEATURE_BEEP_ENABLE type.
29
+ class Beep < LmSensors::Feature::GenFeature
30
+ def def_fmt() @default_formatter = LmSensors::Feature::FMT_BEEP end
31
+ end # End Beep class
32
+ end # End Feature append
33
+ end # End LmSensors inclusion
@@ -0,0 +1,69 @@
1
+ # lib/lmsensors/features/current.rb
2
+
3
+ # Make sure to include the constants
4
+ require_relative "../lm_constants"
5
+ require_relative "./abs_feature"
6
+
7
+ # :nodoc: Append to the main module
8
+ module LmSensors
9
+ # :nodoc: Append to the Feature module
10
+ module Feature
11
+ ##
12
+ # Default current formatting proc
13
+ FMT_CURR = lambda do |feature|
14
+ # Formatted structure
15
+ unit = feature.unit
16
+ out = feature.feature
17
+ tmp = { input: nil, max: nil }
18
+
19
+ # Format the outputs
20
+ # Strip each, in case the unit is empty
21
+ feature.subfs.values.map do |v|
22
+ case v[:subtype]
23
+ when SSF_CURR_INPUT
24
+ tmp[:input] = v[:value]
25
+ out[:input] = "#{v[:value].round(2)} #{unit}".strip
26
+ when SSF_CURR_MAX
27
+ if v[:value] != 0 then
28
+ tmp[:max] = v[:value]
29
+ out[:max] = "#{v[:value].round(2)} #{unit}".strip
30
+ end
31
+ when SSF_CURR_CRIT
32
+ if v[:value] != 0 then
33
+ tmp[:crit] = v[:value]
34
+ out[:crit] = "#{v[:value].round(2)} #{unit}".strip
35
+ end
36
+ when SSF_CURR_MIN
37
+ if v[:value] != 0 then out[:min] = "#{v[:value].round(2)} #{unit}".strip end
38
+ end
39
+ end # End value mapper for fan
40
+
41
+ # Set the check symbols
42
+ # Symbol for input, symbol for limit
43
+ syi, syl = :input, :max
44
+
45
+ # Calculate the percentage of current max
46
+ # :percent is against max, for current
47
+ if tmp[syl] and tmp[syi] then
48
+ perc = ((tmp[syi].to_f / tmp[syl]) * 100).round(2)
49
+ out[:percent] = "#{perc}%".strip
50
+ end # Only if both are present
51
+
52
+ syl = :crit
53
+
54
+ # Calculate the percentage of current crit
55
+ if tmp[syl] and tmp[syi] then
56
+ perc = ((tmp[syi].to_f / tmp[syl]) * 100).round(2)
57
+ out[:percent_crit] = "#{perc}%".strip
58
+ end # Only if both are present
59
+ out
60
+ end # End current proc
61
+
62
+ ##
63
+ # The Current class is appended to the LmSensors module
64
+ # to handle analytic post-processing of the FEATURE_CURR type.
65
+ class Current < LmSensors::Feature::GenFeature
66
+ def def_fmt() @default_formatter = LmSensors::Feature::FMT_CURR end
67
+ end # End Current class
68
+ end # end Feature append
69
+ end # End LmSensors inclusion
@@ -0,0 +1,52 @@
1
+ # lib/lmsensors/featureseatures/fan.rb
2
+
3
+ # Make sure to include the constants
4
+ require_relative "../lm_constants"
5
+ require_relative "./abs_feature"
6
+
7
+ # :nodoc: Append to the main module
8
+ module LmSensors
9
+ # :nodoc: Append to the Feature module
10
+ module Feature
11
+ ##
12
+ # Default formatting proc for
13
+ # the X_FAN subtype.
14
+ FMT_FAN = lambda do |feature|
15
+ # Formatted structure
16
+ unit = feature.unit
17
+ out = feature.feature
18
+ tmp = { input: nil, max: nil }
19
+
20
+ # Format the outputs
21
+ # Strip each, in case the unit is empty
22
+ feature.subfs.values.map do |v|
23
+ case v[:subtype]
24
+ when SSF_FAN_INPUT
25
+ tmp[:input] = v[:value]
26
+ out[:input] = "#{v[:value]} #{unit}".strip
27
+ when SSF_FAN_MAX
28
+ tmp[:max] = v[:value]
29
+ out[:max] = "#{v[:value]} #{unit}".strip
30
+ when SSF_FAN_MIN
31
+ out[:min] = "#{v[:value]} #{unit}".strip
32
+ end
33
+ end # End value mapper for fan
34
+
35
+ # Calculate the percentage of max speed of fan
36
+ if tmp[:max] and tmp[:input] then
37
+ perc = ((tmp[:input].to_f / tmp[:max]) * 100).round(2)
38
+ out[:percent] = "#{perc}%".strip
39
+ end # Only if both are present
40
+ out
41
+ end # End default fan formatter
42
+
43
+ ##
44
+ # The Fan class is appended to the LmSensors module
45
+ # to handle analytic post-processing of the FEATURE_FAN type.
46
+ class Fan < LmSensors::Feature::GenFeature
47
+ ##
48
+ # Override the default formatter
49
+ def def_fmt() @default_formatter = LmSensors::Feature::FMT_FAN end
50
+ end # End Fan class
51
+ end # End Feature append
52
+ end # End LmSensors inclusion
@@ -0,0 +1,35 @@
1
+ # lib/lmsensors/features/voltage.rb
2
+
3
+ # Make sure to include the constants
4
+ require_relative "../lm_constants"
5
+ require_relative "./abs_feature"
6
+
7
+ # :nodoc: Append to the main module
8
+ module LmSensors
9
+ # :nodoc: Append to the Feature module
10
+ module Feature
11
+ ##
12
+ # Default humidity formatting proc.
13
+ #
14
+ # I cannot test this on any of my systems,
15
+ # so it might need to be overridden.
16
+ FMT_HUMIDITY = lambda do |feature|
17
+ # Formatted structure
18
+ unit = feature.unit
19
+ out = feature.feature
20
+
21
+ # Format the outputs
22
+ feature.subfs.map do |k, v|
23
+ out[k] = "#{v[:value].round(2)}#{unit}"
24
+ end # End value mapper for humidity
25
+ out
26
+ end # End humidity proc
27
+
28
+ ##
29
+ # The Humidity class is appended to the LmSensors module
30
+ # to handle analytic post-processing of the FEATURE_HUMIDITY type.
31
+ class Humidity < LmSensors::Feature::GenFeature
32
+ def def_fmt() @default_formatter = LmSensors::Feature::FMT_HUMIDITY end
33
+ end # End Humidity class
34
+ end # End Feature append
35
+ end # End LmSensors inclusion
@@ -0,0 +1,80 @@
1
+ # lib/lmsensors/features/power.rb
2
+
3
+ # Make sure to include the constants
4
+ require_relative "../lm_constants"
5
+ require_relative "./abs_feature"
6
+
7
+ # :nodoc: Append to the main module
8
+ module LmSensors
9
+ # :nodoc: Append to the Feature module
10
+ module Feature
11
+ ##
12
+ # Default power formatting proc
13
+ FMT_POWER = lambda do |feature|
14
+ # Formatted structure
15
+ unit = feature.unit
16
+ out = feature.feature
17
+ tmp = { input: nil, max: nil }
18
+
19
+ # Format the outputs
20
+ # Strip each, in case the unit is empty
21
+ feature.subfs.values.map do |v|
22
+ case v[:subtype]
23
+ when SSF_POWER_INPUT
24
+ out[:input] = "#{v[:value].round(2)} #{unit}".strip
25
+ when SSF_POWER_AVG
26
+ tmp[:average] = v[:value]
27
+ out[:average] = "#{v[:value].round(2)} #{unit}".strip
28
+ when SSF_POWER_MAX
29
+ tmp[:max] = v[:value]
30
+ out[:max] = "#{v[:value].round(2)} #{unit}".strip
31
+ when SSF_POWER_CRIT
32
+ tmp[:crit] = v[:value]
33
+ out[:crit] = "#{v[:value].round(2)} #{unit}".strip
34
+ when SSF_POWER_CAP
35
+ tmp[:cap] = v[:value]
36
+ out[:cap] = "#{v[:value].round(2)} #{unit}".strip
37
+ when SSF_POWER_MIN
38
+ out[:min] = "#{v[:value].round(2)} #{unit}".strip
39
+ end
40
+ end # End value mapper for fan
41
+
42
+ # Set the check symbols
43
+ # Symbol for input, symbol for limit
44
+ syi, syl = :average, :cap
45
+
46
+ # Calculate the percentage of power cap
47
+ # :percent is against cap for power, and it is
48
+ # in respect to :average, not :input, as not all
49
+ # sensors will use input for power.
50
+ if tmp[syl] and tmp[syi] then
51
+ perc = ((tmp[syi].to_f / tmp[syl]) * 100).round(2)
52
+ out[:percent] = "#{perc}%".strip
53
+ end # Only if both are present
54
+
55
+ syl = :max
56
+
57
+ # Calculate the percentage of power max
58
+ if tmp[syl] and tmp[syi] then
59
+ perc = ((tmp[syi].to_f / tmp[syl]) * 100).round(2)
60
+ out[:percent_max] = "#{perc}%".strip
61
+ end # Only if both are present
62
+
63
+ syl = :crit
64
+
65
+ # Calculate the percentage of power crit
66
+ if tmp[syl] and tmp[syi] then
67
+ perc = ((tmp[syi].to_f / tmp[syl]) * 100).round(2)
68
+ out[:percent_crit] = "#{perc}%".strip
69
+ end # Only if both are present
70
+ out
71
+ end # End power proc
72
+
73
+ ##
74
+ # The Power class is appended to the LmSensors module
75
+ # to handle analytic post-processing of the FEATURE_POWER type.
76
+ class Power < LmSensors::Feature::GenFeature
77
+ def def_fmt() @default_formatter = LmSensors::Feature::FMT_POWER end
78
+ end # End Power class
79
+ end # End Feature append
80
+ end # End LmSensors inclusion
@@ -0,0 +1,69 @@
1
+ # lib/lmsensors/features/temp.rb
2
+
3
+ # Make sure to include the constants
4
+ require_relative "../lm_constants"
5
+ require_relative "./abs_feature"
6
+
7
+ # :nodoc: Append to the main module
8
+ module LmSensors
9
+ # :nodoc: Append to the Feature module
10
+ module Feature
11
+ ##
12
+ # Default temperature formatting proc
13
+ FMT_TEMP = lambda do |feature|
14
+ # Formatted structure
15
+ unit = feature.unit
16
+ out = feature.feature
17
+ tmp = { input: nil, max: nil }
18
+
19
+ # Format the outputs
20
+ # Strip each, in case the unit is empty
21
+ feature.subfs.values.map do |v|
22
+ case v[:subtype]
23
+ when SSF_TEMP_INPUT
24
+ tmp[:input] = v[:value]
25
+ out[:input] = "#{v[:value].round(2)} #{unit}".strip
26
+ when SSF_TEMP_MAX
27
+ if v[:value] != 0 then
28
+ tmp[:max] = v[:value]
29
+ out[:max] = "#{v[:value].round(2)} #{unit}".strip
30
+ end
31
+ when SSF_TEMP_CRIT
32
+ if v[:value] != 0 then
33
+ tmp[:crit] = v[:value]
34
+ out[:crit] = "#{v[:value].round(2)} #{unit}".strip
35
+ end
36
+ when SSF_TEMP_MIN
37
+ if v[:value] != 0 then out[:min] = "#{v[:value].round(2)} #{unit}".strip end
38
+ end
39
+ end # End value mapper for fan
40
+
41
+ # Set the check symbols
42
+ # Symbol for input, symbol for limit
43
+ syi, syl = :input, :max
44
+
45
+ # Calculate the percentage of voltage max
46
+ # :percent is against max, for voltage
47
+ if tmp[syl] and tmp[syi] then
48
+ perc = ((tmp[syi].to_f / tmp[syl]) * 100).round(2)
49
+ out[:percent] = "#{perc}%".strip
50
+ end # Only if both are present
51
+
52
+ syl = :crit
53
+
54
+ # Calculate the percentage of voltage crit
55
+ if tmp[syl] and tmp[syi] then
56
+ perc = ((tmp[syi].to_f / tmp[syl]) * 100).round(2)
57
+ out[:percent_crit] = "#{perc}%".strip
58
+ end # Only if both are present
59
+ out
60
+ end # End temp proc
61
+
62
+ ##
63
+ # The Temp class is appended to the LmSensors module
64
+ # to handle analytic post-processing of the FEATURE_TEMP type.
65
+ class Temp < LmSensors::Feature::GenFeature
66
+ def def_fmt() @default_formatter = LmSensors::Feature::FMT_TEMP end
67
+ end # End Temp class
68
+ end # End Feature append
69
+ end # End LmSensors inclusion
@@ -0,0 +1,69 @@
1
+ # lib/lmsensors/features/voltage.rb
2
+
3
+ # Make sure to include the constants
4
+ require_relative "../lm_constants"
5
+ require_relative "./abs_feature"
6
+
7
+ # :nodoc: Append to the main module
8
+ module LmSensors
9
+ # :nodoc: Append to the Feature module
10
+ module Feature
11
+ ##
12
+ # Default voltage formatting proc
13
+ FMT_VOLTAGE = lambda do |feature|
14
+ # Formatted structure
15
+ unit = feature.unit
16
+ out = feature.feature
17
+ tmp = { input: nil, max: nil }
18
+
19
+ # Format the outputs
20
+ # Strip each, in case the unit is empty
21
+ feature.subfs.values.map do |v|
22
+ case v[:subtype]
23
+ when SSF_IN_INPUT
24
+ tmp[:input] = v[:value]
25
+ out[:input] = "#{v[:value].round(2)} #{unit}".strip
26
+ when SSF_IN_MAX
27
+ if v[:value] != 0 then
28
+ tmp[:max] = v[:value]
29
+ out[:max] = "#{v[:value].round(2)} #{unit}".strip
30
+ end
31
+ when SSF_IN_CRIT
32
+ if v[:value] != 0 then
33
+ tmp[:crit] = v[:value]
34
+ out[:crit] = "#{v[:value].round(2)} #{unit}".strip
35
+ end
36
+ when SSF_IN_MIN
37
+ if v[:value] != 0 then out[:min] = "#{v[:value].round(2)} #{unit}".strip end
38
+ end
39
+ end # End value mapper for fan
40
+
41
+ # Set the check symbols
42
+ # Symbol for input, symbol for limit
43
+ syi, syl = :input, :max
44
+
45
+ # Calculate the percentage of voltage max
46
+ # :percent is against max, for voltage
47
+ if tmp[syl] and tmp[syi] then
48
+ perc = ((tmp[syi].to_f / tmp[syl]) * 100).round(2)
49
+ out[:percent] = "#{perc}%".strip
50
+ end # Only if both are present
51
+
52
+ syl = :crit
53
+
54
+ # Calculate the percentage of voltage crit
55
+ if tmp[syl] and tmp[syi] then
56
+ perc = ((tmp[syi].to_f / tmp[syl]) * 100).round(2)
57
+ out[:percent_crit] = "#{perc}%".strip
58
+ end # Only if both are present
59
+ out
60
+ end # End voltage proc
61
+
62
+ ##
63
+ # The Voltage class is appended to the LmSensors module
64
+ # to handle analytic post-processing of the FEATURE_IN type.
65
+ class Voltage < LmSensors::Feature::GenFeature
66
+ def def_fmt() @default_formatter = LmSensors::Feature::FMT_VOLTAGE end
67
+ end # End Voltage class
68
+ end # End Feature append
69
+ end # End LmSensors inclusion