Coder Social home page Coder Social logo

chef-slack_handler's People

Contributors

aaronblythe avatar azrael808 avatar bdwyertech avatar danryan avatar dlactin avatar dude051 avatar glensc avatar hudolejev avatar iennae avatar jazaval avatar jrmuir avatar jujugrrr avatar lmunro avatar lusis avatar martinb3 avatar nicwaller avatar p-pawlak avatar rata avatar rleibman avatar shortdudey123 avatar spuder avatar stefanwork avatar stromweld avatar tas50 avatar tmanda avatar trotttrotttrott avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chef-slack_handler's Issues

Implement CircleCI

We should apply our current best practices to have CI ran through CircleCI with test-kitchen and kitchen-rackspace.

icon_url config not read in slack_handler_webhook.rb

I don't think icon_url is read from config to be read by this line

This block likely needs @icon_url = @config[:icon_url] adding:

  def initialize(config = {})
    # set defaults for any missing attributes
    @config = config
    @timeout = @config[:timeout] || 15
    @icon_emoji = @config[:icon_emoji] || ':fork_and_knife:'
    @username = @config[:username] || 'chef_handler'
    @webhooks = @config[:webhooks]
  end

At latest version problems when changing message_detail_level from basic to other

Hi again.

I have problems after updating to latest 0.7.0 version. I've use web hooks method.

When changing message_detail_level from basic (with basic work without troubles) to other (elapsed, resources) I've receive error.

Running handlers:
[2016-05-06T13:20:29+03:00] WARN: Failed to send message to Slack: undefined local variable or method `updated_resources' for #<SlackHandlerUtil:0x0000000262dd68>
  - Chef::Handler::Slack

Also I try to change:

Valid options here are basic, elapsed, resources
default['chef_client']['handler']['slack']['message_detail_level'] = 'resources'

and for web hook too:
default['chef_client']['handler']['slack']['webhooks']['webhook1']['message_detail_level'] = 'resources'.

Can you check why? Previous 0.6.0 version work fine.

Sends report twice to slack

Running handlers:
[2015-05-19T02:05:47+00:00] ERROR: Running exception handlers
[2015-05-19T02:05:47+00:00] WARN: Sending report to Slack webhook https://hooks.slack.com/services/XXXX/XXXX/XXXXXXXXXXXXXXXX
[2015-05-19T02:05:47+00:00] WARN: Sending report to Slack webhook https://hooks.slack.com/services/XXXX/XXXX/XXXXXXXXXXXXXXXX

  • Chef::Handler::Slack
    Running handlers complete
    [2015-05-19T02:05:47+00:00] ERROR: Exception handlers complete
    [2015-05-19T02:05:47+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
    Chef Client failed. 3 resources updated in 10.692194779 seconds
    [2015-05-19T02:05:48+00:00] ERROR: template[/etc/haproxy/conf.d/default.cfg](haproxy::default line 26) had an error: Chef::Exceptions::FileNotFound: Cookbook 'haproxy' (0.1.0) does not contain a file at any of these locations:
    templates/centos-6.6/defaults.erb
    templates/centos/defaults.erb
    templates/default/defaults.erb
    templates/defaults.erb

haproxy is intentionally broken to test, please ignore that!

Handler does not alert on custom exceptions

I am including a very basic check that chef environment is set on all of my nodes, which looks like this:

if node.environment() == "_default"
  raise "Please re-bootstrap your node including the --environment parameter."
end

While this does successfully kill the chef-client run in these cases, it does not cause the chef-slack handler to send any event to our slack channel. I have tested other errors, and also manually triggering the slack webhook with a curl request and those all still work.

Do I need to reformat my exception somehow to get chef-slack handler to recognize it??

Version 0.7.1

Incorrect commit tagged as 0.1.0

The 0.1.0 tag on this repo is not associated with the right commit. I downloaded the 0.1.0 cookbook from Supermarket and it seems to correspond with commit f32996d.

Currently in this repo, the 0.1.0 tag is on b3f273f. That's a difference of 14 commits.

It's just a minor thing, but it would be nice to have it corrected.

no implicit conversion of Chef::DelayedEvaluator into String

I'm running into this in ubuntu 14.04, chef 12.13.37. Worked fine in chef 12.6.
` * cookbook_file[/var/chef/handlers/slack_handler_util.rb] action create

