fluent-plugin-ping-message 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d22f7754cde3ac1dfd63bebc4a11d243a640490
4
- data.tar.gz: 35b803259bd8b3b6d1ae2bbefa8a1a7fb8a54966
3
+ metadata.gz: a8b9231870fecfb91df01d5f379a8324e1538799
4
+ data.tar.gz: b5ba524177f55d2dc40216ad7e386b145f726200
5
5
  SHA512:
6
- metadata.gz: f2ef631013df77f26d826cbaf59e9725c304d1209b63ba379ead64e0776cbba9278d62a4dbf3e70a70d6ff21bd7bacd3621094a7df21c4a7acf1e9924a1e458f
7
- data.tar.gz: 07b97be23c0f7d869989f5a9d33138d663ef7bd5c3fe4864b74a9493225a52f5210fc3018e8a358e924987b1a6bf9303f29f32b8bcb71c145659cebea2aac288
6
+ metadata.gz: 22aca6fb111b552b6a10be0bb0291ffbc5c5fb727fc5cc6d77df538d263ae44f21d2df50da125c916b1ae780fa47feb4baf3b6df1ae5ab06face873d220f770f
7
+ data.tar.gz: ac4eb11ce057a2f6b1ad724598b6314b3a98d9ac44407f303f2e2efe6809e2b183374d26e8f4fe29df69b30ee700c0333a2be2a1746acb71563bcbdeb852f2e1
@@ -3,6 +3,7 @@ language: ruby
3
3
  rvm:
4
4
  - 2.1
5
5
  - 2.2
6
+ - 2.3.1
6
7
 
7
8
  gemfile:
8
9
  - Gemfile
data/README.md CHANGED
@@ -13,20 +13,63 @@ To generate 1 ping message per 60seconds(default):
13
13
 
14
14
  <source>
15
15
  @type ping_message
16
+ @label @heartbeat_events
16
17
  </source>
17
- #=> tag: 'ping'
18
- # message: {'data' => 'your.hostname.local'}
18
+
19
+ <label @heartbeat_events>
20
+ #=> tag: 'ping'
21
+ # message: {'data' => 'your.hostname.local'}
22
+ <match ping>
23
+ # send hosts w/ ping_message_checker
24
+ </match>
25
+ </label>
19
26
 
20
27
  Change ping message interval into 30 seconds, and fix `tag` and `data`:
21
28
 
22
29
  <source>
23
30
  @type ping_message
31
+ @label @heartbeat_events
24
32
  tag ping.webserver
25
33
  interval 30
26
34
  data ping message from ${hostname}
27
35
  </source>
28
- #=> tag: 'ping.webserver'
29
- # message: {'data' => 'ping message from your.hostname.local'}
36
+
37
+ <label @heartbeat_events>
38
+ #=> tag: 'ping.webserver'
39
+ # message: {'data' => 'ping message from your.hostname.local'}
40
+ </label>
41
+
42
+ `<inject>` section is available to include hostname key or timestamp (unixtime, float or string).
43
+
44
+ <source>
45
+ @type ping_message
46
+ @label @heartbeat_events
47
+ tag ping
48
+ interval 30
49
+ data "this is ping message"
50
+ <inject>
51
+ hostname_key host # {"host": "my.hostname.example.com"}
52
+ time_key time
53
+ time_type unixtime # {"time": 1486014439}
54
+ </inject>
55
+ </source>
56
+
57
+ Example using string time format in specified time zone:
58
+
59
+ <source>
60
+ @type ping_message
61
+ @label @heartbeat_events
62
+ tag ping
63
+ interval 30
64
+ data "this is ping message"
65
+ <inject>
66
+ hostname_key host # {"host": "my.hostname.example.com"}
67
+ time_key time
68
+ time_type string
69
+ time_format "%Y-%m-%d %H:%M:%S" # {"time": "2017-02-01 14:50:38"}
70
+ timezone -0700 # or "localtime yes" / "localtime no" (UTC), ...
71
+ </inject>
72
+ </source>
30
73
 
31
74
  ### PingMessageCheckerOutput
32
75
 
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |gem|
3
3
  gem.name = "fluent-plugin-ping-message"
4
- gem.version = "0.2.1"
4
+ gem.version = "1.0.0"
5
5
  gem.authors = ["TAGOMORI Satoshi"]
6
6
  gem.email = ["tagomoris@gmail.com"]
7
7
  gem.description = %q{for heartbeat monitoring of Fluentd processes}
@@ -14,8 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
15
  gem.require_paths = ["lib"]
16
16
 
