hq-grapher-icinga-perfdata 0.0.2 → 0.1.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: 94e1914febc5bf7eb434e9a634476d59ff90ad58
4
- data.tar.gz: 80ffd42a36dc9ec3687ddb8943e32c5bb772e5a6
3
+ metadata.gz: aadda9b1c55d62a4b9029e8d11fab54de3bab6ee
4
+ data.tar.gz: 6f6664ca1cf5fa7c0a3c56201936de417eb0639f
5
5
  SHA512:
6
- metadata.gz: c416b9758de0a37597a05b45885c3d392c75ba5dae9105e1e439ecb5aae08794382d70db54948a26c0786cd59238f04c8e605b57d470e77f90e9ed006c6fe3e8
7
- data.tar.gz: 619ed6de4fa96ec8bfa5d283d01aa15150aecaa3e6576f2c206a7003e227f3e422d2936d13bc885356020f654d560126caa6cbb8b65bf5316ec960374133584f
6
+ metadata.gz: 01643e863fab4e1afa55081b0423f6e090d37977705b8f6ea6fb4d6435314100dd1562e210ec636ffb2f5f04b99115b007b257e05a3fd0f79eacdc9da051bec9
7
+ data.tar.gz: 0c10ca11a470d334a85486a293aa974597cd27bbdea914cb7fb530cbcd07f37bb6b05036711be74be5eb0a7d411437af88247e4aac22ac56e74358736517ff58
@@ -0,0 +1,66 @@
1
+ @temp-dir
2
+ Feature: Submit data from provided input
3
+
4
+ Background:
5
+
6
+ Given a file "default.config":
7
+ """
8
+ <hq-grapher-icinga-perfdata-config>
9
+
10
+ <daemon host="dhost" port="dport"/>
11
+
12
+ <mapping name="graph1" host="host1" service="service1">
13
+ <value name="data1"/>
14
+ </mapping>
15
+
16
+ <mapping name="graph2" host="host2" service="service2">
17
+ <value name="data2"/>
18
+ </mapping>
19
+
20
+ <mapping name="graph3" host="host3" service="service3">
21
+ <value name="data3"/>
22
+ <value name="data4"/>
23
+ </mapping>
24
+
25
+ <mapping name="graph4" host="host4" service="service4">
26
+ <value name="data 5"/>
27
+ </mapping>
28
+
29
+ <mapping name="graph5" host="host5" service="service5">
30
+ <value name="data'6"/>
31
+ </mapping>
32
+
33
+ </hq-grapher-icinga-perfdata-config>
34
+ """
35
+
36
+ And a file "default.args":
37
+ """
38
+ --config default.config
39
+ input.data
40
+ """
41
+
42
+ Scenario: Basic example
43
+
44
+ Given a file "input.data":
45
+ """
46
+ 10,host1,service1,data1=20
47
+ 20,host1,service1,data1 = 20
48
+ 30,host1,service1,data1=20
49
+ """
50
+
51
+ When I invoke hq-grapher-icinga-perfdata with "default.args"
52
+
53
+ Then it should submit the following data:
54
+ """
55
+ --daemon dhost:dport graph1.rrd 10:20
56
+ --daemon dhost:dport graph1.rrd 30:20
57
+ """
58
+
59
+ And the command stderr should be:
60
+ """
61
+ Ignoring invalid data on line 2: 20,host1,service1,data1 = 20
62
+ """
63
+
64
+ And the command exit status should be non-zero
65
+
66
+ # vim: et ts=2
@@ -1,3 +1,4 @@
1
+ @temp-dir
1
2
  Feature: Submit data from provided input
2
3
 
3
4
  Background:
@@ -32,6 +33,12 @@ Feature: Submit data from provided input
32
33
  </hq-grapher-icinga-perfdata-config>
33
34
  """
34
35
 
36
+ And a file "default.args":
37
+ """
38
+ --config default.config
39
+ input.data
40
+ """
41
+
35
42
  Scenario: Basic example
36
43
 
37
44
  Given a file "input.data":
@@ -39,25 +46,29 @@ Feature: Submit data from provided input
39
46
  10,host1,service1,data1=20
40
47
  """
41
48
 
42
- When I run hq-grapher-icinga-perfdata "--config default.config input.data"
49
+ When I invoke hq-grapher-icinga-perfdata with "default.args"
43
50
 
44
51
  Then it should submit the following data:
45
52
  """
46
53
  --daemon dhost:dport graph1.rrd 10:20
47
54
  """
48
55
 
56
+ And the command exit status should be 0
57
+
49
58
  Scenario: No lines
