Giter Site home page Giter Site logo

zuazo / chef-handler-sns Goto Github PK

View Code? Open in Web Editor NEW
12.0 12.0 11.0 323 KB

Chef report handler to send Amazon SNS notifications on failures or changes.

Home Page: http://zuazo.github.io/chef-handler-sns/

License: Apache License 2.0

Ruby 97.40% HTML 2.60%
amazon aws chef devops handler iam sns

chef-handler-sns's People

Contributors

hltbra avatar michaelshobbs avatar till avatar zuazo avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

chef-handler-sns's Issues

Encoding::UndefinedConversionError

Is there anything we can do in chef-handler-sns to "fix" this?

[2015-07-09T21:34:37+00:00] INFO: Running queued delayed notifications before re-raising exception
[2015-07-09T21:34:37+00:00] ERROR: Running exception handlers
[2015-07-09T21:34:37+00:00] ERROR: Report handler Chef::Handler::Sns raised #<Encoding::UndefinedConversionError: "\xE2" from ASCII-8BIT to UTF-8>
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/aws-sdk-v1-1.53.0/lib/aws/sns/topic.rb:272:in `encode'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/aws-sdk-v1-1.53.0/lib/aws/sns/topic.rb:272:in `to_json'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/aws-sdk-v1-1.53.0/lib/aws/sns/topic.rb:272:in `publish'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-handler-sns-1.2.0/lib/chef/handler/sns.rb:37:in `report'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/handler.rb:226:in `run_report_unsafe'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/handler.rb:214:in `run_report_safely'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/handler.rb:118:in `block in run_exception_handlers'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/handler.rb:117:in `each'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/handler.rb:117:in `run_exception_handlers'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/handler.rb:127:in `block in <class:Handler>'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/client.rb:122:in `call'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/client.rb:122:in `block in run_failed'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/client.rb:121:in `each'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/client.rb:121:in `run_failed'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/client.rb:431:in `rescue in do_run'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/client.rb:441:in `do_run'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/client.rb:200:in `block in run'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/client.rb:194:in `fork'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/client.rb:194:in `run'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/application.rb:215:in `run_chef_client'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/application/client.rb:314:in `block in run_application'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/application/client.rb:306:in `loop'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/application/client.rb:306:in `run_application'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/lib/chef/application.rb:66:in `run'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/releases/20150629124612_3422-20150629124612/vendor/bundle/ruby/2.0.0/gems/chef-11.10.4/bin/chef-client:26:in `<top (required)>'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/current/bin/chef-client:16:in `load'
[2015-07-09T21:34:37+00:00] ERROR: /opt/aws/opsworks/current/bin/chef-client:16:in `<main>'
[2015-07-09T21:34:37+00:00] ERROR: Exception handlers complete

message_structure support

Hello. I'm trying to use the chef-handler-sns cookbook to send SNS notification to few different endpoints (email, lambda). But report function sends messages without defining message_structure option. Can you add support for message_structure?
Btw, if message_structure defined for client.publish() method but has empty (not 'json') value message will be send as plain text.

Is the cookbook for this still under development?

Posting here as well since I noticed a lack of activity for the past year on the cookbook.

Is it still under development? If not, what would need to be done to bring it up to date with this repo.

Looks like the cookbook IS pulling in the latest gem in the issue.

Not sure if my issue is related but the mentioned issue is here: zuazo/chef_handler_sns-cookbook#5

undefined method `fqdn' for #<Chef::Node::Attribute:0x0000000002f1b588>>

chef client version iam using is 14.4.56

can anyone please tell me what went wrong in this.

same code is working fine with chef-client version of 12.7 but doesn't work with versions > 12.7

