Yes, you are right. Refresh is the number of seconds before taking action:
https://github.com/sensu/sensu-docs/blame/6ece8e06ffc28217d0dd130fbab697d644710b1d/source/docs/0.13/checks.md#L382
And that is what it does here:
https://github.com/sensu/sensu-plugin/blob/1c75c7f7f831f800395ba681ffe03de734a52ab7/lib/sensu-handler.rb#L100-L101
So....
This is a bit of a tricky situation. On the one hand, sensu-core has
to provide some sort of function for this (maybe) and give names to
these parameters, so it does, and the sensu-community handlers respect
them.
But, I personally never liked "refresh" "occurrences" and "interval".
So my team at my company decided as a group to say "screw it" and do
our own, we chose "check_every", "alert_after", and "realert_every",
and wrote our on filter_repeated function that works the way we
wanted. (create an event on the first occurrence after the alert_after
threshold. Re-alert every n time afterwards. We have a special "-1"
for exponential backoff. "0" would do what you would want in this
case, realert never.)
So the workaround is to take advantage of the flexibility of Sensu and
blaze your own trail, making handlers work for you, the way you want
them. (by overriding the filter_repeated function)
(Yes, I intend to open source mine to serve as examples so you can
copy. Stay tuned)
Long term, I don't know if there are plans to make these check
tune-ables any better or different. Changing these would break lots of
behavior. But, if you felt strongly that this is an issue, I would
open an issue and see what the sensu-core people say? (I'll vote for
you?)
--
So. Long story short: Yes, "refresh" delays the create event.
Yes, there is a work around, it is to... add a filter_repeated
function in your handler that does what you want.
def filter_repeated
if @event['occurrences'] > 1 && @event['action'] == 'create'
bail 'only handling the first occurrence of this check.'
end
end
Sorry for the long-winded answer. Obviously this is something I've
thought a lot about and wrestled with.
On Tue, Aug 5, 2014 at 10:18 PM, Abhishek Jain <abhi1...@gmail.com> wrote:
> Thanks for the response Kyle. That solves the "resolve" part of things
> where
> it immediately gets handled. But I still have one query: If it affects
> the
> "create" event then even the handling of the first such create
> occurrence
> gets delayed by the refresh interval, right? What if I still want to be
> immediately notified when the first such occurrence happens but not be
> notified again till it gets resolved. Is there a work around for that as
> well, is my question!
>
>
> On Tuesday, 5 August 2014 20:11:47 UTC+5:30, Kyle Anderson wrote:
>>
>> The refresh interval only affects things on the create stage:
>>
>> https://github.com/sensu/sensu-plugin/blob/master/lib/sensu-handler.rb#L99
>>
>> Resolve events are not affected by it.
>>
>> On Tue, Aug 5, 2014 at 3:57 AM, Abhishek Jain <abhi1...@gmail.com> >> >> wrote:
>> > Also, the same goes for detecting an issue as well. A high refresh
>> > interval
>> > on the check could notify of the error quite late which could be
>> > undesirable.
>> >
>> >
>> > On Tuesday, 5 August 2014 16:26:06 UTC+5:30, Abhishek Jain wrote:
>> >>
>> >> Is there a better way of doing this rather than having a high
>> >> refresh
>> >> interval in the check. This is because I might want to know if the
>> >> issue is
>> >> resolved as soon as it is resolved. A high refresh interval on check
>> >> will
>> >> defer the resolved mail as well till the time the check is invoked
>> >> again.
>> >>
>> >> On Tuesday, 13 May 2014 05:42:20 UTC+5:30, Rodrigo Rosenfeld Rosas >> >> >> wrote:
>> >>>
>> >>> Ok, thank you. Sorry, I didn't subscribe to this topic it seems, so
>> >>> I
>> >>> haven't seen this answer before...
>> >>>
>> >>> I'd really prefer for Sensu to only send me a notification of
>> >>> changes,
>> >>> but if this is not possible I'll set a high refresh interval as a
>> >>> work-around.
>> >>>
>> >>> Thanks,
>> >>> Rodrigo.
>> >>>
>> >>> Em quinta-feira, 20 de março de 2014 06h15min01s UTC-3, Alexander >> >> >>> Piavlo >> >> >>> escreveu:
>> >>>>
>> >>>>
>> >>>> just set a very high refresh interval in check definition
>> >>>>
>> >>>> On 03/19/2014 06:57 PM, Rodrigo Rosenfeld Rosas wrote:
>> >>>> > I'd like to get an e-mail everytime some check changes its state
>> >>>> > by
>> >>>> > returning a different exit code.
>> >>>> >
>> >>>> > I'm using the mailer handler from the community repository and I
>> >>>> > notice it inherits from Sensu::Handler (from sensu-plugin gem).
>> >>>> > Looking at its implementation and a the server logs it seems
>> >>>> > everytime
>> >>>> > my checker exits with an error code, the handlers get an event
>> >>>> > with
>> >>>> > action "create".
>> >>>> >
>> >>>> > By default the action won't be called for multiple "create"
>> >>>> > events
>> >>>> > until the timeout specified in the "refresh" setting, so I get
>> >>>> > this
>> >>>> > message in the server logs:
>> >>>> >
>> >>>> > "only handling every 60 occurrences" (interval is set to 30s and
>> >>>> > default refresh is 1800s or 30min)
>> >>>> >
>> >>>> > But I don't want to get an e-mail reminding me every 30 minutes
>> >>>> > (or
>> >>>> > any other time set in the "refresh" setting). I just want to get
>> >>>> > another e-mail once it's resolved. Would that be possible?
>> >>>> >
>> >>>> > Thanks in advance,
>> >>>> > Rodrigo.
>> >>>> >
>> >>>>
>> >