root / plugins / icecast / icecast2_simple @ 809639ab
Historique | Voir | Annoter | Télécharger (1,86 ko)
| 1 | 7a37bfb1 | Lars Kruse | #!/usr/bin/env ruby |
|---|---|---|---|
| 2 | 20ec1339 | Gunnar Wolf | # |
| 3 | # Plugin author: Gunnar Wolf <gwolf@gwolf.org> |
||
| 4 | 17f78427 | Lars Kruse | # |
| 5 | 20ec1339 | Gunnar Wolf | # You are hereby granted authorization to copy, use, modify, distribute, |
| 6 | # and in general do anything you please with this plugin. It is too simple |
||
| 7 | # even to GPL-protect it. |
||
| 8 | # |
||
| 9 | # This plugin expects to receive via environment variables: |
||
| 10 | # |
||
| 11 | # icecast_host - Which host to monitor (default: 127.0.0.1) |
||
| 12 | # icecast_username - Username to connect with (default: admin) |
||
| 13 | # icecast_password - Password to connect with (default: hackme) |
||
| 14 | # icecast_realm - Realm to connect with (default: 'Icecast2 server') |
||
| 15 | # |
||
| 16 | require 'hpricot' |
||
| 17 | require 'open-uri' |
||
| 18 | |||
| 19 | def get_conf |
||
| 20 | # Default values |
||
| 21 | 809639ab | Lars Kruse | conf = { host: '127.0.0.1', port: 8000,
|
| 22 | username: 'admin', password: 'hackme' } |
||
| 23 | 20ec1339 | Gunnar Wolf | conf.keys.each do |key| |
| 24 | 809639ab | Lars Kruse | env_key = format('icecast_%s', key)
|
| 25 | 20ec1339 | Gunnar Wolf | conf[key] = ENV[env_key] if ENV.has_key?(env_key) |
| 26 | end |
||
| 27 | conf |
||
| 28 | end |
||
| 29 | |||
| 30 | def get_data(conf) |
||
| 31 | 17f78427 | Lars Kruse | begin |
| 32 | 809639ab | Lars Kruse | data = Hpricot(open(format('http://%s:%s/admin/stats',
|
| 33 | conf[:host], conf[:port]), |
||
| 34 | http_basic_authentication: [conf[:username], |
||
| 35 | conf[:password]])) |
||
| 36 | 20ec1339 | Gunnar Wolf | rescue OpenURI::HTTPError |
| 37 | 809639ab | Lars Kruse | puts 'Cannot connect: HTTP connection error' |
| 38 | 20ec1339 | Gunnar Wolf | exit 1 |
| 39 | end |
||
| 40 | data |
||
| 41 | end |
||
| 42 | |||
| 43 | def get_values(data) |
||
| 44 | vals = {}
|
||
| 45 | 809639ab | Lars Kruse | %i[sources clients].each do |key| |
| 46 | b0b39b01 | Lars Kruse | elem = data / key |
| 47 | 809639ab | Lars Kruse | vals[key] = if elem.nil? |
| 48 | 0 |
||
| 49 | else |
||
| 50 | elem.innerHTML |
||
| 51 | end |
||
| 52 | 20ec1339 | Gunnar Wolf | end |
| 53 | vals |
||
| 54 | end |
||
| 55 | |||
| 56 | data = get_data(get_conf) |
||
| 57 | vals = get_values(data) |
||
| 58 | |||
| 59 | 809639ab | Lars Kruse | case ARGV[0] |
| 60 | when 'autoconf' |
||
| 61 | 20ec1339 | Gunnar Wolf | puts 'yes' |
| 62 | 809639ab | Lars Kruse | when 'config' |
| 63 | puts 'graph_title Total sources and clients for Icecast' |
||
| 64 | puts 'graph_vlabel listeners' |
||
| 65 | puts 'graph_category streaming' |
||
| 66 | puts 'sources.label Total number of sources' |
||
| 67 | puts 'clients.label Total number of clients' |
||
| 68 | 20ec1339 | Gunnar Wolf | else |
| 69 | 809639ab | Lars Kruse | puts 'sources.value ' + vals[:sources] |
| 70 | puts 'clients.value ' + vals[:clients] |
||
| 71 | 20ec1339 | Gunnar Wolf | end |
