sensu-plugin 2.2.0 → 2.3.0

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: 5779d44ecb71e0614dc179fb8ba0db3cd39a3111
4
- data.tar.gz: 10795a0823625575f4b1638984a603a65e406eb6
3
+ metadata.gz: a61eebfc31a5b1110afdbc0931b0f24fae2be0b6
4
+ data.tar.gz: c55bce147df126c8b799f788ccfceeac5b252e53
5
5
  SHA512:
6
- metadata.gz: b00f35a4eb526215f5c1f13f3732ebb35519491176be7a87495d30279389d4d72b843c1004312fface38633bb5a6d20c9dabb135f99c309a90d3e417ce68d7fc
7
- data.tar.gz: 37d95a80143a85142c43b25d7b5651abc71a5fbc6832ee8e2c8350ef443ae8bec75dede44b76541c37082cd24e2b8a30074cfebd4c2dafa16f2387f3ebd5d759
6
+ metadata.gz: 25436cf2246717c5c24b9101878d8de2f107198db84744e8f7338445de53b3dc1032af7a2006766d403ac556f7e8cdbfd40f57d619e4dd6c69dd5f9a037c34c6
7
+ data.tar.gz: 24e159cf2077552ec1cf46e6e973126b533560ff497a9f0168c66dc4b8f89a1f334f0ccb1d1dd7672032b8bd89a7b18ea94b493c59acf680cc575a508bbda716
@@ -1,6 +1,6 @@
1
1
  module Sensu
2
2
  module Plugin
3
- VERSION = '2.2.0'.freeze
3
+ VERSION = '2.3.0'.freeze
4
4
  EXIT_CODES = {
5
5
  'OK' => 0,
6
6
  'WARNING' => 1,
@@ -17,6 +17,14 @@ module Sensu
17
17
  end
18
18
 
19
19
  class Graphite < Sensu::Plugin::CLI
20
+ # Outputs metrics using the Statsd datagram format
21
+ #
22
+ # @param args [Array<String, Int>] list of arguments
23
+ # @note the argument order should be:
24
+ # `metric_path`: Mandatory, name for the metric,
25
+ # `value`: Mandatory, metric value
26
+ # `timestamp`: Optional, unix timestamp, defaults to current time
27
+ # @return [String] formated metric data
20
28
  def output(*args)
21
29
  return if args.empty?
22
30
  if args[0].is_a?(Exception) || args[1].nil?
@@ -29,7 +37,16 @@ module Sensu
29
37
  end
30
38
 
31
39
  class Statsd < Sensu::Plugin::CLI
40
+ # Outputs metrics using the Statsd datagram format
41
+ #
42
+ # @param args [Array<String, Int>] list of arguments
43
+ # @note the argument order should be:
44
+ # `metric_name`: Mandatory, name for the metric,
45
+ # `value`: Mandatory, metric value
46
+ # `type`: Optional, metric type- `c` for counter, `g` for gauge, `ms` for timer, `s` for set
47
+ # @return [String] formated metric data
32
48
  def output(*args)
49
+ return if args.empty?
33
50
  if args[0].is_a?(Exception) || args[1].nil?
34
51
  puts args[0].to_s
35
52
  else
@@ -38,6 +55,55 @@ module Sensu
38
55
  end
39
56
  end
40
57
  end
58
+
59
+ class Dogstatsd < Sensu::Plugin::CLI
60
+ # Outputs metrics using the DogStatsd datagram format
61
+ #
62
+ # @param args [Array<String, Int>] list of arguments
63
+ # @note the argument order should be:
64
+ # `metric_name`: Mandatory, name for the metric,
65
+ # `value`: Mandatory, metric value
66
+ # `type`: Optional, metric type- `c` for counter, `g` for gauge, `ms` for timer, `h` for histogram, `s` for set
67
+ # `tags`: Optional, a comma separated key:value string `tag1:value1,tag2:value2`
68
+ # @return [String] formated metric data
69
+ def output(*args)
70
+ return if args.empty?
71
+ if args[0].is_a?(Exception) || args[1].nil?
72
+ puts args[0].to_s
73
+ else
74
+ type = args[2] || 'kv'
75
+ tags = args[3] ? "##{args[3]}" : nil
76
+ puts [args[0..1].join(':'), type, tags].compact.join('|')
77
+ end
78
+ end
79
+ end
80
+
81
+ class Influxdb < Sensu::Plugin::CLI
82
+ # Outputs metrics using the InfluxDB line protocol format
83
+ #
84
+ # @param args [Array<String, Int>] list of arguments
85
+ # @note the argument order should be:
86
+ # `measurement_name`: Mandatory, name for the InfluxDB measurement,
87
+ # `fields`: Mandatory, either an integer or a comma separated key=value string `field1=value1,field2=value2`
88
+ # `tags`: Optional, a comma separated key=value string `tag1=value1,tag2=value2`
89
+ # `timestamp`: Optional, unix timestamp, defaults to current time
90
+ # @return [String] formated metric data
91
+ def output(*args)
92
+ return if args.empty?
93
+ if args[0].is_a?(Exception) || args[1].nil?
94
+ puts args[0].to_s
95
+ else
96
+ fields = if args[1].is_a?(Integer)
97
+ "value=#{args[1]}"
98
+ else
99
+ args[1]
100
+ end
101
+ measurement = [args[0], args[2]].compact.join(',')
102
+ ts = args[3] || Time.now.to_i
103
+ puts [measurement, fields, ts].join(' ')
104
+ end
105
+ end
106
+ end
41
107
  end
42
108
  end
43
109
  end
@@ -23,7 +23,10 @@ class TestGraphiteMetricExternal < MiniTest::Test
23
23
 
24
24
  def test_multi
25
25
  lines = run_script.split("\n")
26
- assert lines.size == 2 && lines.all? { |line| line.split("\s").size == 3 }
26
+ assert lines.size == 2
27
+ lines.each do |line|
28
+ assert line.split("\s").size == 3
29
+ end
27
30
  end
28
31
  end
29
32
 
@@ -43,3 +46,38 @@ class TestStatsdMetricExternal < MiniTest::Test
43
46
  end
44
47
  end
45
48
  end
49
+
50
+ class TestDogstatsdMetricExternal < MiniTest::Test
51
+ include SensuPluginTestHelper
52
+
53
+ def setup
54
+ set_script 'external/dogstatsd-output'
55
+ end
56
+
57
+ def test_dogstatsd
58
+ lines = run_script.split("\n")
59
+ assert lines.size == 2
60
+ assert lines.last.split('|').last.split(',').size == 2
61
+ lines.each do |line|
62
+ assert line.split('|').size >= 2
63
+ assert line.split('|').first.split(':').size == 2
64
+ end
65
+ end
66
+ end
67
+
68
+ class TestInfluxdbMetricExternal < MiniTest::Test
69
+ include SensuPluginTestHelper
70
+
71
+ def setup
72
+ set_script 'external/influxdb-output'
73
+ end
74
+
75
+ def test_dogstatsd
76
+ lines = run_script.split("\n")
77
+ assert lines.size == 3
78
+ lines.each do |line|
79
+ assert line.split("\s").size == 3
80
+ assert line.split("\s").first.split(',').size == 3
81
+ end
82
+ end
83
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Decklin Foster
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-08-16 00:00:00.000000000 Z
12
+ date: 2017-08-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json