17
- gem.add_runtime_dependency "fluentd", "< 0.14.0"
18
- gem.add_runtime_dependency "fluent-mixin-config-placeholders", ">= 0.3.0"
17
+ gem.add_runtime_dependency "fluentd", ">= 0.14.0"
19
18
  gem.add_development_dependency "rake"
20
19
  gem.add_development_dependency "test-unit", "~> 3.0"
21
20
  end
@@ -1,49 +1,35 @@
1
- require 'fluent/input'
2
- require 'fluent/mixin/config_placeholders'
1
+ require 'fluent/plugin/input'
2
+ require 'socket'
3
3
 
4
- class Fluent::PingMessageInput < Fluent::Input
4
+ class Fluent::Plugin::PingMessageInput < Fluent::Plugin::Input
5
5
  Fluent::Plugin.register_input('ping_message', self)
6
6
 
7
- # Define `log` method for v0.10.42 or earlier
8
- unless method_defined?(:log)
9
- define_method("log") { $log }
10
- end
11
-
12
- include Fluent::Mixin::ConfigPlaceholders
13
-
14
- config_param :tag, :string, :default => 'ping'
15
- config_param :interval, :integer, :default => 60
16
- config_param :data, :string, :default => `hostname`.chomp
7
+ helpers :timer, :inject
17
8
 
18
- # Define `router` method of v0.12 to support v0.10.57 or earlier
19
- unless method_defined?(:router)
20
- define_method("router") { Fluent::Engine }
21
- end
9
+ config_param :tag, :string, default: 'ping'
10
+ config_param :interval, :integer, default: 60
11
+ config_param :data, :string, default: Socket.gethostname
12
+ config_param :hostname, :string, default: nil
22
13
 
23
- def start
14
+ def configure(conf)
24
15
  super
25
- start_pingloop
26
- end
27
16
 
28
- def shutdown
29
- super
30
- @loop.terminate
31
- @loop.join
17
+ if @data.include?('${hostname}')
18
+ @hostname ||= Socket.gethostname
19
+ @data.gsub!('${hostname}', @hostname)
20
+ end
32
21
  end
33
22
 
34
- def start_pingloop
35
- @loop = Thread.new(&method(:pingloop))
23
+ def multi_workers_ready?
24
+ true
36
25
  end
37
26
 
38
- def pingloop
39
- @last_checked = Fluent::Engine.now
40
- loop do
41
- sleep 0.5
42
- if Fluent::Engine.now - @last_checked >= @interval
43
- @last_checked = Fluent::Engine.now
44
- router.emit(@tag, Fluent::Engine.now, {'data' => @data})
45
- end
27
+ def start
28
+ super
29
+ timer_execute(:in_ping_message_pingpong, @interval) do
30
+ now = Fluent::Engine.now
31
+ record = inject_values_to_record(@tag, now, {'data' => @data})
32
+ router.emit(@tag, now, record)
46
33
  end
47
34
  end
48
-
49
35
  end
@@ -1,37 +1,27 @@
1
- require 'fluent/mixin/config_placeholders'
1
+ require 'fluent/plugin/output'
2
2
 
3
- class Fluent::PingMessageCheckerOutput < Fluent::Output
3
+ class Fluent::Plugin::PingMessageCheckerOutput < Fluent::Plugin::Output
4
4
  Fluent::Plugin.register_output('ping_message_checker', self)
5
5
 
6
- # Define `log` method for v0.10.42 or earlier
7
- unless method_defined?(:log)
8
- define_method("log") { $log }
9
- end
10
-
11
- # Define `router` method of v0.12 to support v0.10.57 or earlier
12
- unless method_defined?(:router)
13
- define_method("router") { Fluent::Engine }
14
- end
15
-
16
- config_param :data_field, :string, :default => 'data'
6
+ helpers :event_emitter, :timer
17
7
 
18
8
  config_param :tag, :string
9
+ config_param :data_field, :string, default: 'data'
10
+ config_param :notifications, :bool, default: true
19
11
 
20
- config_param :notifications, :bool, :default => true
21
- # config_param :report_list, :bool, :default => false # not implemented now
22
-
23
- config_param :check_interval, :integer, :default => 3600
24
- config_param :notification_times, :integer, :default => 3
25
-
26
- config_param :exclude_pattern, :string, :default => nil
27
-
28
- include Fluent::Mixin::ConfigPlaceholders
12
+ config_param :check_interval, :time, default: 3600
13
+ config_param :notification_times, :integer, default: 3
14
+ config_param :exclude_pattern, :string, default: nil
29
15
 
30
16
  def configure(conf)
31
17
  super
