sensu-plugins / sensu-plugins-slack Goto Github PK
View Code? Open in Web Editor NEWSensu Slack chat handlers
Home Page: http://sensu-plugins.io
License: MIT License
Sensu Slack chat handlers
Home Page: http://sensu-plugins.io
License: MIT License
Hello!
My team recently migrated from Slack to Mattermost. Mattermost has support for quite a few Slack webhooks already, this one doesn't seem to work though. Is there anyways support could be implemented.. or a way I could hack this together to work?
{"timestamp":"2016-08-25T22:01:35.778237-0500","level":"info","message":"handler output","handler":{"command":"/opt/sensu/embedded/bin/handler-slack.rb","type":"pipe","severities":["critical","unknown"],"name":"slack"},"output":["/opt/sensu/embedded/lib/ruby/2.3.0/net/http/response.rb:120:in `error!': 500 \"Internal Server Error\" (Net::HTTPFatalError)\n\tfrom /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-1.0.0/bin/handler-slack.rb:149:in `verify_response'\n\tfrom /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-1.0.0/bin/handler-slack.rb:141:in `post_data'\n\tfrom /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-1.0.0/bin/handler-slack.rb:92:in `handle'\n\tfrom /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugin-1.3.0/lib/sensu-handler.rb:57:in `block in <class:Handler>'\n"]}
I understand if this is not possible, being that your primary focus is obviously Slack. If there's nothing you guys can do about, is it possible to make a suggestion for a new plugin that does this?
Thanks.
sensu-plugin 2.7 has new logic to aid mutators and handlers map sensu 2 event data into sensu 1.x event data.
I'm trying to use a message_template
. On upgrade from 1.0.0 to 1.1.1, some of my slack messages were "truncated". It was only showing the notification. I investigated and I think it is due to a fix in 1.1.0: #25. I set the notification
field in some my checks and in the event where it is set the handler is ignoring my message_template
in favour of the raw notification. I think the fix was correct but I'm not sure if the behaviour is correct?
The line that I think is suspicious.
How the logic should work in my head is something like this:
if payload_template {
// use that
} else {
if message_template {
// Use message_template
} else if @event['check']['notification'] {
// Use notification
} else {
// Construct with generated bits
}
}
when sending the data, the response is ignored. when the server returns non-200 status code, the plugin silently drop the error code such as 404.
sensu-plugins-slack/bin/handler-slack.rb
Line 181 in 375cd78
and the result is success even when it is actually failure.
Is there any chance that this awesome plugin will be modified for sensu-go compatibility? It seems to me, that there are major changes in event structure and possibly others, so it won't be easy task.
it seems that Unknown (127) exit codes are not handled by the slack handler and gives this error:
/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-1.0.0/bin/handler-slack.rb:191:in 'fetch': key not found: 127 (KeyError)
from /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-1.0.0/bin/handler-slack.rb:191:in 'color'
from /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-1.0.0/bin/handler-slack.rb:174:in 'payload'
from /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-1.0.0/bin/handler-slack.rb:135:in 'post_data'
from /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-1.0.0/bin/handler-slack.rb:92:in 'handle'
from /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugin-1.4.2/lib/sensu-handler.rb:81:in 'block in <class:Handler>'
hello guys i'm having a problem with the notifications, my slack.json config is the next:
{
"handlers": {
"slack_plataformasdigitales": {
"type": "pipe",
"command": "handler-slack.rb -j slack_plataformasdigitales",
"severities": ["critical", "unknown", "ok" ]
}
},
"slack_plataformasdigitales": {
"webhook_url": "http://webhoook",
"username": "sensu",
"channel": "#alertas",
"timeout": 10
}
}
i need alerts only for critical, ok and unknown. When the check exit 0, 2 or higer i need the notifications, if the cheks go from 2 or higer to 0 the alert is send to slack, but if the check go trought 2 or higer, then 1, and then 0, i only have the critical or unknown alert but never send the ok alert, this is a problem because i check cpu usage, and the team only see the errors and never the resolution, and then go to check the server and this is working fine.
im using ubuntu 14.04.05, sensu 0.26.3 and the latest version of sensu slack plugin.
this is the check
"prod_linux_load": {
"command": "check-load.rb -c 1.25,1,0.95 --per-core",
"interval": 15,
"occurrences": 6,
"refresh": 300,
"subscribers": ["linux_PlatDigCloudServices", "linux_PlatDigSmartProd01", "linux_PlatDigGrillasProd01", "elasticsearch_PlatDigCloudServices", "linux_PlatDigMarketing01", "linux_PlatDigInterProd01"],
"handlers": ["slack_plataformasdigitales"]
}
and this is the log of the sensu server
"timestamp": "2016-12-01T10:07:41.007359-0300",
"level": "info",
"message": "processing event",
"event": {
"client": {
"name": "PlatDigInfluxDB01",
"address": "10.0.0.80",
"subscriptions": ["linux_PlatDigCloudServices", "client:PlatDigInfluxDB01"],
"keepalive": {
"thresholds": {
"warning": 30,
"critical": 60
},
"handlers": ["slack"],
"refresh": 60
},
"version": "0.26.3",
"timestamp": 1480597654
},
"check": {
"command": "check-load.rb -w 0.8,0.8,0.8 -c 0.95,0.95,0.95 --per-core",
"interval": 15,
"occurrences": 6,
"refresh": 300,
"subscribers": ["linux_PlatDigCloudServices", "linux_PlatDigSmartProd01", "linux_PlatDigGrillasProd01", "elasticsearch_PlatDigCloudServices", "linux_PlatDigMarketing01"],
"handlers": ["slack_plataformasdigitales"],
"name": "prod_linux_load",
"issued": 1480597660,
"executed": 1480597660,
"duration": 0.102,
"output": "CheckLoad CRITICAL: Load average: 1.0, 0.57, 0.3\n",
"status": 2,
"type": "standard",
"history": ["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "2", "2", "2", "2", "2"],
"total_state_change": 11
},
"occurrences": 5,
"occurrences_watermark": 5,
"action": "create",
"timestamp": 1480597661,
"id": "dacbe316-0f1a-4d7b-bfc8-8a32125cb416",
"last_state_change": 1480597601,
"last_ok": 1480597586,
"silenced": false,
"silenced_by": []
}
}{
"timestamp": "2016-12-01T10:07:41.773114-0300",
"level": "info",
"message": "handler output",
"handler": {
"type": "pipe",
"command": "handler-slack.rb -j slack_plataformasdigitales",
"severities": ["critical", "unknown", "ok"],
"name": "slack_plataformasdigitales"
},
"output": ["warning: event filtering in sensu-plugin is deprecated, see http://bit.ly/sensu-plugin\nwarning: occurrence filtering in sensu-plugin is deprecated, see http://bit.ly/sensu-plugin\nnot enough occurrences: PlatDigInfluxDB01/prod_linux_load\n"]
}
{
"timestamp": "2016-12-01T10:08:26.028076-0300",
"level": "info",
"message": "processing event",
"event": {
"client": {
"name": "PlatDigInfluxDB01",
"address": "10.0.0.80",
"subscriptions": ["linux_PlatDigCloudServices", "client:PlatDigInfluxDB01"],
"keepalive": {
"thresholds": {
"warning": 30,
"critical": 60
},
"handlers": ["slack"],
"refresh": 60
},
"version": "0.26.3",
"timestamp": 1480597694
},
"check": {
"command": "check-load.rb -w 0.8,0.8,0.8 -c 0.95,0.95,0.95 --per-core",
"interval": 15,
"occurrences": 6,
"refresh": 300,
"subscribers": ["linux_PlatDigCloudServices", "linux_PlatDigSmartProd01", "linux_PlatDigGrillasProd01", "elasticsearch_PlatDigCloudServices", "linux_PlatDigMarketing01"],
"handlers": ["slack_plataformasdigitales"],
"name": "prod_linux_load",
"issued": 1480597705,
"executed": 1480597705,
"duration": 0.106,
"output": "CheckLoad WARNING: Load average: 0.92, 0.62, 0.33\n",
"status": 1,
"type": "standard",
"history": ["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "2", "2", "2", "2", "2", "2", "2", "1"],
"total_state_change": 16
},
"occurrences": 1,
"occurrences_watermark": 7,
"action": "create",
"timestamp": 1480597706,
"id": "dacbe316-0f1a-4d7b-bfc8-8a32125cb416",
"last_state_change": 1480597706,
"last_ok": 1480597586,
"silenced": false,
"silenced_by": []
}
}{
"timestamp": "2016-12-01T10:08:26.028258-0300",
"level": "info",
"message": "handler does not handle event severity",
"handler": {
"type": "pipe",
"command": "handler-slack.rb -j slack_plataformasdigitales",
"severities": ["critical", "unknown", "ok"],
"name": "slack_plataformasdigitales"
},
"event": {
"client": {
"name": "PlatDigInfluxDB01",
"address": "10.0.0.80",
"subscriptions": ["linux_PlatDigCloudServices", "client:PlatDigInfluxDB01"],
"keepalive": {
"thresholds": {
"warning": 30,
"critical": 60
},
"handlers": ["slack"],
"refresh": 60
},
"version": "0.26.3",
"timestamp": 1480597694
},
"check": {
"command": "check-load.rb -w 0.8,0.8,0.8 -c 0.95,0.95,0.95 --per-core",
"interval": 15,
"occurrences": 6,
"refresh": 300,
"subscribers": ["linux_PlatDigCloudServices", "linux_PlatDigSmartProd01", "linux_PlatDigGrillasProd01", "elasticsearch_PlatDigCloudServices", "linux_PlatDigMarketing01"],
"handlers": ["slack_plataformasdigitales"],
"name": "prod_linux_load",
"issued": 1480597705,
"executed": 1480597705,
"duration": 0.106,
"output": "CheckLoad WARNING: Load average: 0.92, 0.62, 0.33\n",
"status": 1,
"type": "standard",
"history": ["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "2", "2", "2", "2", "2", "2", "2", "1"],
"total_state_change": 16
},
"occurrences": 1,
"occurrences_watermark": 7,
"action": "create",
"timestamp": 1480597706,
"id": "dacbe316-0f1a-4d7b-bfc8-8a32125cb416",
"last_state_change": 1480597706,
"last_ok": 1480597586,
"silenced": false,
"silenced_by": []
}
}{
"timestamp": "2016-12-01T10:08:41.031381-0300",
"level": "info",
"message": "processing event",
"event": {
"client": {
"name": "PlatDigInfluxDB01",
"address": "10.0.0.80",
"subscriptions": ["linux_PlatDigCloudServices", "client:PlatDigInfluxDB01"],
"keepalive": {
"thresholds": {
"warning": 30,
"critical": 60
},
"handlers": ["slack"],
"refresh": 60
},
"version": "0.26.3",
"timestamp": 1480597714
},
"check": {
"command": "check-load.rb -w 0.8,0.8,0.8 -c 0.95,0.95,0.95 --per-core",
"interval": 15,
"occurrences": 6,
"refresh": 300,
"subscribers": ["linux_PlatDigCloudServices", "linux_PlatDigSmartProd01", "linux_PlatDigGrillasProd01", "elasticsearch_PlatDigCloudServices", "linux_PlatDigMarketing01"],
"handlers": ["slack_plataformasdigitales"],
"name": "prod_linux_load",
"issued": 1480597720,
"executed": 1480597720,
"duration": 0.11,
"output": "CheckLoad OK: Load average: 0.72, 0.59, 0.33\n",
"status": 0,
"type": "standard",
"history": ["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "2", "2", "2", "2", "2", "2", "2", "1", "0"],
"total_state_change": 22
},
"occurrences": 1,
"occurrences_watermark": 7,
"action": "resolve",
"timestamp": 1480597721,
"id": "dacbe316-0f1a-4d7b-bfc8-8a32125cb416",
"last_state_change": 1480597721,
"last_ok": 1480597721,
"silenced": false,
"silenced_by": []
}
}{
"timestamp": "2016-12-01T10:08:41.814917-0300",
"level": "info",
"message": "handler output",
"handler": {
"type": "pipe",
"command": "handler-slack.rb -j slack_plataformasdigitales",
"severities": ["critical", "unknown", "ok"],
"name": "slack_plataformasdigitales"
},
"output": ["warning: event filtering in sensu-plugin is deprecated, see http://bit.ly/sensu-plugin\nwarning: occurrence filtering in sensu-plugin is deprecated, see http://bit.ly/sensu-plugin\nnot enough occurrences: PlatDigInfluxDB01/prod_linux_load\n"]
}
P.S.: Sorry for my bad English!!
When using a defined handler:
{
"handlers": {
"slack": {
"command": "/bin/handler-slack.rb",
"type": "pipe",
"severities": [
"ok",
"warning",
"critical",
"unknown"
]
}
},
"slack": {
"webhook_url": "SECRET",
"proxy_address": "PRX",
"proxy_port": "80",
"bot_name": "sensu",
"channel": "#channel1"
}
}
It should be possible to override channel config on check.json and send alerts to channel2:
{
"checks": {
"sensu-server": {
"command": "/opt/sensu-community/plugins/processes/check-procs.rb -p bin/sensu-server -c 1",
"handlers": [
"high"
],
"interval": 60,
"standalone": true,
"slack": {
"channel": "#channel2"
}
}
}
}
But messages are always sent only to the channel defined in the handler.
Hi team,
If some one let me know on how to write message_template for slack to display the message in customised format. i am struggling to display the filters in template, if you can show me some guides to read, it will help me to achive on what i want.
Hi, i have a strange error i cant get the handler to work....
Here is my log file, it complains about SSL but it's not a self signed certificate and i have tried to add all CA intermediate but still no luck. I think it's something else.
{"timestamp":"2017-01-30T21:55:55.467577+0100","level":"info","message":"handler output","handler":{"type":"pipe","command":"handler-slack.rb -j slack","severities":["critical","unknown"],"name":"slack"},"output":["/opt/sensu/embedded/lib/ruby/2.3.0/net/http.rb:933:in
connect_nonblock': SSL_connect returned=1 errno=0 state=error: certificate verify failed (OpenSSL::SSL::SSLError)\n\tfrom /opt/sensu/embedded/lib/ruby/2.3.0/net/http.rb:933:in
connect'\n\tfrom /opt/sensu/embedded/lib/ruby/2.3.0/net/http.rb:863:indo_start'\n\tfrom /opt/sensu/embedded/lib/ruby/2.3.0/net/http.rb:852:in
start'\n\tfrom /opt/sensu/embedded/lib/ruby/2.3.0/net/http.rb:1398:inrequest'\n\tfrom /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-1.0.0/bin/handler-slack.rb:140:in
post_data'\n\tfrom /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-1.0.0/bin/handler-slack.rb:92:inhandle'\n\tfrom /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugin-1.4.2/lib/sensu-handler.rb:81:in
block in class:Handler'\nwarning: event filtering in sensu-plugin is deprecated, see http://bit.ly/sensu-plugin\nwarning: occurrence filtering in sensu-plugin is deprecated, see http://bit.ly/sensu-plugin\n"]}
I have try to add an environment variable with export SSL_CERT_FILE but still no luck.
I dont understand why it dont work.
Can someone help me ?
Thanks in advance
Are there a schedule for an upcoming release? Some changes have been merged since the last release in Juli. Specifically the functionality from PR #8 would be very useful for us.
If the fields
array in the handler configuration contains an entry of a field that is not present, an exception is raised. The problems seems to be at this at this line in the code. It suppose it would be better to check if the fields exists and log a more meaningful error message in such cases.
Following the instructions (but using the embedded sensu gem), I get:
$# /opt/sensu/embedded/bin/gem cert --add <(curl -Ls https://raw.githubusercontent.com/sensu-plugins/sensu-plugins.github.io/master/certs/sensu-plugins.pem)
Added '/CN=mattjones/DC=yieldbot/DC=com'
$# /opt/sensu/embedded/bin/gem install sensu-plugins-slack -P MediumSecurity
ERROR: Could not find a valid gem 'sensu-plugins-slack' (>= 0) in any repository
ERROR: Possible alternatives: sensu-plugins-riak, sensu-plugins-ssl, sensu-plugins-apache, sensu-plugins-aws, sensu-plugins-telapi
Hi,
Right now the build notice output is:
status | hostname/checkname: check output
My current custom message:
Status: status
Host: hostname/check
Check: check output
Url: http://sensu-server/#/client/ingenu/hostname?check=checkname
Accomplished by modifying line 144:
From:
"#{@event['check']['status'].to_s.rjust(3)} | #{incident_key}: #{@event['check']['output'].strip}"
To:
"Status:#{@event['check']['status'].to_s.rjust(3)} \nHost: #{incident_key} \nCheck: #{@event['check']['output'].strip} \nUrl: http://sensu-server-URL/#/client/ingenu/#{@event['client']['name']}?check=#{@event['check']['name']}"
Thanks
I am getting the following stack trace in my logs when running this plugin:
{
"timestamp": "2016-06-02T13:59:19.245303+0000",
"level": "info",
"message": "handler output",
"handler": {
"type": "pipe",
"severities": [
"ok",
"critical"
],
"command": "handler-slack.rb",
"webhook_url": "https://hooks.slack.com/services/<REDACTED>",
"name": "slack"
},
"output": [
"/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugin-1.2.0/lib/sensu-handler.rb:134:in `block in filter_silenced': Object#timeout is deprecated, use Timeout.timeout instead.\n/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugin-1.2.0/lib/sensu-handler.rb:134:in `block in filter_silenced': Object#timeout is deprecated, use Timeout.timeout instead.\n/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugin-1.2.0/lib/sensu-handler.rb:134:in `block in filter_silenced': Object#timeout is deprecated, use Timeout.timeout instead.\n/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-0.1.2/bin/handler-slack.rb:82:in `get_setting': undefined method `[]' for nil:NilClass (NoMethodError)\n\tfrom /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-0.1.2/bin/handler-slack.rb:54:in `message_template'\n\tfrom /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-0.1.2/bin/handler-slack.rb:91:in `build_description'\n\tfrom /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-0.1.2/bin/handler-slack.rb:86:in `handle'\n\tfrom /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugin-1.2.0/lib/sensu-handler.rb:55:in `block in <class:Handler>'\n"
]
}
It looks like this is the main issue: get_setting': undefined method []' for nil:NilClass (NoMethodError)\n\tfrom /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-0.1.2/bin/handler-slack.rb:54
cat /etc/sensu/conf.d/handlers/slack.json
{
"handlers": {
"slack": {
"type": "pipe",
"severities": [
"ok",
"critical"
],
"command": "handler-slack.rb",
"webhook_url": "https://hooks.slack.com/services/<REDACTED>"
}
}
}
If an event has a playbook message or link we should include it in the slack message. Closed #18 is a potential PR for this.
We had some issues with our implementation of the slack handler with the payload_template option configured. Our template looked like this, very similar to the example in the README :
{ "attachments": [ { "fallback": "<%= @event["check"]["output"] %>", "color": "<%= color %>", "title": "<%= @event["check"]["name"] %> (<%= @event["client"]["name"] %>)", "text": "<%= @event["check"]["output"].gsub('"', '\\"') %>" } ] }
What we found was that with the above template we were losing messages containing escaped double quotes in the output. Eg.
from the CheckPostgresAlive in sensu-plugins-postgres:
"output":"CheckPostgres CRITICAL: Error message: FATAL: database \"mon-test\" does not exist\n"
We were able to correct this(i.e. slack alerts now being recieved and displaying as expected) by changing the gsub to read :
gsub('"', '\"')
^^^ note one less backslash.
Can you update the readme if I have correctly interpreted this.
Using two separate handlers with different webhooks does not work, it always sends to just one regardless of what handler is used. Even using a copy of the handler script with a different name still sends to the first one.
Is something being cached?
if we use an internal slack compatible endpoint that uses http - then the line below breaks the request, since it forced the request to use https...
sensu-plugins-slack/bin/handler-slack.rb
Line 150 in 6bef292
the error we receive is
{"timestamp":"2019-01-23T12:19:56.779398+0200","level":"error","message":"handler output","handler":{"type":"pipe","severities":["ok","warning","critical","unknown"],"command":"handler-slack.rb -j slack_chopchop","name":"slack_chopchop"},"event":{"id":"a5c5eb89-300f-4a3b-82f8-e10c54bedf4b"},"output":["/opt/sensu/embedded/lib/ruby/2.4.0/net/protocol.rb:44:in connect_nonblock': SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol (OpenSSL::SSL::SSLError)\n\tfrom /opt/sensu/embedded/lib/ruby/2.4.0/net/protocol.rb:44:in
ssl_socket_connect'\n\tfrom /opt/sensu/embedded/lib/ruby/2.4.0/net/http.rb:948:in connect'\n\tfrom /opt/sensu/embedded/lib/ruby/2.4.0/net/http.rb:887:in
do_start'\n\tfrom /opt/sensu/embedded/lib/ruby/2.4.0/net/http.rb:876:in start'\n\tfrom /opt/sensu/embedded/lib/ruby/2.4.0/net/http.rb:1407:in
request'\n\tfrom /opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugins-slack-3.1.1/bin/handler-slack.rb:161:in post_data'\n\tfrom /opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugins-slack-3.1.1/bin/handler-slack.rb:113:in
handle'\n\tfrom /opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugin-2.7.0/lib/sensu-handler.rb:89:in `block in class:Handler'\n"]}
Hi,
I integrated the handler into my sensu configuration but can't get messages sent to my slack channel.
Inside the server log all I can see is the following error:
{"timestamp":"2017-01-02T14:22:28.652071+0200","level":"info","message":"handler output","handler":{"type":"pipe","command":"/opt/sensu/embedded/bin/ruby /var/lib/gems/1.9.1/gems/sensu-plugins-slack-0.0.1/bin/handler-slack.rb","severities":["critical","unknown"],"name":"slack"},"output":["/opt/sensu/embedded/lib/ruby/2.0.0/net/http.rb:878:in initialize': Connection timed out - connect(2) (Errno::ETIMEDOUT)\n","\tfrom /opt/sensu/embedded/lib/ruby/2.0.0/net/http.rb:878:in
open'\n","\tfrom /opt/sensu/embedded/lib/ruby/2.0.0/net/http.rb:878:in block in connect'\n","\tfrom /opt/sensu/embedded/lib/ruby/2.0.0/timeout.rb:52:in
timeout'\n","\tfrom /opt/sensu/embedded/lib/ruby/2.0.0/net/http.rb:877:in connect'\n","\tfrom /opt/sensu/embedded/lib/ruby/2.0.0/net/http.rb:862:in
do_start'\n","\tfrom /opt/sensu/embedded/lib/ruby/2.0.0/net/http.rb:851:in start'\n","\tfrom /opt/sensu/embedded/lib/ruby/2.0.0/net/http.rb:1373:in
request'\n","\tfrom /var/lib/gems/1.9.1/gems/sensu-plugins-slack-0.0.1/bin/handler-slack.rb:74:in post_data'\n","\tfrom /var/lib/gems/1.9.1/gems/sensu-plugins-slack-0.0.1/bin/handler-slack.rb:54:in
handle'\n","\tfrom /opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugin-1.2.0/lib/sensu-handler.rb:55:in `block in class:Handler'\n"]}
Any suggestions?
Thanks
Tal
Hello,
I thought I would leave a comment here explaining how I (finally) got the slack multichannel handler to work.
Bearing in mind, I'm a newbie to Sensu, a newbie to Ruby and fairly new to slack, the cards were stacked against me from the start :-(
My working handler config (/etc/sensu/conf.d/handlers/slack.json) is as follows ...
{
"handlers": {
"slack": {
"command": "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-1.0.0/bin/handler-slack-multichannel.rb",
"type": "pipe",
"severities": [
"ok",
"warning",
"critical",
"unknown"
]
}
},
"slack": {
"channels": {
"default": [
],
"compulsory": [
]
},
"webhook_url": "https://hooks.slack.com/services/HIDDEN/SECRETk",
"proxy_addr": "proxyt",
"proxy_port": "3128",
"bot_name": "SensuBot",
"icon_url": "http://sensuapp.org/img/sensu_logo_large-c92d73db.png",
"icon_emoji": ":snowman:"
}
}
I then installed the sensu slack plugin gem as follows
/opt/sensu/embedded/bin/gem install sensu-plugins-slack
The event that I was testing was (/tmp/eventdata.json) is
"id": "ef6b87d2-1f89-439f-8bea-33881436ab90",
"action": "create",
"timestamp": 1460172826,
"occurrences": 1,
"refresh": 60,
"check": {
"slack": {"channels":["#devops_team"]},
"type": "standard",
"total_state_change": 11,
"history": ["0", "0", "1", "1", "2", "2"],
"status": 2,
"output": "Just Paul testing - sorry",
"executed": 1460172826,
"issued": 1460172826,
"name": "test_check",
"thresholds": {
"critical": 180,
"warning": 120
}
},
"client": {
"timestamp": 1460172596,
"version": "0.29.0",
"socket": {
"port": 3030,
"bind": "127.0.0.1"
},
"subscriptions": [
"production"
],
"environment": "development",
"address": "127.0.0.1",
"name": "intdasa1"
}
}
and then I tested this by running ...
cat /tmp/eventdata.json | /opt/sensu/embedded/bin/ruby /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-1.0.0/bin/handler-slack-multichannel.rb
NOTE - I have a proxy in my infrastructure as specified by the entries in the handler code, slack.json
Hope this helps others avoid my pain
I experience that the slack handler does not always seem to work. In the sensu-server.log I see:
{
"timestamp": "2017-09-27T11:47:34.157563+0200",
"level": "info",
"message": "handler output",
"handler": {
"command": "handler-slack.rb",
"type": "pipe",
"filters": [
"production_environment",
"state_change_with_occurrences_critical"
],
"severities": [
"ok",
"critical"
],
"handle_flapping": false,
"handle_silenced": false,
"name": "slack"
},
"event": {
"id": "e47824be-0e42-4586-8944-77c946ab84c3"
},
"output": [
"warning: event filtering in sensu-plugin is deprecated, see http://bit.ly/sensu-plugin\nconnection refused attempting to query the sensu api for a stash\nconnection refused attempting to query the sensu api for a stash\nconnection refused attempting to query the sensu api for a stash\nwarning: occurrence filtering in sensu-plugin is deprecated, see http://bit.ly/sensu-plugin\nonly handling every 60 occurrences: myexamplehost.org/check_http_example_api\n"
]
}
In cases that the handler DOES work I see also the client and check hash in the hash above. How can this be fixed?
Just an FYI the payload_template on the readme page fails to pass json validation due to conflicting quotation marks.
http://
links should outright be https://
to not have to rely on the webserver to do the redirect.
The images linked in the readme and handler are missing too.
README.md:[![Gem Version](https://badge.fury.io/rb/sensu-plugins-slack.svg)](http://badge.fury.io/rb/sensu-plugins-slack)
README.md: "icon_url": "http://sensuapp.org/img/sensu_logo_large-c92d73db.png",
README.md:[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
bin/handler-slack-multichannel.rb: icon_url: 'http://sensuapp.org/img/sensu_logo_large-c92d73db.png',
bin/handler-slack.rb: icon_url: slack_icon_url ? slack_icon_url : 'http://sensuapp.org/img/sensu_logo_large-c92d73db.png',
I was unable to find them on the sensu site after digging around a few file locations.
The default Slack handler sometimes hangs if the network fails, leading to high load on the Sensu server.
I will be submitting a PR for rewriting this as an extension with a few protections around failure conditions.
I has configured one channel in slack.json but i want to send to N others with override using in check but my checks only send if channel are configured in slack.json like:
...
"webhook_urls": {
"zz": "https://hooks.slack.com/services/BLA/bla123"
},
...
On this way only work to checks notify zz
channel other checks doesn't work.
This webhook should working to all channels and can override with check channel, right?
EDIT:
I currently use this way, this webhook and with this configuration and the check overwrite the "default" channel but in previous version of
E.G.
on cliente the check is
{
"checks": {
"sensu_api_process_check": {
"command": "check-process.rb -p 'sleep'",
"standalone": true,
"handlers": ["slack", "graphite", "default"],
"interval": 10,
"ttl": 300,
"aggregate": "dev",
"slack": {
"channels": [ "#eng" ]
}
}
}
}
I am trying to update the message to Slack to use the client name in place of the address in slack messages. I thought using a payload_template
would allow me to customize it, but when I add it I no longer get any slack notices. I looked over the noted posted in #24 and #16 The message template is working and has been for a while. What, am I missing?
handler-sklack.json
{
"handlers": {
"slack": {
"type": "pipe",
"command": "handler-slack.rb",
"severities": [
"critical",
"unknown"
],
"template": "/etc/sensu/templates/slack.erb",
"filters": [
"recurrences"
]
},
"slack-test": {
"type": "pipe",
"command": "handler-slack.rb",
"severities": [
"critical",
"unknown"
],
"message_template": "/etc/sensu/templates/slack.erb",
"payload_template": "/etc/sensu/templates/slack_payload.erb"
},
"slack": {
"webhook_url": "https://hooks.slack.com/services/...",
"channel": "#dev-alerts-test",
"bot_name": "sensu",
"icon_emoji": ":siren:",
"dashboard": "http://sensu.domain.com:3000/#/events",
"message_template": "/etc/sensu/templates/slack.erb"
}
}
slack_payload.erb
{
icon_url: slack_icon_url ? slack_icon_url : 'http://sensuapp.org/img/sensu_logo_large-c92d73db.png',
attachments: [{
title: "#{@event['client']['name']} - #{translate_status}",
text: [slack_message_prefix, notice].compact.join(' '),
color: color,
fields: client_fields
}]
}
}
slack.erb
<%= @event["check"]["output"].gsub('"', '\\"') %>
Alert-Time: <%= Time.at(@event["check"]["issued"]) %>
Using fields for tips or url links in alert configurations. Sometimes our alerts include them, sometimes they dont. In all cases currently the message includes blank sections which isn't very attractive.
There may be an argument for showing the field name and not including a value at all to demonstrate that the user hasn't included this information, but that seems to be implict based on its absence on a message?
Thanks for looking at this. I've spent a good day and a half trying to make this work. No matter what settings I use, where I put the files, or how I configure the thing sends messages. I've resorted to simply trying to make it post a message to requestb.in to make sure that it will send any message. The documentation on setting up handlers is not very detailed in Sensu. The link you have to installation really just says, install a gem :). I read through the sensu handler docs and check docs. I had the default handler working to just pipe commands to cat. I have also setup other handlers and checks. But sending to Slack fails silently. I'm sure I'm missing something or have done this wrong. I would love to have more details on how to actually set this up. I am not using the Enterprise server. Here are the details.
Setup:
I tried putting the config in the handler folder. Since that didn't work I ended up with the following in /etc/sensu/config.json
.
"handlers":{
"default": {
"type": "set",
"handlers":[
"slack"
]
},
"slack": {
"type": "pipe",
"command": "/usr/local/bin/handler-slack.rb"
}
},
"slack": {
"webhook_url": "http://requestb.in/1i40g351",
"template" : ""
}
again, just trying to get it to post to requestb.in.
In the sensu server logs I get messages like this
{"timestamp":"2016-06-17T18:01:50.822635+0000","level":"info","message":"handler output","handler":{"type":"pipe","command":"/usr/local/bin/handler-slack.rb","name":"slack"},"output":["only handling every 180 occurrences: test.docker/load_docker_metrics\n"]}
So I see that it is sending something, or trying to, to the slack handler. Heeding the warning, 180 occurrences, I left it on overnight. I run the check every 10 seconds. That's every 30 minutes. This morning I have nothing logged to requestb.in.
I have another check running that logs this
{"timestamp":"2016-06-17T18:03:20.708416+0000","level":"info","message":"processing event","event":{"client":{"name":"test.docker","address":"10.0.2.15","subscriptions":["docker"],"version":"0.25.1","timestamp":1466186589},"check":{"command":"check-process.rb -p cron","subscribers":["production"],"standalone":true,"interval":60,"handlers":["slack"],"name":"cron","issued":1466186603,"executed":1466186603,"duration":0.435,"output":"CheckProcess CRITICAL: Found 0 matching processes; cmd /cron/\n","status":2,"type":"standard","history":["2","2","2","2","2","2","2","2","2","2","2","2","2","2","2","2","2","2","2","2","2"],"total_state_change":0},"occurrences":1186,"action":"create","timestamp":1466186600,"id":"4e00b3aa-0a94-43c9-8108-13a173a05405","last_state_change":1466115322,"last_ok":null}}
This other check, which should send to slack, also does not trigger any messages to requestb.in. I have also left this running for over 12 hours.
Hopefully this is enough info understand what is happening and not too much info to overwhelm. I really would love to get this working. If sensu enterprise is required that is also an option for me.
I'm trying to pass some metadata from the check into the slack message. Both a custom param "owner" as well as the # of occurrences it's had. In both cases (see the bottom screenshot) the field name appears in the check, but not the value.
I'm not sure the best way to test handlers as I haven't written one yet, but just blasting out the @event
variable to system logs seems to just
Maybe this feature is known to not be working, or I'm doing it wrong?
Client check:
[root@devcorepptl918 ~]# cat /etc/sensu/conf.d/checks/chk-proc-puppetdb_process.json
{
"checks": {
"chk-proc-puppetdb_process": {
"command": "check-process.rb --pattern 'puppetdb' --critical-under 5",
"handlers": [
"slack"
],
"interval": 10,
"occurrences": 2,
"subscribers": [
"all"
],
"standalone": true,
"owner": "bswift"
}
}
}
Handler config
[root@devcoremonl905 sensu]# cat /etc/sensu/conf.d/handlers/slack.json
{
"handlers": {
"slack": {
"command": "handler-slack.rb",
"type": "pipe",
"filters": [
],
"severities": [
"critical"
]
}
},
"slack": {
"webhook_url": "https://hooks.slack.com/services/--redacted---",
"fields": [
"owner",
"occurrences"
]
}
}
This is the slack message:
It would be useful for an alert to be able to send back a link to some internal documentation, graphs, etc.
Alert: 1 | somehost/diskuse: ['OK - / 55% used.' 'WARNING - /opt 85% used.']
Playbook: 1 | somehost/diskuse: "You'll want to review https://example.com/link/to/internal/documentation and check historical graphs at https://example.com/grafana/graphs/located/here"
Sensu should support this https://sensuapp.org/docs/latest/reference/checks.html#example
Some example code is located at https://gist.github.com/johntdyer/aec1672ee21aede1f899
The README only specifies the path to a template file, but doesn't say what that template should contain.
When using the "surround" field in the configuration to specify markup formatting, it does not have any effect. Slack does not render it. The Slack API documentation states that by default no formatting takes place in attachments. You have to pass an additional field mrkdwn_in
in the attachment JSON that defines which attachments fields are to be processed for markup rendering. Maybe the API has changed since the writing of this handler.
The handler configuration could have an additional field to enable markup if desired. Or even let the user define for which fields. Not sure what would be better.
I installed this plugin today using "gem install". I have put the configuration in several different locations but the plugin can't seem to read the configuration.
Sensu-server.log:
{"timestamp":"2015-09-30T23:30:49.381040+0000","level":"warn","message":"config file applied changes","file":"/etc/sensu/conf.d/handlers/slack_config.json","changes":{"slack":[null,{"webhook_url":"https://hooks.slack.com/services/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","template":""}]}}
<snip>
{"timestamp":"2015-09-30T23:25:04.992044+0000","level":"info","message":"handler output","handler":{"type":"pipe","command":"/usr/local/bin/handler-slack.rb","severites":["critical","unknown"],"name":"slack"},"output":["/usr/local/share/ruby/gems/2.0/gems/sensu-plugins-slack-0.0.4/bin/handler-slack.rb:62:in `get_setting': undefined method `[]' for nil:NilClass (NoMethodError)\n","\tfrom /usr/local/share/ruby/gems/2.0/gems/sensu-plugins-slack-0.0.4/bin/handler-slack.rb:50:in `message_template'\n","\tfrom /usr/local/share/ruby/gems/2.0/gems/sensu-plugins-slack-0.0.4/bin/handler-slack.rb:71:in `build_description'\n","\tfrom /usr/local/share/ruby/gems/2.0/gems/sensu-plugins-slack-0.0.4/bin/handler-slack.rb:66:in `handle'\n","\tfrom /usr/local/share/ruby/gems/2.0/gems/sensu-plugin-1.1.0/lib/sensu-handler.rb:55:in `block in <class:Handler>'\n"]}
/etc/sensu/conf.d/handlers/slack_handler.json:
{
"handlers": {
"slack": {
"type" : "pipe",
"command" : "/usr/local/bin/handler-slack.rb",
"severites": ["critical", "unknown"]
}
}
}
/etc/sensu/conf.d/handlers/slack_config.json:
{
"slack": {
"webhook_url": "https://hooks.slack.com/services/...",
"template" : ""
}
}
After upgrading sensu to 26.3 and uchiwa 18.2 silenced events are still being triggered. Is this an issue with the handler not checking to see if the event is silenced? Or am I missing something else?
Thanks,
Dylan
As the title of this issue says, the icon_emoji attribute is not supported by the multichannel plugin. The README.md lists the attribute as valid for the multichannel plugin, but support for it is not present in the code itself.
The code on GitHub for version 0.1.2 doesn't match what's installed if you run sensu-install, as there's been a few commits since 0.1.2 and there's no tags or branches to avoid confusion.
I'm working off of the 0.1.2 release and cannot use a payload template for multi-channel support.
I have in my /etc/sensu/conf.d/slack_handler.json:
{
"slack": {
"webhook_url": "<%= @url_slack_integration %>",
"payload_template": "/etc/sensu/conf.d/slack-payload.erb",
"channels": {
"default": ["#alerts"],
"compulsory": ["#alerts"]
}
}
}
However the payload_template isn't being read, and instead a default output (which I can't modify) is generated.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.