sensu/sensu-community-plugins — pull request #706 by sharkerz (2014-08-11 09:45:56+00:00)
Title: Fix remediation handler

Hi guys,

This is my first PR here, I hope I am doing all the steps fine.

We tried to implement the remediation in our infrastructure, and we saw a few small bugs in the remediation handler (which is awesome and you can't imagine how well are we going to sleep at night thanks to this).

As we think the remediation is a really important feature, I decided to make it work at any cost, and this is the result of it. There are two small issues:

1. The `trigger_on` property, if is inside the `remediation` dictionary, will break the script (as with the current loop, `trigger_on` is an array and it tries to access that value expecting at least an `occurrences` key. This was a tricky one because the script was breaking silently. My solution was to put the `trigger_on` property outside the `remediation` dictionary, which is perfectly fine.
2. The `occurrences` loop is wrong, the `next` statement will break the inner loop, that is the `occurrences` array loop, instead of the outer loop (`remediations`) which avoids to add it to the remediations to check list. So basically, if the event is matching the severity, it doesn't matter what you put in occurrences, as it will be always triggered. The solution for this was to create a flag and just add it if there is at least 1 occurrence matching. Of course the code is a bit less beautiful, but it works.

Keep the good work!