warmfusion / sensu-extension-snmptrap

An SNMP Trap extension for Sensu that runs inside the Sensu-Client waiting for SNMP events to come in
MIT License
7 stars 9 forks source link

Template variables are only replaced once for each trap #4

Open dave-hassett-rft opened 8 years ago

dave-hassett-rft commented 8 years ago

It seems that when a trap is received once, then again with different arguments, the template variable replacements from the first trap are retained. This appears to be related to the "trapdef" argument to the process_v2c_trap(trap, trapdef) method, which is only being passed by reference. The variable replacements are processed on the first trap call, but have already been replaced on the second call (and subsequent calls), so does nothing.

I'll send a merge request for a possible fix for this issue shortly.

warmfusion commented 8 years ago

It took a little while to work out what you mean; but i think I understand the situation;

  1. Trap definitions are loaded into a hash
  2. The first SNMP Trap that gets handled mutates the hash template values directly
  3. A second SNMP trap gets handled uses the now modified trapdef which no longer has template values to replace
warmfusion commented 8 years ago

Hi @dhassett-tr - I've released a new version of the plugin that includes your changes in #5 - Can you check it's working as you'd expect for me?

dave-hassett-rft commented 8 years ago

Thanks - I'll check when I get a moment. Much appreciated.