fluent-plugin-boundio 0.0.2 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -16,9 +16,18 @@ gem install fluent-plugin-boundio
16
16
  /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-boundio
17
17
  `````
18
18
 
19
- ## Output Configuration
19
+ ## Configuration
20
20
 
21
- ### Output Sample
21
+ ### Message Format
22
+ `````
23
+ fluent_logger.post('notify.call', {
24
+ :message => 'Hello World!', # Required
25
+ :number => '090-1234-5678', # Optional
26
+ :voice => 'male' # Optional
27
+ })
28
+ `````
29
+
30
+ ### Sample
22
31
  `````
23
32
  <source>
24
33
  type http
@@ -27,22 +36,32 @@ gem install fluent-plugin-boundio
27
36
 
28
37
  <match notify.call>
29
38
  type boundio
30
- user_serial_id YOUR_BOUNDIO_USER_SERIAL_ID
31
- api_key YOUR_BOUNDIO_API_KEY
32
- user_key YOUR_BOUNDIO_USER_KEY
33
- default_number 09012345678
39
+ user_serial_id BOUNDIO_USER_SERIAL_ID # Required
40
+ api_key BOUNDIO_API_KEY # Required
41
+ user_key BOUNDIO_USER_KEY # Required
42
+ default_number 090-1234-5678 # Optional
43
+ default_voice female # Optional [female/male] (default: female)
34
44
  # http://boundio.jp/docs/%E3%83%87%E3%83%99%E3%83%AD%E3%83%83%E3%83%91%E3%83%BC%E3%83%84%E3%83%BC%E3%83%AB
35
45
  developer_tool yes
36
46
  </match>
37
47
  `````
38
48
 
39
- ### Debug
49
+ ### Quick Test
40
50
  `````
41
- $ curl http://localhost:8888/notify.call -F 'json={"number":"09012345678","message":"Help! System ABC has down."}'
51
+ # test call to 09012345678 and say "Help! System ABC has down." with male voice.
52
+ $ curl http://localhost:8888/notify.call -F 'json={"number":"09012345678","voice":"male","message":"Help! System ABC has down."}'
53
+
54
+ # check boundio activity log
42
55
  $ tail -f /var/log/td-agent/td-agent.log
