# Can you make a simple 'pipe' handler respect 'occurences' and 'refresh'?

**URL:** <https://discourse.sensu.io/t/can-you-make-a-simple-pipe-handler-respect-occurences-and-refresh/553>\
**Category:** Sensu Classic (EOL)\
**Created:** [March 7, 2016, 5:25pm UTC](https://discourse.sensu.io/t/can-you-make-a-simple-pipe-handler-respect-occurences-and-refresh/553 "2016-03-07T17:25:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vincent\_Cojot](https://avatars.discourse-cdn.com/v4/letter/v/7993a0/32.png) [@Vincent\_Cojot](https://discourse.sensu.io/u/Vincent_Cojot)\
**Post date:** [March 7, 2016, 5:25pm UTC](https://discourse.sensu.io/t/can-you-make-a-simple-pipe-handler-respect-occurences-and-refresh/553/1 "2016-03-07T17:25:27Z")

</div>

Dear All,

I’ve been struggling with that one…

I work in a limited environment (it’s a cool company but there are some things I cannot do) where:

1. the only version (at this time) of sensu that I can use is 0.16.0 (and it’s not the rpm available on Sensu’s website, unfortunately).

2. I cannot do ‘gem install’ of any kind (breaks supportability) but I can add rpm packages or simple self-contained scripts.

The latter prevents me from using most of the sensu-plugins developed by the community because they include a gem dependency of some kind at some step or another…

I’m limited to the following gems:

# gem list|grep sensu

sensu (0.16.0)

sensu-em (2.4.0)

sensu-extension (1.0.0)

sensu-extensions (1.0.0)

sensu-logger (1.0.0)

sensu-settings (1.2.0)

sensu-spawn (1.1.0)

sensu-transport (2.4.0)

So I’m trying to have Sensu send alerts by e-mail and make it -NOT- send e-mail -EVERY- minute for every alert…

My checks include something like this:

“ntpd\_health”: {

“handlers”: [“email”],

“command”: “{{ sensu\_plugins\_path }}/check\_ntpmon --okpeers 1”,

“subscribers”: [

“overcld\_generic”

],

“interval”: 60, “occurences”: 2, “refresh”: 1800

},

And the handler is a simple pipe:

{

“handlers”:

{

“email”: {

“command”: “python -mjson.tool|mail -v -s ‘Sensu alert’ -r [sensu-mail@company.org](mailto:sensu-mail@company.org) -S smtp-use-starttls -S ssl-verify=ignore -S smtp-auth=login -S ssl-verify=ignore -S nss-config-dir=/etc/pki/nssdb [recipient@company.org](mailto:recipient@company.org)”,

“type”: “pipe”

}

}

}

Alerts by e-mail work… but of course ‘occurences’ and ‘refresh’ are being ignored and I get an e-mail per alert per minute…

(on [https://sensuapp.org/docs/0.16/handlers](https://sensuapp.org/docs/0.16/handlers), it -DOES- say that " _Warning_: These trivial (pipe) handlers will not respect the popular `refresh` and `occurences` settings ",

So I’m not very surprised…

Is there a way to make a the handler a bit ‘smarter’ ? Or alternatively is there a mail handler that only had one of the above ‘gems’ as a requirement and that I could use?

I’m so new to Sensu, I’m a bit at loss…

Thanks for reading,

Vincent S. Cojot

---

<div class="post-metadata">

**Author:** ![Kyle\_Anderson](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@Kyle\_Anderson](https://discourse.sensu.io/u/Kyle_Anderson)\
**Post date:** [March 8, 2016, 3:28am UTC](https://discourse.sensu.io/t/can-you-make-a-simple-pipe-handler-respect-occurences-and-refresh/553/2 "2016-03-08T03:28:28Z")

</div>

Can you install gems in a bundle? If so you could install gems in an  
isolated bundle to your heart's content and then just point sensu at  
those "binaries" ?  
The steps would be:  
- make a Gemfile with the gems you want to use (sensu-plugins-mailer, etc)  
- bundle install --path something  
- bundle exec mail\_something ?  
I'm sure this \*could\* work, but seems like a lot of work to get around  
this limitation. Don't do this if you are not comfortable with  
bundler/ruby.

Other alternatives are installing the gems you needs and converting  
them to rpms with fpm (I've previously done this in a similar  
environment to you)  
So like:  
&nbsp;&nbsp;&nbsp;&nbsp;fpm -s gem -t deb sensu-handler; rpm -Uvh sensu-plugin\*.rpm  
Without knowing more about your ruby setup it is hard to know if this  
is a good idea or not.

Can you confirm when you run gem list | grep sensu, is that against  
the omnibus gem? Or system gem? (sounds like it may be system gem  
if it wasn't from a package from the website)

As a real last resort, as you see those handlers just read stdin -\>  
stdout. Your python code \*could\* do filtering on its own without the  
sensu-handler gem.  
(You would be re-implementing  
[https://github.com/sensu-plugins/sensu-plugin/blob/f1889faa5144650e2d8ca35816d659dd455c49e5/lib/sensu-handler.rb#L118](https://github.com/sensu-plugins/sensu-plugin/blob/f1889faa5144650e2d8ca35816d659dd455c49e5/lib/sensu-handler.rb#L118),  
and probably other filter\_ functions)  
Basically filling in the blanks here:  
[https://github.com/sensu/sensu-plugin-python/blob/master/sensu\_plugin/handler.py#L17](https://github.com/sensu/sensu-plugin-python/blob/master/sensu_plugin/handler.py#L17)

> **···**
>
> On Mon, Mar 7, 2016 at 9:25 AM, Vincent Cojot \<vincent.cojot@gmail.com\> wrote:
> 
> > Dear All,
> > 
> > I've been struggling with that one..
> > 
> > I work in a limited environment (it's a cool company but there are some  
> > things I cannot do) where:
> > 
> > 1) the only version (at this time) of sensu that I can use is 0.16.0 (and  
> > it's not the rpm available on Sensu's website, unfortunately).
> > 
> > 2) I cannot do 'gem install' of any kind (breaks supportability) but I can  
> > add rpm packages or simple self-contained scripts.
> > 
> > The latter prevents me from using most of the sensu-plugins developed by the  
> > community because they include a gem dependency of some kind at some step or  
> > another..  
> > I'm limited to the following gems:
> > 
> > # gem list|grep sensu  
> > sensu (0.16.0)  
> > sensu-em (2.4.0)  
> > sensu-extension (1.0.0)  
> > sensu-extensions (1.0.0)  
> > sensu-logger (1.0.0)  
> > sensu-settings (1.2.0)  
> > sensu-spawn (1.1.0)  
> > sensu-transport (2.4.0)
> > 
> > So I'm trying to have Sensu send alerts by e-mail and make it -NOT- send  
> > e-mail -EVERY- minute for every alert..
> > 
> > My checks include something like this:  
> > &nbsp;&nbsp;&nbsp;&nbsp;"ntpd\_health": {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"handlers": ["email"],  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"command": "{{ sensu\_plugins\_path }}/check\_ntpmon --okpeers 1",  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"subscribers": [  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"overcld\_generic"  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;],  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"interval": 60, "occurences": 2, "refresh": 1800  
> > &nbsp;&nbsp;&nbsp;&nbsp;},
> > 
> > And the handler is a simple pipe:  
> > {  
> > &nbsp;&nbsp;&nbsp;"handlers":  
> > &nbsp;&nbsp;&nbsp;{  
> > &nbsp;&nbsp;&nbsp;&nbsp;"email": {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"command": "python -mjson.tool|mail -v -s 'Sensu alert' -r  
> > sensu-mail@company.org -S smtp-use-starttls -S ssl-verify=ignore -S  
> > smtp-auth=login -S ssl-verify=ignore -S nss-config-dir=/etc/pki/nssdb  
> > recipient@company.org",  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"type": "pipe"  
> > &nbsp;&nbsp;&nbsp;&nbsp;}  
> > }  
> > }
> > 
> > Alerts by e-mail work.. but of course 'occurences' and 'refresh' are being  
> > ignored and I get an e-mail per alert per minute..  
> > (on [https://sensuapp.org/docs/0.16/handlers](https://sensuapp.org/docs/0.16/handlers), it -DOES- say that " Warning:  
> > These trivial (pipe) handlers will not respect the popular refresh and  
> > occurences settings ",  
> > So I'm not very surprised..
> > 
> > Is there a way to make a the handler a bit 'smarter' ? Or alternatively is  
> > there a mail handler that only had one of the above 'gems' as a requirement  
> > and that I could use?
> > 
> > I'm so new to Sensu, I'm a bit at loss..
> > 
> > Thanks for reading,
> > 
> > Vincent S. Cojot

---

<div class="post-metadata">

**Author:** ![Vincent\_Cojot](https://avatars.discourse-cdn.com/v4/letter/v/7993a0/32.png) [@Vincent\_Cojot](https://discourse.sensu.io/u/Vincent_Cojot)\
**Post date:** [April 7, 2016, 8:42pm UTC](https://discourse.sensu.io/t/can-you-make-a-simple-pipe-handler-respect-occurences-and-refresh/553/3 "2016-04-07T20:42:56Z")

</div>

Hi Kyle,  
Thanks for your answer. I didn’t know you could turn gems into rpms. I will look into that.

For the record, here’s how I solved this issue (And I wish to thank David Moreau-Simard for his help).

I added a ‘filters’ field as well as a ‘severities’ field to my e-mail handler… Here’s the relevant part of that json:

{

“handlers”:

{

“email”: {

“command”: “python -mjson.tool|mail -v -S [smtp=mx.company.com](http://smtp=mx.company.com) -s ‘Sensu alert (SC)’ -r …”,

“filters”: [

“filter\_check\_retry\_occurrences”

],

“severities”: [

“ok”,

“warning”,

“critical”,

“unknown”

],

“type”: “pipe”

}

}

The filter (here ‘filter\_check\_retry\_occurrences’) was written by David and it is quite simple in essence, adding ‘occurences’ checking where it isn’t already used.

The code was taken from this repo:

> <https://github.com/rdo-infra/ansible-role-rdomonitoring/blob/master/files/filter_check_retry_occurrences.rb>

filter\_check\_retry\_occurrences.rb had to be installed under /etc/sensu/extensions in order to be loaded properly…

That was it!

Kind regards,

Vincent

> **···**
>
> On Monday, March 7, 2016 at 10:28:30 PM UTC-5, Kyle Anderson wrote:
> 
> > Can you install gems in a bundle? If so you could install gems in an  
> > isolated bundle to your heart’s content and then just point sensu at  
> > those “binaries” ?  
> > The steps would be:
> > 
> > - make a Gemfile with the gems you want to use (sensu-plugins-mailer, etc)
> > - bundle install --path something
> > - bundle exec mail\_something ?  
> > I’m sure this _could_ work, but seems like a lot of work to get around  
> > this limitation. Don’t do this if you are not comfortable with  
> > bundler/ruby.
> > 
> > Other alternatives are installing the gems you needs and converting  
> > them to rpms with fpm (I’ve previously done this in a similar  
> > environment to you)  
> > So like:  
> > fpm -s gem -t deb sensu-handler; rpm -Uvh sensu-plugin\*.rpm  
> > Without knowing more about your ruby setup it is hard to know if this  
> > is a good idea or not.
> > 
> > Can you confirm when you run gem list | grep sensu, is that against  
> > the omnibus gem? Or system gem? (sounds like it may be system gem  
> > if it wasn’t from a package from the website)
> > 
> > As a real last resort, as you see those handlers just read stdin →   
> > stdout. Your python code _could_ do filtering on its own without the  
> > sensu-handler gem.  
> > (You would be re-implementing  
> > [https://github.com/sensu-plugins/sensu-plugin/blob/f1889faa5144650e2d8ca35816d659dd455c49e5/lib/sensu-handler.rb#L118](https://github.com/sensu-plugins/sensu-plugin/blob/f1889faa5144650e2d8ca35816d659dd455c49e5/lib/sensu-handler.rb#L118),  
> > and probably other filter\_ functions)  
> > Basically filling in the blanks here:  
> > [https://github.com/sensu/sensu-plugin-python/blob/master/sensu\_plugin/handler.py#L17](https://github.com/sensu/sensu-plugin-python/blob/master/sensu_plugin/handler.py#L17)
> > 
> > On Mon, Mar 7, 2016 at 9:25 AM, Vincent Cojot [vincen...@gmail.com](mailto:vincen...@gmail.com) wrote:
> > 
> > > Dear All,
> > > 
> > > I’ve been struggling with that one…
> > > 
> > > I work in a limited environment (it’s a cool company but there are some  
> > > things I cannot do) where:
> > > 
> > > 1. the only version (at this time) of sensu that I can use is 0.16.0 (and  
> > > it’s not the rpm available on Sensu’s website, unfortunately).
> > > 
> > > 2. I cannot do ‘gem install’ of any kind (breaks supportability) but I can  
> > > add rpm packages or simple self-contained scripts.
> > > 
> > > The latter prevents me from using most of the sensu-plugins developed by the  
> > > community because they include a gem dependency of some kind at some step or  
> > > another…  
> > > I’m limited to the following gems:
> > > 
> > > # gem list|grep sensu
> > > 
> > > sensu (0.16.0)  
> > > sensu-em (2.4.0)  
> > > sensu-extension (1.0.0)  
> > > sensu-extensions (1.0.0)  
> > > sensu-logger (1.0.0)  
> > > sensu-settings (1.2.0)  
> > > sensu-spawn (1.1.0)  
> > > sensu-transport (2.4.0)
> > > 
> > > So I’m trying to have Sensu send alerts by e-mail and make it -NOT- send  
> > > e-mail -EVERY- minute for every alert…
> > > 
> > > My checks include something like this:  
> > > “ntpd\_health”: {  
> > > “handlers”: [“email”],  
> > > “command”: “{{ sensu\_plugins\_path }}/check\_ntpmon --okpeers 1”,  
> > > “subscribers”: [  
> > > “overcld\_generic”  
> > > ],  
> > > “interval”: 60, “occurences”: 2, “refresh”: 1800  
> > > },
> > > 
> > > And the handler is a simple pipe:  
> > > {  
> > > “handlers”:  
> > > {  
> > > “email”: {  
> > > “command”: “python -mjson.tool|mail -v -s ‘Sensu alert’ -r  
> > > [sensu...@company.org](mailto:sensu...@company.org) -S smtp-use-starttls -S ssl-verify=ignore -S  
> > > smtp-auth=login -S ssl-verify=ignore -S nss-config-dir=/etc/pki/nssdb  
> > > [reci...@company.org](mailto:reci...@company.org)”,  
> > > “type”: “pipe”  
> > > }  
> > > }  
> > > }
> > > 
> > > Alerts by e-mail work… but of course ‘occurences’ and ‘refresh’ are being  
> > > ignored and I get an e-mail per alert per minute…  
> > > (on [https://sensuapp.org/docs/0.16/handlers](https://sensuapp.org/docs/0.16/handlers), it -DOES- say that " Warning:  
> > > These trivial (pipe) handlers will not respect the popular refresh and  
> > > occurences settings ",  
> > > So I’m not very surprised…
> > > 
> > > Is there a way to make a the handler a bit ‘smarter’ ? Or alternatively is  
> > > there a mail handler that only had one of the above ‘gems’ as a requirement  
> > > and that I could use?
> > > 
> > > I’m so new to Sensu, I’m a bit at loss…
> > > 
> > > Thanks for reading,
> > > 
> > > Vincent S. Cojot
