Struggling to get slack report to two different channels

Hi all
I am trying to get certain alerts to one slack channel and rest to a separate one. I am using sensu 0.26.5. I have two json files for handlers in /etc/sensu/conf.d

  1. cops_slack.json

{

“handlers”: {

“cops_slack”: {

“type”: “pipe”,

“command”: “/etc/sensu/handlers/cops_slack.rb”

}

},

“slack”: {

“webhook_url”:"https://hooks.slack.com/services/XXXDDDD,

“channel”: “#alerts1”,

“bot_name”: “Sensu”,

“markdown_enabled”: true

}

}

  1. my_handler.json

{

“handlers”: {

“slack”: {

“type”: “pipe”,

“command”: “/etc/sensu/handlers/my_handler_slack.rb”

}

},

“slack”: {

“webhook_url”: “https://hooks.slack.com/services/XXX”,

“channel”: “#backend-core-alerts”,

“bot_name”: “Sensu”,

“markdown_enabled”: true

}

}

I am specifying handler to use in the check definition, for example:

{

“checks”: {

“cassandra_ntp”: {

“handler”: “cops_slack”,

“command”: “check-process.rb -p ntp -W 1”,

“subscribers”: [

“ABCD”

],

“interval”: 60

}

}

}

This setup is not working for me. For some strange reasons if I remove my_handler.json from conf.d/ cops_slack handler would kick in as expected and would report to the expected channel but as soon as I bring back my_handler (restart sensu server, api) the same check now would report to the channel mentioned in my_handler. I have reproduced this several times and am out of ideas here. I would be grateful if some one can help me out here.

Thanks

All the json files in conf.d get merged together, so there is only one “slack”: configuration hash manifesting.

You will probably have to do something that understands multi-channel more natively

https://github.com/sensu-plugins/sensu-plugins-slack/blob/master/bin/handler-slack-multichannel.rb

···

On Wed, Feb 22, 2017 at 7:09 PM, aiman parvaiz aimanparvaiz@gmail.com wrote:

Hi all
I am trying to get certain alerts to one slack channel and rest to a separate one. I am using sensu 0.26.5. I have two json files for handlers in /etc/sensu/conf.d

  1. cops_slack.json

{

“handlers”: {

“cops_slack”: {

“type”: “pipe”,

“command”: “/etc/sensu/handlers/cops_slack.rb”

}

},

“slack”: {

“webhook_url”:"https://hooks.slack.com/services/XXXDDDD,

“channel”: “#alerts1”,

“bot_name”: “Sensu”,

“markdown_enabled”: true

}

}

  1. my_handler.json

{

“handlers”: {

“slack”: {

“type”: “pipe”,

“command”: “/etc/sensu/handlers/my_handler_slack.rb”

}

},

“slack”: {

“webhook_url”: “https://hooks.slack.com/services/XXX”,

“channel”: “#backend-core-alerts”,

“bot_name”: “Sensu”,

“markdown_enabled”: true

}

}

I am specifying handler to use in the check definition, for example:

{

“checks”: {

“cassandra_ntp”: {

“handler”: “cops_slack”,

“command”: “check-process.rb -p ntp -W 1”,

“subscribers”: [

“ABCD”

],

“interval”: 60

}

}

}

This setup is not working for me. For some strange reasons if I remove my_handler.json from conf.d/ cops_slack handler would kick in as expected and would report to the expected channel but as soon as I bring back my_handler (restart sensu server, api) the same check now would report to the channel mentioned in my_handler. I have reproduced this several times and am out of ideas here. I would be grateful if some one can help me out here.

Thanks

Aahh that would explain the behavior. Thanks Kyle for this pointer, I will look in to slack-multichannel.

···

On Wednesday, February 22, 2017 at 8:48:08 PM UTC-8, Kyle Anderson wrote:

All the json files in conf.d get merged together, so there is only one “slack”: configuration hash manifesting.

You will probably have to do something that understands multi-channel more natively

https://github.com/sensu-plugins/sensu-plugins-slack/blob/master/bin/handler-slack-multichannel.rb

On Wed, Feb 22, 2017 at 7:09 PM, aiman parvaiz aimanp...@gmail.com wrote:

