hq-grapher-icinga-perfdata 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/features/submit-data.feature +159 -0
- data/features/support/env.rb +25 -0
- data/features/support/steps.rb +30 -0
- data/lib/hq/grapher-icinga-perfdata/script.rb +156 -0
- metadata +176 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bba3199231ea9bcfe2452b6be48f0a99a5fd03c0
|
4
|
+
data.tar.gz: 282c44ab80be3ab1a62a9e7b411ca736b61398c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 578f4394a1acd6fc0850f91661807b0677705f814ee646a43781afc676d0d2c2fa745408699d4361c7008efd87d871aae0e2fca09a07d8a15e4d5d274c729a04
|
7
|
+
data.tar.gz: 10d3962a8b00098e4a69a22d372dc41fa643b84b02e5590a4b1b217db77f6f6045c6994756a30933608508ab5de84c8a49e3405631f723a55023612c9ea33d77
|
@@ -0,0 +1,159 @@
|
|
1
|
+
Feature: Submit data from provided input
|
2
|
+
|
3
|
+
Background:
|
4
|
+
|
5
|
+
Given a file "default.config":
|
6
|
+
"""
|
7
|
+
<hq-grapher-icinga-perfdata-config>
|
8
|
+
|
9
|
+
<daemon host="dhost" port="dport"/>
|
10
|
+
|
11
|
+
<mapping name="graph1" host="host1" service="service1">
|
12
|
+
<value name="data1"/>
|
13
|
+
</mapping>
|
14
|
+
|
15
|
+
<mapping name="graph2" host="host2" service="service2">
|
16
|
+
<value name="data2"/>
|
17
|
+
</mapping>
|
18
|
+
|
19
|
+
<mapping name="graph3" host="host3" service="service3">
|
20
|
+
<value name="data3"/>
|
21
|
+
<value name="data4"/>
|
22
|
+
</mapping>
|
23
|
+
|
24
|
+
<mapping name="graph4" host="host4" service="service4">
|
25
|
+
<value name="data 5"/>
|
26
|
+
</mapping>
|
27
|
+
|
28
|
+
<mapping name="graph5" host="host5" service="service5">
|
29
|
+
<value name="data'6"/>
|
30
|
+
</mapping>
|
31
|
+
|
32
|
+
</hq-grapher-icinga-perfdata-config>
|
33
|
+
"""
|
34
|
+
|
35
|
+
Scenario: Basic example
|
36
|
+
|
37
|
+
Given a file "input.data":
|
38
|
+
"""
|
39
|
+
10,host1,service1,data1=20
|
40
|
+
"""
|
41
|
+
|
42
|
+
When I run hq-grapher-icinga-perfdata "--config default.config input.data"
|
43
|
+
|
44
|
+
Then it should submit the following data:
|
45
|
+
"""
|
46
|
+
--daemon dhost:dport graph1.rrd 10:20
|
47
|
+
"""
|
48
|
+
|
49
|
+
Scenario: No lines
|
50
|
+
|
51
|
+
Given a file "input.data":
|
52
|
+
"""
|
53
|
+
"""
|
54
|
+
|
55
|
+
When I run hq-grapher-icinga-perfdata "--config default.config input.data"
|
56
|
+
|
57
|
+
Then it should submit the following data:
|
58
|
+
"""
|
59
|
+
"""
|
60
|
+
|
61
|
+
Scenario: Multiple lines
|
62
|
+
|
63
|
+
Given a file "input.data":
|
64
|
+
"""
|
65
|
+
10,host1,service1,data1=20
|
66
|
+
30,host2,service2,data2=40
|
67
|
+
"""
|
68
|
+
|
69
|
+
When I run hq-grapher-icinga-perfdata "--config default.config input.data"
|
70
|
+
|
71
|
+
Then it should submit the following data:
|
72
|
+
"""
|
73
|
+
--daemon dhost:dport graph1.rrd 10:20
|
74
|
+
--daemon dhost:dport graph2.rrd 30:40
|
75
|
+
"""
|
76
|
+
|
77
|
+
Scenario: Multiple data points
|
78
|
+
|
79
|
+
Given a file "input.data":
|
80
|
+
"""
|
81
|
+
10,host3,service3,data3=20 data4=30
|
82
|
+
"""
|
83
|
+
|
84
|
+
When I run hq-grapher-icinga-perfdata "--config default.config input.data"
|
85
|
+
|
86
|
+
Then it should submit the following data:
|
87
|
+
"""
|
88
|
+
--daemon dhost:dport graph3.rrd 10:20:30
|
89
|
+
"""
|
90
|
+
|
91
|
+
Scenario: Extra information
|
92
|
+
|
93
|
+
Given a file "input.data":
|
94
|
+
"""
|
95
|
+
10,host1,service1,data1=20units;30;40;50;60
|
96
|
+
"""
|
97
|
+
|
98
|
+
When I run hq-grapher-icinga-perfdata "--config default.config input.data"
|
99
|
+
|
100
|
+
Then it should submit the following data:
|
101
|
+
"""
|
102
|
+
--daemon dhost:dport graph1.rrd 10:20
|
103
|
+
"""
|
104
|
+
|
105
|
+
Scenario: Space in data name
|
106
|
+
|
107
|
+
Given a file "input.data":
|
108
|
+
"""
|
109
|
+
10,host4,service4,'data 5'=20
|
110
|
+
"""
|
111
|
+
|
112
|
+
When I run hq-grapher-icinga-perfdata "--config default.config input.data"
|
113
|
+
|
114
|
+
Then it should submit the following data:
|
115
|
+
"""
|
116
|
+
--daemon dhost:dport graph4.rrd 10:20
|
117
|
+
"""
|
118
|
+
|
119
|
+
Scenario: Apostrophe in data name
|
120
|
+
|
121
|
+
Given a file "input.data":
|
122
|
+
"""
|
123
|
+
10,host5,service5,'data''6'=20
|
124
|
+
"""
|
125
|
+
|
126
|
+
When I run hq-grapher-icinga-perfdata "--config default.config input.data"
|
127
|
+
|
128
|
+
Then it should submit the following data:
|
129
|
+
"""
|
130
|
+
--daemon dhost:dport graph5.rrd 10:20
|
131
|
+
"""
|
132
|
+
|
133
|
+
Scenario: Missing value
|
134
|
+
|
135
|
+
Given a file "input.data":
|
136
|
+
"""
|
137
|
+
10,host3,service3,data4=30
|
138
|
+
"""
|
139
|
+
|
140
|
+
When I run hq-grapher-icinga-perfdata "--config default.config input.data"
|
141
|
+
|
142
|
+
Then it should submit the following data:
|
143
|
+
"""
|
144
|
+
--daemon dhost:dport graph3.rrd 10:U:30
|
145
|
+
"""
|
146
|
+
|
147
|
+
Scenario: No values
|
148
|
+
|
149
|
+
Given a file "input.data":
|
150
|
+
"""
|
151
|
+
10,host1,service1,
|
152
|
+
"""
|
153
|
+
|
154
|
+
When I run hq-grapher-icinga-perfdata "--config default.config input.data"
|
155
|
+
|
156
|
+
Then it should submit the following data:
|
157
|
+
"""
|
158
|
+
--daemon dhost:dport graph1.rrd 10:U
|
159
|
+
"""
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "cucumber/rspec/doubles"
|
2
|
+
|
3
|
+
require "shellwords"
|
4
|
+
require "tmpdir"
|
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
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
After do
|
19
|
+
|
20
|
+
# clean up temporary directory
|
21
|
+
|
22
|
+
Dir.chdir @olddir
|
23
|
+
FileUtils.rm_rf @tmpdir
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,30 @@
|
|
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.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
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require "rrd"
|
2
|
+
require "xml"
|
3
|
+
|
4
|
+
require "hq/tools/getopt"
|
5
|
+
|
6
|
+
module HQ
|
7
|
+
module GrapherIcingaPerfdata
|
8
|
+
|
9
|
+
class Script
|
10
|
+
|
11
|
+
attr_accessor :args
|
12
|
+
attr_accessor :status
|
13
|
+
|
14
|
+
attr_accessor :stdout
|
15
|
+
attr_accessor :stderr
|
16
|
+
|
17
|
+
def main
|
18
|
+
|
19
|
+
process_args
|
20
|
+
|
21
|
+
read_config
|
22
|
+
|
23
|
+
@args.each do
|
24
|
+
|filename|
|
25
|
+
process_file filename
|
26
|
+
end
|
27
|
+
|
28
|
+
@status = 0
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def process_args
|
33
|
+
|
34
|
+
@opts, @args =
|
35
|
+
Tools::Getopt.process @args, [
|
36
|
+
|
37
|
+
{ :name => :config,
|
38
|
+
:required => true },
|
39
|
+
|
40
|
+
]
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
def read_config
|
45
|
+
|
46
|
+
config_doc =
|
47
|
+
XML::Document.file @opts[:config]
|
48
|
+
|
49
|
+
@config_elem =
|
50
|
+
config_doc.root
|
51
|
+
|
52
|
+
@daemon_elem =
|
53
|
+
@config_elem.find_first("daemon")
|
54
|
+
|
55
|
+
@mappings = Hash[
|
56
|
+
@config_elem.find("mapping").map {
|
57
|
+
|mapping_elem|
|
58
|
+
[
|
59
|
+
{
|
60
|
+
host: mapping_elem["host"],
|
61
|
+
service: mapping_elem["service"],
|
62
|
+
},
|
63
|
+
{
|
64
|
+
name: mapping_elem["name"],
|
65
|
+
values: mapping_elem.find("value").map {
|
66
|
+
|value_elem|
|
67
|
+
value_elem["name"]
|
68
|
+
}
|
69
|
+
},
|
70
|
+
]
|
71
|
+
}
|
72
|
+
]
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
def process_file filename
|
77
|
+
|
78
|
+
File.open filename, "r" do
|
79
|
+
|file_io|
|
80
|
+
|
81
|
+
while line = file_io.gets
|
82
|
+
|
83
|
+
timestamp_str, host, service, data_str =
|
84
|
+
line.split ",", 4
|
85
|
+
|
86
|
+
timestamp = timestamp_str.to_i
|
87
|
+
|
88
|
+
data = Hash[
|
89
|
+
parse_data(data_str),
|
90
|
+
]
|
91
|
+
|
92
|
+
mapping_key = {
|
93
|
+
host: host,
|
94
|
+
service: service,
|
95
|
+
}
|
96
|
+
|
97
|
+
mapping = @mappings[mapping_key]
|
98
|
+
|
99
|
+
next unless mapping
|
100
|
+
|
101
|
+
RRD.update \
|
102
|
+
"--daemon",
|
103
|
+
"%s:%s" % [
|
104
|
+
@daemon_elem["host"],
|
105
|
+
@daemon_elem["port"],
|
106
|
+
],
|
107
|
+
"%s.rrd" % mapping[:name],
|
108
|
+
[
|
109
|
+
timestamp_str,
|
110
|
+
* mapping[:values].map { |name| data[name] || "U" },
|
111
|
+
].join(":")
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
def parse_data rest
|
120
|
+
|
121
|
+
return [] if rest =~ /^\s*$/
|
122
|
+
|
123
|
+
regexp =
|
124
|
+
/^
|
125
|
+
(?:
|
126
|
+
([^' ]+)
|
127
|
+
|
|
128
|
+
'((?:[^']|'')*)'
|
129
|
+
) =
|
130
|
+
(-?\d+(?:\.[\d]+)?)
|
131
|
+
(?:\S*)
|
132
|
+
(?:\s(.+))?
|
133
|
+
$/x
|
134
|
+
|
135
|
+
match_data = regexp.match rest
|
136
|
+
|
137
|
+
return nil unless match_data
|
138
|
+
|
139
|
+
name = match_data[1] || match_data[2]
|
140
|
+
name.gsub! "''", "'"
|
141
|
+
|
142
|
+
value = match_data[3]
|
143
|
+
|
144
|
+
new_rest = match_data[4]
|
145
|
+
|
146
|
+
return [
|
147
|
+
[ name, value ],
|
148
|
+
* new_rest ? parse_data(new_rest) : [],
|
149
|
+
]
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
end
|
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hq-grapher-icinga-perfdata
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Pharaoh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hq-tools
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.3.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.3.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: libxml-ruby
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.6.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.6.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rrd-ffi
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.2.14
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.2.14
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: capybara
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: cucumber
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.2.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.2.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 10.0.3
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 10.0.3
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.12.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.12.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec_junit_formatter
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: HQ tool to send icinga perfdata to rrd
|
140
|
+
email:
|
141
|
+
- james@phsys.co.uk
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- lib/hq/grapher-icinga-perfdata/script.rb
|
147
|
+
- features/submit-data.feature
|
148
|
+
- features/support/steps.rb
|
149
|
+
- features/support/env.rb
|
150
|
+
homepage: https://github.com/jamespharaoh/hq-grapher-icinga-perfdata
|
151
|
+
licenses: []
|
152
|
+
metadata: {}
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - '>='
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 1.3.6
|
167
|
+
requirements: []
|
168
|
+
rubyforge_project: hq-grapher-icinga-perfdata
|
169
|
+
rubygems_version: 2.0.0
|
170
|
+
signing_key:
|
171
|
+
specification_version: 4
|
172
|
+
summary: HQ grapher icinga perffdata
|
173
|
+
test_files:
|
174
|
+
- features/submit-data.feature
|
175
|
+
- features/support/steps.rb
|
176
|
+
- features/support/env.rb
|