50
59
 
51
60
  Given a file "input.data":
52
61
  """
53
62
  """
54
63
 
55
- When I run hq-grapher-icinga-perfdata "--config default.config input.data"
64
+ When I invoke hq-grapher-icinga-perfdata with "default.args"
56
65
 
57
66
  Then it should submit the following data:
58
67
  """
59
68
  """
60
69
 
70
+ And the command exit status should be 0
71
+
61
72
  Scenario: Multiple lines
62
73
 
63
74
  Given a file "input.data":
@@ -66,7 +77,7 @@ Feature: Submit data from provided input
66
77
  30,host2,service2,data2=40
67
78
  """
68
79
 
69
- When I run hq-grapher-icinga-perfdata "--config default.config input.data"
80
+ When I invoke hq-grapher-icinga-perfdata with "default.args"
70
81
 
71
82
  Then it should submit the following data:
72
83
  """
@@ -74,6 +85,8 @@ Feature: Submit data from provided input
74
85
  --daemon dhost:dport graph2.rrd 30:40
75
86
  """
76
87
 
88
+ And the command exit status should be 0
89
+
77
90
  Scenario: Multiple data points
78
91
 
79
92
  Given a file "input.data":
@@ -81,13 +94,15 @@ Feature: Submit data from provided input
81
94
  10,host3,service3,data3=20 data4=30
82
95
  """
83
96
 
84
- When I run hq-grapher-icinga-perfdata "--config default.config input.data"
97
+ When I invoke hq-grapher-icinga-perfdata with "default.args"
85
98
 
86
99
  Then it should submit the following data:
87
100
  """
88
101
  --daemon dhost:dport graph3.rrd 10:20:30
89
102
  """
90
103
 
104
+ And the command exit status should be 0
105
+
91
106
  Scenario: Extra information
92
107
 
93
108
  Given a file "input.data":
@@ -95,13 +110,15 @@ Feature: Submit data from provided input
95
110
  10,host1,service1,data1=20units;30;40;50;60
96
111
  """
97
112
 
98
- When I run hq-grapher-icinga-perfdata "--config default.config input.data"
113
+ When I invoke hq-grapher-icinga-perfdata with "default.args"
99
114
 
100
115
  Then it should submit the following data:
101
116
  """
102
117
  --daemon dhost:dport graph1.rrd 10:20
103
118
  """
104
119
 
120
+ And the command exit status should be 0
121
+
105
122
  Scenario: Space in data name
106
123
 
107
124
  Given a file "input.data":
@@ -109,13 +126,15 @@ Feature: Submit data from provided input
109
126
  10,host4,service4,'data 5'=20
110
127
  """
111
128
 
112
- When I run hq-grapher-icinga-perfdata "--config default.config input.data"
129
+ When I invoke hq-grapher-icinga-perfdata with "default.args"
113
130
 
114
131
  Then it should submit the following data:
115
132
  """
116
133
  --daemon dhost:dport graph4.rrd 10:20
117
134
  """
118
135
 
136
+ And the command exit status should be 0
137
+
119
138
  Scenario: Apostrophe in data name
120
139
 
121
140
  Given a file "input.data":
@@ -123,13 +142,15 @@ Feature: Submit data from provided input
123
142
  10,host5,service5,'data''6'=20
124
143
  """
125
144
 
126
- When I run hq-grapher-icinga-perfdata "--config default.config input.data"
145
+ When I invoke hq-grapher-icinga-perfdata with "default.args"
127
146
 
128
147
  Then it should submit the following data:
129
148
  """
130
149
  --daemon dhost:dport graph5.rrd 10:20
131
150
  """
132
151
 
152
+ And the command exit status should be 0
153
+
133
154
  Scenario: Missing value
134
155
 
135
156
  Given a file "input.data":
@@ -137,13 +158,15 @@ Feature: Submit data from provided input
137
158
  10,host3,service3,data4=30
138
159
  """
139
160
 
140
- When I run hq-grapher-icinga-perfdata "--config default.config input.data"
161
+ When I invoke hq-grapher-icinga-perfdata with "default.args"
141
162
 
142
163
  Then it should submit the following data:
143
164
  """
144
165
  --daemon dhost:dport graph3.rrd 10:U:30
145
166
  """
146
167
 
168
+ And the command exit status should be 0
169
+
147
170
  Scenario: No values
148
171
 
149
172
  Given a file "input.data":
@@ -151,9 +174,11 @@ Feature: Submit data from provided input
151
174
  10,host1,service1,
