diff --git a/virginmedia/README.md b/virginmedia/README.md new file mode 100644 index 0000000..70c0770 --- /dev/null +++ b/virginmedia/README.md @@ -0,0 +1,9 @@ +This is the virgin media pack + +It is written in ruby and requires that ruby >= 1.9.3 is installed on your system. + +# Ubuntu 14.04 Instructions +> apt-get install -y build-essential zlib1g-dev ruby1.9.1 ruby1.9.1-dev + +# Install required ruby modules +> gem install nokogiri diff --git a/virginmedia/dashboards/virgin-media.yaml b/virginmedia/dashboards/virgin-media.yaml new file mode 100644 index 0000000..aa2762e --- /dev/null +++ b/virginmedia/dashboards/virgin-media.yaml @@ -0,0 +1,167 @@ +title: VirginMedia +period: 3600 +positions: + - title: Status + data_type: nagios + type: status + color: maroon + row: 1 + col: 1 + size_x: 1 + size_y: 1 + legend: false + icon: true + series: + - metric: virginmedia.status + scope: + tag: virginmedia + - title: Download (Mb) + data_type: number + type: number + color: navy + row: 1 + col: 2 + size_x: 1 + size_y: 1 + legend: false + icon: true + filter: max + symbol: arrow-down + series: + - metric: virginmedia.download + scope: + tag: zfs + - title: Upload (Mb) + data_type: number + type: number + color: olive + row: 1 + col: 3 + size_x: 1 + size_y: 1 + legend: false + icon: true + filter: max + symbol: arrow-up + series: + - metric: virginmedia.upload + scope: + tag: zfs + - title: Downstream Channels + data_type: number + type: number + color: blue + row: 1 + col: 4 + size_x: 1 + size_y: 1 + legend: false + icon: true + filter: max + symbol: arrow-circle-o-down + series: + - metric: virginmedia.downstream.channels + scope: + tag: virginmedia + - title: Upstream Channels + data_type: number + type: number + color: teal + row: 1 + col: 5 + size_x: 1 + size_y: 1 + legend: false + icon: true + filter: max + symbol: arrow-circle-o-up + series: + - metric: virginmedia.upstream.channels + scope: + tag: virginmedia + - title: Average Noise + data_type: number + type: number + color: purple + row: 1 + col: 6 + size_x: 1 + size_y: 1 + legend: false + icon: true + filter: avg + symbol: bell + series: + - metric: virginmedia.downstream.average + scope: + tag: virginmedia + - title: Average PowerLevel + data_type: number + type: number + color: maroon + row: 1 + col: 7 + size_x: 1 + size_y: 1 + legend: false + icon: true + filter: avg + symbol: bolt + series: + - metric: virginmedia.upstream.average + scope: + tag: virginmedia + - title: Downstream Noise + data_type: number + type: detailed-chart + color: navy + row: 2 + col: 1 + size_x: 7 + size_y: 3 + legend: true + icon: true + filter: avg + series: + - metric: virginmedia.downstream.7 + scope: + tag: virginmedia + - metric: virginmedia.downstream.6 + scope: + tag: virginmedia + - metric: virginmedia.downstream.8 + scope: + tag: virginmedia + - metric: virginmedia.downstream.5 + scope: + tag: virginmedia + - metric: virginmedia.downstream.4 + scope: + tag: virginmedia + - metric: virginmedia.downstream.3 + scope: + tag: virginmedia + - metric: virginmedia.downstream.2 + scope: + tag: virginmedia + - metric: virginmedia.downstream.1 + scope: + tag: virginmedia + - title: Upstream PowerLevels + data_type: number + type: detailed-chart + color: lime + row: 5 + col: 1 + size_x: 7 + size_y: 3 + legend: true + icon: true + filter: avg + series: + - metric: virginmedia.upstream.1 + scope: + tag: virginmedia + - metric: virginmedia.upstream.4 + scope: + tag: virginmedia diff --git a/virginmedia/package.yaml b/virginmedia/package.yaml new file mode 100644 index 0000000..1561b8a --- /dev/null +++ b/virginmedia/package.yaml @@ -0,0 +1,8 @@ +title: VirginMedia +author: Russell-IO +version: 1.0.0 +description: Dashboard monitoring speed, power levels & noise +icon: + name: virginmedia + background: "#C12833" + foreground: white diff --git a/virginmedia/plugins/virginmedia.rb b/virginmedia/plugins/virginmedia.rb new file mode 100755 index 0000000..9d27ec8 --- /dev/null +++ b/virginmedia/plugins/virginmedia.rb @@ -0,0 +1,51 @@ +#!/usr/bin/env ruby +require 'nokogiri' +require 'open-uri' + +vm_operational = Nokogiri::HTML(open("http://192.168.100.1/cgi-bin/VmRouterStatusOperationCfgCgi")) do |config| + config.options = Nokogiri::XML::ParseOptions::NOBLANKS | Nokogiri::XML::ParseOptions::NONET +end +vm_downstream = Nokogiri::HTML(open("http://192.168.100.1/cgi-bin/VmRouterStatusDownstreamCfgCgi")) do |config| + config.options = Nokogiri::XML::ParseOptions::NOBLANKS | Nokogiri::XML::ParseOptions::NONET +end +vm_upstream = Nokogiri::HTML(open("http://192.168.100.1/cgi-bin/VmRouterStatusUpstreamCfgCgi")) do |config| + config.options = Nokogiri::XML::ParseOptions::NOBLANKS | Nokogiri::XML::ParseOptions::NONET +end + +# Filter down to the data that we are interested in +vm_download = vm_operational.css("#cableModemDownstream").first.children.children.to_a[5].children.to_a[1].children.to_a +vm_download = vm_download[2].children.to_s.split(" ")[0].to_f / 1024 / 1024 +vm_upload = vm_operational.css("#cableModemDownstream").first.children.children.to_a[8].children.to_a[1].children.to_a +vm_upload = vm_upload[2].children.to_s.split(" ")[0].to_f / 1024 / 1024 +vm_downstream_data = vm_downstream.css("#cableModemDownstream").first.children.children.to_a[3].children.to_a[7].children.to_a +vm_downstream_data = vm_downstream_data.values_at(* vm_downstream_data.each_index.select {|i| i.even?}) +vm_upstream_data = vm_upstream.css("#cableModemDownstream").first.children.children.to_a[3].children.to_a[7].children.to_a +vm_upstream_data = vm_upstream_data.values_at(* vm_upstream_data.each_index.select {|i| i.even?}) + +# Clean up the data +vm_downstream_data.shift +vm_upstream_data.shift + +# Build a fresh array +c = 0; vm_downstream_power_levels = Array.new +vm_downstream_data.each {|i| c += 1; vm_downstream_power_levels.push({c => i.children.to_s})} +c = 0; vm_upstream_power_levels = Array.new +vm_upstream_data.each {|i| c += 1; vm_upstream_power_levels.push({c => i.children.to_s})} + +# Remove invalid enteries in fresh array +vm_downstream_power_levels_clean = Array.new +vm_downstream_power_levels.each {|i| if i.first[1].to_s != 'N/A'; vm_downstream_power_levels_clean.push(i); end } +vm_upstream_power_levels_clean = Array.new +vm_upstream_power_levels.each {|i| if i.first[1].to_s != 'N/A'; vm_upstream_power_levels_clean.push(i); end } + +# Build nagios format output +speed = "download=#{vm_download.round(2)} Mb;;;; upload=#{vm_upload.round(2)} Mb;;;; " +m = nil; a = nil +vm_downstream_power_levels_clean.each {|p| m = m.to_s + 'downstream.' + p.first[0].to_s + '=' + p.first[1].to_s + ';;;; '; a = a.to_f + p.first[1].to_f } +downstream = "#{m}downstream.average=#{(a.to_f / vm_downstream_power_levels_clean.count).round(2)};;;; downstream.channels=#{vm_downstream_power_levels_clean.count};;;; " +m = nil; a = nil +vm_upstream_power_levels_clean.each {|p| m = m.to_s + 'upstream.' + p.first[0].to_s + '=' + p.first[1].to_s + ';;;; '; a = a.to_f + p.first[1].to_f } +upstream = "#{m}upstream.average=#{(a.to_f / vm_upstream_power_levels_clean.count).round(2)};;;; upstream.channels=#{vm_upstream_power_levels_clean.count};;;; " + +# Print out the response +puts "OK | #{speed}#{downstream}#{upstream}" diff --git a/virginmedia/rules/virginmedia.yaml b/virginmedia/rules/virginmedia.yaml new file mode 100644 index 0000000..ab0a486 --- /dev/null +++ b/virginmedia/rules/virginmedia.yaml @@ -0,0 +1,17 @@ +title: Production VirginMedia +criteria: + - metric: virginmedia.downstream.1 + scope: + tag: virginmedia + condition: + timeout: 0 + threshold: 37 + - metric: virginmedia.upstream.1 + scope: + tag: virginmedia + condition: + timeout: 0 + threshold: 47 +actions: + - emails: [] + message: ''