1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-08-09 23:43:57 +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

@ -18,10 +18,10 @@ require 'open-uri'
def get_conf
# Default values
conf = { :host => '127.0.0.1', :port => 8000,
:username => 'admin', :password => 'hackme' }
conf = { host: '127.0.0.1', port: 8000,
username: 'admin', password: 'hackme' }
conf.keys.each do |key|
env_key = sprintf('icecast_%s', key)
env_key = format('icecast_%s', key)
conf[key] = ENV[env_key] if ENV.has_key?(env_key)
end
conf
@ -29,12 +29,12 @@ end
def get_data(conf)
begin
data = Hpricot(open(sprintf('http://%s:%s/admin/stats',
conf[:host], conf[:port]),
:http_basic_authentication => [conf[:username],
conf[:password]]))
data = Hpricot(open(format('http://%s:%s/admin/stats',
conf[:host], conf[:port]),
http_basic_authentication: [conf[:username],
conf[:password]]))
rescue OpenURI::HTTPError
puts "Cannot connect: HTTP connection error"
puts 'Cannot connect: HTTP connection error'
exit 1
end
data
@ -42,13 +42,13 @@ end
def get_values(data)
vals = {}
[:sources, :clients].each do |key|
%i[sources clients].each do |key|
elem = data / key
if elem.nil?
vals[key] = 0
else
vals[key] = elem.innerHTML
end
vals[key] = if elem.nil?
0
else
elem.innerHTML
end
end
vals
end
@ -56,15 +56,16 @@ end
data = get_data(get_conf)
vals = get_values(data)
if ARGV[0] == 'autoconf'
case ARGV[0]
when 'autoconf'
puts 'yes'
elsif ARGV[0] == 'config'
puts "graph_title Total sources and clients for Icecast"
puts "graph_vlabel listeners"
puts "graph_category streaming"
puts "sources.label Total number of sources"
puts "clients.label Total number of clients"
when 'config'
puts 'graph_title Total sources and clients for Icecast'
puts 'graph_vlabel listeners'
puts 'graph_category streaming'
puts 'sources.label Total number of sources'
puts 'clients.label Total number of clients'
else
puts "sources.value " + vals[:sources]
puts "clients.value " + vals[:clients]
puts 'sources.value ' + vals[:sources]
puts 'clients.value ' + vals[:clients]
end