From 20ec1339d1eec090ad72f1d6a2bb65fea5f25026 Mon Sep 17 00:00:00 2001 From: Gunnar Wolf Date: Mon, 21 Jan 2008 19:41:15 +0100 Subject: [PATCH] Initial version --- plugins/other/icecast2_simple | 70 +++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 plugins/other/icecast2_simple diff --git a/plugins/other/icecast2_simple b/plugins/other/icecast2_simple new file mode 100755 index 00000000..32f6b5c0 --- /dev/null +++ b/plugins/other/icecast2_simple @@ -0,0 +1,70 @@ +#!/usr/bin/ruby +# +# Plugin author: Gunnar Wolf +# +# 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 + conf = {:host => '127.0.0.1', :port => 8000, + :username => 'admin', :password => 'hackme' } + conf.keys.each do |key| + env_key = sprintf('icecast_%s', key) + conf[key] = ENV[env_key] if ENV.has_key?(env_key) + end + conf +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]])) + rescue OpenURI::HTTPError + puts "Cannot connect: HTTP connection error" + exit 1 + end + data +end + +def get_values(data) + vals = {} + [:sources, :clients].each do |key| + elem = data/key + if elem.nil? + vals[key] = 0 + else + vals[key] = elem.innerHTML + end + end + vals +end + +data = get_data(get_conf) +vals = get_values(data) + +if ARGV[0] == 'autoconf' + puts 'yes' +elsif ARGV[0] == 'config' + puts "graph_title Total sources and clients for Icecast" + puts "graph_vlabel listeners" + puts "graph_category Icecast" + 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] +end