32
18
  @exclude_regex = @exclude_pattern ? Regexp.compile(@exclude_pattern) : nil
33
19
  end
34
20
 
21
+ def multi_workers_ready?
22
+ true
23
+ end
24
+
35
25
  def start
36
26
  super
37
27
  @checks = {}
@@ -40,17 +30,26 @@ class Fluent::PingMessageCheckerOutput < Fluent::Output
40
30
  # 0: checked in this term
41
31
  # 1,2,...: counts of ping missing notifications
42
32
  @mutex = Mutex.new
43
- start_watch
44
- end
45
-
46
- def shutdown
47
- super
48
- @watcher.terminate
49
- @watcher.join
33
+ timer_execute(:out_ping_messager_chacker_timer, @check_interval) do
34
+ begin
35
+ check_and_flush
36
+ rescue => e
37
+ log.warn "unexpected error", error: e
38
+ log.warn_backtrace
39
+ end
40
+ end
50
41
  end
51
42
 
52
- def start_watch
53
- @watcher = Thread.new(&method(:watch))
43
+ def process(tag, es)
44
+ datalist = []
45
+ es.each do |time,record|
46
+ datalist.push record[@data_field] if @exclude_regex.nil? or not @exclude_regex.match(record[@data_field])
47
+ end
48
+ datalist.uniq!
49
+ update_state(datalist)
50
+ rescue => e
51
+ log.warn "unexpected error while processing events", error: e
52
+ log.warn_backtrace
54
53
  end
55
54
 
56
55
  def update_state(list)
@@ -85,7 +84,7 @@ class Fluent::PingMessageCheckerOutput < Fluent::Output
85
84
  end
86
85
  end
87
86
  end
88
-
87
+
89
88
  if @notifications
90
89
  notifications.each do |data|
91
90
  router.emit(@tag, Fluent::Engine.now, {@data_field => data})
@@ -94,32 +93,4 @@ class Fluent::PingMessageCheckerOutput < Fluent::Output
94
93
 
95
94
  notifications
96
95
  end
97
-
98
- def watch
99
- @last_checked = Fluent::Engine.now
100
- loop do
101
- sleep 1
102
- begin
103
- if Fluent::Engine.now - @last_checked >= @check_interval
104
- check_and_flush()
105
- @last_checked = Fluent::Engine.now
106
- end
107
- rescue => e
108
- log.warn "out_ping_message_checker: #{e.class} #{e.message} #{e.backtrace.first}"
109
- end
110
- end
111
- end
112
-
113
- def emit(tag, es, chain)
114
- datalist = []
115
- es.each do |time,record|
116
- datalist.push record[@data_field] if @exclude_regex.nil? or not @exclude_regex.match(record[@data_field])
117
- end
118
- datalist.uniq!
119
- update_state(datalist)
120
-
121
- chain.next
122
- rescue => e
123
- log.warn "out_ping_message_checker: #{e.message} #{e.class} #{e.backtrace.first}"
124
- end
125
96
  end
@@ -0,0 +1,25 @@
1
+ require 'helper'
2
+ require 'fluent/test/driver/input'
3
+
4
+ class PingMessageCheckerInputTest < Test::Unit::TestCase
5
+ def setup
6
+ Fluent::Test.setup
7
+ end
8
+
9
+ CONFIG = %[
10
+ tag ping.message
11
+ ]
12
+
13
+ def create_driver(conf = CONFIG)
14
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::PingMessageInput).configure(conf)
15
+ end
16
+
17
+ def test_configure
18
+ assert_nothing_raised {
19
+ create_driver(CONFIG)
20
+ }
21
+ assert_nothing_raised {
22
+ create_driver('')
23
+ }
24
+ end
25
+ end
@@ -1,4 +1,5 @@
1
1
  require 'helper'
2
+ require 'fluent/test/driver/output'
2
3
 
3
4
  class PingMessageCheckerOutputTest < Test::Unit::TestCase
4
5
  def setup
@@ -9,38 +10,38 @@ class PingMessageCheckerOutputTest < Test::Unit::TestCase
9
10
  tag ping.message.checker
10
11
  ]
11
12
 
12
- def create_driver(conf = CONFIG, tag='test.input')
13
- Fluent::Test::OutputTestDriver.new(Fluent::PingMessageCheckerOutput, tag).configure(conf)
13
+ def create_driver(conf = CONFIG)
14
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::PingMessageCheckerOutput).configure(conf)
14
15
  end
15
16
 
16
17
  def test_configure
17
18
  assert_nothing_raised {
18
- d = create_driver(CONFIG)
19
+ create_driver(CONFIG)
19
20
  }
