vaimo-messages-handler 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +8 -0
- data/LICENSE_VAIMO.txt +17 -0
- data/README.md +48 -0
- data/bin/send-message.rb +81 -0
- data/lib/vaimo-messages-handler.rb +66 -0
- data/lib/vaimo-messages-handler/version.rb +9 -0
- metadata +194 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 691c1d7faf680a4854849ec97558333fc3658f9d
|
4
|
+
data.tar.gz: 988c34d23d492b61a5b71117637c566e834c61ed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b9592305b1c0a20e3699a923b1ada334977915c5d12ba8841d5c379051c5d830831c7143fb1de0030aa19a7747657195002d271c5c976af8482461a61f1b8e90
|
7
|
+
data.tar.gz: 04720bfa575fd43f8121d3fb733614626cd9b871af54639be541088b7bcf4c1cbc75f6b4312c7635ecd111aa0e2e8d9e95bc6028fc5372eeed5add3c0cffd870
|
data/CHANGELOG.md
ADDED
data/LICENSE_VAIMO.txt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Copyright © 2009-2018 Vaimo Group.
|
2
|
+
|
3
|
+
Vaimo reserves all rights in the Program as delivered. The Program
|
4
|
+
or any portion thereof may not be reproduced in any form whatsoever without
|
5
|
+
the written consent of Vaimo, except as provided by licence. A licence
|
6
|
+
under Vaimo's rights in the Program may be available directly from
|
7
|
+
Vaimo.
|
8
|
+
|
9
|
+
Disclaimer:
|
10
|
+
THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
|
11
|
+
THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
12
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
13
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
14
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
15
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
16
|
+
OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
|
17
|
+
IN THE PROGRAM.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
## Vaimo Messages Handler plugin for Sensu
|
2
|
+
|
3
|
+
## Functionality
|
4
|
+
|
5
|
+
## Files
|
6
|
+
* bin/send-message.rb
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
### VaimoMessages
|
11
|
+
|
12
|
+
Create a json config file with your web_hook, auth_token, recipient and from.
|
13
|
+
|
14
|
+
```json
|
15
|
+
{
|
16
|
+
"vaimo-messages": {
|
17
|
+
"web_hook": "http://to.web.hook.urli/send",
|
18
|
+
"auth_token": "XXXXXXXXXXXXXXXXXXXXXXXXX",
|
19
|
+
"recipient": "group",
|
20
|
+
"from": "Sensu"
|
21
|
+
}
|
22
|
+
}
|
23
|
+
```
|
24
|
+
|
25
|
+
Set your check to use the handler and define the playsms recipients.
|
26
|
+
|
27
|
+
```json
|
28
|
+
{
|
29
|
+
"checks": {
|
30
|
+
"check-disk-usage": {
|
31
|
+
"command": "check-disk-usage.rb -w :::disk.warning|80::: -c :::disk.critical|90:::",
|
32
|
+
"subscribers": [
|
33
|
+
"production"
|
34
|
+
],
|
35
|
+
"handlers": [
|
36
|
+
"vaimo-messages"
|
37
|
+
],
|
38
|
+
"interval": 60
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
```
|
43
|
+
|
44
|
+
## Installation
|
45
|
+
|
46
|
+
[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
|
47
|
+
|
48
|
+
## Notes
|
data/bin/send-message.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# send-message.rb
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Sensu Messages Handler For Custom Messages gateway
|
7
|
+
#
|
8
|
+
# OUTPUT:
|
9
|
+
# None unless there is an error
|
10
|
+
#
|
11
|
+
# PLATFORMS:
|
12
|
+
# Linux
|
13
|
+
#
|
14
|
+
# DEPENDENCIES:
|
15
|
+
# gem: sensu-handler
|
16
|
+
#
|
17
|
+
# USAGE:
|
18
|
+
#
|
19
|
+
# Configure your vaimo-messages web_hook, auth_token, recipient and from here:
|
20
|
+
# vaimo-messages.json
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
#
|
24
|
+
# LICENSE:
|
25
|
+
# Copyright (c) Vaimo Group. All rights reserved.
|
26
|
+
# See LICENSE_VAIMO.txt for license details.
|
27
|
+
#
|
28
|
+
|
29
|
+
require 'date'
|
30
|
+
require 'sensu-handler'
|
31
|
+
require 'timeout'
|
32
|
+
|
33
|
+
# VaimoMessages Handler
|
34
|
+
class VaimoMessagesHandler < Sensu::Handler
|
35
|
+
def send_message
|
36
|
+
client = VaimoMessages::Client.new(
|
37
|
+
web_hook: web_hook,
|
38
|
+
auth_token: auth_token,
|
39
|
+
receiver: recipient,
|
40
|
+
from: from
|
41
|
+
)
|
42
|
+
|
43
|
+
client.send_message(server: server, level: 'error', component: component)
|
44
|
+
end
|
45
|
+
|
46
|
+
def web_hook
|
47
|
+
settings['vaimo-messages']['web_hook']
|
48
|
+
end
|
49
|
+
|
50
|
+
def auth_token
|
51
|
+
settings['vaimo-messages']['auth_token']
|
52
|
+
end
|
53
|
+
|
54
|
+
def recipient
|
55
|
+
settings['vaimo-messages']['recipient']
|
56
|
+
end
|
57
|
+
|
58
|
+
def from
|
59
|
+
if settings['vaimo-messages']['from'].is_a?(String)
|
60
|
+
return settings['vaimo-messages']['from']
|
61
|
+
end
|
62
|
+
|
63
|
+
Null
|
64
|
+
end
|
65
|
+
|
66
|
+
def server
|
67
|
+
@event['client']['name']
|
68
|
+
end
|
69
|
+
|
70
|
+
def component
|
71
|
+
@event['check']['name']
|
72
|
+
end
|
73
|
+
|
74
|
+
def handle
|
75
|
+
Timeout.timeout 10 do
|
76
|
+
send_message
|
77
|
+
end
|
78
|
+
rescue Timeout::Error
|
79
|
+
puts 'timed out while attempting to send message'
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'vaimo-messages-handler/version'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
# Messages for Vaimo System
|
7
|
+
module VaimoMessages
|
8
|
+
# Client for Sending data to WebHook
|
9
|
+
class Client
|
10
|
+
def initialize(options = {})
|
11
|
+
@web_hook = options.fetch(:web_hook)
|
12
|
+
@auth_token = options.fetch(:auth_token)
|
13
|
+
@receiver = options.fetch(:receiver)
|
14
|
+
|
15
|
+
@from = options.fetch(:from)
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_args(args)
|
19
|
+
{
|
20
|
+
auth_token: @auth_token,
|
21
|
+
receiver: @receiver,
|
22
|
+
from: @from,
|
23
|
+
server: key_value(args, :server, Null),
|
24
|
+
level: key_value(args, :level, Null),
|
25
|
+
message: key_value(args, :message, Null),
|
26
|
+
component: key_value(args, :component, Null)
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def key_value(args, key, default)
|
31
|
+
args.fetch(key).is_a?(String) ? args[key] : default
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse_response(response)
|
35
|
+
data = JSON.parse(response)
|
36
|
+
|
37
|
+
hash = {}
|
38
|
+
data.each do |key, value|
|
39
|
+
hash[key] = value
|
40
|
+
end
|
41
|
+
|
42
|
+
raise ErrorHandler "Messages WebHook: #{hash['message']}" if hash['error']
|
43
|
+
|
44
|
+
hash
|
45
|
+
end
|
46
|
+
|
47
|
+
def send_message(args)
|
48
|
+
header = ['Content-Type' => 'text/json']
|
49
|
+
|
50
|
+
uri = URI.parse(@web_hook)
|
51
|
+
|
52
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
53
|
+
http.use_ssl = true
|
54
|
+
|
55
|
+
request = Net::HTTP::Post.new(uri.request_uri, header)
|
56
|
+
request.body = parse_args(args).to_json
|
57
|
+
|
58
|
+
response = http.request(request)
|
59
|
+
|
60
|
+
parse_response(response.body)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class ErrorHandler < StandardError
|
65
|
+
end
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vaimo-messages-handler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Margus Heinmaa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-04 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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: codeclimate-test-reporter
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.4'
|
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.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.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: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.1'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.1'
|
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.40.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.40.0
|
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 Handler Messages
|
154
|
+
email: "<margus.heinmaa@vaimo.com>"
|
155
|
+
executables:
|
156
|
+
- send-message.rb
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- CHANGELOG.md
|
161
|
+
- LICENSE_VAIMO.txt
|
162
|
+
- README.md
|
163
|
+
- bin/send-message.rb
|
164
|
+
- lib/vaimo-messages-handler.rb
|
165
|
+
- lib/vaimo-messages-handler/version.rb
|
166
|
+
homepage: https://bitbucket.org/vaimo/vaimo-messages-handler
|
167
|
+
licenses:
|
168
|
+
- Private
|
169
|
+
metadata:
|
170
|
+
development_status: active
|
171
|
+
production_status: unstable - testing recommended
|
172
|
+
release_draft: 'false'
|
173
|
+
release_prerelease: 'false'
|
174
|
+
post_install_message:
|
175
|
+
rdoc_options: []
|
176
|
+
require_paths:
|
177
|
+
- lib
|
178
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: 2.1.0
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
requirements: []
|
189
|
+
rubyforge_project:
|
190
|
+
rubygems_version: 2.5.2.3
|
191
|
+
signing_key:
|
192
|
+
specification_version: 4
|
193
|
+
summary: Sensu plugins for Messages handling
|
194
|
+
test_files: []
|