fluent-plugin-spectrum 0.0.1 → 0.0.2

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: 9bc88f1954fef9f516c4ef7c8f7fd134a6ed957d
4
- data.tar.gz: de6e8bfdd3f67695df5de0f2f62fee25f9c15a91
3
+ metadata.gz: 4a907d9e3749f2604e633e9d2e7d208b2595eca8
4
+ data.tar.gz: 6bf4af623fa6d9aed08638ea59d474a694bf2e87
5
5
  SHA512:
6
- metadata.gz: ec23275e1753d9d7bce921d6a8e3a6df5a48225dcde19a9fb5aaf6f7d1f3a1352a8b415676d7c131e1c54a4d657f12aaac1643ca9697adbed7de92df773cfb36
7
- data.tar.gz: 54f6270b853b64f33290044b9d9a910dc7adb8d25aa3dacc2165ea91711a6ad643f79f7fb61d991aa3d575c2dbadf24a2c1727c0d43ae7b905fb76698fd745cd
6
+ metadata.gz: b6d14688b87fa043d58a4eaef3394507a82c64b0178a7d32f435a00d5d1c6ea429a1ed44853cd8c4af268d997ca7d3a0748b78e40d4dbf2e75fc020440783266
7
+ data.tar.gz: a48028226c73f7a715a43861ed31fe9eec1ecf2aac9ba7ec536a88cfa6ed39ba1b81b2314326fc1ea29021001115ba012266d206837b214fc2f3783407e91378
data/README.md CHANGED
@@ -20,17 +20,19 @@ Or install it yourself as:
20
20
  ## Usage
21
21
  Add the following into your fluentd config.
22
22
 
23
- <source>
24
- type spectrum # required, choosing the input plugin.
25
- endpoint hostname # required, FQDN of Spectrum EndPoint
26
- username ws_user # optional, interface to listen on, default 0 for all.
27
- password ws_password # optional, interface to listen on, default 0 for all.
28
- tag alert.spectrum # optional, tag to assign to events, default is alert.spectrum
29
- </source>
30
-
31
- <match alert.spectrum>
32
- type stdout
33
- </match>
23
+ <source>
24
+ type spectrum # required, choosing the input plugin
25
+ endpoint spectrumapi.corp.yourdomain.net # required, FQDN of spectrum endpoint
26
+ user username # required, username for APIs
27
+ pass password # required, password for APIs
28
+ tag alert.spectrum # optional, tag to assign to events, default is alert.spectrum
29
+ interval 60 # optional, interval in seconds for how often to poll, defaults to 300
30
+ include_raw false # optional, include original object as key raw
31
+ </source>
32
+
33
+ <match alert.spectrum>
34
+ type stdout
35
+ </match>
34
36
 
35
37
  Now startup fluentd
36
38
 
@@ -40,4 +42,8 @@ Send a test
40
42
  TBD
41
43
 
42
44
  ## To Do
43
- Things left to do, not in any particular order.
45
+ Add retry login. On timeout/failure retry, how often, increasing delay? (how would that affect polling time, possible duplicates?)
46
+ All flag to allow specifying spectrum attributes to get or get _ALL_
47
+ Add flag to allow start date/time if users want to backfill data from a specific date. then start loop.
48
+ Add flag to disable loop, if users only wanted to backfill from datetime to now or specific end time.
49
+ change loop to allow multiple runs to stack on eachother to avoid missing data?
@@ -3,7 +3,7 @@ $:.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.1"
6
+ gem.version = "0.0.2"
7
7
  gem.date = '2015-02-24'
8
8
  gem.authors = ["Alex Pena"]
9
9
  gem.email = ["alex_pena@intuit.com"]
@@ -2,9 +2,19 @@ module Fluent
2
2
  # TODO:
3
3
  # Add a fields all or list option
4
4
  # error checking in every section
5
+ # class for handling interval in loop
6
+ class TimerWatcher < Coolio::TimerWatcher
7
+ def initialize(interval, repeat, &callback)
8
+ @callback = callback
9
+ super(interval, repeat)
10
+ end # def initialize
11
+ def on_timer
12
+ @callback.call
13
+ end # def on_timer
14
+ end
15
+
5
16
  class SpectrumInput < Input
6
17
  Fluent::Plugin.register_input('spectrum', self)
7
-
8
18
  config_param :tag, :string, :default => "alert.spectrum"
9
19
  config_param :endpoint, :string, :default => "pleasechangeme.com" #fqdn of endpoint
10
20
  config_param :interval, :integer, :default => '300' #Default 5 minutes
@@ -13,6 +23,19 @@ module Fluent
13
23
  config_param :include_raw, :string, :default => "false" #Include original object as raw
14
24
  config_param :attributes, :string, :default => "ALL" # fields to include, ALL for... well, ALL.
15
25
 
26
+ # function to UTF8 encode
27
+ def to_utf8(str)
28
+ str = str.force_encoding('UTF-8')
29
+ return str if str.valid_encoding?
30
+ str.encode("UTF-8", 'binary', invalid: :replace, undef: :replace, replace: '')
31
+ end
32
+
33
+ def parseAttributes(alarmAttribute)
34
+ key = @spectrum_access_code[alarmAttribute['@id'].to_s].to_s
35
+ value = ((to_utf8(alarmAttribute['$'].to_s)).strip).gsub(/\r?\n/, " ")
36
+ return key,value
37
+ end
38
+
16
39
  def initialize
17
40
  require 'rest_client'
18
41
  require 'json'
@@ -92,24 +115,23 @@ module Fluent
92
115
  super
93
116
  @loop.stop
94
117
  @thread.join
118
+ rescue
119
+ $log.error "Spectrum :: unexpected error", :error=>$!.to_s
120
+ $log.error_backtrace
95
121
  end # def shutdown
