fluent-plugin-xymon 0.0.0 → 0.0.1
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 +4 -4
- data/README.md +56 -3
- data/fluent-plugin-xymon.gemspec +1 -1
- data/lib/fluent/plugin/out_xymon.rb +22 -6
- data/spec/lib/fluent/plugin/out_xymon_spec.rb +162 -41
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fd92cc021f3265eab81dc7686fb83e38fd264c90
|
|
4
|
+
data.tar.gz: ef2af36358feff0305086e5203ae306ff58349e0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0083c8f3517f050d65b254314f110838c94e73b4b6ef4e9fcc06454796a8b5276bafc9c21fb93b8171d69be89b4f9b104fd6ab6743555d154f69cb21b08626fc
|
|
7
|
+
data.tar.gz: 777017a4b5d5923aa2244539a98b99e6acb8fcddd0f5358e5b0f74a5f30bdbfc9f56b145dfc266a351e9b7413d0d4a7f52d1920a14760773eae9478012b27188
|
data/README.md
CHANGED
|
@@ -6,7 +6,9 @@ Fluentd output plugin to post message to xymon
|
|
|
6
6
|
|
|
7
7
|
Install gem
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
````
|
|
10
|
+
fluent-gem install fluent-plugin-xymon
|
|
11
|
+
````
|
|
10
12
|
|
|
11
13
|
## config
|
|
12
14
|
|
|
@@ -14,10 +16,57 @@ Install gem
|
|
|
14
16
|
config_param :xymon_server, :string
|
|
15
17
|
config_param :xymon_port, :string, :default => '1984'
|
|
16
18
|
config_param :color, :string, :default => 'green'
|
|
17
|
-
config_param :
|
|
18
|
-
config_param :
|
|
19
|
+
config_param :hostname, :string
|
|
20
|
+
config_param :testname, :string
|
|
19
21
|
config_param :name_key, :string
|
|
22
|
+
config_param :custom_determine_color_code, :string, :default => nil
|
|
23
|
+
````
|
|
24
|
+
|
|
25
|
+
### example
|
|
26
|
+
|
|
27
|
+
<store>
|
|
28
|
+
type xymon
|
|
29
|
+
xymon_server 127.0.0.1
|
|
30
|
+
xymon_port 1984
|
|
31
|
+
color green
|
|
32
|
+
hostname web-server-01
|
|
33
|
+
testname CPU
|
|
34
|
+
name_key CPUUtilization
|
|
35
|
+
custom_determine_color_code if value.to_i > 90; 'red'; else 'green'; end
|
|
36
|
+
</store>
|
|
37
|
+
|
|
38
|
+
## config_param :custom_determine_color_code
|
|
39
|
+
|
|
40
|
+
set ruby code of determinate color to custom_determine_color_code.
|
|
41
|
+
|
|
42
|
+
### Parameter
|
|
43
|
+
|
|
44
|
+
time, record, value
|
|
45
|
+
|
|
46
|
+
### Example
|
|
47
|
+
|
|
48
|
+
#### everytime 'green'
|
|
49
|
+
|
|
50
|
+
````
|
|
51
|
+
custom_determine_color_code return 'green'
|
|
52
|
+
````
|
|
53
|
+
|
|
54
|
+
#### if value > 90 then 'red' else 'green'
|
|
55
|
+
|
|
56
|
+
````
|
|
57
|
+
custom_determine_color_code if value > 90; 'red'; else 'green'; end
|
|
20
58
|
````
|
|
59
|
+
### config_param :color
|
|
60
|
+
|
|
61
|
+
ignore :color if custom_determine_color_code is exist and valid.
|
|
62
|
+
use :color if custom_determine_color_code is noting or invalid
|
|
63
|
+
|
|
64
|
+
### If raise some exception
|
|
65
|
+
|
|
66
|
+
server didn't respond
|
|
67
|
+
|
|
68
|
+
- use config color value
|
|
69
|
+
- write warn log
|
|
21
70
|
|
|
22
71
|
## Contributing
|
|
23
72
|
|
|
@@ -26,3 +75,7 @@ Install gem
|
|
|
26
75
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
27
76
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
28
77
|
5. Create new Pull Request
|
|
78
|
+
|
|
79
|
+
## releases
|
|
80
|
+
2013/08/09 0.0.0 1st release
|
|
81
|
+
2013/08/10 0.0.1 https://github.com/bash0C7/fluent-plugin-xymon/pull/1
|
data/fluent-plugin-xymon.gemspec
CHANGED
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |spec|
|
|
6
6
|
spec.name = "fluent-plugin-xymon"
|
|
7
|
-
spec.version = '0.0.
|
|
7
|
+
spec.version = '0.0.1'
|
|
8
8
|
spec.authors = ["bash0C7"]
|
|
9
9
|
spec.email = ["koshiba+github@4038nullpointer.com"]
|
|
10
10
|
spec.description = "Fluentd output plugin to post message to xymon"
|
|
@@ -10,12 +10,21 @@ module Fluent
|
|
|
10
10
|
config_param :xymon_server, :string
|
|
11
11
|
config_param :xymon_port, :string, :default => '1984'
|
|
12
12
|
config_param :color, :string, :default => 'green'
|
|
13
|
-
config_param :
|
|
14
|
-
config_param :
|
|
13
|
+
config_param :hostname, :string
|
|
14
|
+
config_param :testname, :string
|
|
15
15
|
config_param :name_key, :string
|
|
16
|
+
config_param :custom_determine_color_code, :string, :default => nil
|
|
16
17
|
|
|
17
18
|
def configure(conf)
|
|
18
19
|
super
|
|
20
|
+
|
|
21
|
+
@custom_determine_color = nil
|
|
22
|
+
begin
|
|
23
|
+
@custom_determine_color = eval("lambda {|time, record, value| #{@custom_determine_color_code}}") if @custom_determine_color_code
|
|
24
|
+
rescue Exception
|
|
25
|
+
raise Fluent::ConfigError, "custom_determine_color_code: #{$!.class}, '#{$!.message}'"
|
|
26
|
+
end
|
|
27
|
+
|
|
19
28
|
end
|
|
20
29
|
|
|
21
30
|
def start
|
|
@@ -31,7 +40,7 @@ module Fluent
|
|
|
31
40
|
es.each {|time,record|
|
|
32
41
|
next unless value = record[@name_key]
|
|
33
42
|
|
|
34
|
-
messages.push build_message(time, value)
|
|
43
|
+
messages.push build_message(time, record, value)
|
|
35
44
|
}
|
|
36
45
|
messages.each do |message|
|
|
37
46
|
post(message)
|
|
@@ -40,9 +49,16 @@ module Fluent
|
|
|
40
49
|
chain.next
|
|
41
50
|
end
|
|
42
51
|
|
|
43
|
-
def build_message time, value
|
|
52
|
+
def build_message time, record, value
|
|
53
|
+
begin
|
|
54
|
+
color = @custom_determine_color.call(time, record, value) if @custom_determine_color
|
|
55
|
+
rescue Exception
|
|
56
|
+
$log.warn "raises exception: #{$!.class}, '#{$!.message}', '#{@custom_determine_color_code}', '#{time}', '#{record}', '#{value}'"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
color ||= @color
|
|
44
60
|
body = "#{@name_key}=#{value}"
|
|
45
|
-
message = "status #{@
|
|
61
|
+
message = "status #{@hostname}.#{@testname} #{color} #{Time.at(time)} #{@testname} #{body}\n\n#{body}"
|
|
46
62
|
|
|
47
63
|
message
|
|
48
64
|
end
|
|
@@ -61,4 +77,4 @@ module Fluent
|
|
|
61
77
|
end
|
|
62
78
|
|
|
63
79
|
end
|
|
64
|
-
end
|
|
80
|
+
end
|
|
@@ -1,88 +1,209 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe do
|
|
4
|
-
let(:
|
|
5
|
-
|
|
4
|
+
let(:driver) {Fluent::Test::OutputTestDriver.new(Fluent::XymonOutput, 'test.metrics').configure(config)}
|
|
5
|
+
let(:instance) {driver.instance}
|
|
6
|
+
|
|
7
|
+
describe 'config' do
|
|
8
|
+
let(:config) {
|
|
9
|
+
%[
|
|
6
10
|
xymon_server 127.0.0.1
|
|
7
11
|
xymon_port 1984
|
|
8
|
-
color
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
color red
|
|
13
|
+
hostname host1
|
|
14
|
+
testname column1
|
|
11
15
|
name_key field1
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
let(:driver) {
|
|
16
|
-
Fluent::Test::OutputTestDriver.new(Fluent::XymonOutput, 'test.metrics').configure(config)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
describe 'config' do
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
|
|
20
19
|
context do
|
|
21
|
-
subject {
|
|
20
|
+
subject {instance.xymon_server}
|
|
22
21
|
it{should == '127.0.0.1'}
|
|
23
22
|
end
|
|
24
23
|
|
|
25
24
|
context do
|
|
26
|
-
subject {
|
|
25
|
+
subject {instance.xymon_port}
|
|
27
26
|
it{should == '1984'}
|
|
28
27
|
end
|
|
29
28
|
|
|
30
29
|
context do
|
|
31
|
-
subject {
|
|
30
|
+
subject {instance.color}
|
|
32
31
|
it{should == 'red'}
|
|
33
32
|
end
|
|
34
33
|
|
|
35
34
|
context do
|
|
36
|
-
subject {
|
|
35
|
+
subject {instance.hostname}
|
|
37
36
|
it{should == 'host1'}
|
|
38
37
|
end
|
|
39
38
|
|
|
40
39
|
context do
|
|
41
|
-
subject {
|
|
40
|
+
subject {instance.testname}
|
|
42
41
|
it{should == 'column1'}
|
|
43
42
|
end
|
|
44
43
|
|
|
45
44
|
context do
|
|
46
|
-
subject {
|
|
45
|
+
subject {instance.name_key}
|
|
47
46
|
it{should == 'field1'}
|
|
48
47
|
end
|
|
49
48
|
|
|
49
|
+
describe 'custom_determine_color_code' do
|
|
50
|
+
context 'not_exist' do
|
|
51
|
+
let(:config) {
|
|
52
|
+
%[
|
|
53
|
+
xymon_server 127.0.0.1
|
|
54
|
+
xymon_port 1984
|
|
55
|
+
color red
|
|
56
|
+
hostname host1
|
|
57
|
+
testname column1
|
|
58
|
+
name_key field1
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
subject {instance.custom_determine_color_code}
|
|
63
|
+
it{should be_nil}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
context 'exist custom_determine_color_code' do
|
|
67
|
+
let(:config) {
|
|
68
|
+
%[
|
|
69
|
+
xymon_server 127.0.0.1
|
|
70
|
+
xymon_port 1984
|
|
71
|
+
color red
|
|
72
|
+
hostname host1
|
|
73
|
+
testname column1
|
|
74
|
+
name_key field1
|
|
75
|
+
custom_determine_color_code #{custom_determine_color_code}
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
context 'valid syntax' do
|
|
79
|
+
let(:custom_determine_color_code) {"return 'green'"}
|
|
80
|
+
|
|
81
|
+
subject {instance.custom_determine_color_code}
|
|
82
|
+
it{should == custom_determine_color_code}
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context 'invalid syntax' do
|
|
86
|
+
let(:custom_determine_color_code) {"(><)"}
|
|
87
|
+
|
|
88
|
+
subject {lambda{instance.custom_determine_color_code}}
|
|
89
|
+
it{should raise_error(Fluent::ConfigError)}
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
50
93
|
end
|
|
51
94
|
|
|
52
95
|
describe 'build_message' do
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
96
|
+
let(:name_key) {'field1'}
|
|
97
|
+
|
|
98
|
+
let(:record) {{ name_key => 50, 'otherfield' => 99}}
|
|
99
|
+
let(:time) {0}
|
|
100
|
+
let(:value) {record[name_key]}
|
|
101
|
+
|
|
102
|
+
let(:built) {instance.build_message(time, record, value)}
|
|
103
|
+
context 'empty custom_determine_color_code' do
|
|
104
|
+
let(:config) {
|
|
105
|
+
%[
|
|
106
|
+
xymon_server 127.0.0.1
|
|
107
|
+
xymon_port 1984
|
|
108
|
+
color red
|
|
109
|
+
hostname host1
|
|
110
|
+
testname column1
|
|
111
|
+
name_key field1
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
subject {built}
|
|
116
|
+
it{should == "status #{instance.hostname}.#{instance.testname} #{instance.color} #{Time.at(0)} #{instance.testname} #{instance.name_key}=50\n\n#{instance.name_key}=50"}
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
context 'exist custom_determine_color_code' do
|
|
120
|
+
let(:config) {
|
|
121
|
+
%[
|
|
122
|
+
xymon_server 127.0.0.1
|
|
123
|
+
xymon_port 1984
|
|
124
|
+
color red
|
|
125
|
+
hostname host1
|
|
126
|
+
testname column1
|
|
127
|
+
name_key #{name_key}
|
|
128
|
+
custom_determine_color_code #{custom_determine_color_code}
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
context 'valid custom_determine_color_code' do
|
|
133
|
+
let(:custom_determine_color_code) {"if value.to_i > 90; 'red'; else 'green'; end"}
|
|
134
|
+
|
|
135
|
+
subject {built}
|
|
136
|
+
it{should == "status #{instance.hostname}.#{instance.testname} #{'green'} #{Time.at(time)} #{instance.testname} #{instance.name_key}=#{value}\n\n#{instance.name_key}=#{value}"}
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
context 'invalid syntax custom_determine_color_code' do
|
|
140
|
+
let(:custom_determine_color_code) {'Fluent::XymonOutput::UNDEFINED_CONST'}
|
|
141
|
+
|
|
142
|
+
subject {
|
|
143
|
+
mock($log).warn("raises exception: NameError, 'uninitialized constant #{custom_determine_color_code}', 'Fluent::XymonOutput::UNDEFINED_CONST', '#{time}', '#{record.to_s}', '#{record[name_key]}'").times 1
|
|
144
|
+
built
|
|
145
|
+
}
|
|
146
|
+
it{should == "status #{instance.hostname}.#{instance.testname} #{instance.color} #{Time.at(time)} #{instance.testname} #{instance.name_key}=#{value}\n\n#{instance.name_key}=#{value}"}
|
|
147
|
+
end
|
|
56
148
|
end
|
|
57
149
|
end
|
|
58
150
|
|
|
59
151
|
describe 'emit' do
|
|
60
|
-
|
|
152
|
+
let(:record) {{ 'field1' => 50, 'otherfield' => 99}}
|
|
153
|
+
let(:time) {0}
|
|
61
154
|
let(:posted) {
|
|
62
155
|
d = driver
|
|
63
156
|
mock(IO).popen("nc '#{d.instance.xymon_server}' '#{d.instance.xymon_port}'", 'w').times 1
|
|
64
|
-
d.emit(
|
|
65
|
-
d.run
|
|
157
|
+
d.emit(record, Time.at(time))
|
|
158
|
+
d.run
|
|
66
159
|
}
|
|
67
160
|
|
|
68
|
-
context do
|
|
161
|
+
context 'empty custom_determine_color_code' do
|
|
162
|
+
let(:config) {
|
|
163
|
+
%[
|
|
164
|
+
xymon_server 127.0.0.1
|
|
165
|
+
xymon_port 1984
|
|
166
|
+
color red
|
|
167
|
+
hostname host1
|
|
168
|
+
testname column1
|
|
169
|
+
name_key field1
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
|
|
69
173
|
subject {posted}
|
|
70
174
|
it{should_not be_nil}
|
|
71
175
|
end
|
|
72
176
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
177
|
+
context 'exist custom_determine_color_code' do
|
|
178
|
+
let(:name_key) {'field1'}
|
|
179
|
+
let(:config) {
|
|
180
|
+
%[
|
|
181
|
+
xymon_server 127.0.0.1
|
|
182
|
+
xymon_port 1984
|
|
183
|
+
color red
|
|
184
|
+
hostname host1
|
|
185
|
+
testname column1
|
|
186
|
+
name_key #{name_key}
|
|
187
|
+
custom_determine_color_code #{custom_determine_color_code}
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
context 'valid code' do
|
|
192
|
+
let(:custom_determine_color_code) {"if value.to_i > 90; 'red'; else 'green'; end"}
|
|
193
|
+
|
|
194
|
+
subject {posted}
|
|
195
|
+
it{should_not be_nil}
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
context 'runtime error' do
|
|
199
|
+
let(:custom_determine_color_code) {'Fluent::XymonOutput::UNDEFINED_CONST'}
|
|
200
|
+
|
|
201
|
+
subject {
|
|
202
|
+
mock($log).warn("raises exception: NameError, 'uninitialized constant Fluent::XymonOutput::UNDEFINED_CONST', 'Fluent::XymonOutput::UNDEFINED_CONST', '#{time}', '#{record.to_s}', '#{record[name_key]}'").times 1
|
|
203
|
+
posted
|
|
204
|
+
}
|
|
205
|
+
it{should_not be_nil}
|
|
206
|
+
end
|
|
207
|
+
end
|
|
87
208
|
end
|
|
88
|
-
end
|
|
209
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fluent-plugin-xymon
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- bash0C7
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2013-08-
|
|
11
|
+
date: 2013-08-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: fluentd
|