1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

Ruby plugins: apply code changes as suggested by "rubocop --auto-correct"

This commit is contained in:
Lars Kruse 2020-08-25 17:06:15 +02:00
parent b0b39b018e
commit 809639ab65
33 changed files with 904 additions and 910 deletions

View file

@ -1,6 +1,4 @@
#!/usr/bin/env ruby
# encoding: utf-8
# Plugin to monitor Room Alert 11E environmental units.
# Requires ruby and the ruby SNMP library.
#
@ -34,31 +32,31 @@
require 'snmp'
base_oid = "enterprises.20916.1.3.1"
base_oid = 'enterprises.20916.1.3.1'
case $0.match('[^_]+$')[0]
when "temperature"
when 'temperature'
subchannel = 1
name = "temperature"
label = "°C"
letter = "t"
when "humidity"
name = 'temperature'
label = '°C'
letter = 't'
when 'humidity'
subchannel = 3
name = "humidity"
label = "% Relative Humidity"
letter = "h"
name = 'humidity'
label = '% Relative Humidity'
letter = 'h'
else
exit 1
end
def is_vb_valid(vb, subchannel)
return (vb.name[-1] == 0 and vb.name[-2] == subchannel and vb.value > 1)
(vb.name[-1] == 0 and vb.name[-2] == subchannel and vb.value > 1)
end
def field_name(unit, vb, letter)
clean_unit = unit.gsub(/[.-]/, '_')
sensor = vb.name[-3].to_s
return "#{clean_unit}_#{letter}#{sensor}"
"#{clean_unit}_#{letter}#{sensor}"
end
def label(unit, vb)
@ -67,28 +65,24 @@ def label(unit, vb)
label = "#{unit} " + (ENV["label_#{clean_unit}_#{sensor}"] || "sensor #{sensor}")
end
units = (ENV['units'] || "").split(/\s+/)
community = ENV['community'] || "public"
units = (ENV['units'] || '').split(/\s+/)
community = ENV['community'] || 'public'
case ARGV[0]
when "autoconf"
puts "no"
when 'autoconf'
puts 'no'
exit 0
when "config"
when 'config'
puts "graph_title Room Alert 11E units (#{name} probes)"
puts "graph_vlabel #{label}"
puts "graph_category sensors"
if name == "humidity"
puts "graph_args --lower-limit 0 --upper-limit 100"
end
puts 'graph_category sensors'
puts 'graph_args --lower-limit 0 --upper-limit 100' if name == 'humidity'
units.each do |unit|
SNMP::Manager.open(:Host => unit,
:Community => community,
:Version => :SNMPv1) do |manager|
SNMP::Manager.open(Host: unit,
Community: community,
Version: :SNMPv1) do |manager|
manager.walk(base_oid) do |vb|
if not is_vb_valid(vb, subchannel)
next
end
next unless is_vb_valid(vb, subchannel)
puts "#{field_name(unit, vb, letter)}.label #{label(unit, vb)}"
end
@ -98,13 +92,11 @@ when "config"
end
units.each do |unit|
SNMP::Manager.open(:Host => unit,
:Community => community,
:Version => :SNMPv1) do |manager|
SNMP::Manager.open(Host: unit,
Community: community,
Version: :SNMPv1) do |manager|
manager.walk(base_oid) do |vb|
if not is_vb_valid(vb, subchannel)
next
end
next unless is_vb_valid(vb, subchannel)
puts "#{field_name(unit, vb, letter)}.value #{vb.value.to_f / 100}"
end