riemann-tools 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/riemann-haproxy CHANGED
@@ -21,7 +21,7 @@ class Riemann::Tools::Haproxy
21
21
  row = row.to_hash
22
22
  ns = "haproxy #{row['pxname']} #{row['svname']}"
23
23
  row.each do |property, metric|
24
- unless property == 'pxname' || property == 'svname'
24
+ unless (property.nil? || property == 'pxname' || property == 'svname')
25
25
  report(
26
26
  :host => @uri.host,
27
27
  :service => "#{ns} #{property}",
data/bin/riemann-health CHANGED
@@ -62,7 +62,6 @@ class Riemann::Tools::Health
62
62
  end
63
63
 
64
64
  def alert(service, state, metric, description)
65
- puts service
66
65
  report(
67
66
  :service => service.to_s,
68
67
  :state => state.to_s,
data/bin/riemann-resmon CHANGED
@@ -10,13 +10,25 @@ class Riemann::Tools::Resmon
10
10
  opt :resmon_hostfile, 'File with hostnames running Resmon (one URI per line)', type: :string
11
11
  opt :read_timeout, 'Faraday read timeout', type: :int, default: 2
12
12
  opt :open_timeout, 'Faraday open timeout', type: :int, default: 1
13
+ opt :fqdn, 'Use FQDN for event host'
14
+
13
15
 
14
16
  def initialize
15
17
  @hosts = File.read(options[:resmon_hostfile]).split("\n")
16
18
  super
17
19
  end
18
20
 
19
- def safe_get(uri)
21
+
22
+ # Work out the hostname to submit with the event
23
+ def get_event_host(host)
24
+ unless options[:fqdn]
25
+ return host.split('.')[0]
26
+ end
27
+ return host
28
+ end
29
+
30
+ # Handles HTTP connections and GET requests safely
31
+ def safe_get(uri, event_host)
20
32
  # Handle connection timeouts
21
33
  response = nil
22
34
  begin
@@ -26,7 +38,7 @@ class Riemann::Tools::Resmon
26
38
  req.options[:open_timeout] = options[:open_timeout]
27
39
  end
28
40
  rescue => e
29
- report(:host => uri.host,
41
+ report(:host => event_host,
30
42
  :service => "resmon",
31
43
  :state => "critical",
32
44
  :description => "HTTP connection error: #{e.class} - #{e.message}"
@@ -37,14 +49,16 @@ class Riemann::Tools::Resmon
37
49
 
38
50
  def tick
39
51
  @hosts.each do |host|
52
+
40
53
  uri = URI(host)
54
+ event_host = get_event_host(uri.host)
41
55
 
42
- response = safe_get(uri)
56
+ response = safe_get(uri, event_host)
43
57
  next if response.nil?
44
58
 
45
59
  # Handle non-200 responses
46
60
  if response.status != 200
47
- report(:host => uri.host,
61
+ report(:host => event_host,
48
62
  :service => "resmon",
49
63
  :state => "critical",
50
64
  :description => "HTTP connection error: #{response.status} - #{response.body}"
@@ -58,7 +72,7 @@ class Riemann::Tools::Resmon
58
72
  timestamp = result.xpath('last_update').first.text
59
73
  result.xpath('metric').each do |metric|
60
74
  hash = {
61
- host: uri.host,
75
+ host: event_host,
62
76
  service: "#{result.attributes['module'].value}`#{result.attributes['service'].value}`#{metric.attributes['name'].value}",
63
77
  time: timestamp.to_i
64
78
  }
data/lib/riemann/tools.rb CHANGED
@@ -3,6 +3,7 @@ module Riemann
3
3
  require 'rubygems'
4
4
  require 'trollop'
5
5
  require 'riemann/client'
6
+ require 'timeout'
6
7
 
7
8
  def self.included(base)
8
9
  base.instance_eval do
@@ -25,40 +26,38 @@ module Riemann
25
26
  p.parse ARGV
26
27
  end
27
28
  end
28
-
29
+
29
30
  opt :host, "Riemann host", :default => '127.0.0.1'
30
31
  opt :port, "Riemann port", :default => 5555
31
32
  opt :event_host, "Event hostname", :type => String
32
33
  opt :interval, "Seconds between updates", :default => 5
33
34
  opt :tag, "Tag to add to events", :type => String, :multi => true
34
35
  opt :ttl, "TTL for events", :type => Integer
36
+ opt :attribute, "Attribute to add to the event", :type => String, :multi => true
37
+ opt :timeout, "Timeout (in seconds) when waiting for acknowledgements", :default => 30
35
38
  end
36
39
  end
37
40
 
38
- def initialize
39
- super
40
- end
41
-
42
- def tool_options
43
- {}
44
- end
45
-
46
41
  # Returns parsed options (cached) from command line.
47
42
  def options
48
43
  @options ||= self.class.options
49
44
  end
50
45
  alias :opts :options
51
46
 
52
- # Add a new command line option
53
- def opt(*a)
54
- @option_parser.opt *a
47
+ def attributes
48
+ @attributes ||= Hash[options[:attribute].map do |attr|
49
+ k,v = attr.split(/=/)
50
+ if k and v
51
+ [k,v]
52
+ end
53
+ end]
55
54
  end
56
55
 
57
56
  def report(event)
58
57
  if options[:tag]
59
58
  event[:tags] = options[:tag]
60
59
  end
61
-
60
+
62
61
  if options[:ttl]
63
62
  event[:ttl] = options[:ttl]
64
63
  end
@@ -67,7 +66,13 @@ module Riemann
67
66
  event[:host] = options[:event_host]
68
67
  end
69
68
 
70
- riemann << event
69
+ begin
70
+ Timeout::timeout(options[:timeout]) do
71
+ riemann << event.merge(attributes)
72
+ end
73
+ rescue Timeout::Error
74
+ riemann.connect
75
+ end
71
76
  end
72
77
 
73
78
  def riemann
@@ -87,7 +92,7 @@ module Riemann
87
92
  $stderr.puts "#{e.class} #{e}\n#{e.backtrace.join "\n"}"
88
93
  end
89
94
 
90
- # Sleep.
95
+ # Sleep.
91
96
  sleep(options[:interval] - ((Time.now - t0) % options[:interval]))
92
97
  end
93
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riemann-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-30 00:00:00.000000000 Z
12
+ date: 2013-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: riemann-client
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.2.1
21
+ version: 0.2.2
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.2.1
29
+ version: 0.2.2
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: trollop
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -156,7 +156,6 @@ executables:
156
156
  - riemann-diskstats
157
157
  - riemann-riak-ring
158
158
  - riemann-cloudant
159
- - riemann-kvminstances
160
159
  - riemann-nginx-status
161
160
  - riemann-kvminstance
162
161
  - riemann-net
@@ -173,7 +172,6 @@ files:
173
172
  - bin/riemann-haproxy
174
173
  - bin/riemann-health
175
174
  - bin/riemann-kvminstance
176
- - bin/riemann-kvminstances
177
175
  - bin/riemann-memcached
178
176
  - bin/riemann-munin
179
177
  - bin/riemann-net
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.expand_path('../../lib/riemann/tools', __FILE__)
4
-
5
- class Riemann::Tools::KVM
6
- include Riemann::Tools
7
-
8
- def tick
9
-
10
- #determine how many instances I have according to libvirt
11
- kvm_instances = %x[virsh list |grep i-|wc -l]
12
-
13
- #submit them to riemann
14
- report(
15
- :service => "KVM Running VMs",
16
- :metric => kvm_instances.to_i,
17
- :state => "info"
18
- )
19
- end
20
- end
21
-
22
- Riemann::Tools::KVM.run