================================================================================
Error executing action `create` on resource 'cookbook_file[/var/chef/handlers/slack_handler_util.rb]'
================================================================================

TypeError
---------
no implicit conversion of Chef::DelayedEvaluator into String

Cookbook Trace:
---------------
/var/chef/cache/cookbooks/slack_handler/recipes/default.rb:42:in `from_file'
/var/chef/cache/cookbooks/moxi-slack/recipes/default.rb:14:in `from_file'

Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/slack_handler/recipes/default.rb

 37: cookbook_file "#{node['chef_handler']['handler_path']}/slack_handler_util.rb" do
 38:   source 'slack_handler_util.rb'
 39:   mode "0600"
 40:   action :nothing
 41:   # end
 42: end.run_action(:create)

Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/slack_handler/recipes/default.rb:37:in `from_file'

cookbook_file("/var/chef/handlers/slack_handler_util.rb") do
  provider Chef::Provider::CookbookFile
  action [:nothing]
  retries 0
  retry_delay 2
  default_guard_interpreter :default
  source "slack_handler_util.rb"
  declared_type "cookbook_file"
  cookbook_name "slack_handler"
  recipe_name "default"
  mode "0600"
  atomic_update #<Chef::DelayedEvaluator:0x00000001d8ce98@/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.13.37/lib/chef/resource/file.rb:53>
  path #<Chef::DelayedEvaluator:0x00000001d8df78@/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.13.37/lib/chef/property.rb:180>
end

Platform:
---------
x86_64-linux`

I also had a similar error with with chef_handler, but was able to resolve the issue by changing that to use just directory instead of remote_directory to make the handler_path on disk. The newer version of chef doesn't seem to appreciate the run_action with more complex resources. Interestingly if I run just the slack integration recipe by itself, it doesn't fail. But in a full chef run it does.

NameError: uninitialized constant Chef::Handler::Slack

I'm executing:
chef-client -o 'recipe[existing], 'recipe[newrecipe]' --why-run
on a server to test the second recipe without having to add it to the run-list.
My existing recipe contains the handler and a bunch of other recipes.
When adding the recipe to the run-list, there is no issue.
When running the command above, an error presents itself:

Cookbook Trace:

/var/chef/cache/cookbooks/chef_handler/libraries/helpers.rb:51:in `get_class'
/var/chef/cache/cookbooks/chef_handler/providers/default.rb:48:in `block in class_from_file'
/var/chef/cache/cookbooks/cpla_b_handler_mattermost/recipes/default.rb:58:in `from_file'
/var/chef/cache/cookbooks/cpla_r_core/recipes/default.rb:10:in `from_file'

Relevant File Content:

/var/chef/cache/cookbooks/chef_handler/libraries/helpers.rb:

44: ancestors = class_full_name.split('::')
45: class_name = ancestors.pop
46:
47: # We need to search the ancestors only for the first/uppermost namespace of the class, so we
48: # need to enable the #const_get inherit paramenter only when we are searching in Kernel scope
49: # (see COOK-4117).
50: parent = ancestors.inject(Kernel) { |scope, const_name| scope.const_get(const_name, scope === Kernel) }
51>> child = parent.const_get(class_name, parent === Kernel)
52: [parent, child]
53: end
54: end
55: end
56:

better handling of webhook messages with encoding problems

Every once in a while we see errors like this

Failed to send message to Slack: "\xE2" from ASCII-8BIT to UTF-8

which seems to stem from chef output including non utf-8 characters. It would probably be better to enforce utf-8 encoding on such messages instead of failing to send the message.

Integrating Slack Handler into client.rb?