152
175
  """
153
176
 
154
- When I run hq-grapher-icinga-perfdata "--config default.config input.data"
177
+ When I invoke hq-grapher-icinga-perfdata with "default.args"
155
178
 
156
179
  Then it should submit the following data:
157
180
  """
158
181
  --daemon dhost:dport graph1.rrd 10:U
159
182
  """
183
+
184
+ And the command exit status should be 0
@@ -1,25 +1,11 @@
1
1
  require "cucumber/rspec/doubles"
2
2
 
3
- require "shellwords"
4
- require "tmpdir"
3
+ require "hq/cucumber/command"
4
+ require "hq/cucumber/temp-dir"
5
5
 
6
- require "hq/grapher-icinga-perfdata/script"
7
-
8
- Before do
9
-
10
- # temporary directory
11
-
12
- @olddir = Dir.pwd
13
- @tmpdir = Dir.tmpdir
14
- Dir.chdir @tmpdir
6
+ require "rrd"
15
7
 
16
- end
17
-
18
- After do
19
-
20
- # clean up temporary directory
21
-
22
- Dir.chdir @olddir
23
- FileUtils.rm_rf @tmpdir
8
+ require "hq/grapher-icinga-perfdata/script"
24
9
 
25
- end
10
+ $commands["hq-grapher-icinga-perfdata"] =
11
+ HQ::GrapherIcingaPerfdata::Script
@@ -0,0 +1,17 @@
1
+ # stub rrd update and capture data
2
+
3
+ Before do
4
+
5
+ @rrd_updates = []
6
+
7
+ RRD::Wrapper.stub(:update) do
8
+ |*args|
9
+ @rrd_updates << args.join(" ")
10
+ end
11
+
12
+ end
13
+
14
+ Then /^it should submit the following data:$/ do
15
+ |data_string|
16
+ @rrd_updates.should == data_string.split("\n")
17
+ end
@@ -1,21 +1,18 @@
1
1
  require "rrd"
2
2
  require "xml"
3
3
 
4
+ require "hq/tools/base-script"
4
5
  require "hq/tools/getopt"
5
6
 
6
7
  module HQ
7
8
  module GrapherIcingaPerfdata
8
9
 
9
- class Script
10
-
11
- attr_accessor :args
12
- attr_accessor :status
13
-
14
- attr_accessor :stdout
15
- attr_accessor :stderr
10
+ class Script < Tools::BaseScript
16
11
 
17
12
  def main
18
13
 
14
+ @status = 0
15
+
19
16
  process_args
20
17
 
21
18
  read_config
@@ -25,8 +22,6 @@ class Script
25
22
  process_file filename
26
23
  end
27
24
 
28
- @status = 0
29
-
30
25
  end
31
26
 
32
27
  def process_args
@@ -78,16 +73,33 @@ class Script
78
73
  File.open filename, "r" do
79
74
  |file_io|
80
75
 
76
+ line_number = -1
77
+
81
78
  while line = file_io.gets
82
79
 
80
+ line_number = line_number + 1
81
+
83
82
  timestamp_str, host, service, data_str =
84
83
  line.split ",", 4
85
84
 
86
85
  timestamp = timestamp_str.to_i
87
86
 
88
- data = Hash[
89
- parse_data(data_str),
90
- ]
87
+ data_array = parse_data data_str
88
+
89
+ unless data_array
90
+
91
+ @stderr.puts "Ignoring invalid data on line %s: %s" % [
92
+ line_number + 1,
93
+ line.strip,
94
+ ]
95
+
96
+ @status = 1
97
+
98
+ next
99
+
100
+ end
101
+
102
+ data = Hash[data_array]
91
103
 
92
104
  mapping_key = {
93
105
  host: host,
@@ -118,8 +130,12 @@ class Script
118
130
 
119
131
  def parse_data rest
120
132
 
133
+ # empty string is easy
134
+
121
135
  return [] if rest =~ /^\s*$/
122
136
 
137
+ # get next lot of data using regex
138
+
123
139
  regexp =
124
140
  /^
125
141
  (?:
@@ -134,20 +150,31 @@ class Script
134
150
 
135
151
  match_data = regexp.match rest
136
152
 
137
- return nil unless match_data
153
+ return false unless match_data
138
154
 
139
155
  name = match_data[1] || match_data[2]
140
156
  name.gsub! "''", "'"
141
157
 
142
158
  value = match_data[3]
143
159
 
144
- new_rest = match_data[4]
160
+ new_rest = match_data[4] || ""
161
+
162
+ # parse rest of string recursively
163
+
164
+ new_rest_parsed =
165
+ parse_data new_rest
166
+
167
+ return false \
168
+ unless new_rest_parsed
169
+
170
+ # and return
145
171
 
146
172
  return [
147
173
  [ name, value ],
148
- * new_rest ? parse_data(new_rest) : [],
174
+ * new_rest_parsed,
149
175
  ]
150
176
 
177
+
151
178
  end
152
179
 
153
180
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hq-grapher-icinga-perfdata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Pharaoh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-16 00:00:00.000000000 Z
11
+ date: 2013-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hq-tools
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.0
19
+ version: 0.8.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.3.0
26
+ version: 0.8.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: libxml-ruby
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,89 +53,103 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.2.14
55
55
  - !ruby/object:Gem::Dependency
56
- name: capybara
56
+ name: cucumber
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '>='
60
60
  - !ruby/object:Gem::Version
61
- version: 2.0.2
61
+ version: 1.3.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
- version: 2.0.2
68
+ version: 1.3.1
69
69
  - !ruby/object:Gem::Dependency
70
- name: cucumber
70
+ name: hq-dev
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - '>='
74
88
  - !ruby/object:Gem::Version
75
- version: 1.2.1
89
+ version: 1.7.7
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - '>='
81
95
  - !ruby/object:Gem::Version
82
- version: 1.2.1
96
+ version: 1.7.7
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rake
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - '>='
88
102
  - !ruby/object:Gem::Version
89
- version: 10.0.3
103
+ version: 10.0.4
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - '>='
95
109
  - !ruby/object:Gem::Version
96
- version: 10.0.3
110
+ version: 10.0.4
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rspec
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - '>='
102
116
  - !ruby/object:Gem::Version
103
- version: 2.12.0
117
+ version: 2.13.0
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - '>='
109
123
  - !ruby/object:Gem::Version
110
- version: 2.12.0
124
+ version: 2.13.0
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rspec_junit_formatter
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - '>='
116
130
  - !ruby/object:Gem::Version
117
- version: '0'
131
+ version: 0.1.6
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - '>='
123
137
  - !ruby/object:Gem::Version
124
- version: '0'
138
+ version: 0.1.6
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: simplecov
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
143
  - - '>='
130
144
  - !ruby/object:Gem::Version
131
- version: '0'
145
+ version: 0.7.1
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - '>='
137
151
  - !ruby/object:Gem::Version
138
- version: '0'
152
+ version: 0.7.1
139
153
  description: HQ tool to send icinga perfdata to rrd
140
154
  email:
141
155
  - james@phsys.co.uk
@@ -146,8 +160,9 @@ extra_rdoc_files: []
146
160
  files:
147
161
  - lib/hq/grapher-icinga-perfdata/script.rb
148
162
  - features/submit-data.feature
149
- - features/support/steps.rb
163
+ - features/error-handling.feature
150
164
  - features/support/env.rb
165
+ - features/support/rrd.rb
151
166
  - bin/hq-grapher-icinga-perfdata
152
167
  homepage: https://github.com/jamespharaoh/hq-grapher-icinga-perfdata
153
168
  licenses: []
@@ -168,11 +183,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
183
  version: 1.3.6
169
184
  requirements: []
170
185
  rubyforge_project: hq-grapher-icinga-perfdata
171
- rubygems_version: 2.0.0
186
+ rubygems_version: 2.0.3
172
187
  signing_key:
173
188
  specification_version: 4
174
- summary: HQ grapher icinga perffdata
189
+ summary: HQ grapher icinga perfdata
175
190
  test_files:
176
191
  - features/submit-data.feature
177
- - features/support/steps.rb
192
+ - features/error-handling.feature
178
193
  - features/support/env.rb
194
+ - features/support/rrd.rb
@@ -1,30 +0,0 @@
1
- Given /^a file "(.*?)":$/ do
2
- |file_name, file_contents|
3
-
4
- File.open file_name, "w" do
5
- |file_io|
6
- file_io.print file_contents
7
- end
8
-
9
- end
10
-
11
- When /^I run hq-grapher-icinga-perfdata "(.*?)"$/ do
12
- |args_string|
13
-
14
- @script = HQ::GrapherIcingaPerfdata::Script.new
15
- @script.args = Shellwords.split args_string
16
-
17
- @rrd_updates = []
18
- RRD::Wrapper.stub(:update) do
19
- |*args|
20
- @rrd_updates << args.join(" ")
21
- end
22
-
23
- @script.main
24
-
25
- end
26
-
27
- Then /^it should submit the following data:$/ do
28
- |data_string|
29
- @rrd_updates.should == data_string.split("\n")
30
- end