alerty-plugin-amazon_sns 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 335ee382ff098d4cf442d0df9946d437b8f06205
4
+ data.tar.gz: 3f4045bf36be219118a2dbdffe0f78118192ac85
5
+ SHA512:
6
+ metadata.gz: 1cc660c16aa0e9a7dedf1b568461b628536adf76c7ee74484f42aa889f827e9a5fbc5fef5f0f5a6e053346c391ddd4f73fe94841d4c6ee4130fc2875db2a3c5c
7
+ data.tar.gz: 6ff066bb2cb98cbdfe2546255bb852e0e2736d5853934ba532101ab9bca297af149c4cc2d56040010fd20631eb679e8dfbf7c8a5f6bef6c76c365cdd92ecf2e8
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *~
2
+ .bundle
3
+ .pryrc
4
+ .rvmrc
5
+ .rbenv-version
6
+ .ruby-version
7
+ .yardoc
8
+ .DS_Store
9
+ Gemfile.lock
10
+ coverage
11
+ doc
12
+ log
13
+ tmp
14
+ vendor
15
+ *.swp
16
+ pkg/
17
+ .env
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem 'pry'
5
+ gem 'pry-nav'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Naotoshi Seo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Alerty::Plugin::AmazonSns
2
+
3
+ Amazon SNS plugin for alerty
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'alerty-plugin-amazon_sns'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install alerty-plugin-amazon_sns
20
+
21
+ ## Configuration
22
+
23
+ * **type**: must be `amazon_sns`
24
+ * **topc_name**: Amazon SNS topic name
25
+ * **subject**: subject of alert. `${command}` is replaced with a given command, `${hostname}` is replaced with the hostname ran a command
26
+ * **aws_region**: AWS Region. (default: ENV["AWS_REGION'])
27
+ * **aws_access_key_id**: Credential key id (default: ENV['AWS_SECRET_KEY_id'] or ~/.aws/credentials or instance profile on EC2)
28
+ * **aws_secret_access_key**: Credential secret access_key (default: ENV['AWS_SECRET_ACCESS_KEY'] or ~/.aws/credentials or instance profile on EC2)
29
+
30
+ See [example.yml](./example.yml)
31
+
32
+ ## ChangeLog
33
+
34
+ See [CHANGELOG.md](./CHANGELOG.md)
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `gemspec`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sonots/alerty-plugin-amazon_sns. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
45
+
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
50
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "alerty-plugin-amazon_sns"
5
+ spec.version = "0.0.1"
6
+ spec.authors = ["Naotoshi Seo"]
7
+ spec.email = ["sonots@gmail.com"]
8
+
9
+ spec.summary = %q{Amazon SNS plugin for alerty}
10
+ spec.description = %q{Amazon SNS plugin for alerty}
11
+ spec.homepage = "https://github.com/sonots/alerty-plugin-amazon_sns"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.bindir = "exe"
16
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_runtime_dependency "alerty"
20
+ spec.add_runtime_dependency "aws-sdk"
21
+ spec.add_runtime_dependency "dotenv"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "alerty/plugin/ikachan"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/example.yml ADDED
@@ -0,0 +1,6 @@
1
+ log_path: STDOUT
2
+ log_level: debug
3
+ plugins:
4
+ - type: amazon_sns
5
+ topic_arn: arn:aws:sns:ap-northeast-1:318088369558:alert
6
+ subject: "FAILURE: [${hostname}] ${command}"
@@ -0,0 +1,49 @@
1
+ require 'alerty'
2
+ require 'aws-sdk'
3
+ require 'dotenv'
4
+ Dotenv.load
5
+
6
+ class Alerty
7
+ class Plugin
8
+ class AmazonSns
9
+ def initialize(config)
10
+ raise ConfigError.new('amazon_sns: topic_arn is not configured') unless config.topic_arn
11
+ raise ConfigError.new('amazon_sns: subject is not configured') unless config.subject
12
+ # see http://docs.aws.amazon.com/sdkforruby/api/Aws/SNS/Client.html
13
+ # ENV or ~/.aws/credentials or instance profile on EC2, or alerty config file
14
+ params = {}
15
+ params[:region] = config.aws_region if config.aws_region
16
+ params[:access_key_id] = config.aws_access_key_id if config.aws_access_key_id
17
+ params[:secret_access_key] = config.aws_secret_access_key if config.aws_secret_access_key
18
+ @client = Aws::SNS::Client.new(params)
19
+ @subject = config.subject
20
+ @topic_arn = config.topic_arn
21
+ @num_retries = config.num_retries || 3
22
+ end
23
+
24
+ def alert(record)
25
+ message = record[:output]
26
+ subject = expand_placeholder(@subject, record)
27
+ retries = 0
28
+ begin
29
+ @client.publish(topic_arn: @topic_arn, message: message, subject: subject)
30
+ Alerty.logger.info "Sent #{{subject: subject, message: message}} to #{@topic_arn}"
31
+ rescue => e
32
+ retries += 1
33
+ sleep 1
34
+ if retries <= @num_retries
35
+ retry
36
+ else
37
+ raise e
38
+ end
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def expand_placeholder(str, record)
45
+ str.gsub('${command}', record[:command]).gsub!('${hostname}', record[:hostname])
46
+ end
47
+ end
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alerty-plugin-amazon_sns
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Naotoshi Seo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: alerty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Amazon SNS plugin for alerty
98
+ email:
99
+ - sonots@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - CODE_OF_CONDUCT.md
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - alerty-plugin-amazon_sns.gemspec
111
+ - bin/console
112
+ - bin/setup
113
+ - example.yml
114
+ - lib/alerty/plugin/amazon_sns.rb
115
+ homepage: https://github.com/sonots/alerty-plugin-amazon_sns
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.2.2
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Amazon SNS plugin for alerty
139
+ test_files: []