fluent-plugin-spectrum 0.0.6 → 0.0.7

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: 0c949d2e99ee26e2c94f69cc95f51691bfcb6c06
4
- data.tar.gz: a0a20f56156aebccbbb21da927b1d7e145622d60
3
+ metadata.gz: dce92432a6a0648acac71c3abcc728f1f7cb313b
4
+ data.tar.gz: 9e12765096932803e03d30e71c09a3cb78bf0718
5
5
  SHA512:
6
- metadata.gz: 00b234557427b77bc8ed240f432f74ebb6114cb844af5740eca0215d308ee38e16bde66cdf5147081323794a596ee29cb39cd6515b962849b1f34afc9e9b45cd
7
- data.tar.gz: 51d6ba395c211abea598b69cabb28178c91b03d2238c631b1909597fd5a6d8f102db1d8a0bca665450c77da34dc38a383a63503637496b17e52ced3327dc652c
6
+ metadata.gz: 8e6419d7bcbcfe308e0a2d62b916f6e61b5cc1327569317a5d65be87a728d358042dfd316f8038a893e40fe1a686bd41a81611b1e192c1ff4b5d07c93871cb82
7
+ data.tar.gz: efabb69d231fb482311be547596ae17c5486d995837af219aa8cd6e7441145731148daed2903dce4d82d44fc266fa3fdf16a3cafea4a67a944a7c133eb7f81f1
data/.travis.yml CHANGED
@@ -12,4 +12,8 @@ branches:
12
12
  only:
13
13
  - master
14
14
 