20
21
  assert_raise(Fluent::ConfigError) {
21
- d = create_driver('')
22
+ create_driver('')
22
23
  }
23
24
  end
24
25
 
25
26
  def test_found_not_emit
26
- d1 = create_driver(CONFIG, 'ping.webserver')
27
+ d1 = create_driver(CONFIG)
27
28
  flushed = nil
28
- d1.run do
29
- d1.emit({'data' => 'your.hostname.local'})
29
+ d1.run(default_tag: 'ping.webserver') do
30
+ d1.feed({'data' => 'your.hostname.local'})
30
31
  flushed = d1.instance.check_and_flush
31
32
  assert_equal [], flushed
32
33
 
33
- d1.emit({'data' => 'your.hostname.local'})
34
+ d1.feed({'data' => 'your.hostname.local'})
34
35
  flushed = d1.instance.check_and_flush
35
36
  assert_equal [], flushed
36
37
  end
37
38
  end
38
39
 
39
40
  def test_missing_emit
40
- d1 = create_driver(CONFIG, 'ping.webserver')
41
+ d1 = create_driver(CONFIG)
41
42
  flushed = nil
42
- d1.run do
43
- d1.emit({'data' => 'your.hostname.local'})
43
+ d1.run(default_tag: 'ping.webserver') do
44
+ d1.feed({'data' => 'your.hostname.local'})
44
45
  flushed = d1.instance.check_and_flush
45
46
  assert_equal [], flushed
46
47
 
@@ -50,10 +51,10 @@ class PingMessageCheckerOutputTest < Test::Unit::TestCase
50
51
  end
51
52
 
52
53
  def test_notification_times
53
- d1 = create_driver(CONFIG + %[notification_times 3], 'ping.webserver')
54
+ d1 = create_driver(CONFIG + %[notification_times 3])
54
55
  flushed = nil
55
- d1.run do
56
- d1.emit({'data' => 'your.hostname.local'})
56
+ d1.run(default_tag: 'ping.webserver') do
57
+ d1.feed({'data' => 'your.hostname.local'})
57
58
  flushed = d1.instance.check_and_flush
58
59
  assert_equal [], flushed
59
60
 
@@ -72,10 +73,10 @@ class PingMessageCheckerOutputTest < Test::Unit::TestCase
72
73
  end
73
74
 
74
75
  def test_recovery
75
- d1 = create_driver(CONFIG + %[notification_times 3], 'ping.webserver')
76
+ d1 = create_driver(CONFIG + %[notification_times 3])
76
77
  flushed = nil
77
- d1.run do
78
- d1.emit({'data' => 'your.hostname.local'})
78
+ d1.run(default_tag: 'ping.webserver') do
79
+ d1.feed({'data' => 'your.hostname.local'})
79
80
  flushed = d1.instance.check_and_flush
80
81
  assert_equal [], flushed
81
82
 
@@ -85,7 +86,7 @@ class PingMessageCheckerOutputTest < Test::Unit::TestCase
85
86
  flushed = d1.instance.check_and_flush
86
87
  assert_equal 'your.hostname.local', flushed.first
87
88
 
88
- d1.emit({'data' => 'your.hostname.local'})
89
+ d1.feed({'data' => 'your.hostname.local'})
89
90
  flushed = d1.instance.check_and_flush
90
91
  assert_equal [], flushed
91
92
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-ping-message
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TAGOMORI Satoshi
@@ -12,32 +12,18 @@ date: 2017-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "<"
18
- - !ruby/object:Gem::Version
19
- version: 0.14.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.14.0
27
- - !ruby/object:Gem::Dependency
28
- name: fluent-mixin-config-placeholders
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: 0.3.0
19
+ version: 0.14.0
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: 0.3.0
26
+ version: 0.14.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -84,6 +70,7 @@ files:
84
70
  - lib/fluent/plugin/in_ping_message.rb
85
71
  - lib/fluent/plugin/out_ping_message_checker.rb
86
72
  - test/helper.rb
73
+ - test/plugin/test_in_ping_message.rb
87
74
  - test/plugin/test_out_ping_message_checker.rb
88
75
  homepage: https://github.com/tagomoris/fluent-plugin-ping-message
89
76
  licenses:
@@ -111,4 +98,5 @@ specification_version: 4
111
98
  summary: Fluentd plugin to send/check ping messages
112
99
  test_files:
113
100
  - test/helper.rb
101
+ - test/plugin/test_in_ping_message.rb
114
102
  - test/plugin/test_out_ping_message_checker.rb