bipbip 0.5.9 → 0.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 940f0155867f0e16e1c4a7c0b7ba8b710b0a0191
4
- data.tar.gz: ffa66de8788189c9774081d1e8a2fe63d085b071
3
+ metadata.gz: cf1d48bb34bcf5158a9389079923fff2fe8eb55f
4
+ data.tar.gz: d02e8c7f9b4edc8379995501390e366507e1a73e
5
5
  SHA512:
6
- metadata.gz: 897fd316611fdd5a84e41299381098b099edb3a1d531a92c950a8ee74aed2352dc3dc96017d127ab700ea75119610fb16e72f79e70ba080584bb8e27b601d10a
7
- data.tar.gz: 3258dfbf44197e4d6c49a7094396a64b9d6a826a2e794c93c7954f5ae38c23a48ec727ca9bc460dffe912872012ce004f59050cdc5afd176eacc1804766e40a2
6
+ metadata.gz: c108d106ff9a506aefbf4b39bcf0d0e90082360f5954b41dc835527c8e0e0bedd934dc3da1acd7dc05f1a42b44dd2de285e15444c01f82f2b884d3b2b688d4ef
7
+ data.tar.gz: 20978afd5260bd4cd32b3ef33c7496ef2411e5b54a90c440e8e0b6e420dea52c238ab5c7baf09638af14fd57b8d9e03dc97850193ce2bea920a8274b0d2034ff
data/README.md CHANGED
@@ -99,6 +99,7 @@ These service plugins ship with bipbip:
99
99
  - postfix
100
100
  - elasticsearch
101
101
  - puppet
102
+ - command
102
103
 
103
104
  Please refer to [/docu/services.md](/docu/services.md) for information about the individual plugins and their configuration options.
104
105
 
data/lib/bipbip/plugin.rb CHANGED
@@ -68,9 +68,9 @@ module Bipbip
68
68
  end
69
69
 
70
70
  def source_identifier
71
- identifier = Bipbip.fqdn
71
+ identifier = Bipbip.fqdn + '::' + metric_group
72
72
  unless config.empty?
73
- identifier += '::' + config.values.first.to_s
73
+ identifier += '::' + config.values.first.to_s.gsub(/[^\w]/, '_')
74
74
  end
75
75
  identifier
76
76
  end
@@ -0,0 +1,67 @@
1
+ require 'open3'
2
+ require 'json'
3
+
4
+ module Bipbip
5
+
6
+ class Plugin::Command < Plugin
7
+
8
+ attr_accessor :schema
9
+
10
+ def metrics_schema
11
+ @schema ||= find_schema
12
+ end
13
+
14
+ def monitor
15
+ Hash[command_output.map { |metric, value| [metric, metric_value(value)] }]
16
+ end
17
+
18
+ private
19
+
20
+ def metric_value(value)
21
+ value = value['value'] if detect_operation_mode(value) == :advanced
22
+ value = 1 if value == 'true' or value == true
23
+ value = 0 if value == 'false' or value == false
24
+ value
25
+ end
26
+
27
+ def find_schema
28
+ command_output.map do |metric, value|
29
+ case detect_operation_mode(value)
30
+ when :simple
31
+ {:name => "#{metric}", :type => 'gauge'}
32
+ when :advanced
33
+ {:name => "#{metric}", :type => value['type'], :unit => value['unit']}
34
+ end
35
+ end
36
+ end
37
+
38
+ def detect_operation_mode(value)
39
+ {true => :advanced, false => :simple}.fetch(value.is_a?(Hash))
40
+ end
41
+
42
+ def command_output
43
+ JSON.parse(exec_command)
44
+ end
45
+
46
+ def exec_command
47
+ command = config['command'].to_s
48
+
49
+ output_stdout = output_stderr = exit_code = nil
50
+ Open3.popen3(command) { |stdin, stdout, stderr, wait_thr|
51
+ output_stdout = stdout.read.chomp
52
+ output_stderr = stderr.read.chomp
53
+ exit_code = wait_thr.value
54
+ }
55
+
56
+ unless exit_code.success?
57
+ message = ['Command execution failed:', command]
58
+ message.push 'STDOUT:', output_stdout unless output_stdout.empty?
59
+ message.push 'STDERR:', output_stderr unless output_stderr.empty?
60
+ raise message.join("\n")
61
+ end
62
+
63
+ output_stdout
64
+ end
65
+
66
+ end
67
+ end
@@ -1,3 +1,3 @@
1
1
  module Bipbip
2
- VERSION = '0.5.9'
2
+ VERSION = '0.5.10'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bipbip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.5.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cargo Media
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-01-12 00:00:00.000000000 Z
13
+ date: 2015-01-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: copperegg
@@ -225,6 +225,7 @@ files:
225
225
  - lib/bipbip/helper.rb
226
226
  - lib/bipbip/plugin.rb
227
227
  - lib/bipbip/plugin/apache2.rb
228
+ - lib/bipbip/plugin/command.rb
228
229
  - lib/bipbip/plugin/elasticsearch.rb
229
230
  - lib/bipbip/plugin/fastcgi_php_apc.rb
230
231
  - lib/bipbip/plugin/fastcgi_php_fpm.rb