15
- script: bundle exec rake test
15
+ script: bundle exec rake test
16
+
17
+ addons:
18
+ code_climate:
19
+ repo_token: c13cd5d4ecf62009fa2ad6afca2d11098375c731929a774231dcda32eb1cf63c
data/README.md CHANGED
@@ -4,10 +4,10 @@ fluent-plugin-spectrum is an input plug-in for [Fluentd](http://fluentd.org)
4
4
 
5
5
  ## Status
6
6
  [![Build Status](https://travis-ci.org/Bigel0w/fluent-plugin-spectrum.png?branch=master)](https://travis-ci.org/Bigel0w/fluent-plugin-spectrum)
7
- [![Coverage Status](https://coveralls.io/repos/Bigel0w/fluent-plugin-spectrum/badge.png?branch=master)](https://coveralls.io/r/Bigel0w/fluent-plugin-spectrum?branch=master)
8
- [![Dependency Status](https://gemnasium.com/Bigel0w/fluent-plugin-spectrum.svg)](https://gemnasium.com/Bigel0w/fluent-plugin-spectrum)
9
- [![Code Climate](https://codeclimate.com/github/Bigel0w/fluent-plugin-spectrum/badges/gpa.svg)](https://codeclimate.com/github/Bigel0w/fluent-plugin-spectrum)
10
7
  [![Gem Version](https://badge.fury.io/rb/fluent-plugin-spectrum.png)](http://badge.fury.io/rb/fluent-plugin-spectrum)
8
+ [![Test Coverage](https://codeclimate.com/github/Bigel0w/fluent-plugin-spectrum/badges/coverage.svg)](https://codeclimate.com/github/Bigel0w/fluent-plugin-spectrum)
9
+ [![Code Climate](https://codeclimate.com/github/Bigel0w/fluent-plugin-spectrum/badges/gpa.svg)](https://codeclimate.com/github/Bigel0w/fluent-plugin-spectrum)
10
+ [![Dependency Status](https://gemnasium.com/Bigel0w/fluent-plugin-spectrum.svg)](https://gemnasium.com/Bigel0w/fluent-plugin-spectrum)
11
11
 
12
12
  ## Installation
13
13
 
@@ -29,56 +29,53 @@ Add the following into your fluentd config.
29
29
 
30
30
  Simple:
31
31
 
32
- <source>
33
- type spectrum # required, choosing the input plugin
34
- endpoint spectrum.yourdomain.com # required, FQDN of spectrum endpoint
35
- user username # required, username for APIs
36
- pass password # required, password for APIs
37
- tag alert.spectrum # optional, tag to assign to events, default is alert.spectrum
38
- interval 60 # optional, interval in seconds for how often to poll, defaults to 300
39
- include_raw false # optional, include original object as key raw
32
+ <source>
33
+ type spectrum
34
+ endpoint spectrum.yourdomain.com # required, FQDN of endpoint
35
+ user username # required
36
+ pass password # required
37
+ interval 60 # optional, interval in seconds, defaults to 300
40
38
  </source>
41
-
42
- <match alert.spectrum>
43
- type stdout
44
- </match>
39
+ <match alert.spectrum>
40
+ type stdout
41
+ </match>
45
42
 
46
43
  Advanced:
47
44
 
48
- <source>
49
- type spectrum # required, choosing the input plugin
50
- endpoint spectrum.yourdomain.com # required, FQDN of spectrum endpoint
51
- user username # required, username for APIs
52
- pass password # required, password for APIs
53
- tag alert.spectrum # optional, tag to assign to events, default is alert.spectrum
54
- interval 60 # optional, interval in seconds for how often to poll, defaults to 300
55
- include_raw true # optional, include original object as key raw
45
+ <source>
46
+ type spectrum
47
+ endpoint spectrum.yourdomain.com # required, FQDN of endpoint
48
+ user username # required
49
+ pass password # required
50
+ interval 60 # optional, interval in seconds, defaults to 300
51
+ state_file /tmp/spectrum_state # optional, file to keep state
56
52
  </source>
57
53
  # using rename_key to map to new keynames
58
- <match alert.spectrum>
59
- type rename_key
60
- deep_rename false
61
- remove_tag_prefix alert.spectrum
62
- append_tag alert
63
- rename_rule1 HOSTNAME source_hostname
64
- rename_rule2 IP_ADDRESS source_ip
65
- rename_rule3 ALARM_TITLE event_name
66
- rename_rule4 SEVERITY criticality
67
- rename_rule5 CREATION_DATE creation_time
68
- rename_rule6 ORIGINATING_EVENT_ATTR alert_description
69
- rename_rule7 MODEL_STRING source_type
70
- rename_rule8 ALARM_ID source_event_id
71
- rename_rule9 GC_NAME environment
72
- </match>
73
- # using key_picker to remove extra fields
74
- <match alert>
75
- type key_picker
76
- keys event_type,intermediary_source,source_event_id,creation_time,criticality,event_name,source_hostname,source_ip,alert_description,source_type,environment,raw
77
- add_tag_prefix processed.
78
- </match>
79
- <match processed.alert>
80
- type stdout
81
- </match>
54
+ <match alert.spectrum>
55
+ type rename_key
56
+ deep_rename false
57
+ remove_tag_prefix alert.spectrum
58
+ append_tag alert
59
+ rename_rule1 HOSTNAME source_hostname
60
+ rename_rule2 IP_ADDRESS source_ip
61
+ rename_rule3 ALARM_TITLE event_name
62
+ rename_rule4 SEVERITY criticality
63
+ rename_rule5 CREATION_DATE creation_time
64
+ rename_rule6 ORIGINATING_EVENT_ATTR alert_description
65
+ rename_rule7 MODEL_STRING source_type
66
+ rename_rule8 ALARM_ID source_event_id
67
+ rename_rule9 GC_NAME environment
68
+ </match>
69
+ # using key_picker to remove extra fields
70
+ <match alert>
71
+ type key_picker
72
+ keys event_type,intermediary_source,source_event_id,creation_time,criticality,event_name,source_hostname,source_ip,alert_description,source_type,environment
73
+ add_tag_prefix processed.
74
+ </match>
75
+ # send to STDOUT
76
+ <match processed.alert>
77
+ type stdout
78
+ </match>
82
79
 
83
80
  Now startup fluentd
84
81
 
@@ -3,8 +3,8 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = "fluent-plugin-spectrum"
6
- gem.version = "0.0.6"
7
- gem.date = '2015-04-04'
6
+ gem.version = "0.0.7"
7
+ gem.date = '2015-04-06'
8
8
  gem.authors = ["Alex Pena"]
9
9
  gem.email = ["pena.alex@gmail.com"]
10
10
  gem.summary = %q{Fluentd plugin for managing monitoring alerts from CA Spectrum}
@@ -20,6 +20,8 @@ Gem::Specification.new do |gem|
20
20
  gem.add_development_dependency "rake", '~> 10.0'
21
21
  gem.add_development_dependency "bundler", '~> 1.6'
22
22
  gem.add_development_dependency "test-unit", '~> 3.0'
23
+ gem.add_development_dependency "codeclimate-test-reporter", '~> 0.4'
24
+
23
25
  # runtime deps
24
26
  gem.add_runtime_dependency "fluentd", '~> 0.12'
25
27
  gem.add_runtime_dependency "json", '~> 1.8'
@@ -13,7 +13,6 @@ module Fluent
13
13
  config_param :interval, :integer, :default => INTERVAL_MIN
14
14
  config_param :select_limit, :integer, :default => 10000
15
15
  config_param :include_raw, :bool, :default => "false"
16
- config_param :debug_mode, :bool, :default => false
17
16
 
18
17
  # Classes
19
18
  class TimerWatcher < Coolio::TimerWatcher
@@ -37,10 +36,9 @@ module Fluent
37
36
  if File.exists?(@path)
38
37
  @data = YAML.load_file(@path)
39
38
  if @data == false || @data == []
40
- # this happens if an users created an empty file accidentally
41
39
  @data = {}
42
40
  elsif !@data.is_a?(Hash)
43
- raise "state_file on #{@path.inspect} is invalid"
41
+ raise "Spectrum :: ConfigError state_file on #{@path.inspect} is invalid"
44
42
  end
45
43
  else
46
44
  @data = {}
@@ -93,17 +91,14 @@ module Fluent
93
91
  def configure(conf)
94
92
  super
95
93
  @conf = conf
96
- # Only check configs if debug is off
97
- unless @debug_mode
98
- # Verify configs
99
- # Stop if required fields are not set
100
- unless @endpoint && @username && @password
101
- raise ConfigError, "Spectrum :: ConfigError 'endpoint' and 'username' and 'password' must be all specified."
102
- end
103
- # Enforce min interval
104
- if @interval.to_i < INTERVAL_MIN
105
- raise ConfigError, "Spectrum :: ConfigError 'interval' must be #{INTERVAL_MIN} or over."
106
- end
94
+ # Verify configs
95
+ # Stop if required fields are not set
96
+ unless @endpoint && @username && @password
97
+ raise ConfigError, "Spectrum :: ConfigError 'endpoint' and 'username' and 'password' must be all specified."
98
+ end
99
+ # Enforce min interval
100
+ if @interval.to_i < INTERVAL_MIN
101
+ raise ConfigError, "Spectrum :: ConfigError 'interval' must be #{INTERVAL_MIN} or over."
107
102
  end
108
103
  # Warn about optional state file
109
104
  unless @state_file
@@ -164,13 +159,6 @@ module Fluent
164
159
  @url = 'http://' + @endpoint.to_s + '/spectrum/restful/alarms'
165
160
  RestClient::Resource.new(@url, :user => @username, :password => @password, :open_timeout => 5, :timeout => (@interval * 3))
166
161
  end
167
- ### need to add this but first figure out how to pass a one time override for timeout since get takes a longtime to return
168
- #test = resource.get
169
- #if test.code.to_s == 200
170
- # $log.info "Spectrum :: Config testing #{@endpoint} succeeded with #{test.code.to_s} response code"
171
- #else
172
- # raise Fluent::ConfigError, "http test failed"
173
- #end
174
162
  end # def configure
175
163
 
176
164
  def start
@@ -200,20 +188,11 @@ module Fluent
200
188
  pollingStart = Engine.now.to_i
201
189
  if @state_store.last_records.has_key?("spectrum")
202
190
  alertStartTime = @state_store.last_records['spectrum']
203
- if @debug_mode
204
- $log.info "Spectrum :: Got time record from state_store - #{alertStartTime}"
205
- end
206
191
  else
207
192
  alertStartTime = (pollingStart.to_i - @interval.to_i)
208
- if @debug_mode
209
- $log.info "Spectrum :: Got time record from initial config - #{alertStartTime}"
210
- end
211
193
  end
212
194
  pollingEnd = ''
213
195
  pollingDuration = ''
214
- if @debug_mode
215
- $log.info "Spectrum :: Polling alerts for time period < #{alertStartTime.to_i}"
216
- end
217
196
  # Format XML for spectrum post
218
197
  @xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
219
198
  <rs:alarm-request throttlesize=\"#{select_limit}\"
@@ -237,13 +216,10 @@ module Fluent
237
216
  # Post to Spectrum and parse results
238
217
  begin
239
218
  res=resource.post @xml,:content_type => 'application/xml',:accept => 'application/json'
240
- if @debug_mode
241
- $log.info "Spectrum :: Response code #{res.code.to_s}"
242
- end
243
219
  body = JSON.parse(res.body)
244
- pollingEnd = Engine.now.to_i
220
+ pollingEnd = Time.parse(res.headers[:date]).to_i
245
221
  @state_store.last_records['spectrum'] = pollingEnd
246
- pollingDuration = pollingEnd - pollingStart
222
+ pollingDuration = Engine.now.to_i - pollingStart
247
223
  end
248
224
 
249
225
  # Processing for multiple alerts returned
@@ -297,9 +273,7 @@ module Fluent
297
273
  else
298
274
  $log.info "Spectrum :: returned #{body['ns1.alarm-response-list']['@total-alarms'].to_i} alarms for period < #{alertStartTime.to_i} took #{pollingDuration.to_i} seconds, ended at #{pollingEnd}"
299
275
  end
300
- @state_store.update!
301
- #return
302
- #exit
276
+ @state_store.update!
303
277
  end
304
278
  end # def input
305
279
  end # class SpectrumInput
data/test/helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
1
4
  require 'bundler'
2
5
  require 'test/unit'
3
6
  require 'fluent/test'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-spectrum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Pena
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-04 00:00:00.000000000 Z
11
+ date: 2015-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: codeclimate-test-reporter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.4'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: fluentd
57
71
  requirement: !ruby/object:Gem::Requirement