How to use multiple email handlers?

I’m trying to add an additional email handler which is separate and distinct from my default email handler to send an email another email address with the “subject_prefix” set. When I add this new handler(prod) and cause the check to alert, I am seeing two emails being sent but only to the email address that I have configured for the default handler. Also noteworthy is that both of these emails sent to the default handler email address has the subject_prefix set. This is obviously odd because my default handler doesn’t have the subject_prefix set so I wouldn’t expect my default handler to add the “subject_prefix” AND I would not expect the newly added handler to be sending to the email address specified in default_handler.json.

$ cat default_handler.json

{

“handlers”: {

“default”: {

“type”: “pipe”,

“command”: “/opt/sensu/embedded/bin/handler-mailer.rb”

}

},

“mailer”: {

“admin_gui”: “http://mon01.domain.com:3000/”,

“mail_from”: "sensu@mon01.domain.com",

“mail_to”: "ops@domain.com",

“smtp_address”: “mailserverIP”,

“smtp_port”: “25”,

“smtp_domain”: “domain.com

}

}

$ cat prod_handler.json

{

“handlers”: {

“prod”: {

“command”: “/opt/sensu/embedded/bin/handler-mailer.rb”,

“type”: “pipe”

}

},

“mailer”: {

“subject_prefix”: “TAG”,

“admin_gui”: “http://mon01.domain.com:3000/”,

“mail_from”: "sensu@mon01.domain.com",

“mail_to”: "alerts@domain.com",

“smtp_address”: “mailserverIP”,

“smtp_domain”: “domain.com”,

“smtp_port”: 25

}

}

cat check_crond.json

{

“checks”: {

“crond”: {

“command”: “/usr/lib/nagios/plugins/check_procs -c 1:1 -a ‘/usr/sbin/cron -f’ -u root”,

“handlers”: [

“prod”,

“default”

],

“interval”: 60,

“standalone”: true,

“user”: “sensu”

}

}

}

I have been able to add a second handlers for pagerduty alongside the default handler to some of my checks and they work fine but two email handlers do not. What am I doing wrong?

thank you,

Bob

I see this in sensu-server.log after a sensu-server restart:

{“timestamp”:“2018-04-29T20:08:56.665546-0700”,“level”:“warn”,“message”:“loading config file”,“file”:“/etc/sensu/conf.d/default_handler.json”}

