sensu-plugins-hangouts-chat 0.0.2

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
+ SHA256:
3
+ metadata.gz: 9c9868c75ad962aec39cc8aa459ac54b83123f784fbcecea996fae7cb5661a6b
4
+ data.tar.gz: 18d4115263373fffbdf25e1a8b87649d1bdad674867223a86617a6e29e9010e6
5
+ SHA512:
6
+ metadata.gz: 8961182ee6f4dce5408d2f8a1b06c0dbeaef2f63df10e5afcff5b8fbc540bb1706a274b7264f74d4b7a4ca75bd18c80735341f3bc5160a849340692730ebd654
7
+ data.tar.gz: 7abc1ad9bf6cebed4eaf69071d2bec370a8ac496886757520fb2010a072819342a3ccf7997001793d4f3ca99611c5e0c4d999c63b31ce93311f4a97861e176c8
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Change Log
2
+ This project adheres to [Semantic Versioning](http://semver.org/).
3
+
4
+ ## [Unreleased]
5
+
6
+ - initial release
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2018 Clever-Age
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # sensu-plugins-hangouts-chat
2
+ [![Build Status](https://travis-ci.org/clevertoday/sensu-plugins-hangouts-chat.svg?branch=master)](https://travis-ci.org/clevertoday/sensu-plugins-hangouts-chat)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/d4ed4e715bf90cbe6422/maintainability)](https://codeclimate.com/github/clevertoday/sensu-plugins-hangouts-chat/maintainability)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/d4ed4e715bf90cbe6422/test_coverage)](https://codeclimate.com/github/clevertoday/sensu-plugins-hangouts-chat/test_coverage)
5
+
6
+
7
+ ## Files
8
+
9
+ - `bin/handler-hangouts-chat.rb`
10
+
11
+ ## Usage
12
+
13
+ After installation, you have to set up a pipe type handler, like so:
14
+
15
+ ```json
16
+ {
17
+ "handlers": {
18
+ "hangouts_chat": {
19
+ "type": "pipe",
20
+ "command": "handler-hangouts-chat.rb"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ This gem also expects a JSON configuration file with the following contents:
27
+
28
+
29
+ ```json
30
+ {
31
+ "hangouts_chat": {
32
+ "webhook_url": "YOUR_WEBHOOK_URL",
33
+ }
34
+ }
35
+ ```
36
+
37
+ ## Installation
38
+
39
+ [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
40
+
41
+ ## Testing
42
+
43
+ ```bash
44
+ cat <<EOF | bundle exec bin/handler-hangouts-chat.rb -u "WEBHOOK_URL"
45
+ {
46
+ "client": {
47
+ "name": "client"
48
+ },
49
+ "check": {
50
+ "status": 1,
51
+ "name": "name",
52
+ "source": "source",
53
+ "output": "Hello, warning"
54
+ }
55
+ }
56
+ EOF
57
+ ```
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # Sensu Handler: Google Hangouts Chat
6
+ #
7
+ # This handler script is used to send notifications to Google Hangouts Chat rooms.
8
+ #
9
+
10
+ require 'sensu-handler'
11
+ require 'json'
12
+
13
+ class HangoutsChat < Sensu::Handler
14
+ option :json_config,
15
+ description: 'Configuration key name',
16
+ short: '-j JSONCONFIG',
17
+ long: '--json JSONCONFIG',
18
+ default: 'hangouts_chat'
19
+
20
+ option :webhook_url,
21
+ short: '-u WEBHOOK_URL',
22
+ description: 'The webhook url',
23
+ long: '--url WEBHOOK_URL',
24
+ default: nil
25
+
26
+ def hangouts_chat_webhook_url
27
+ config[:webhook_url] || get_setting('webhook_url')
28
+ end
29
+
30
+ def get_setting(name)
31
+ settings[config[:json_config]][name]
32
+ rescue TypeError, NoMethodError => e
33
+ puts "settings: #{settings}"
34
+ puts "hangouts chat key: #{config[:json_config]}. This should not be a file name/path."
35
+ puts "
36
+ key name: #{name}. This is the key in config that broke.
37
+ Check the hangouts chat key to make sure it's parent key exists
38
+ "
39
+ puts "error: #{e.message}"
40
+ exit 3 # unknown
41
+ end
42
+
43
+ def incident_key
44
+ @event['client']['name'] + '/' + @event['check']['name']
45
+ end
46
+
47
+ def incident_description
48
+ @event['check']['output']
49
+ end
50
+
51
+ def incident_formated_message
52
+ {
53
+ 'text' => "#{incident_key}: #{incident_description}"
54
+ }
55
+ end
56
+
57
+ def handle
58
+ post_data(JSON.generate(incident_formated_message))
59
+ end
60
+
61
+ def post_data(body)
62
+ uri = URI(hangouts_chat_webhook_url)
63
+ http = Net::HTTP.new(uri.host, uri.port)
64
+ http.use_ssl = true
65
+ req = Net::HTTP::Post.new("#{uri.path}?#{uri.query}", 'Content-Type' => 'application/json')
66
+ req.body = body
67
+ response = http.request(req)
68
+ verify_response(response)
69
+ end
70
+
71
+ def verify_response(response)
72
+ case response
73
+ when Net::HTTPSuccess
74
+ true
75
+ else
76
+ raise response.error!
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sensu-plugins-hangouts-chat/version'
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SensuPluginsHangoutsChat
4
+ module Version
5
+ MAJOR = 0
6
+ MINOR = 0
7
+ PATCH = 2
8
+
9
+ VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,219 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-hangouts-chat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Benjamin Digeon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: erubis
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.7.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.7.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sensu-plugin
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: github-markup
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.5'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.5'
97
+ - !ruby/object:Gem::Dependency
98
+ name: redcarpet
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.4'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.4'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.59.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.59.2
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.16'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.16'
153
+ - !ruby/object:Gem::Dependency
154
+ name: webmock
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '3.4'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '3.4'
167
+ - !ruby/object:Gem::Dependency
168
+ name: yard
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 0.9.11
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 0.9.11
181
+ description: Sensu plugins for google hangouts chat
182
+ email: "<bdigeon@clever-age.com>"
183
+ executables:
184
+ - handler-hangouts-chat.rb
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - CHANGELOG.md
189
+ - LICENSE
190
+ - README.md
191
+ - bin/handler-hangouts-chat.rb
192
+ - lib/sensu-plugins-hangouts-chat.rb
193
+ - lib/sensu-plugins-hangouts-chat/version.rb
194
+ homepage: https://github.com/clevertoday/sensu-plugins-hangouts-chat
195
+ licenses:
196
+ - MIT
197
+ metadata: {}
198
+ post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
199
+ in /etc/default/sensu
200
+ rdoc_options: []
201
+ require_paths:
202
+ - lib
203
+ required_ruby_version: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: 2.3.0
208
+ required_rubygems_version: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: '0'
213
+ requirements: []
214
+ rubyforge_project:
215
+ rubygems_version: 2.7.7
216
+ signing_key:
217
+ specification_version: 4
218
+ summary: Sensu plugins for Google Hangouts Chat
219
+ test_files: []