I'd like to integrate the slack handler directly into client.rb and not have it run as part of the cookbook. I want the handler to catch convergence failures and other errors that might occur before a runlist even gets going. I'm not clear on what I need to do this, although my initial attempt looks something like this:

In /etc/chef/client.d in a file called slack.rb

require 'rubygems'
require '/var/chef/handlers/slack_handler_webhook'
​
slack_handler = Chef::Handler::Slack.new
​
start_handlers << slack_handler
report_handlers << slack_handler
exception_handlers << slack_handler

But this is sofar not working. Can I integrate this in this way?

webhook triggered on success with fail_only=true

In 4.0, with fail_only set to true, I'm getting :skull: Chef client run succeeded messages upon successful Chef runs.

Proposed change to slack_handler_webhook:

        if run_status.success? && !webhook['fail_only']
          slack_message(" :white_check_mark: Chef client run #{run_status_human_readable} on #{run_status.node.name} #{run_status_detail(webhook['detail_level'])}", webhook['url'])
          sending_to_slack = true
        else
          sending_to_slack = true
          slack_message(" :skull: Chef client run #{run_status_human_readable} on #{run_status.node.name} #{run_status_detail(webhook['detail_level'])}", webhook['url'], run_status.exception)
        end

should be

        if run_status.success?
          unless webhook['fail_only']
            sending_to_slack = true
            slack_message(" :white_check_mark: Chef client run #{run_status_human_readable} on #{run_status.node.name} #{run_status_detail(webhook['detail_level'])}", webhook['url'])
          end
        else
          sending_to_slack = true
          slack_message(" :skull: Chef client run #{run_status_human_readable} on #{run_status.node.name} #{run_status_detail(webhook['detail_level'])}", webhook['url'], run_status.exception)
        end

undefined method `run_context' for Chef:Class

as there's no minimum chef version mentioned, not sure that is the issue.

i've configured to use webhook mode and get such error at the end of the run:

Running handlers:
[2016-05-31T12:46:33+03:00] WARN: Failed to send message to Slack: undefined method `run_context' for Chef:Class
  - Chef::Handler::Slack
  - SyslogReporting
Running handlers complete
 # chef-client --version
Chef: 11.16.4

Add support for environment

In some environments, the node names are reasonably obscure so it may be good to include an option to send the chef environment. I believe this is usually accessed via node.chef_environment.

Ridley error when uploading cookbook

ERROR -- : Cookbook file /Users/admin/.berkshelf/cookbooks/slack_handler-0.9.0/files/default/slack_handler_util.rb has a ruby syntax error:
ERROR -- : Ridley::Errors::CookbookSyntaxError: Invalid ruby files in cookbook: slack_handler (0.9.0).

There's a syntax error in #52 - totally my fault, sorry!

Support for conditional slack notifications?

I'm using this cookbook to send reports to slack every time chef runs. Is there a way to send a conditional notification, say if a specific was updated?

If not, then are there any plans to add a LWRP (or custom resource) that can be notified / subscribed to?

Usage 2, setting attributes from the recipe level

I originally had this working setting everything for Usage 2 at the environment level, except the following, configured in the cookbook attribute file:

case node.chef_environment
when "staging" 
  node.default['chef_client']['handler']['slack']['webhooks']['name'].push('webhook1')
  node.default['chef_client']['handler']['slack']['webhooks']['name'].push('webhook2')
when "production"
  node.default['chef_client']['handler']['slack']['webhooks']['name'].push('webhook1')
  node.default['chef_client']['handler']['slack']['webhooks']['name'].push('webhook2')
end

That worked well, until I attempted to factor it out to the recipe level. My recipe looked like this:

# Configures Slack integration
# https://github.com/rackspace-cookbooks/chef-slack_handler

include_recipe "slack_handler"

# Send successes to #staging and #production.  Send failed runs to #errors.
case node.chef_environment
when "staging" 
  node.default['chef_client']['handler']['slack']['webhooks']['name'].push('webhook1')
  node.default['chef_client']['handler']['slack']['webhooks']['name'].push('webhook2')