{“timestamp”:“2018-04-29T20:08:56.665595-0700”,“level”:“warn”,“message”:“config file applied changes”,“file”:“/etc/sensu/conf.d/default_handler.json”,“changes”:{"handl

ers":{“default”:[null,{“type”:“pipe”,“command”:“/opt/sensu/embedded/bin/handler-mailer.rb”}]},“mailer”:{“mail_to”:[“alerts@domain.com”,“ops@domain.com”]}}}

My default_handler.json config is somehow picking up two email address. One I configured in prod_handler.json as well as the one in default_handler.json. This is not what I expect.

I’m uncertain if I am supposed to be able to configure multiple handlers that use handler-mailer.rb. I may be misunderstanding how this is supposed to work in sensu.

thanks.

···

On Sunday, April 29, 2018 at 12:43:10 PM UTC-7, Bob A wrote:

I’m trying to add an additional email handler which is separate and distinct from my default email handler to send an email another email address with the “subject_prefix” set. When I add this new handler(prod) and cause the check to alert, I am seeing two emails being sent but only to the email address that I have configured for the default handler. Also noteworthy is that both of these emails sent to the default handler email address has the subject_prefix set. This is obviously odd because my default handler doesn’t have the subject_prefix set so I wouldn’t expect my default handler to add the “subject_prefix” AND I would not expect the newly added handler to be sending to the email address specified in default_handler.json.

$ cat default_handler.json

{

“handlers”: {

“default”: {

“type”: “pipe”,

“command”: “/opt/sensu/embedded/bin/handler-mailer.rb”

}

},

“mailer”: {

“admin_gui”: “http://mon01.domain.com:3000/”,

“mail_from”: “sensu@mon01.domain.com”,

“mail_to”: “ops@domain.com”,

“smtp_address”: “mailserverIP”,

“smtp_port”: “25”,

“smtp_domain”: “domain.com

}

}

$ cat prod_handler.json

{

“handlers”: {

“prod”: {

“command”: “/opt/sensu/embedded/bin/handler-mailer.rb”,

“type”: “pipe”

}

},

“mailer”: {

“subject_prefix”: “TAG”,

“admin_gui”: “http://mon01.domain.com:3000/”,

“mail_from”: “sensu@mon01.domain.com”,

“mail_to”: “alerts@domain.com”,

“smtp_address”: “mailserverIP”,

“smtp_domain”: “domain.com”,

“smtp_port”: 25

}

}

cat check_crond.json

{

“checks”: {

“crond”: {

“command”: “/usr/lib/nagios/plugins/check_procs -c 1:1 -a ‘/usr/sbin/cron -f’ -u root”,

“handlers”: [

“prod”,

“default”

],

“interval”: 60,

“standalone”: true,

“user”: “sensu”

}

}

}

I have been able to add a second handlers for pagerduty alongside the default handler to some of my checks and they work fine but two email handlers do not. What am I doing wrong?

thank you,

Bob

This is how I got added an additional email handler:

$ cat basecamp_handler.json

{

“basecamp”: {

“admin_gui”: “http://mon01.domain:3000/”,

“mail_from”: “sensu@mon01.domain.com”,

“mail_to”: “xxx@domain.com”,

“smtp_address”: “IPaddress”,

“smtp_domain”: “inbox25.com”,

“smtp_port”: 25,

“subject_prefix”: “Discussion:”

},

“handlers”: {

“basecamp”: {

“command”: “/opt/sensu/embedded/bin/handler-mailer.rb -j basecamp”,

“type”: “pipe”

}

}

}

I can call the handler named ‘basecamp’ in the above example.

···

On Sunday, April 29, 2018 at 12:43:10 PM UTC-7, Bob A wrote:

I’m trying to add an additional email handler which is separate and distinct from my default email handler to send an email another email address with the “subject_prefix” set. When I add this new handler(prod) and cause the check to alert, I am seeing two emails being sent but only to the email address that I have configured for the default handler. Also noteworthy is that both of these emails sent to the default handler email address has the subject_prefix set. This is obviously odd because my default handler doesn’t have the subject_prefix set so I wouldn’t expect my default handler to add the “subject_prefix” AND I would not expect the newly added handler to be sending to the email address specified in default_handler.json.

$ cat default_handler.json

{

“handlers”: {

“default”: {

“type”: “pipe”,

“command”: “/opt/sensu/embedded/bin/handler-mailer.rb”

}

},

“mailer”: {

“admin_gui”: “http://mon01.domain.com:3000/”,

“mail_from”: “sensu@mon01.domain.com”,

“mail_to”: “ops@domain.com”,

“smtp_address”: “mailserverIP”,

“smtp_port”: “25”,

“smtp_domain”: “domain.com

}

}

$ cat prod_handler.json

{

“handlers”: {

“prod”: {

“command”: “/opt/sensu/embedded/bin/handler-mailer.rb”,

“type”: “pipe”

}

},

“mailer”: {

“subject_prefix”: “TAG”,

“admin_gui”: “http://mon01.domain.com:3000/”,

“mail_from”: “sensu@mon01.domain.com”,

“mail_to”: “alerts@domain.com”,

“smtp_address”: “mailserverIP”,

“smtp_domain”: “domain.com”,

“smtp_port”: 25

}

}

cat check_crond.json

{

“checks”: {

“crond”: {

“command”: “/usr/lib/nagios/plugins/check_procs -c 1:1 -a ‘/usr/sbin/cron -f’ -u root”,

“handlers”: [

“prod”,

“default”

],

“interval”: 60,

“standalone”: true,

“user”: “sensu”

}

}

}

I have been able to add a second handlers for pagerduty alongside the default handler to some of my checks and they work fine but two email handlers do not. What am I doing wrong?

thank you,

Bob

Hey Bob,

I want to thank you for keeping everyone up to date as you figure it out. I know others appreciate it as well when the find this thread later on. Thank you!

Best,

···

Matt Broberg

VP of Community, Sensu

Join us at the 2018 Sensu Summit, August 22-23, 2018 in Portland, OR!

On Wed, May 2, 2018 at 6:46 PM, Bob A bob.ababurko@gmail.com wrote:

This is how I got added an additional email handler:

$ cat basecamp_handler.json

{

“basecamp”: {

“admin_gui”: “http://mon01.domain:3000/”,

“mail_from”: “sensu@mon01.domain.com”,

“mail_to”: “xxx@domain.com”,

“smtp_address”: “IPaddress”,

“smtp_domain”: “inbox25.com”,

“smtp_port”: 25,

“subject_prefix”: “Discussion:”

},

“handlers”: {

“basecamp”: {

“command”: “/opt/sensu/embedded/bin/handler-mailer.rb -j basecamp”,

“type”: “pipe”

}

}

}

I can call the handler named ‘basecamp’ in the above example.

On Sunday, April 29, 2018 at 12:43:10 PM UTC-7, Bob A wrote:

I’m trying to add an additional email handler which is separate and distinct from my default email handler to send an email another email address with the “subject_prefix” set. When I add this new handler(prod) and cause the check to alert, I am seeing two emails being sent but only to the email address that I have configured for the default handler. Also noteworthy is that both of these emails sent to the default handler email address has the subject_prefix set. This is obviously odd because my default handler doesn’t have the subject_prefix set so I wouldn’t expect my default handler to add the “subject_prefix” AND I would not expect the newly added handler to be sending to the email address specified in default_handler.json.

$ cat default_handler.json

{

“handlers”: {

“default”: {

“type”: “pipe”,

“command”: “/opt/sensu/embedded/bin/handler-mailer.rb”

}

},

“mailer”: {

“admin_gui”: “http://mon01.domain.com:3000/”,

“mail_from”: “sensu@mon01.domain.com”,

“mail_to”: “ops@domain.com”,

“smtp_address”: “mailserverIP”,

“smtp_port”: “25”,

“smtp_domain”: “domain.com

}

}

$ cat prod_handler.json

{

“handlers”: {

“prod”: {

“command”: “/opt/sensu/embedded/bin/handler-mailer.rb”,

“type”: “pipe”

}

},

“mailer”: {

“subject_prefix”: “TAG”,

“admin_gui”: “http://mon01.domain.com:3000/”,

“mail_from”: “sensu@mon01.domain.com”,

“mail_to”: “alerts@domain.com”,

“smtp_address”: “mailserverIP”,

“smtp_domain”: “domain.com”,

“smtp_port”: 25

}

}

cat check_crond.json

{

“checks”: {

“crond”: {

“command”: “/usr/lib/nagios/plugins/check_procs -c 1:1 -a ‘/usr/sbin/cron -f’ -u root”,

“handlers”: [

“prod”,

“default”

],

“interval”: 60,

“standalone”: true,

“user”: “sensu”

}

}

}

I have been able to add a second handlers for pagerduty alongside the default handler to some of my checks and they work fine but two email handlers do not. What am I doing wrong?

thank you,

Bob