Running handlers:
[2018-09-20T09:41:46+00:00] ERROR: Report handler Chef::Handler::Sns raised #<NoMethodError: undefined method fqdn' for #<Chef::Node::Attribute:0x0000000002f1b588>> [2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/node.rb:263:in public_send'
[2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/node.rb:263:in method_missing' [2018-09-20T09:41:46+00:00] ERROR: (erubis):3:in block in evaluate'
[2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/erubis-2.7.0/lib/erubis/evaluator.rb:74:in instance_eval' [2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/erubis-2.7.0/lib/erubis/evaluator.rb:74:in evaluate'
[2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-handler-sns-2.1.0/lib/chef/handler/sns.rb:302:in sns_body' [2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-handler-sns-2.1.0/lib/chef/handler/sns.rb:138:in report'
[2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/handler.rb:257:in run_report_unsafe' [2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/handler.rb:245:in run_report_safely'
[2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/handler.rb:123:in block in run_report_handlers' [2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/handler.rb:121:in each'
[2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/handler.rb:121:in run_report_handlers' [2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/handler.rb:133:in block in class:Handler'
[2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/client.rb:445:in block in run_completed_successfully' [2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/client.rb:444:in each'
[2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/client.rb:444:in run_completed_successfully' [2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/client.rb:301:in run'
[2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/application.rb:303:in run_with_graceful_exit_option' [2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/application.rb:279:in block in run_chef_client'
[2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/local_mode.rb:44:in with_server_connectivity' [2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/application.rb:261:in run_chef_client'
[2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/application/client.rb:440:in run_application' [2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/application.rb:66:in run'
[2018-09-20T09:41:46+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/bin/chef-client:25:in <top (required)>' [2018-09-20T09:41:46+00:00] ERROR: /usr/bin/chef-client:75:in load'
[2018-09-20T09:41:46+00:00] ERROR: /usr/bin/chef-client:75:in `

'

  • Chef::Handler::Sns
    Running handlers complete

Deprecated features used!
Resource chef_handler has been loaded from a cookbook. The resource chef_handler is now included in Chef and will take precedence over the existing cookbook resource in the next major release of Chef (15.0, April 2019). You may be able to remove this cookbook dependency from your runlist if you do not use other recipes/resources/libraries from the cookbook. Alternatively there may be a newer version of this cookbook without the chef_handler resource. at 1 location:
- /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/log.rb:51:in `caller_location'
See https://docs.chef.io/deprecations_map_collision.html for further details.

Gem::LoadError with OpsWorks

I'm having some issues when attempting to use the chef-handler-sns gem in OpsWorks stacks. It seems Gem::Specification.find_by_name() doesn't find the gem even though I see it installed in the logs and can find it on the file system. I'm guessing this has to do with the fact OpsWorks runs in a bundle? However, I'm fairly new to Chef and Ruby for that matter. Here's what I'm seeing and how I'm attempting to use the gem. The only way I've made this work is ,of course, to hard code the path to the gem. Any help would be greatly appreciated.

error:

Gem::LoadError
--------------
Could not find 'chef-handler-sns' (>= 0) among 55 total gem(s)

gem path:

find / -name chef-handler-sns-1.1.0
/opt/aws/opsworks/releases/20140516131848_313/vendor/bundle/ruby/2.0.0/gems/chef-handler-sns-1.1.0

sns-handler.rb:

include_recipe 'chef_handler::default'

cookbook_file 'chef_handler_sns_body.erb' do
  path '/tmp/chef_handler_sns_body.erb'
  owner 'root'
  group 'root'
  mode '0600'
end

# Handler configuration options
argument_array = [
  :access_key => node[:aws][:access_key_id],
  :secret_key => node[:aws][:secret_access_key],
  :topic_arn => 'arn:aws:sns:us-east-1:xxxxxxxxxxxxxx:NotifyMe',
  :subject => "Chef-run: <%= node.name %> - <%= run_status.success? ? 'ok' : 'error' %>",
  :body_template => '/tmp/chef_handler_sns_body.erb',
]
include_recipe "xml::ruby"

chef_gem "chef-handler-sns"

chef_handler "Chef::Handler::Sns" do
  source "#{Gem::Specification.find_by_name("chef-handler-sns").lib_dirs_glob}/chef/handler/sns"
  arguments argument_array
  supports :exception => true
  action :enable
end

AWS::SNS::Errors::InvalidClientTokenId when using version 1.1.0

I'm getting the aforementioned error since upgrading to 1.1.0. The following config work with 0.2.6. Any thoughts on what I'm doing incorrectly?

argument_array = [
  :access_key => node[:aws][:access_key_id],
  :secret_key => node[:aws][:secret_access_key],
  :topic_arn => 'arn:aws:sns:us-east-1:XXXXXXXXXXXX:NotifyMe',
  :subject => "Chef-run: <%= node.name %> - <%= run_status.success? ? 'ok' : 'error' %>",
  :body_template => '/tmp/chef_handler_sns_body.erb',
]

...
Opsworks sns_handler_path stuffs.....
...

chef_handler 'Chef::Handler::Sns' do
  source "#{sns_handler_path}/chef/handler/sns"
  arguments argument_array
  supports :exception => true
  action :enable
end

full stack trace:

[2014-06-23T19:42:58+00:00] ERROR: Report handler Chef::Handler::Sns raised #<AWS::SNS::Errors::InvalidClientTokenId: The security token included in the request is invalid>
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/bundle/ruby/1.8/gems/aws-sdk-1.32.0/lib/aws/core/client.rb:368:in `return_or_raise'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/bundle/ruby/1.8/gems/aws-sdk-1.32.0/lib/aws/core/client.rb:469:in `client_request'
[2014-06-23T19:42:58+00:00] ERROR: (eval):3:in `publish'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/bundle/ruby/1.8/gems/aws-sdk-1.32.0/lib/aws/sns/topic.rb:277:in `publish'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/bundle/ruby/1.8/gems/chef-handler-sns-1.1.0/lib/chef/handler/sns.rb:37:in `report'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/gems/chef-11.4.4/bin/../lib/chef/handler.rb:226:in `run_report_unsafe'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/gems/chef-11.4.4/bin/../lib/chef/handler.rb:214:in `run_report_safely'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/gems/chef-11.4.4/bin/../lib/chef/handler.rb:118:in `run_exception_handlers'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/gems/chef-11.4.4/bin/../lib/chef/handler.rb:117:in `each'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/gems/chef-11.4.4/bin/../lib/chef/handler.rb:117:in `run_exception_handlers'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/gems/chef-11.4.4/bin/../lib/chef/handler.rb:127
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/gems/chef-11.4.4/bin/../lib/chef/client.rb:120:in `call'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/gems/chef-11.4.4/bin/../lib/chef/client.rb:120:in `run_failed'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/gems/chef-11.4.4/bin/../lib/chef/client.rb:119:in `each'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/gems/chef-11.4.4/bin/../lib/chef/client.rb:119:in `run_failed'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/gems/chef-11.4.4/bin/../lib/chef/client.rb:485:in `do_run'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/gems/chef-11.4.4/bin/../lib/chef/client.rb:200:in `run'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/gems/chef-11.4.4/bin/../lib/chef/application.rb:190:in `run_chef_client'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/gems/chef-11.4.4/bin/../lib/chef/application/solo.rb:239:in `run_application'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/gems/chef-11.4.4/bin/../lib/chef/application/solo.rb:231:in `loop'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/gems/chef-11.4.4/bin/../lib/chef/application/solo.rb:231:in `run_application'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/gems/chef-11.4.4/bin/../lib/chef/application.rb:73:in `run'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/releases/20140514153150_227/vendor/gems/chef-11.4.4/bin/chef-solo:25
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/current/bin/chef-solo:16:in `load'
[2014-06-23T19:42:58+00:00] ERROR: /opt/aws/opsworks/current/bin/chef-solo:16
[2014-06-23T19:42:58+00:00] ERROR: Exception handlers complete

Troubleshooting handlers

Is there a debug mode to set for troubleshooting? With supports to to true for both exception and report, we're only getting notified to reports.

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.