Permalink
Browse files

added riemann-resmon

  • Loading branch information...
1 parent 48d57f7 commit 3855212152ac57cedd24e5834b6dfd5f66a04daf @goblin goblin committed Feb 22, 2013
Showing with 49 additions and 0 deletions.
  1. +49 −0 bin/riemann-resmon
View
@@ -0,0 +1,49 @@
+#!/usr/bin/env ruby
+
+require File.expand_path('../../lib/riemann/tools', __FILE__)
+
+class Riemann::Tools::Resmon
+ include Riemann::Tools
+ require 'nokogiri'
+ require 'faraday'
+
+ opt :resmon_hostfile, 'File with hostnames running Resmon (one URI per line)', type: :string
+
+ def initialize
+ @hosts = File.read(options[:resmon_hostfile]).split("\n")
+ super
+ end
+
+ def tick
+ @hosts.each do |host|
+ uri = URI(host)
+
+ doc = Nokogiri::XML(
+ Faraday.new(uri).get.body
+ )
+
+ results = doc.xpath('//ResmonResults/ResmonResult').each do |result|
+ timestamp = result.xpath('last_update').first.text
+ result.xpath('metric').each do |metric|
+ hash = {
+ host: uri.host,
+ service: "#{result.attributes['module'].value}`#{result.attributes['service'].value}`#{metric.attributes['name'].value}",
+ time: timestamp.to_i
+ }
+ case metric.attributes['type'].value
+ when /[iIlLn]/
+ hash[:metric] = metric.text
+ when 's'
+ hash[:description] = metric.text
+ when '0'
+ raise 'dunno what 0 is yet'
+ end
+
+ report(hash)
+ end
+ end
+ end
+ end
+end
+
+Riemann::Tools::Resmon.run

0 comments on commit 3855212

Please sign in to comment.