sensu-extensions-snmp-trap 0.0.29 → 0.0.30

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fe24a3cec32cec72abb25b7c029c1505f72689d
4
- data.tar.gz: b3be12a352cd9484bd7ebc7e993b155e55fb30f6
3
+ metadata.gz: 685c31eceffb21bc8acbd3ed90424b912524a154
4
+ data.tar.gz: 6899b9c27bbdb66b276ed9d2cb25c5e63e8ade5d
5
5
  SHA512:
6
- metadata.gz: a7bd382470f3c7ce7b401a0a739c45007b83785106168d767246a03a727be8fa710813275d83e4da6a8f7d91e0f535cf7476edc18c8b57d3b87fc5b232cfe3ef
7
- data.tar.gz: 9542c7465a2568b12b845cc36084d85d9b8a35b56bf1455b15fe41dead6ce2d8da641b2603ecfa4730a2c336d8b3b4d6df505af99f8db7bca8a6e40dcae4b77f
6
+ metadata.gz: 07f81872568a1a16412d77b761f47cbcd0666a944fd50ee7c6cdf93fbeb1d112e5cb5efa00926006c7062f9919a55e740f06979ec7c533b674fbd96d62f34dca
7
+ data.tar.gz: e499acae86185bd041973e0a30ef3147af8d74e7424d7ccf08b2e4b665fba43f015036941b50b9f7b2977a4971b5365848f86e2ed2808fb1d5e09a3037b842c4
@@ -7,11 +7,11 @@ module Sensu
7
7
  class SNMPTrap < Check
8
8
 
9
9
  RESULT_MAP = [
10
- [/checkname/i, :name],
11
- [/notification/i, :output],
12
- [/description/i, :output],
13
- [/pansystemseverity/i, Proc.new { |value| value > 3 ? 2 : 0 }, :status],
14
- [/severity/i, :status]
10
+ [/checkname/i, "name"],
11
+ [/notification/i, "output"],
12
+ [/description/i, "output"],
13
+ [/pansystemseverity/i, Proc.new { |value| value > 3 ? 2 : 0 }, "status"],
14
+ [/severity/i, "status"]
15
15
  ]
16
16
 
17
17
  RESULT_STATUS_MAP = [
@@ -56,12 +56,40 @@ module Sensu
56
56
  :handlers => ["default"],
57
57
  :mibs_dir => "/etc/sensu/mibs",
58
58
  :imported_dir => File.join(Dir.tmpdir, "sensu_snmp_imported_mibs"),
59
- :custom_attributes => {}
59
+ :result_attributes => {},
60
+ :mappings => {
61
+ :result => [],
62
+ :result_status => []
63
+ }
60
64
  }
61
65
  @options.merge!(@settings[:snmp_trap]) if @settings[:snmp_trap].is_a?(Hash)
62
66
  @options
63
67
  end
64
68
 
69
+ def result_map
70
+ return @result_map if @result_map
71
+ if options[:mappings] &&
72
+ options[:mappings].is_a?(Hash) &&
73
+ options[:mappings][:result] &&
74
+ options[:mappings][:result].is_a?(Array)
75
+ @result_map = options[:mappings][:result] + RESULT_MAP
76
+ else
77
+ @result_map = RESULT_MAP
78
+ end
79
+ end
80
+
81
+ def result_status_map
82
+ return @result_status_map if @result_status_map
83
+ if options[:mappings] &&
84
+ options[:mappings].is_a?(Hash) &&
85
+ options[:mappings][:result_status] &&
86
+ options[:mappings][:result_status].is_a?(Array)
87
+ @result_status_map = options[:mappings][:result_status] + RESULT_STATUS_MAP
88
+ else
89
+ @result_status_map = RESULT_STATUS_MAP
90
+ end
91
+ end
92
+
65
93
  def start_snmpv2_listener!
66
94
  @listener = SNMP::TrapListener.new(
67
95
  :host => options[:bind],
@@ -242,7 +270,7 @@ module Sensu
242
270
 
243
271
  def determine_trap_status(trap)
244
272
  oid_symbolic_name = determine_trap_oid(trap)
245
- mapping = RESULT_STATUS_MAP.detect do |mapping|
273
+ mapping = result_status_map.detect do |mapping|
246
274
  oid_symbolic_name =~ mapping.first
247
275
  end
248
276
  mapping ? mapping.last : 0
@@ -250,11 +278,11 @@ module Sensu
250
278
 
251
279
  def process_trap(trap)
252
280
  @logger.debug("snmp trap check extension processing a v2 trap")
253
- result = options[:custom_attributes].merge(
281
+ result = options[:result_attributes].merge(
254
282
  {
255
- :source => determine_hostname(trap.source_ip),
256
- :handlers => options[:handlers],
257
- :snmp_trap => {}
283
+ "source" => determine_hostname(trap.source_ip),
284
+ "handlers" => options[:handlers],
285
+ "snmp_trap" => {}
258
286
  }
259
287
  )
260
288
  trap.varbind_list.each do |varbind|
@@ -262,8 +290,8 @@ module Sensu
262
290
  type_conversion = RUBY_ASN1_MAP[varbind.value.asn1_type]
263
291
  if type_conversion
264
292
  value = varbind.value.send(type_conversion)
265
- result[:snmp_trap][symbolic_name] = value
266
- mapping = RESULT_MAP.detect do |mapping|
293
+ result["snmp_trap"][symbolic_name] = value
294
+ mapping = result_map.detect do |mapping|
267
295
  symbolic_name =~ mapping.first
268
296
  end
269
297
  if mapping && !result[mapping.last]
@@ -281,9 +309,9 @@ module Sensu
281
309
  })
282
310
  end
283
311
  end
284
- result[:name] ||= determine_trap_name(trap)
285
- result[:output] ||= determine_trap_output(trap)
286
- result[:status] ||= determine_trap_status(trap)
312
+ result["name"] ||= determine_trap_name(trap)
313
+ result["output"] ||= determine_trap_output(trap)
314
+ result["status"] ||= determine_trap_status(trap)
287
315
  send_result(result)
288
316
  end
289
317
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-extensions-snmp-trap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.29
4
+ version: 0.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Extensions and contributors