sensu-plugins-rocketchat 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2b3aaf8d48976d2470d2df7a7dbc1c5ba864f611
4
+ data.tar.gz: 0d638d9830a820efc7db383a06a53cb9980157ed
5
+ SHA512:
6
+ metadata.gz: 147ddf2eadf3d1148cc9405753d3dfadd8b8ed19447c21880c0cd5e7f9e2db1555ce87071dff370f30c3c1b33f13b377be9214c21b51b7693bf700a3728bbf34
7
+ data.tar.gz: dfc1eb9f312ba3fbd127a6ba8c2625fb26f6c256a12563052357dc0abee321c9f17a73eeb0663ad9141c313434727d42a48fc631e56bf20e2fbf7405621504b5
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## 0.0.1 - 2017-09-16
8
+ ### Added
9
+ - Rocket.Chat handler
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Sensu Community Plugins
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,43 @@
1
+ ## Sensu-Plugins-Rocketchat
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/sensu-plugins-rocketchat.svg)](http://badge.fury.io/rb/sensu-plugins-rocketchat)
4
+
5
+ ## Functionality
6
+
7
+ Sends notifications to Rocket.Chat through REST API
8
+
9
+ ## Files
10
+
11
+ * bin/handler-rocketchat.rb
12
+
13
+ ## Usage
14
+
15
+ Configure Rocket.Chat credentials, url and channel:
16
+
17
+ ```
18
+ {
19
+ "rocketchat": {
20
+ "username": "username",
21
+ "password": "password",
22
+ "api_url": "https://chat.example.com",
23
+ "channel": "sensu"
24
+ }
25
+ }
26
+ ```
27
+
28
+ Create a handler:
29
+
30
+ ```
31
+ {
32
+ "handlers": {
33
+ "rocketchat": {
34
+ "type": "pipe",
35
+ "command": "/opt/sensu/embedded/bin/handler-rocketchat.rb"
36
+ }
37
+ }
38
+ }
39
+ ```
40
+
41
+ ## Installation
42
+
43
+ [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
@@ -0,0 +1,26 @@
1
+ #!/opt/sensu/embedded/bin/ruby
2
+
3
+ require 'sensu-handler'
4
+ require 'rocketchat'
5
+ require_relative '../lib/sensu-plugins-rocketchat/content_generator.rb'
6
+
7
+ class NotifyRocketchat < Sensu::Handler #:nodoc:
8
+ def handle
9
+ session = rocketchat_session
10
+ session.chat.post_message(channel: settings['rocketchat']['channel'],
11
+ text: content)
12
+ session.logout
13
+ end
14
+
15
+ private
16
+
17
+ def rocketchat_session
18
+ rocket_server = RocketChat::Server.new(settings['rocketchat']['api_url'])
19
+ rocket_server.login(settings['rocketchat']['username'],
20
+ settings['rocketchat']['password'])
21
+ end
22
+
23
+ def content
24
+ SensuPluginsRocketchat::ContentGenerator.new(@event).content
25
+ end
26
+ end
@@ -0,0 +1,2 @@
1
+ require 'sensu-plugins-rocketchat/version'
2
+ require 'sensu-plugins-rocketchat/content_generator'
@@ -0,0 +1,57 @@
1
+ require 'erubis'
2
+
3
+ module SensuPluginsRocketchat
4
+ # Generates notification body from event data
5
+ class ContentGenerator
6
+ def initialize(event)
7
+ @event = event
8
+ @client = event['client']
9
+ @check = event['check']
10
+ end
11
+
12
+ def content
13
+ eruby = Erubis::Eruby.new(body)
14
+ eruby.result(binding)
15
+ end
16
+
17
+ private
18
+
19
+ def body
20
+ <<-BODY.gsub(/^\s+/, '')
21
+ <%= output %>
22
+ Host: <%= @client['name'] %>
23
+ Timestamp: <%= Time.at(@check['issued']) %>
24
+ Address: <%= @client['address'] %>
25
+ Check Name: <%= @check['name'] %>
26
+ Command: <%= command %>
27
+ Status: <%= status %>
28
+ Occurrences: <%= @event['occurrences'] %>
29
+ BODY
30
+ end
31
+
32
+ def command
33
+ strip_passwords(@check['command'])
34
+ end
35
+
36
+ def output
37
+ strip_passwords(@check['output'])
38
+ end
39
+
40
+ def strip_passwords(str)
41
+ str.gsub(/(\s-p|\s-P|\s--password)(\s*\S+)/, '\1 [FILTERED]')
42
+ end
43
+
44
+ def status
45
+ case @check['status']
46
+ when 0
47
+ 'OK'
48
+ when 1
49
+ 'WARNING'
50
+ when 2
51
+ 'CRITICAL'
52
+ else
53
+ 'UNKNOWN'
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,9 @@
1
+ module SensuPluginsRocketchat
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ PATCH = 1
6
+
7
+ VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,197 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-rocketchat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sensu-Plugins and contributors
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-16 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: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rocketchat
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.13
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.13
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.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
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: '12.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '12.0'
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: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.49.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.49.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.4'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.4'
139
+ - !ruby/object:Gem::Dependency
140
+ name: yard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.8'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.8'
153
+ description: Sensu Rocket.chat plugins
154
+ email: "<info@zubkov.info>"
155
+ executables:
156
+ - handler-rocketchat.rb
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - CHANGELOG.md
161
+ - LICENSE
162
+ - README.md
163
+ - bin/handler-rocketchat.rb
164
+ - lib/sensu-plugins-rocketchat.rb
165
+ - lib/sensu-plugins-rocketchat/content_generator.rb
166
+ - lib/sensu-plugins-rocketchat/version.rb
167
+ homepage: https://github.com/sekrett/sensu-plugins-rocketchat
168
+ licenses:
169
+ - MIT
170
+ metadata:
171
+ maintainer: sensu-plugin
172
+ development_status: active
173
+ production_status: unstable - testing recommended
174
+ release_draft: 'false'
175
+ release_prerelease: 'false'
176
+ post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
177
+ in /etc/default/sensu
178
+ rdoc_options: []
179
+ require_paths:
180
+ - lib
181
+ required_ruby_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: 2.0.0
186
+ required_rubygems_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ requirements: []
192
+ rubyforge_project:
193
+ rubygems_version: 2.6.11
194
+ signing_key:
195
+ specification_version: 4
196
+ summary: Sensu plugins for Rocket.chat
197
+ test_files: []