2018-07-11 18:58:23 +02:00
|
|
|
#!/usr/bin/env ruby
|
2008-01-21 19:41:15 +01:00
|
|
|
#
|
|
|
|
# Plugin author: Gunnar Wolf <gwolf@gwolf.org>
|
2018-08-02 02:03:42 +02:00
|
|
|
#
|
2008-01-21 19:41:15 +01:00
|
|
|
# You are hereby granted authorization to copy, use, modify, distribute,
|
|
|
|
# and in general do anything you please with this plugin. It is too simple
|
|
|
|
# even to GPL-protect it.
|
|
|
|
#
|
|
|
|
# This plugin expects to receive via environment variables:
|
|
|
|
#
|
|
|
|
# icecast_host - Which host to monitor (default: 127.0.0.1)
|
|
|
|
# icecast_username - Username to connect with (default: admin)
|
|
|
|
# icecast_password - Password to connect with (default: hackme)
|
|
|
|
# icecast_realm - Realm to connect with (default: 'Icecast2 server')
|
|
|
|
#
|
|
|
|
require 'hpricot'
|
|
|
|
require 'open-uri'
|
|
|
|
|
|
|
|
def get_conf
|
|
|
|
# Default values
|
2020-08-25 17:06:15 +02:00
|
|
|
conf = { host: '127.0.0.1', port: 8000,
|
|
|
|
username: 'admin', password: 'hackme' }
|
2008-01-21 19:41:15 +01:00
|
|
|
conf.keys.each do |key|
|
2020-08-25 17:06:15 +02:00
|
|
|
env_key = format('icecast_%s', key)
|
2008-01-21 19:41:15 +01:00
|
|
|
conf[key] = ENV[env_key] if ENV.has_key?(env_key)
|
|
|
|
end
|
|
|
|
conf
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_data(conf)
|
2018-08-02 02:03:42 +02:00
|
|
|
begin
|
2020-08-25 17:06:15 +02:00
|
|
|
data = Hpricot(open(format('http://%s:%s/admin/stats',
|
|
|
|
conf[:host], conf[:port]),
|
|
|
|
http_basic_authentication: [conf[:username],
|
|
|
|
conf[:password]]))
|
2008-01-21 19:41:15 +01:00
|
|
|
rescue OpenURI::HTTPError
|
2020-08-25 17:06:15 +02:00
|
|
|
puts 'Cannot connect: HTTP connection error'
|
2008-01-21 19:41:15 +01:00
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
data
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_values(data)
|
|
|
|
vals = {}
|
2020-08-25 17:06:15 +02:00
|
|
|
%i[sources clients].each do |key|
|
2020-08-25 16:52:39 +02:00
|
|
|
elem = data / key
|
2020-08-25 17:06:15 +02:00
|
|
|
vals[key] = if elem.nil?
|
|
|
|
0
|
|
|
|
else
|
|
|
|
elem.innerHTML
|
|
|
|
end
|
2008-01-21 19:41:15 +01:00
|
|
|
end
|
|
|
|
vals
|
|
|
|
end
|
|
|
|
|
|
|
|
data = get_data(get_conf)
|
|
|
|
vals = get_values(data)
|
|
|
|
|
2020-08-25 17:06:15 +02:00
|
|
|
case ARGV[0]
|
|
|
|
when 'autoconf'
|
2008-01-21 19:41:15 +01:00
|
|
|
puts 'yes'
|
2020-08-25 17:06:15 +02:00
|
|
|
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'
|
2008-01-21 19:41:15 +01:00
|
|
|
else
|
2020-08-25 17:06:15 +02:00
|
|
|
puts 'sources.value ' + vals[:sources]
|
|
|
|
puts 'clients.value ' + vals[:clients]
|
2008-01-21 19:41:15 +01:00
|
|
|
end
|