sensu-plugin-trello 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9db527133757885cc086b65951299c564169bc8b
4
+ data.tar.gz: 31d1975df42e5952a03987a56ea410a47e9f1010
5
+ SHA512:
6
+ metadata.gz: c9c7fc70a4dd85c58b65ab42365b057e5205085f3570cf1c6ceeb347480b018725c0d31c5f07543c842ba17e894bd0eb61aa19fd0ff2430b49c32c723fbd08d2
7
+ data.tar.gz: 1984abf19acc52eeba2d9b4358d96a0e1d631a35bb2b1e63b810d05a22355b151cc1f7bbd60101a9a7a836e784cf771b19f95f8f21b79873708198012727ff66
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sensu-plugin-trello.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Hauke Altmann
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,71 @@
1
+ # Sensu check for new incidents in Trello
2
+
3
+ Checks for cards in a trello list. If cards are present, the check returns
4
+ _CRITICAL_, containing name and date of last activity of card. When more
5
+ than one card is present, all card names and dates are returned with *;*
6
+ delimiter.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'sensu-plugin-trello'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install sensu-plugin-trello
23
+
24
+ ## CONFIGURATION
25
+ Configuration of API key and API token should be done through the sensu
26
+ settings file located in _/etc/sensu/conf.d/_.
27
+
28
+ _api_key_ and _api_token_ can be obtained from [Trello](https://trello.com/app-key).
29
+ _list_ can be obtained by adding _.json_ to a card in the browser in the
30
+ list that should be monitored and search for _idList_ in the JSON-output.
31
+ Note that in a production environment, _api_key_ and _api_token_ should be
32
+ specified in the Sensu settings rather than through CLI parameters.
33
+
34
+ ## USAGE
35
+ Check if a specific trello list is empty or contains cards
36
+
37
+ ### Required parameters
38
+
39
+ | Parameter | Description |
40
+ | --------- | ----------------------------------- |
41
+ | -l LIST | id of the Trello list to be checked |
42
+ | -k KEY | Trello API key |
43
+ | -t TOKEN | Trello API token |
44
+
45
+ ### Optional parameters
46
+
47
+ | Parameter | Description |
48
+ | --------- | --------------- |
49
+ | -h HOST | Trello API host |
50
+ | -p PORT | Trello API port |
51
+
52
+ ### Example:
53
+ ```
54
+ ./bin/check-trello-incidents.rb -k 123456789012 -t 1234567890121234567890 -l 1234567890
55
+ ```
56
+
57
+ ## Development
58
+
59
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
60
+
61
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, 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).
62
+
63
+ ## Contributing
64
+
65
+ Bug reports and pull requests are welcome on GitHub at https://github.com/aboutsource/sensu-plugin-trello.
66
+
67
+
68
+ ## License
69
+
70
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
71
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Check for new incidents in Trello
4
+ #
5
+ # DESCRIPTION:
6
+ # Checks for cards in a trello list. If cards are present, the check returns
7
+ # CRITICAL, containing name and date of last activity of card. When more
8
+ # than one card is present, all card names and dates are returned with ';'
9
+ # delimiter.
10
+ #
11
+ # CONFIGURATION:
12
+ # Configuration of API key and API token should be done through the sensu
13
+ # settings file located in /etc/sensu/conf.d/.
14
+ #
15
+ # 'api_key' and 'api_token' can be obtained from Trello
16
+ # (https://trello.com/app-key). 'list' can be obtained by adding .json
17
+ # to a card in the browser in the list that should be monitored and search
18
+ # for 'idList' in the JSON-output. Note that in a production environment,
19
+ # api_key and api_token must be specified in the sensu settings rather than
20
+ # through CLI parameters.
21
+ #
22
+ # OUTPUT:
23
+ # plain text
24
+ #
25
+ #
26
+ # USAGE:
27
+ # Check if a specific trello list is empty or contains cards
28
+ # ./check-trello-incidents.rb -k 123456789012 -t 1234567890121234567890 \
29
+ # -l 1234567890
30
+ #
31
+
32
+
33
+ require 'sensu-plugin/check/cli'
34
+ require 'sensu-plugin/utils'
35
+ require 'json'
36
+ require 'yaml'
37
+ require 'net/http'
38
+
39
+ class CheckTrelloIncidents < Sensu::Plugin::Check::CLI
40
+ include Sensu::Plugin::Utils
41
+
42
+ option :host,
43
+ description: 'Trello host address',
44
+ short: '-h HOST',
45
+ long: '--host HOST',
46
+ default: 'api.trello.com'
47
+
48
+ option :port,
49
+ description: 'Trello port',
50
+ short: '-p PORT',
51
+ long: '--port PORT',
52
+ default: '443'
53
+
54
+ option :list,
55
+ description: 'Trello list to check',
56
+ short: '-l LIST',
57
+ long: '--list LIST'
58
+
59
+ option :api_key,
60
+ description: 'Trello API key',
61
+ short: '-k KEY',
62
+ long: '--api-key KEY'
63
+
64
+ option :api_token,
65
+ description: 'Trello API token',
66
+ short: '-t TOKEN',
67
+ long: '--api-token TOKEN'
68
+
69
+ def run
70
+ host = config[:host]
71
+ port = config[:port]
72
+ key = config[:api_key] || settings['trello_incidents']['api']['key']
73
+ token = config[:api_token] || settings['trello_incidents']['api']['token']
74
+ list = config[:list]
75
+
76
+ begin
77
+ Timeout.timeout(10) do
78
+ check_list(host, port, key, token, list)
79
+ end
80
+ rescue Timeout::Error
81
+ unknown 'Connection timed out'
82
+ rescue => e
83
+ unknown 'Error: ' + e.message
84
+ end
85
+
86
+ end
87
+
88
+ def check_list(host, port, key, token, list)
89
+ if list.match(/\A[a-z0-9]*\z/).nil?
90
+ raise 'Invalid value for list parameter: ' + list
91
+ end
92
+
93
+ path = '/1/lists/' + list + '/cards'
94
+
95
+ uri = URI.parse('https://' + host + ':' + port + path)
96
+ params = { :key => key, :token => token }
97
+ uri.query = URI.encode_www_form(params)
98
+ res = Net::HTTP.get_response(uri)
99
+
100
+ unless res.code =~ /^2/
101
+ unknown res.code
102
+ end
103
+
104
+ incidents = JSON.parse(res.body)
105
+
106
+ if(incidents.empty?)
107
+ ok 'No new incidents'
108
+ else
109
+ msgs = []
110
+ incidents.each do |incident|
111
+ msgs.push(incident['name'] + ' ' + incident['dateLastActivity'])
112
+ end
113
+ msg = msgs.join(';')
114
+
115
+ critical msg
116
+ end
117
+ end
118
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sensu/plugin/trello"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,15 @@
1
+ {
2
+ "checks": {
3
+ "trello_incidents": {
4
+ "command": "check-trello-incidents.rb -l <TRELLO-LIST-ID>",
5
+ "interval": 120,
6
+ "standalone": true
7
+ }
8
+ },
9
+ "trello_incidents": {
10
+ "api": {
11
+ "key": "<TRELLO-API-KEY>",
12
+ "token": "<TRELLO-API-TOKEN>"
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,9 @@
1
+ require "sensu/plugin/trello/version"
2
+
3
+ module Sensu
4
+ module Plugin
5
+ module Trello
6
+ # Your code goes here...
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Sensu
2
+ module Plugin
3
+ module Trello
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sensu/plugin/trello/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sensu-plugin-trello"
8
+ spec.version = Sensu::Plugin::Trello::VERSION
9
+ spec.authors = ["Hauke Altmann"]
10
+ spec.email = ["hauke.altmann@aboutsource.net"]
11
+
12
+ spec.summary = 'Check if a Trello list contains card(s)'
13
+ spec.description = 'Used for incident management where a card represents an incident.'
14
+ spec.homepage = "https://github.com/aboutsource/sensu-plugin-trello"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = Dir.glob('bin/**/*.rb').map { |file| File.basename(file) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'sensu-plugin', '~> 2.1'
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugin-trello
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hauke Altmann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sensu-plugin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Used for incident management where a card represents an incident.
56
+ email:
57
+ - hauke.altmann@aboutsource.net
58
+ executables:
59
+ - check-trello-incidents.rb
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/check-trello-incidents.rb
69
+ - bin/console
70
+ - bin/setup
71
+ - check_trello_incidents.config.example.json
72
+ - lib/sensu/plugin/trello.rb
73
+ - lib/sensu/plugin/trello/version.rb
74
+ - sensu-plugin-trello.gemspec
75
+ homepage: https://github.com/aboutsource/sensu-plugin-trello
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.5.1
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Check if a Trello list contains card(s)
99
+ test_files: []