43
56
  `````
44
57
 
58
+ ## Reference
59
+
60
+ ### Use Case1: make a call when it goes to over 5 times 500_errors in a minutes.
61
+ http://github.com/y-ken/fluent-plugin-boundio/blob/master/example.conf
62
+
45
63
  ## Backend Service
64
+ You can register to get 20 times trial call credit.
46
65
  http://boundio.jp/
47
66
 
48
67
  ## TODO
@@ -53,3 +72,4 @@ Copyright © 2012- Kentaro Yoshida (@yoshi_ken)
53
72
 
54
73
  ## License
55
74
  Apache License, Version 2.0
75
+
@@ -0,0 +1,115 @@
1
+ ## It is a example to make a call when it goes to over 5 times 500_errors in a minutes.
2
+ ##
3
+ ## * Apache LogFormat (httpd.conf)
4
+ ## LogFormat "%V %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %D" combined
5
+ ##
6
+ ## * Target Website
7
+ ## www.example.com
8
+ ##
9
+ ## * required plugin
10
+ ## fluent-plugin-rewrite-tag-filter
11
+ ## fluent-plugin-datacounter
12
+ ## fluent-plugin-notifier
13
+ ## fluent-plugin-parser
14
+ ## fluent-plugin-boundio
15
+
16
+ ## following an access_log
17
+ <source>
18
+ type tail
19
+ path /var/log/httpd/access_log
20
+ format /^(?<domain>[^ ]*) (?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<status>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)" (?<response_time>[^ ]*))?$/
21
+ time_format %d/%b/%Y:%H:%M:%S %z
22
+ tag log.apache.access
23
+ pos_file /var/log/td-agent/apache_access.pos
24
+ </source>
25
+
26
+ ## extract the target domain and rewrite tag name to site.ExampleWebSite
27
+ <match log.apache.access>
28
+ type rewrite_tag_filter
29
+ rewriterule1 domain ^www.example.com$ site.ExampleWebSite
30
+ </match>
31
+
32
+ ## count values of "status" by each pattern
33
+ # Record Sample:
34
+ # site.ExampleWebSite: {"domain":"www.example.com","host":"127.0.0.1","user":"-","method":"GET","path":"/home","status":"200","size":"12121","referer":"-","agent":"Wget","response_time":"0"}
35
+ <match site.ExampleWebSite>
36
+ type copy
37
+ <store>
38
+ type stdout
39
+ </store>
40
+ <store>
41
+ type datacounter
42
+ unit minute
43
+ count_key status
44
+ tag count.responsecode.ExampleWebSite
45
+ aggregate all
46
+ pattern1 200 ^200$
47
+ pattern2 2xx ^2\d\d$
48
+ pattern3 301 ^301$
49
+ pattern4 302 ^302$
50
+ pattern5 3xx ^3\d\d$
51
+ pattern6 403 ^403$
52
+ pattern7 404 ^404$
53
+ pattern8 410 ^410$
54
+ pattern9 4xx ^4\d\d$
55
+ pattern10 500 ^5\d\d$
56
+ outcast_unmatched false
57
+ </store>
58
+ </match>
59
+
60
+ ## output a record when the "status_500" value exceed threshold.
61
+ # Record Sample:
62
+ # count.responsecode.ExampleWebSite: {"unmatched_count":0,"unmatched_rate":0.0,"unmatched_percentage":0.0,"200_count":0,"200_rate":0.0,"200_percentage":0.0,"2xx_count":0,"2xx_rate":0.0,"2xx_percentage":0.0,"301_count":0,"301_rate":0.0,"301_percentage":0.0,"302_count":0,"302_rate":0.0,"302_percentage":0.0,"3xx_count":0,"3xx_rate":0.0,"3xx_percentage":0.0,"403_count":0,"403_rate":0.0,"403_percentage":0.0,"404_count":0,"404_rate":0.0,"404_percentage":0.0,"410_count":0,"410_rate":0.0,"410_percentage":0.0,"4xx_count":0,"4xx_rate":0.0,"4xx_percentage":0.0,"500_count":20,"500_rate":0.33,"500_percentage":100.0}
63
+ <match count.responsecode.ExampleWebSite>
64
+ type copy
65
+ <store>
66
+ type stdout
67
+ </store>
68
+ <store>
69
+ type notifier
70
+ input_tag_remove_prefix count.responsecode
71
+ <def>
72
+ pattern status_500
73
+ check numeric_upward
74
+ warn_threshold 5
75
+ crit_threshold 20
76
+ tag alert.http_500_error
77
+ target_key_pattern ^500_count$
78
+ </def>
79
+ </store>
80
+ </match>
81
+
82
+ ## build an alert message
83
+ # Record Sample:
84
+ # alert.http_500_error: {"pattern":"status_500","target_tag":"ExampleWebSite","target_key":"500_count","check_type":"numeric_upward","level":"crit","threshold":20.0,"value":20.0,"message_time":"2012-10-18 20:08:52 +0900"}
85
+ <match alert.http_500_error>
86
+ type copy
87
+ <store>
88
+ type stdout
89
+ </store>
90
+ <store>
91
+ type deparser
92
+ tag notify.call
93
+ # format WebSite has down level %s. The service of %s %s is exceed %s times. This threshold is %s now. Thank you.
94
+ format サイトが落ちました。レベルは%s。%sの%sが%s回を超えました。しきい値は%sです。対応お願いします。
95
+ format_key_names level,target_tag,target_key,value,threshold
96
+ key_name message
97
+ reserve_data no
98
+ </store>
99
+ </match>
100
+
101
+ # make a call to 09012345678
102
+ <match notify.call>
103
+ type copy
104
+ <store>
105
+ type stdout
106
+ </store>
107
+ <store>
108
+ type boundio
109
+ user_serial_id YOUR_BOUNDIO_USER_SERIAL_ID
110
+ api_key YOUR_BOUNDIO_API_KEY
111
+ user_key YOUR_BOUNDIO_USER_KEY
112
+ default_number 09012345678
113
+ developer_tool yes
114
+ </store>
115
+ </match>
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fluent-plugin-boundio"
6
- s.version = "0.0.2"
6
+ s.version = "0.1.1"
7
7
  s.authors = ["Kentaro Yoshida"]
8
8
  s.email = ["y.ken.studio@gmail.com"]
9
9
  s.homepage = "https://github.com/y-ken/fluent-plugin-boundio"
@@ -2,46 +2,52 @@
2
2
  class Fluent::BoundioOutput < Fluent::Output
3
3
  Fluent::Plugin.register_output('boundio', self)
4
4
 
5
+ VOICE_MAP = {'female' => 0, 'male' => 1}
6
+
5
7
  config_param :user_serial_id, :string
6
8
  config_param :user_key, :string, :default => nil # Optional at this time
7
9
  config_param :api_key, :string
8
- config_param :default_number, :string
10
+ config_param :default_number, :string, :default => nil
11
+ config_param :default_voice, :string, :default => 'male'
9
12
  config_param :developer_tool, :string, :default => 'no'
10
13
 
11
14
  def initialize
12
15
  super
13
-
14
16
  require 'uri'
15
17
  require 'net/https'
16
18
  end
17
19
 
18
20
  def configure(conf)
19
21
  super
22
+ unless VOICE_MAP.include?(@default_voice)
23
+ raise Fluent::ConfigError, "boundio: invalid value for default_voice(male/female): #{@default_voice}"
24
+ end
20
25
  @developer_tool = Fluent::Config.bool_value(@developer_tool) || false
21
- @voice_type = 1
26
+ $log.info "boundio: using developer tool api" if @developer_tool
22
27
  end
23
28
 
24
29
  def emit(tag, es, chain)
25
30
  es.each do |time,record|
26
31
  number = record['number'].nil? ? @default_number : record['number']
27
- call(number, record['message'])
32
+ voice = VOICE_MAP.include?(record['voice']) ? record['voice'] : @default_voice
33
+ call(number, record['message'], voice)
28
34
  end
29
35
 
30
36
  chain.next
31
37
  end
32
38
 
33
- def call(number, message)
39
+ def call(number, message, voice = 'male')
34
40
  begin
35
41
  https = Net::HTTP.new('boundio.jp', 443)
36
42
  https.use_ssl = true
37
- cast = "file_d(#{message}, #{@voice_type})"
38
- query = 'key=' + @api_key + '&tel_to=' + number + '&cast=' + cast
43
+ cast = "file_d(#{message}, #{VOICE_MAP[voice]})"
44
+ query = 'key=' + @api_key + '&tel_to=' + number.gsub('-','') + '&cast=' + cast
39
45
  path = @developer_tool ? '/api/vd2/' : '/api/v2/'
40
46
  response = https.post(path + @user_serial_id + '/call', URI.escape(query))
41
- $log.info "boundio makeing a call: #{path} #{message} "
42
- $log.info "boundio call result: #{response.body}"
47
+ $log.info "boundio: makeing a call to #{number} and say '#{message}'"
48
+ $log.info "boundio: call result: #{response.body}"
43
49
  rescue => e
44
- $log.error("Boundio Error: #{e.message}")
50
+ $log.error "boundio: Error: #{e.message}"
45
51
  end
46
52
  end
47
53
  end
@@ -6,9 +6,9 @@ class BoundioOutputTest < Test::Unit::TestCase
6
6
  end
7
7
 
8
8
  CONFIG = %[
9
- user_serial_id YOUR_BOUNDIO_USER_SERIAL_ID
10
- api_key YOUR_BOUNDIO_API_KEY
11
- user_key YOUR_BOUNDIO_USER_KEY
9
+ user_serial_id BOUNDIO_USER_SERIAL_ID
10
+ api_key BOUNDIO_API_KEY
11
+ user_key BOUNDIO_USER_KEY
12
12
  default_number 09012345678
13
13
  ]
14
14
 
@@ -21,15 +21,15 @@ class BoundioOutputTest < Test::Unit::TestCase
21
21
  d = create_driver('')
22
22
  }
23
23
  d = create_driver %[
24
- user_serial_id YOUR_BOUNDIO_USER_SERIAL_ID
25
- api_key YOUR_BOUNDIO_API_KEY
26
- user_key YOUR_BOUNDIO_USER_KEY
24
+ user_serial_id BOUNDIO_USER_SERIAL_ID
25
+ api_key BOUNDIO_API_KEY
26
+ user_key BOUNDIO_USER_KEY
27
27
  default_number 09012345678
28
28
  ]
29
29
  d.instance.inspect
30
- assert_equal 'YOUR_BOUNDIO_USER_SERIAL_ID', d.instance.user_serial_id
31
- assert_equal 'YOUR_BOUNDIO_API_KEY', d.instance.api_key
32
- assert_equal 'YOUR_BOUNDIO_USER_KEY', d.instance.user_key
30
+ assert_equal 'BOUNDIO_USER_SERIAL_ID', d.instance.user_serial_id
31
+ assert_equal 'BOUNDIO_API_KEY', d.instance.api_key
32
+ assert_equal 'BOUNDIO_USER_KEY', d.instance.user_key
33
33
  assert_equal '09012345678', d.instance.default_number
34
34
  end
35
35
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-boundio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-18 00:00:00.000000000 Z
12
+ date: 2012-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd
16
- requirement: &11291020 !ruby/object:Gem::Requirement
16
+ requirement: &21687940 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *11291020
24
+ version_requirements: *21687940
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: fluentd
27
- requirement: &11290580 !ruby/object:Gem::Requirement
27
+ requirement: &21687500 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *11290580
35
+ version_requirements: *21687500
36
36
  description:
37
37
  email:
38
38
  - y.ken.studio@gmail.com
@@ -45,6 +45,7 @@ files:
45
45
  - LICENSE.txt
46
46
  - README.md
47
47
  - Rakefile
48
+ - example.conf
48
49
  - fluent-plugin-boundio.gemspec
49
50
  - lib/fluent/plugin/out_boundio.rb
50
51
  - test/helper.rb