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 +4 -4
- data/lib/sensu/extensions/snmp-trap.rb +44 -16
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 685c31eceffb21bc8acbd3ed90424b912524a154
|
4
|
+
data.tar.gz: 6899b9c27bbdb66b276ed9d2cb25c5e63e8ade5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,
|
11
|
-
[/notification/i,
|
12
|
-
[/description/i,
|
13
|
-
[/pansystemseverity/i, Proc.new { |value| value > 3 ? 2 : 0 },
|
14
|
-
[/severity/i,
|
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
|
-
:
|
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 =
|
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[:
|
281
|
+
result = options[:result_attributes].merge(
|
254
282
|
{
|
255
|
-
|
256
|
-
|
257
|
-
|
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[
|
266
|
-
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[
|
285
|
-
result[
|
286
|
-
result[
|
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
|
|