Hi all
I am trying to get certain alerts to one slack channel and rest to a separate one. I am using sensu 0.26.5. I have two json files for handlers in /etc/sensu/conf.d

  1. cops_slack.json

{

“handlers”: {

“cops_slack”: {

“type”: “pipe”,

“command”: “/etc/sensu/handlers/cops_slack.rb”

}

},

“slack”: {

“webhook_url”:"https://hooks.slack.com/services/XXXDDDD,

“channel”: “#alerts1”,

“bot_name”: “Sensu”,

“markdown_enabled”: true

}

}

  1. my_handler.json

{

“handlers”: {

“slack”: {

“type”: “pipe”,

“command”: “/etc/sensu/handlers/my_handler_slack.rb”

}

},

“slack”: {

“webhook_url”: “https://hooks.slack.com/services/XXX”,

“channel”: “#backend-core-alerts”,

“bot_name”: “Sensu”,

“markdown_enabled”: true

}

}

I am specifying handler to use in the check definition, for example:

{

“checks”: {

“cassandra_ntp”: {

“handler”: “cops_slack”,

“command”: “check-process.rb -p ntp -W 1”,

“subscribers”: [

“ABCD”

],

“interval”: 60

}

}

}

This setup is not working for me. For some strange reasons if I remove my_handler.json from conf.d/ cops_slack handler would kick in as expected and would report to the expected channel but as soon as I bring back my_handler (restart sensu server, api) the same check now would report to the channel mentioned in my_handler. I have reproduced this several times and am out of ideas here. I would be grateful if some one can help me out here.

Thanks

The documentation embedded into the source for the handler-slack-multichannel is a bit sparse. Any ideas on how one would define the various channels? For the basic slack module, one has to define a webhook_url. Presumably, with the multichannel plugin, one would have a list of webhook_urls to define for the various channels (default, compulsory, etc). I’ve tried a few variations on my own, but to no avail. Any guidance would be most appreciated!

···

On Wednesday, February 22, 2017 at 11:48:08 PM UTC-5, Kyle Anderson wrote:

All the json files in conf.d get merged together, so there is only one “slack”: configuration hash manifesting.

You will probably have to do something that understands multi-channel more natively

https://github.com/sensu-plugins/sensu-plugins-slack/blob/master/bin/handler-slack-multichannel.rb

On Wed, Feb 22, 2017 at 7:09 PM, aiman parvaiz aimanp...@gmail.com wrote:

Hi all
I am trying to get certain alerts to one slack channel and rest to a separate one. I am using sensu 0.26.5. I have two json files for handlers in /etc/sensu/conf.d

  1. cops_slack.json

{

“handlers”: {

“cops_slack”: {

“type”: “pipe”,

“command”: “/etc/sensu/handlers/cops_slack.rb”

}

},

“slack”: {

“webhook_url”:"https://hooks.slack.com/services/XXXDDDD,

“channel”: “#alerts1”,

“bot_name”: “Sensu”,

“markdown_enabled”: true

}

}

  1. my_handler.json

{

“handlers”: {

“slack”: {

“type”: “pipe”,

“command”: “/etc/sensu/handlers/my_handler_slack.rb”

}

},

“slack”: {

“webhook_url”: “https://hooks.slack.com/services/XXX”,

“channel”: “#backend-core-alerts”,

“bot_name”: “Sensu”,

“markdown_enabled”: true

}

}

I am specifying handler to use in the check definition, for example:

{

“checks”: {

“cassandra_ntp”: {

“handler”: “cops_slack”,

“command”: “check-process.rb -p ntp -W 1”,

“subscribers”: [

“ABCD”

],

“interval”: 60

}

}

}

This setup is not working for me. For some strange reasons if I remove my_handler.json from conf.d/ cops_slack handler would kick in as expected and would report to the expected channel but as soon as I bring back my_handler (restart sensu server, api) the same check now would report to the channel mentioned in my_handler. I have reproduced this several times and am out of ideas here. I would be grateful if some one can help me out here.

Thanks

Hey David
The way I got it working is as follows:

I am using multichannel_slack.rb and I have it’s json file in the conf.d directory, this is the content of that file:

{

“handlers”: {

“multi_slack”: {

“channels”: {

“default”: [“alerts”]

},

“type”: “pipe”,

“command”: “/etc/sensu/handlers/multichannel_slack.rb”

}

},

“slack”: {

“webhook_url”:“Unlock your productivity potential with Slack Platform | Slack”,

“channel”: “alerts”,

“bot_name”: “Sensu”,

“markdown_enabled”: true

}

}

All alerts by default go to alerts, in cases where I want to report to some other channel I include the channel name in the json of the check, for example:

{

“checks”: {

“cassandra_check”: {

“command”: “check-process.rb -p cassandra -C 1 -x ‘.log$’”,

“handler”:“multi_slack”,

“subscribers”: [

“cassandra”,

],

“slack”: {

“channels”:[“#cops-alerts”]

},

“interval”: 60

}

}

}

and this way I am able to get alerts sent to various channels, my requirement was to send the alert to any one of the channels depending on the check and this solution works for that case.

I hope this helps.

Thanks

···

On Thursday, April 20, 2017 at 5:21:21 AM UTC-7, David R wrote:

The documentation embedded into the source for the handler-slack-multichannel is a bit sparse. Any ideas on how one would define the various channels? For the basic slack module, one has to define a webhook_url. Presumably, with the multichannel plugin, one would have a list of webhook_urls to define for the various channels (default, compulsory, etc). I’ve tried a few variations on my own, but to no avail. Any guidance would be most appreciated!

On Wednesday, February 22, 2017 at 11:48:08 PM UTC-5, Kyle Anderson wrote:

All the json files in conf.d get merged together, so there is only one “slack”: configuration hash manifesting.

You will probably have to do something that understands multi-channel more natively

https://github.com/sensu-plugins/sensu-plugins-slack/blob/master/bin/handler-slack-multichannel.rb

On Wed, Feb 22, 2017 at 7:09 PM, aiman parvaiz aimanp...@gmail.com wrote:

Hi all
I am trying to get certain alerts to one slack channel and rest to a separate one. I am using sensu 0.26.5. I have two json files for handlers in /etc/sensu/conf.d

  1. cops_slack.json

{

“handlers”: {

“cops_slack”: {

“type”: “pipe”,

“command”: “/etc/sensu/handlers/cops_slack.rb”

}

},

“slack”: {

“webhook_url”:"https://hooks.slack.com/services/XXXDDDD,

“channel”: “#alerts1”,

“bot_name”: “Sensu”,

“markdown_enabled”: true

}

}

  1. my_handler.json

{

“handlers”: {

“slack”: {

“type”: “pipe”,

“command”: “/etc/sensu/handlers/my_handler_slack.rb”

}

},

“slack”: {

“webhook_url”: “https://hooks.slack.com/services/XXX”,

“channel”: “#backend-core-alerts”,

“bot_name”: “Sensu”,

“markdown_enabled”: true

}

}

I am specifying handler to use in the check definition, for example:

{

“checks”: {

“cassandra_ntp”: {

“handler”: “cops_slack”,

“command”: “check-process.rb -p ntp -W 1”,

“subscribers”: [

“ABCD”

],

“interval”: 60

}

}

}

This setup is not working for me. For some strange reasons if I remove my_handler.json from conf.d/ cops_slack handler would kick in as expected and would report to the expected channel but as soon as I bring back my_handler (restart sensu server, api) the same check now would report to the channel mentioned in my_handler. I have reproduced this several times and am out of ideas here. I would be grateful if some one can help me out here.

Thanks

Hey, Aiman,

This is immensely helpful; thank you!

David

···

On Tuesday, April 25, 2017 at 1:24:10 PM UTC-4, aiman parvaiz wrote:

Hey David
The way I got it working is as follows:

I am using multichannel_slack.rb and I have it’s json file in the conf.d directory, this is the content of that file:

{

“handlers”: {

“multi_slack”: {

“channels”: {

“default”: [“alerts”]

},

“type”: “pipe”,

“command”: “/etc/sensu/handlers/multichannel_slack.rb”

}

},

“slack”: {

“webhook_url”:“https://hooks.slack.com/asdervsdft”,

“channel”: “alerts”,

“bot_name”: “Sensu”,

“markdown_enabled”: true

}

}

All alerts by default go to alerts, in cases where I want to report to some other channel I include the channel name in the json of the check, for example:

{

“checks”: {

“cassandra_check”: {

“command”: “check-process.rb -p cassandra -C 1 -x ‘.log$’”,

“handler”:“multi_slack”,

“subscribers”: [

“cassandra”,

],

“slack”: {

“channels”:[“#cops-alerts”]

},

“interval”: 60

}

}

}

and this way I am able to get alerts sent to various channels, my requirement was to send the alert to any one of the channels depending on the check and this solution works for that case.

I hope this helps.

Thanks

On Thursday, April 20, 2017 at 5:21:21 AM UTC-7, David R wrote:

The documentation embedded into the source for the handler-slack-multichannel is a bit sparse. Any ideas on how one would define the various channels? For the basic slack module, one has to define a webhook_url. Presumably, with the multichannel plugin, one would have a list of webhook_urls to define for the various channels (default, compulsory, etc). I’ve tried a few variations on my own, but to no avail. Any guidance would be most appreciated!

On Wednesday, February 22, 2017 at 11:48:08 PM UTC-5, Kyle Anderson wrote:

All the json files in conf.d get merged together, so there is only one “slack”: configuration hash manifesting.

You will probably have to do something that understands multi-channel more natively

https://github.com/sensu-plugins/sensu-plugins-slack/blob/master/bin/handler-slack-multichannel.rb

On Wed, Feb 22, 2017 at 7:09 PM, aiman parvaiz aimanp...@gmail.com wrote:

Hi all
I am trying to get certain alerts to one slack channel and rest to a separate one. I am using sensu 0.26.5. I have two json files for handlers in /etc/sensu/conf.d

  1. cops_slack.json

{

“handlers”: {

“cops_slack”: {

“type”: “pipe”,

“command”: “/etc/sensu/handlers/cops_slack.rb”

}

},

“slack”: {

“webhook_url”:"https://hooks.slack.com/services/XXXDDDD,

“channel”: “#alerts1”,

“bot_name”: “Sensu”,

“markdown_enabled”: true

}

}

  1. my_handler.json

{

“handlers”: {

“slack”: {

“type”: “pipe”,

“command”: “/etc/sensu/handlers/my_handler_slack.rb”

}

},

“slack”: {

“webhook_url”: “https://hooks.slack.com/services/XXX”,

“channel”: “#backend-core-alerts”,

“bot_name”: “Sensu”,

“markdown_enabled”: true

}

}

I am specifying handler to use in the check definition, for example:

{

“checks”: {

“cassandra_ntp”: {

“handler”: “cops_slack”,

“command”: “check-process.rb -p ntp -W 1”,

“subscribers”: [

“ABCD”

],

“interval”: 60

}

}

}

This setup is not working for me. For some strange reasons if I remove my_handler.json from conf.d/ cops_slack handler would kick in as expected and would report to the expected channel but as soon as I bring back my_handler (restart sensu server, api) the same check now would report to the channel mentioned in my_handler. I have reproduced this several times and am out of ideas here. I would be grateful if some one can help me out here.

Thanks

Aiman,

I was still running into an issue as we have a proxy, but your example really helped me to find the solution, and I wanted to share it here.

For those using a proxy and wanting to use handler-slack-multichannel.rb, know that the setting/option for proxy_address is NOT the same in handler-slack-multichannel.rb as in handler-slack.rb.

The handler-slack.rb file uses/expects proxy_address to be passed as setting/parameter in ones slack handler configuration. Whereas handler-slack-multichannel.rb expects proxy_addr in the handler configuration - this is the key difference. Before I found this, none of my alerts were going to slack at all.

I never would have went into the source had you not posted your config. When I saw your config I said “Huh, where in handler-slack.rb can we define markdown mode? I don’t see it on their main documentation page, let me look at the source.” When it wasn’t in the source code for handler-slack.rb, I went to look at handler-slack-multichannel.rb and saw it declared there. For giggles I thought “I wonder if all of the proxy get_settings options are the same here?” and they weren’t.

So, hopefully this helps someone who’s using a proxy and still wants slack multichannel goodness.

Thanks, again, Aiman!

David

···

On Tuesday, April 25, 2017 at 2:16:46 PM UTC-4, David R wrote:

Hey, Aiman,

This is immensely helpful; thank you!

David

On Tuesday, April 25, 2017 at 1:24:10 PM UTC-4, aiman parvaiz wrote:

Hey David
The way I got it working is as follows:

I am using multichannel_slack.rb and I have it’s json file in the conf.d directory, this is the content of that file:

{

“handlers”: {

“multi_slack”: {

“channels”: {

“default”: [“alerts”]

},

“type”: “pipe”,

“command”: “/etc/sensu/handlers/multichannel_slack.rb”

}

},

“slack”: {

“webhook_url”:“https://hooks.slack.com/asdervsdft”,

“channel”: “alerts”,

“bot_name”: “Sensu”,

“markdown_enabled”: true

}

}

All alerts by default go to alerts, in cases where I want to report to some other channel I include the channel name in the json of the check, for example:

{

“checks”: {

“cassandra_check”: {

“command”: “check-process.rb -p cassandra -C 1 -x ‘.log$’”,

“handler”:“multi_slack”,

“subscribers”: [

“cassandra”,

],

“slack”: {

“channels”:[“#cops-alerts”]

},

“interval”: 60

}

}

}

and this way I am able to get alerts sent to various channels, my requirement was to send the alert to any one of the channels depending on the check and this solution works for that case.

I hope this helps.

Thanks

On Thursday, April 20, 2017 at 5:21:21 AM UTC-7, David R wrote:

The documentation embedded into the source for the handler-slack-multichannel is a bit sparse. Any ideas on how one would define the various channels? For the basic slack module, one has to define a webhook_url. Presumably, with the multichannel plugin, one would have a list of webhook_urls to define for the various channels (default, compulsory, etc). I’ve tried a few variations on my own, but to no avail. Any guidance would be most appreciated!

On Wednesday, February 22, 2017 at 11:48:08 PM UTC-5, Kyle Anderson wrote:

All the json files in conf.d get merged together, so there is only one “slack”: configuration hash manifesting.

You will probably have to do something that understands multi-channel more natively

https://github.com/sensu-plugins/sensu-plugins-slack/blob/master/bin/handler-slack-multichannel.rb

On Wed, Feb 22, 2017 at 7:09 PM, aiman parvaiz aimanp...@gmail.com wrote:

Hi all
I am trying to get certain alerts to one slack channel and rest to a separate one. I am using sensu 0.26.5. I have two json files for handlers in /etc/sensu/conf.d

  1. cops_slack.json

{

“handlers”: {

“cops_slack”: {

“type”: “pipe”,

“command”: “/etc/sensu/handlers/cops_slack.rb”

}

},

“slack”: {

“webhook_url”:"https://hooks.slack.com/services/XXXDDDD,

“channel”: “#alerts1”,

“bot_name”: “Sensu”,

“markdown_enabled”: true

}

}

  1. my_handler.json

{

“handlers”: {

“slack”: {

“type”: “pipe”,

“command”: “/etc/sensu/handlers/my_handler_slack.rb”

}

},

“slack”: {

“webhook_url”: “https://hooks.slack.com/services/XXX”,

“channel”: “#backend-core-alerts”,

“bot_name”: “Sensu”,

“markdown_enabled”: true

}

}

I am specifying handler to use in the check definition, for example:

{

“checks”: {

“cassandra_ntp”: {

“handler”: “cops_slack”,

“command”: “check-process.rb -p ntp -W 1”,

“subscribers”: [

“ABCD”

],

“interval”: 60

}

}

}

This setup is not working for me. For some strange reasons if I remove my_handler.json from conf.d/ cops_slack handler would kick in as expected and would report to the expected channel but as soon as I bring back my_handler (restart sensu server, api) the same check now would report to the channel mentioned in my_handler. I have reproduced this several times and am out of ideas here. I would be grateful if some one can help me out here.

Thanks

Glad to be of help!!