96
122
 
97
123
  def run
98
124
  @loop.run
125
+ rescue
126
+ $log.error "Spectrum :: unexpected error", :error=>$!.to_s
127
+ $log.error_backtrace
99
128
  end # def run
100
129
 
101
130
  def input
102
131
  alertStartTime = Engine.now.to_i - @interval.to_i
103
- $log.info "Spectrum :: Polling for alerts for time period: #{alertStartTime.to_i} - #{Engine.now.to_i}"
132
+ $log.info "Spectrum :: Polling alerts for time period: #{alertStartTime.to_i} - #{Engine.now.to_i}"
104
133
 
105
- # function to UTF8 encode
106
- def to_utf8(str)
107
- str = str.force_encoding('UTF-8')
108
- return str if str.valid_encoding?
109
- str.encode("UTF-8", 'binary', invalid: :replace, undef: :replace, replace: '')
110
- end
111
-
112
- # XML for spectrum post
134
+ # Format XML for spectrum post
113
135
  @xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
114
136
  <rs:alarm-request throttlesize=\"10000\"
115
137
  xmlns:rs=\"http://www.ca.com/spectrum/restful/schema/request\"
@@ -132,51 +154,57 @@ module Fluent
132
154
  # Post to Spectrum and parse results
133
155
  responsePost=spectrumEnd.post @xml,:content_type => 'application/xml',:accept => 'application/json'
134
156
  body = JSON.parse(responsePost.body)
135
- # Only continue if we have alarms in results
157
+
158
+ # Processing for multiple alerts returned
136
159
  if body['ns1.alarm-response-list']['@total-alarms'].to_i > 1
137
- $log.info "Spectrum :: returned #{body['ns1.alarm-response-list']['@total-alarms'].to_i} alarms"
138
- # iterate through alarms in results
160
+ $log.info "Spectrum :: returned #{body['ns1.alarm-response-list']['@total-alarms'].to_i} alarms for period #{alertStartTime.to_i} - #{Engine.now.to_i}"
161
+ # iterate through each alarm
139
162
  body['ns1.alarm-response-list']['ns1.alarm-responses']['ns1.alarm'].each do |alarm|
163
+ # Create initial structure
140
164
  record_hash = Hash.new # temp hash to hold attributes of alarm
165
+ raw_array = Array.new # temp hash to hold attributes of alarm for raw
141
166
  record_hash['event_type'] = @tag.to_s
142
167
  record_hash['intermediary_source'] = @endpoint.to_s
143
- # iterate though alarm attributes and add to temp hash
168
+ # iterate though alarm attributes
144
169
  alarm['ns1.attribute'].each do |attribute|
145
- record_hash[@spectrum_access_code[attribute['@id'].to_s].to_s] = to_utf8(attribute['$'].to_s)
170
+ key,value = parseAttributes(attribute)
171
+ record_hash[key] = value
172
+ if @include_raw.to_s == "true"
173
+ raw_array << { "#{key}" => "#{value}" }
174
+ end
146
175
  end
147
- # include raw?
176
+ # append raw object
148
177
  if @include_raw.to_s == "true"
149
- record_hash['raw'] = alarm
178
+ record_hash[:raw] = raw_array
150
179
  end
151
180
  Engine.emit(@tag, record_hash['CREATION_DATE'].to_i,record_hash)
152
181
  end
182
+ # Processing for single alarm returned
153
183
  elsif body['ns1.alarm-response-list']['@total-alarms'].to_i == 1
154
- $log.info "Spectrum :: returned #{body['ns1.alarm-response-list']['@total-alarms'].to_i} alarms"
184
+ $log.info "Spectrum :: returned #{body['ns1.alarm-response-list']['@total-alarms'].to_i} alarms for period #{alertStartTime.to_i} - #{Engine.now.to_i}"
185
+ # Create initial structure
155
186
  record_hash = Hash.new # temp hash to hold attributes of alarm
187
+ raw_array = Array.new # temp hash to hold attributes of alarm for raw
156
188
  record_hash['event_type'] = @tag.to_s
157
189
  record_hash['intermediary_source'] = @endpoint.to_s
158
190
  # iterate though alarm attributes and add to temp hash
159
191
  body['ns1.alarm-response-list']['ns1.alarm-responses']['ns1.alarm']['ns1.attribute'].each do |attribute|
160
- record_hash[@spectrum_access_code[attribute['@id'].to_s].to_s] = to_utf8(attribute['$'].to_s)
192
+ key,value = parseAttributes(attribute)
193
+ record_hash[key] = value
194
+ if @include_raw.to_s == "true"
195
+ raw_array << { "#{key}" => "#{value}" }
196
+ end
161
197
  end
162
- # include raw?
198
+ # append raw object
163
199
  if @include_raw.to_s == "true"
164
- record_hash['raw'] = alarm
200
+ record_hash[:raw] = raw_array
165
201
  end
166
202
  Engine.emit(@tag, record_hash['CREATION_DATE'].to_i,record_hash)
167
- end
168
- end
203
+ # No alarms returned
204
+ else
205
+ $log.info "Spectrum :: returned #{body['ns1.alarm-response-list']['@total-alarms'].to_i} alarms for period #{alertStartTime.to_i} - #{Engine.now.to_i}"
206
+ end
207
+
208
+ end # def input
169
209
  end # class SpectrumInput
170
-
171
- # class for handling interval in loop
172
- class TimerWatcher < Coolio::TimerWatcher
173
- def initialize(interval, repeat, &callback)
174
- @callback = callback
175
- super(interval, repeat)
176
- end # def initialize
177
- def on_timer
178
- @callback.call
179
- end # def on_timer
180
- end
181
-
182
210
  end # module Fluent
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-spectrum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Pena