sensu-plugins-snmptrap-extension 0.1.0 → 0.2.0
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/CHANGELOG.md +18 -6
- data/README.md +140 -40
- data/bin/extension-snmptrap.rb +74 -53
- data/lib/sensu-plugins-snmptrap-extension/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9a0ba4669fb05ae1039fbf59f4bb0a282f593ab
|
4
|
+
data.tar.gz: 36686e2a0d14e5e979a9896e6be199cf12ddd507
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b73adb6c909802ba22b8371de7a5fa019d8073f709604881e2498a67c7a6ce97a6d5f7463e49380290de05fc99d69877732c3a1148588a23197baebca6079b8
|
7
|
+
data.tar.gz: 0deabed059f0438d22a63f33207fb72f1c986273420755a93547f3388ba874fb56318c4f63842a3cf728932762a741d5a382b7481df4dd4592bbceb24f3ab3c5
|
data/CHANGELOG.md
CHANGED
@@ -3,16 +3,28 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
3
3
|
|
4
4
|
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
|
5
5
|
|
6
|
-
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
### Added
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
|
12
|
+
## [0.2.0] - 2016-06-04
|
7
13
|
### Added
|
8
|
-
-
|
9
|
-
|
10
|
-
|
14
|
+
- README: Instructions on installation
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
- Log message handling from @amdprophet
|
18
|
+
- Autodiscovery of sensu-client's JIT event socket
|
19
|
+
- Better handling when the event socket is missing/unconfigured
|
20
|
+
|
11
21
|
|
12
22
|
### Changed
|
13
|
-
-
|
23
|
+
- README: Reformatting and extended examples
|
24
|
+
- Reduced the log noise by reducing the log severity on a number of messages
|
25
|
+
|
14
26
|
|
15
27
|
|
16
|
-
## 0.0
|
28
|
+
## [0.1.0] - 2016-06-04
|
17
29
|
### Added
|
18
30
|
- initial release
|
data/README.md
CHANGED
@@ -4,93 +4,193 @@ Creates an SNMP trap listening to all incoming traps on the configured interface
|
|
4
4
|
|
5
5
|
[](https://travis-ci.org/warmfusion/sensu-extension-snmptrap)
|
6
6
|
|
7
|
-
|
7
|
+
[](https://badge.fury.io/rb/sensu-plugins-snmptrap-extension)
|
8
8
|
|
9
|
-
Also able to run as a 'polling' service in either Check or Metrics mode where values can be directly compared against expectations (eg value > 10)
|
10
|
-
or where values are sent to Sensu as metrics values for charting or other purposes.
|
11
9
|
|
10
|
+
# Installation
|
12
11
|
|
13
|
-
|
12
|
+
As sensu extensions cannot be dynamically loaded by sensu at runtime, you must
|
13
|
+
install the extension manually once the gem has installed.
|
14
14
|
|
15
|
-
|
16
|
-
and includes a traps configuration element that describes:
|
15
|
+
If you're using the EMBEDDED_RUBY from sensu;
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
* `trap` - A hash of key/value pairs that can be used as template values in the event
|
21
|
-
* `event` - The template event to send to Sensu, including {template} variables for customisation based on the message
|
17
|
+
```
|
18
|
+
sensu-install -p sensu-plugins-snmptrap-extension
|
22
19
|
|
20
|
+
ln -s /opt/sensu/embedded/lib/ruby/gems/*/gems/sensu-plugins-snmptrap-extension-*/bin/extension-snmptrap.rb /etc/sensu/extensions/extension-snmptrap.rb
|
21
|
+
```
|
23
22
|
|
24
|
-
|
23
|
+
If using standalone ruby;
|
25
24
|
|
26
|
-
|
27
|
-
|
25
|
+
```
|
26
|
+
gem install sensu-plugins-snmptrap-extension
|
28
27
|
|
29
|
-
|
30
|
-
|
28
|
+
ln -s $(gem environment gemdir)/gems/sensu-plugins-snmptrap-extension*/bin/extension-snmptrap.rb /etc/sensu/extensions/extension-snmptrap.rb
|
29
|
+
```
|
31
30
|
|
32
|
-
|
33
|
-
> can't get resolved) and 'source' contains the IP address (with no lookups)
|
31
|
+
## Configuration
|
34
32
|
|
35
|
-
|
33
|
+
The SNMPTrap configuration is defined in a json file inside conf.d/extensions (or anywhere sensu consumes configuration)
|
34
|
+
and includes a traps configuration element that describes:
|
36
35
|
|
36
|
+
* An array of traps that the extension will monitor for events (from any host) which includes
|
37
|
+
* `trap_oid` - the identity of the trap
|
38
|
+
* `trap` - A hash of key/value pairs that can be used as template values in the event
|
39
|
+
* `event` - The template event to send to Sensu, including {template} variables for customisation based on the message
|
37
40
|
|
38
|
-
{
|
39
|
-
"snmp": {
|
40
|
-
|
41
|
-
}
|
42
|
-
}
|
43
41
|
|
44
42
|
### Trap Configuration
|
45
43
|
|
46
|
-
Each SNMP Trap is configured in its own configuration file. This lets you easily create configuration through Puppet/Chef etc without
|
47
|
-
having to manipulate the same configuration file.
|
48
|
-
|
49
|
-
Simply create a uniquely named json file in `/etc/sensu/traps.d` containing the definition of the trap(s) you wish to capture and
|
50
|
-
act upon.
|
44
|
+
Each SNMP Trap is configured in its own configuration file. This lets you easily create configuration through Puppet/Chef etc without having to manipulate the same configuration file.
|
51
45
|
|
46
|
+
Simply create a uniquely named json file in `/etc/sensu/traps.d` containing the definition of the trap(s) you wish to capture and act upon.
|
52
47
|
|
48
|
+
```
|
53
49
|
[
|
54
50
|
{
|
55
51
|
"trap_oid": "1.3.6.1.4.1.8072.2.3.0.1",
|
56
52
|
"trap": {
|
57
|
-
"heartbeatrate": "1.3.6.1.4.1.8072.2.3.2.1"
|
53
|
+
"heartbeatrate": "1.3.6.1.4.1.8072.2.3.2.1"
|
58
54
|
},
|
59
55
|
"event": {
|
60
56
|
"name": "snmp-trap-{hostname}",
|
61
57
|
"status": 1,
|
62
|
-
"output": "Heartbeat Rate {heartbeatrate}",
|
63
|
-
"handler": "default"
|
58
|
+
"output": "Heartbeat Rate {heartbeatrate}",
|
59
|
+
"handler": "default",
|
60
|
+
"client": "{hostname}"
|
64
61
|
}
|
65
62
|
},
|
66
63
|
...
|
67
64
|
]
|
65
|
+
```
|
68
66
|
|
69
67
|
The JSON file is an array of trap definitions containing:
|
70
68
|
|
71
69
|
* trap_oid
|
72
70
|
* Definition: (String) The OID to monitor for events on
|
73
71
|
* trap
|
74
|
-
* Definition: (Array) Key/Value pairs representing named variables (key)
|
75
|
-
|
72
|
+
* Definition: (Array) Key/Value pairs representing named variables (key)
|
73
|
+
against the OID values of the message elements (value) which can then be
|
74
|
+
used as template values in the event section
|
76
75
|
* event
|
77
|
-
* Definition: (Hash) The event to trigger if the SNMP trap is
|
78
|
-
|
76
|
+
* Definition: (Hash) The event to trigger if the SNMP trap is received - Accepts any
|
77
|
+
value that will then get sent to sensu as a normal check event - this includes
|
78
|
+
handlers, subdues, or custom key/value pairs as you require.
|
79
79
|
* name
|
80
|
-
* Definition: (String) The name of the sensu check that is sent to the
|
80
|
+
* Definition: (String) The name of the sensu check that is sent to the
|
81
|
+
sensu-client - ALPHANUMERIC and should be fairly unique (Required)
|
81
82
|
* status
|
82
|
-
* Definition: (Numeric) The numeric status of the status
|
83
|
+
* Definition: (Numeric) The numeric status of the status
|
84
|
+
(0-OK, 1-Warning, 2-Critical, 3-Unknown) (Required)
|
83
85
|
* output
|
84
86
|
* Definition: (String) The message to send to the sensu client (Required)
|
85
87
|
* handler
|
86
88
|
* Definition: (String) The handler that the sensu-server should use to process this event (Optional)
|
87
89
|
|
90
|
+
#### Templating
|
91
|
+
|
92
|
+
Any value defined in `trap` that contains an OID that is included in the incoming trap can be used as part of any element of the
|
93
|
+
event being sent to Sensu. This includes handlers, names (Only AlphaNumeric allow), status etc etc.
|
94
|
+
|
95
|
+
Simply wrap your template in braces and it will be automatically replaced during processing. See the heartbeatrate in the example
|
96
|
+
below.
|
97
|
+
|
98
|
+
> Note: The 'source' and 'hostname' variables are automatically provided to you. Hostname contains the FQDN name of the server (or the IP if it
|
99
|
+
> can't get resolved) and 'source' contains the IP address (with no lookups)
|
100
|
+
|
101
|
+
### Override SNMP default configuration
|
102
|
+
|
103
|
+
The SNMPTrap extension provides some simple configuration options which are shown
|
104
|
+
below;
|
105
|
+
|
106
|
+
{
|
107
|
+
"snmp": {
|
108
|
+
bind: '0.0.0.0',
|
109
|
+
port: 1062,
|
110
|
+
community: 'public',
|
111
|
+
handler: 'default',
|
112
|
+
send_interval: 60,
|
113
|
+
trapdefs_dir: '/etc/sensu/traps.d',
|
114
|
+
mibs_dir: '/etc/sensu/mibs',
|
115
|
+
client_socket_bind: settings[:client][:socket][:bind],
|
116
|
+
client_socket_port: settings[:client][:socket][:port]
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
|param|type|default|description|
|
121
|
+
|----|----|----|---|
|
122
|
+
|:bind|:string|0.0.0.0| IP to bind the SNMPTrap listener to |
|
123
|
+
|:port|:integer|1062| Port to bind the SNMPTrap listener to |
|
124
|
+
|:community|:string|"public"| *NOT USED* |
|
125
|
+
|:handler|:string|"default"| *NOT USED* |
|
126
|
+
|:send_interval|:integer|60| *NOT USED* |
|
127
|
+
|:trapdefs_dir|:string|"/etc/sensu/traps.d"| Path to directory containing trap.json files to watch for |
|
128
|
+
|:mibs_dir|:string|"/etc/sensu/mibs"| *NOT USED* - Loading MIBs causes the extension to lock up |
|
129
|
+
|:client_socket_bind|:string| `settings[:client][:socket][:bind]` | IP to send events to when handled |
|
130
|
+
|:client_socket_port|:integer| `settings[:client][:socket][:port]` | Port to send events to when handled|
|
131
|
+
|
132
|
+
#### client_socket_xxx
|
133
|
+
|
134
|
+
SNMPTrap has to use the sensu client socket to emit events when traps arrive.
|
135
|
+
This is because there does not appear to be an asynchronous mechanism to send
|
136
|
+
event objects into sensu-client directly, so instead a brief TCP connection
|
137
|
+
to the sensu-client is made.
|
88
138
|
|
89
|
-
|
139
|
+
The extension tries to get the configuration from the sensu config.json, so
|
140
|
+
this should not require changing, but if you'd like to send events to another
|
141
|
+
sensu-client you can do so here.
|
90
142
|
|
91
|
-
Handy Test script:
|
92
143
|
|
144
|
+
## Appendix
|
145
|
+
|
146
|
+
### snmp-mibs-downloader - My SNMP doesn't work
|
147
|
+
|
148
|
+
If youre using a Debian/Ubuntu based distro, you may find it hard to get SNMP working
|
149
|
+
as it doens't include the set of MIB definitions required for alot of common systems.
|
150
|
+
|
151
|
+
This is because those definitions have been copyrighted by various organisations and
|
152
|
+
as such can only be obtained on the 'non-free' channels.
|
153
|
+
|
154
|
+
To help get setup without having to install the non-free distribution, you can use
|
155
|
+
the following few commands to get updated (and therefore working) MIB lists
|
156
|
+
|
157
|
+
|
158
|
+
```
|
159
|
+
apt-get install smistrip snmp
|
160
|
+
wget http://ftp.uk.debian.org/debian/pool/non-free/s/snmp-mibs-downloader/snmp-mibs-downloader_1.1_all.deb
|
161
|
+
dpkg -i snmp-mibs-downloader_1.1_all.deb
|
162
|
+
```
|
163
|
+
|
164
|
+
|
165
|
+
### Testing your configuration
|
166
|
+
|
167
|
+
Add a configuration file like this into `/etc/sensu/traps.d/example_heartbeat.json`
|
168
|
+
|
169
|
+
```
|
170
|
+
[
|
171
|
+
{
|
172
|
+
"trap_oid": "1.3.6.1.4.1.8072.2.3.0.1",
|
173
|
+
"trap": {
|
174
|
+
"heartbeatrate": "1.3.6.1.4.1.8072.2.3.2.1"
|
175
|
+
},
|
176
|
+
"event": {
|
177
|
+
"name": "snmp-trap-{hostname}",
|
178
|
+
"status": 1,
|
179
|
+
"output": "Heartbeat Rate {heartbeatrate}",
|
180
|
+
"handler": "default"
|
181
|
+
}
|
182
|
+
}
|
183
|
+
]
|
184
|
+
```
|
185
|
+
|
186
|
+
And then run the following command;
|
187
|
+
|
188
|
+
```
|
93
189
|
snmptrap -v 2c -c public localhost:1062 "" NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatNotification netSnmpExampleHeartbeatRate i 123456
|
190
|
+
```
|
191
|
+
|
192
|
+
> Requires the `snmp` package to be installed
|
94
193
|
|
194
|
+
# License
|
95
195
|
|
96
|
-
Released under the same terms as Sensu (the MIT license).
|
196
|
+
Released under the same terms as Sensu (the MIT license).
|
data/bin/extension-snmptrap.rb
CHANGED
@@ -4,17 +4,29 @@
|
|
4
4
|
#
|
5
5
|
# DESCRIPTION:
|
6
6
|
# Handles incoming SNMP Traps and emits sensu events
|
7
|
-
# Creates an SNMP trap listening to all incoming traps on any interface and
|
7
|
+
# Creates an SNMP trap listening to all incoming traps on any interface and
|
8
|
+
# triggers events into sensu as JIT clients specifying the source of the event.
|
8
9
|
#
|
9
|
-
# Also able to run as a 'polling' service in either Check or Metrics mode
|
10
|
-
# where values can be directly compared against expectations (eg value > 10)
|
11
|
-
# or where values are sent to Sensu as metrics values for charting or
|
12
|
-
# other purposes.
|
13
10
|
#
|
14
11
|
# {
|
15
12
|
# "snmp": { }
|
16
13
|
# }
|
17
14
|
#
|
15
|
+
# Default options are;
|
16
|
+
# {
|
17
|
+
# "snmp": {
|
18
|
+
# bind: '0.0.0.0',
|
19
|
+
# port: 1062,
|
20
|
+
# community: 'public',
|
21
|
+
# handler: 'default',
|
22
|
+
# send_interval: 60,
|
23
|
+
# trapdefs_dir: '/etc/sensu/traps.d',
|
24
|
+
# mibs_dir: '/etc/sensu/mibs',
|
25
|
+
# client_socket_bind: settings[:client][:socket][:bind],
|
26
|
+
# client_socket_port: settings[:client][:socket][:port]
|
27
|
+
# }
|
28
|
+
# }
|
29
|
+
#
|
18
30
|
# OUTPUT:
|
19
31
|
# N/A - Extension submits multiple events of different types based on snmp configuration
|
20
32
|
#
|
@@ -56,16 +68,6 @@ include SNMP
|
|
56
68
|
module Sensu
|
57
69
|
module Extension
|
58
70
|
class SNMPTrapHandler < Check
|
59
|
-
# assume the /etc/sensu/extensions folder as location for relative
|
60
|
-
data_path = File.expand_path(File.dirname(__FILE__) + '/../mibs')
|
61
|
-
|
62
|
-
DEFAULT_MIB_PATH = nil
|
63
|
-
if File.exist?(data_path)
|
64
|
-
DEFAULT_MIB_PATH = data_path
|
65
|
-
else
|
66
|
-
@logger.info "Could not find default MIB directory, tried:\n #{data_path}"
|
67
|
-
end
|
68
|
-
|
69
71
|
def name
|
70
72
|
'SnmpTrapHandler'
|
71
73
|
end
|
@@ -83,7 +85,9 @@ module Sensu
|
|
83
85
|
handler: 'default',
|
84
86
|
send_interval: 60,
|
85
87
|
trapdefs_dir: '/etc/sensu/traps.d',
|
86
|
-
mibs_dir: '/etc/sensu/mibs'
|
88
|
+
mibs_dir: '/etc/sensu/mibs',
|
89
|
+
client_socket_bind: settings[:client][:socket][:bind],
|
90
|
+
client_socket_port: settings[:client][:socket][:port]
|
87
91
|
}
|
88
92
|
@options.merge!(@settings[:snmp]) if @settings[:snmp].is_a?(Hash)
|
89
93
|
@options
|
@@ -97,37 +101,50 @@ module Sensu
|
|
97
101
|
}
|
98
102
|
end
|
99
103
|
|
100
|
-
def
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
# do something with the file here
|
106
|
-
@logger.info file
|
107
|
-
@trapdefs.concat Array(JSON.parse(File.read(file)))
|
104
|
+
def validate
|
105
|
+
|
106
|
+
if options[:client_socket_bind].nil?
|
107
|
+
@logger.warn "couldnt find client socket binding - is it defined? https://sensuapp.org/docs/latest/reference/clients.html#socket-attributes"
|
108
|
+
false
|
108
109
|
end
|
110
|
+
true
|
111
|
+
end
|
109
112
|
|
110
|
-
|
113
|
+
def post_init
|
114
|
+
if !validate
|
115
|
+
@logger.error "failed to validate the #{name} extension"
|
116
|
+
else
|
117
|
+
# Setup SNMPTrap
|
118
|
+
@logger.debug "loading SNMPTrap definitions from #{options[:trapdefs_dir]}"
|
119
|
+
@trapdefs = []
|
120
|
+
Dir.glob(options[:trapdefs_dir] + '/*.json') do |file|
|
121
|
+
@logger.debug "Reading #{file}..."
|
122
|
+
@trapdefs.concat Array(::JSON.parse(File.read(file)))
|
123
|
+
end
|
111
124
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
@
|
116
|
-
|
117
|
-
|
118
|
-
|
125
|
+
@logger.debug "loaded trapdefs..."
|
126
|
+
@logger.debug @trapdefs.to_json
|
127
|
+
|
128
|
+
@mibs = []
|
129
|
+
Dir.glob(options[:mibs_dir] + '/*.yaml') do |file|
|
130
|
+
# do something with the file here
|
131
|
+
@logger.debug "reading MIB configuration from #{File.basename(file, '.yaml')}"
|
132
|
+
@mibs << File.basename(file, '.yaml')
|
133
|
+
end
|
134
|
+
@logger.debug @mibs.to_json
|
119
135
|
|
120
|
-
|
136
|
+
start_trap_listener
|
137
|
+
end
|
121
138
|
end
|
122
139
|
|
123
140
|
def run(_data = nil, _options = {}, &callback)
|
124
|
-
@logger.warn('SNMP
|
141
|
+
@logger.warn('SNMP trap: run called as a check - this is not supported')
|
125
142
|
output = 'SNMPHandler extension should not be called as a standalone check'
|
126
143
|
callback.call(output, 3)
|
127
144
|
end
|
128
145
|
|
129
146
|
def start_trap_listener
|
130
|
-
@logger.info('
|
147
|
+
@logger.info('starting SNMPTrap listener...')
|
131
148
|
|
132
149
|
SNMP::TrapListener.new(Host: options[:bind], Port: options[:port]) do |manager|
|
133
150
|
# Need patched Gem to allow the following functions/lookups
|
@@ -140,13 +157,11 @@ module Sensu
|
|
140
157
|
# @mib = manager.mib
|
141
158
|
|
142
159
|
manager.on_trap_v1 do |trap|
|
143
|
-
@logger.
|
144
|
-
@logger.info trap.to_json
|
160
|
+
@logger.warn('SNMPTrap caught an snmp v1 trap which not currently handled')
|
145
161
|
end
|
146
162
|
|
147
163
|
manager.on_trap_v2c do |trap|
|
148
|
-
@logger.
|
149
|
-
@logger.info(trap.to_json)
|
164
|
+
@logger.debug('v2-Trap caught')
|
150
165
|
|
151
166
|
processed = false
|
152
167
|
@trapdefs.each do |trapdef|
|
@@ -159,16 +174,16 @@ module Sensu
|
|
159
174
|
@logger.debug 'trap ' + trap.trap_oid.inspect
|
160
175
|
# only accept configured traps
|
161
176
|
if trap.trap_oid == trapdef_oid
|
162
|
-
@logger.info "
|
177
|
+
@logger.info "SNMPTrap is processing a defined snmp v2 trap oid:#{trap.trap_oid}"
|
163
178
|
process_v2c_trap trap, trapdef
|
164
179
|
processed = true
|
165
180
|
break
|
166
181
|
end
|
167
|
-
@logger.debug "
|
182
|
+
@logger.debug "ignoring unrecognised trap: #{trap.trap_oid}" unless processed
|
168
183
|
end
|
169
184
|
end
|
170
185
|
|
171
|
-
@logger.info("
|
186
|
+
@logger.info("SNMPTrap listener has started on #{options[:bind]}:#{options[:port]}")
|
172
187
|
end
|
173
188
|
end
|
174
189
|
|
@@ -179,12 +194,18 @@ module Sensu
|
|
179
194
|
def publish_check_result(check)
|
180
195
|
# a little risky: we're assuming Sensu-Client is listening on Localhost:3030
|
181
196
|
# for submitted results : https://sensuapp.org/docs/latest/clients#client-socket-input
|
182
|
-
@logger.
|
197
|
+
@logger.debug "sending SNMP check event: #{check.to_json}"
|
183
198
|
|
184
|
-
host =
|
185
|
-
port =
|
186
|
-
|
187
|
-
|
199
|
+
host = options[:client_socket_bind]
|
200
|
+
port = options[:client_socket_port]
|
201
|
+
|
202
|
+
begin
|
203
|
+
@logger.debug "opening connection to #{host}:#{port}"
|
204
|
+
t = TCPSocket.new host, port
|
205
|
+
t.write(check.to_json + "\n")
|
206
|
+
rescue Exception => e
|
207
|
+
@logger.error(e)
|
208
|
+
end
|
188
209
|
end
|
189
210
|
|
190
211
|
def process_v2c_trap(trap, trapdef)
|
@@ -192,14 +213,14 @@ module Sensu
|
|
192
213
|
begin
|
193
214
|
hostname = Resolv.getname(trap.source_ip)
|
194
215
|
rescue Resolv::ResolvError
|
195
|
-
@logger.debug("
|
216
|
+
@logger.debug("unable to resolve name for #{trap.source_ip}")
|
196
217
|
end
|
197
218
|
|
198
219
|
fields = {}
|
199
220
|
fields[:source] = trap.source_ip
|
200
221
|
fields[:hostname] = hostname
|
201
222
|
|
202
|
-
@logger.debug('
|
223
|
+
@logger.debug('checking trap definition for key/value template pairs')
|
203
224
|
Array(trapdef['trap']).each do |key, value|
|
204
225
|
begin
|
205
226
|
value = SNMP::ObjectId.new(value)
|
@@ -211,19 +232,19 @@ module Sensu
|
|
211
232
|
@logger.debug trap.varbind_list.inspect
|
212
233
|
val = trap.varbind_list.find { |vb| vb.name == value }
|
213
234
|
if val.nil?
|
214
|
-
@logger.warn("trap.#{key} has OID(#{value}) that was not found in incoming trap -
|
235
|
+
@logger.warn("trap.#{key} has OID(#{value}) that was not found in incoming trap - check your configuration")
|
215
236
|
end
|
216
|
-
@logger.debug("
|
237
|
+
@logger.debug("discovered value of #{key} is '#{val}'")
|
217
238
|
fields[key] = val.value unless val.nil?
|
218
239
|
end
|
219
240
|
|
220
|
-
@logger.debug("
|
241
|
+
@logger.debug("template fields are: #{fields.inspect}")
|
221
242
|
|
222
243
|
# Replace any {template} values in the event with the value of
|
223
244
|
# snmp values defined in the traps configuration
|
224
245
|
fields.each do |key, value|
|
225
246
|
trapdef['event'].each do |k, v|
|
226
|
-
@logger.debug("
|
247
|
+
@logger.debug("looking for #{key} in #{trapdef['event'][k]}")
|
227
248
|
begin
|
228
249
|
trapdef['event'][k] = v.gsub("{#{key}}", value.to_s.gsub('/', '-'))
|
229
250
|
rescue
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-snmptrap-extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Toby Jackson
|
8
|
-
- Peter Daugavietis
|
7
|
+
- Toby Jackson
|
8
|
+
- Peter Daugavietis
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain:
|