This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--format progress documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
language: ruby | ||
#bundler_args: --without development | ||
|
||
env: | ||
- CI=true | ||
rvm: | ||
- 1.9.2 | ||
- 1.9.3 | ||
gemfile: | ||
- Gemfile | ||
before_install: | ||
- bundle install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source "http://rubygems.org/" | ||
|
||
gem 'rake' | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require "bundler/gem_tasks" | ||
|
||
require 'rspec/core/rake_task' | ||
RSpec::Core::RakeTask.new(:spec) do |spec| | ||
spec.rspec_opts = [ '-I', 'lib', '-I', 'spec' ] | ||
spec.pattern = FileList['spec/**/*_spec.rb'] | ||
end | ||
|
||
RSpec::Core::RakeTask.new(:rcov) do |spec| | ||
spec.rspec_opts = [ '-I', 'lib', '-I', 'spec' ] | ||
spec.pattern = FileList['spec/**/*_spec.rb'] | ||
spec.rcov = true | ||
end | ||
|
||
task :default => :spec | ||
|
||
begin | ||
require 'yard' | ||
YARD::Rake::YardocTask.new | ||
rescue LoadError | ||
task :yardoc do | ||
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
$:.push File.expand_path("../lib", __FILE__) | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "chef-handler-slack" | ||
s.version = "0.1.0" | ||
s.authors = ["Derek Smith"] | ||
s.email = ["[email protected]"] | ||
s.homepage = "https://github.com/tinyspeck/chef-handler-slack" | ||
s.summary = %q{Chef reports generated to a channel in Slack} | ||
s.description = %q{Chef reports generated to a channel in Slack} | ||
s.license = "MIT" | ||
|
||
|
||
s.files = `git ls-files`.split("\n") | ||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.require_paths = ["lib"] | ||
|
||
# specify any dependencies here; for example: | ||
s.add_development_dependency "rspec" | ||
s.add_runtime_dependency "chef", '>= 0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# | ||
# Author:: Derek Smith <[email protected]> | ||
# Copyright:: Copyright (c) 2014, Derek Smith | ||
# License:: Apache License, Version 2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
require "rubygems" | ||
Gem.clear_paths | ||
require "chef" | ||
require "chef/handler" | ||
|
||
require "net/http" | ||
require "uri" | ||
require "json" | ||
|
||
class SlackReporting < Chef::Handler | ||
attr_accessor :source, :team, :icon_emoj, :channel, :token, :username | ||
|
||
def initialize(options = {}) | ||
@source = options[:source] || "#{Chef::Config[:node_name]}" | ||
@channel = options[:channel] || "#test" | ||
@api_key = options[:token] || "token" | ||
@team = options[:team] || "doesnotexist" | ||
@username = options[:username] || "chef" | ||
end | ||
|
||
def report | ||
gemspec = if Gem::Specification.respond_to? :find_by_name | ||
Gem::Specification.find_by_name('chef-handler-slack') | ||
else | ||
Gem.source_index.find_name('chef-handler-slack').last | ||
end | ||
|
||
Chef::Log.debug("#{gemspec.full_name} loaded as a handler.") | ||
|
||
params = { | ||
:username => @username, | ||
:icon_emoji => @icon_emoj, | ||
:channel => @channel, | ||
:text => "HELLO", | ||
} | ||
|
||
begin | ||
http = Net::HTTP.new | ||
uri = URI.parse("https://#{@team}.slack.com/services/hooks/incoming-webhook?token=#{@token}") | ||
req = Net::HTTP::Post.new(uri) | ||
req.set_form_data(params) | ||
http.request(req) | ||
rescue Exception => e | ||
puts "#{e}" | ||
end | ||
end | ||
end |