when "production"
  node.default['chef_client']['handler']['slack']['webhooks']['name'].push('webhook1')
  node.default['chef_client']['handler']['slack']['webhooks']['name'].push('webhook2')
end

# Note: Verbosity is configured at the environment level.   
# Options are 'basic', 'elapsed' and 'resources'.

Running it this way broke something. I'm not sure what. We no longer get slack notifications to either of the three channels we have configured (#staging, #production, and #errors).

Output.

Not sure if this is a problem with the code, or my use case, or ?? Maybe I missed something obvious moving the attributes out of the attribute file?

I'd appreciate a little guidance.

new version of chef

got this error. can you check this.

Chef::Exceptions::ValidationFailed


Option action must be equal to one of: enable, disable! You passed :nothing.
Cookbook Trace: ---------------
/var/chef/cache/cookbooks/slack_handler/recipes/default.rb:47:in block in from_file' /var/chef/cache/cookbooks/slack_handler/recipes/default.rb:42:infrom_file'

Relevant File Content:


/var/chef/cache/cookbooks/slack_handler/recipes/default.rb:
40: end.run_action(:create)
41: 42: chef_handler "Chef::Handler::Slack" do
43: source handler_file
44: arguments [
45: node['chef_client']['handler']['slack']
46: ]
47>> action :nothing
48: end.run_action(:enable)
49:

Initial run fails due to missing /var/chef/handlers directory

I've been running into an issue with chef-client runs after adding this handler that causes the check-in to fail due to a missing /var/chef/handlers directory.

Code

As simple as the following:

include_recipe 'chef-client::cron'
include_recipe 'slack_handler'

Stack Trace

Chef::Exceptions::EnclosingDirectoryDoesNotExist
------------------------------------------------
cookbook_file[/var/chef/handlers/slack_handler_util.rb] (slack_handler::default line 37) had an error: Chef::Exceptions::EnclosingDirectoryDoesNotExist: Parent directory /var/chef/handlers does not exist.

Cookbook Trace:
---------------
  /var/chef/cache/cookbooks/slack_handler/recipes/default.rb:42:in `from_file'
  /var/chef/cache/cookbooks/cascade-cloud-instance/recipes/default.rb:22:in `from_file'
  /var/chef/cache/cookbooks/cloud-client-tdi/recipes/default.rb:10:in `from_file'

Relevant File Content:
----------------------
/var/chef/cache/cookbooks/slack_handler/recipes/default.rb:

 35:  end
 36:  
 37:  cookbook_file "#{node['chef_handler']['handler_path']}/slack_handler_util.rb" do
 38:    source 'slack_handler_util.rb'
 39:    mode "0600"
 40:    action :nothing
 41:    # end
 42>> end.run_action(:create)
 43:  
 44:  cookbook_file handler_file do
 45:    source handler_source
 46:    mode "0600"
 47:    action :nothing
 48:    # end
 49:  end.run_action(:create)
 50:  
 51:  chef_handler "Chef::Handler::Slack" do

Platform:
---------
x86_64-linux

Node is running on Amazon Linux (ami-0b33d91d) and is already bootstrapped. What's strange is didn't run into this issue when originally setting things up in test with the same exact setup.

Is it recommended to manually ensure /var/chef/handlers exists before including the recipe, or is this an issue with the Slack handler?

WARN: Failed to send message to Slack: undefined local variable or method `run_context' for #<SlackHandlerUtil:0x00000001d8e1d0>

Hi,

I met this error when using slack_handler.

Here's the log:

Recipe: chef_handler::default

  • remote_directory[/var/chef/handlers] action create
    Recipe:
* cookbook_file[/var/chef/handlers/README] action create (up to date)
 (up to date)

