Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added riemann-resmon

  • Loading branch information...
commit 3855212152ac57cedd24e5834b6dfd5f66a04daf 1 parent 48d57f7
goblin goblin authored

Showing 1 changed file with 49 additions and 0 deletions. Show diff stats Hide diff stats

  1. +49 0 bin/riemann-resmon
49 bin/riemann-resmon
... ... @@ -0,0 +1,49 @@
  1 +#!/usr/bin/env ruby
  2 +
  3 +require File.expand_path('../../lib/riemann/tools', __FILE__)
  4 +
  5 +class Riemann::Tools::Resmon
  6 + include Riemann::Tools
  7 + require 'nokogiri'
  8 + require 'faraday'
  9 +
  10 + opt :resmon_hostfile, 'File with hostnames running Resmon (one URI per line)', type: :string
  11 +
  12 + def initialize
  13 + @hosts = File.read(options[:resmon_hostfile]).split("\n")
  14 + super
  15 + end
  16 +
  17 + def tick
  18 + @hosts.each do |host|
  19 + uri = URI(host)
  20 +
  21 + doc = Nokogiri::XML(
  22 + Faraday.new(uri).get.body
  23 + )
  24 +
  25 + results = doc.xpath('//ResmonResults/ResmonResult').each do |result|
  26 + timestamp = result.xpath('last_update').first.text
  27 + result.xpath('metric').each do |metric|
  28 + hash = {
  29 + host: uri.host,
  30 + service: "#{result.attributes['module'].value}`#{result.attributes['service'].value}`#{metric.attributes['name'].value}",
  31 + time: timestamp.to_i
  32 + }
  33 + case metric.attributes['type'].value
  34 + when /[iIlLn]/
  35 + hash[:metric] = metric.text
  36 + when 's'
  37 + hash[:description] = metric.text
  38 + when '0'
  39 + raise 'dunno what 0 is yet'
  40 + end
  41 +
  42 + report(hash)
  43 + end
  44 + end
  45 + end
  46 + end
  47 +end
  48 +
  49 +Riemann::Tools::Resmon.run

0 comments on commit 3855212

Please sign in to comment.
Something went wrong with that request. Please try again.