Recipe: slack_handler::default

  • cookbook_file[/var/chef/handlers/slack_handler_util.rb] action create (up to date)
  • cookbook_file[/var/chef/handlers/slack_handler_webhook.rb] action create (up to date)
  • chef_handler[Chef::Handler::Slack] action enable
    • disable Chef::Handler::Slack as a start handler
    • disable Chef::Handler::Slack as a report handler
    • disable Chef::Handler::Slack as a exception handler
    • load Chef::Handler::Slack from /var/chef/handlers/slack_handler_webhook.rb
    • enable chef_handler[Chef::Handler::Slack] as a start handler
    • enable chef_handler[Chef::Handler::Slack] as a report handler
    • enable chef_handler[Chef::Handler::Slack] as a exception handler
  • ruby_block[trigger_start_handlers] action create[2016-09-16T10:54:52+00:00] WARN: Failed to send message to Slack: undefined local variable or method `run_context' for #SlackHandlerUtil:0x00000001d8e1d0

Chef client version

$ chef -v
Chef Development Kit Version: 0.9.0
chef-client version: 12.5.1
berks version: 4.0.1
kitchen version: 1.4.2

Here's the config I've put on node config:

"chef_client": {
"handler": {
"slack": {
"webhooks": {
"name": ["webhook1"],
"webhook1": {
"url": "[MY HOOK URL]"
}
},
"timeout": 30,
"username": "Chef Bot",
"icon_emoji": ":fork_and_knife:",
"fail_only": false,
"send_start_message": true,
"message_detail_level": "resource",
"cookbook_detail_level": "all",
"send_environment": true
}
}
}

Please tell if you need to provide more information.
Thank you.

Add support for cookbook context

It'd be nice to see the cookbooks and versions that have run in the notification to Slack. Would just need to incorporate something like #{run_status_cookbooks} into the slack_message calls then define this method:

  def run_status_cookbooks
    cookbooks = run_status.run_context.cookbook_collection
    "#{cookbooks.keys.map {|x| cookbooks[x].name.to_s + ' ' + cookbooks[x].version} }"
  end

I mostly grabbed that from here and yet to try a run of this.

why-run mode not working when using this cookbook

I noticed that why-run mode is broken when this cookbook is in my runlist. I'm guessing that this is due to handlers not being loaded in why-run (see chef-cookbooks/chef_handler#40):

  * chef_handler[Chef::Handler::Slack] action enable
    - Would disable Chef::Handler::Slack as a start handler
    - Would disable Chef::Handler::Slack as a report handler
    - Would disable Chef::Handler::Slack as a exception handler
    - Would load Chef::Handler::Slack from /var/chef/handlers/slack_handler_webhook.rb
    ================================================================================
    Error executing action `enable` on resource 'chef_handler[Chef::Handler::Slack]'
    ================================================================================

    NameError
    ---------
    uninitialized constant Slack

    Cookbook Trace:
    ---------------
    /var/chef/cache/cookbooks/chef_handler/libraries/helpers.rb:51:in `const_get'
    /var/chef/cache/cookbooks/chef_handler/libraries/helpers.rb:51:in `get_class'
    /var/chef/cache/cookbooks/chef_handler/providers/default.rb:48:in `block in class_from_file'
    /var/chef/cache/cookbooks/slack_handler/recipes/default.rb:58:in `from_file'
    /var/chef/cache/cookbooks/orcasnet/recipes/default.rb:20:in `from_file'

Honestly, I'm not sure whether there's anything about the Slack handler recipe that could change to fix this. I'm not sure why it's even looking up the constant in the first place. But... maybe you have some ideas?

Support webhook default configuration from Slack UI

Slack supports default configuration for icon and name of a webhook.

Inside (slack_handler_webhook.rb)[https://github.com/rackspace-cookbooks/chef-slack_handler/blob/master/files/default/slack_handler_webhook.rb] could the defaults be removed so the defaults built into Slack take effect instead? So remove the || ':fork_and_knife:' and || 'chef_handler' parts from this block:

  def initialize(config = {})
    # set defaults for any missing attributes
    @config = config
    @timeout = @config[:timeout] || 15
    @icon_emoji = @config[:icon_emoji]
    @username = @config[:username]
    @webhooks = @config[:webhooks]
  end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.