sensu-plugins-plivo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +12 -0
- data/LICENSE +22 -0
- data/README.md +83 -0
- data/bin/handler-plivosms.rb +117 -0
- data/lib/sensu-plugins-plivo.rb +1 -0
- data/lib/sensu-plugins-plivo/version.rb +9 -0
- metadata +238 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c4b643343d092fa539bfe5f712ac0ffab4e5554b
|
4
|
+
data.tar.gz: 67fd29be6b0f118792cb7ed1c926b901361dda95
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: edc6913605e5ba9973dcd6750c99e005441ce9a41258e5aa2bb0d9aa859b76fcad27855d239f5d13601360edf863a164ff31c926683da4e0e0e84435ab8823e3
|
7
|
+
data.tar.gz: 3bbbef346f250d85471dcbffbb6da34ae689d1e855777c84c715043bc6c534305386e71a73eab99d9318a8b795b61dd46166b089af4244f6a86e3ea5efe889d8
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#Change Log
|
2
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
3
|
+
|
4
|
+
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
|
5
|
+
|
6
|
+
## [Unreleased]
|
7
|
+
|
8
|
+
## 0.0.1 - 2016-05-18
|
9
|
+
### Added
|
10
|
+
- initial release
|
11
|
+
|
12
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-p/compare/0.0.2...HEAD
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Sensu-Plugins
|
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,83 @@
|
|
1
|
+
## Sensu-Plugins-plivo
|
2
|
+
|
3
|
+
## Functionality
|
4
|
+
|
5
|
+
## Files
|
6
|
+
* bin/handler-plivosms.rb
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
```
|
11
|
+
{
|
12
|
+
"plivosms":{
|
13
|
+
"id":"AC0ds98gd098g", // auth id
|
14
|
+
"token":"a9d8ag98daf98ga9fd8g", // auth token
|
15
|
+
"number":"15551112222", // the sms will be sent from this number, include country code
|
16
|
+
"recipients":{
|
17
|
+
"15552223333": {
|
18
|
+
"subscriptions":[ "web" ], // subscriptions that should trigger sms
|
19
|
+
"checks":[], // checks that should trigger sms
|
20
|
+
"cutoff": 1 // 1 for warning, 2 for critical alerts (default is 2)
|
21
|
+
},
|
22
|
+
"11111222222": {
|
23
|
+
"subscriptions":[ 'all' ], // 'all'
|
24
|
+
"checks":[ "mysql-alive" ],
|
25
|
+
"cutoff": 2
|
26
|
+
},
|
27
|
+
"11111223333": { // not specifying "subscriptions" is same as 'all'
|
28
|
+
"checks":[ "check_dns", "check_http" ]
|
29
|
+
},
|
30
|
+
"11111224444": {
|
31
|
+
"cutoff": 1 // "subscriptions" and "checks" are optional, defaults 'all'
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
Example Sensu Core Integration
|
38
|
+
/etc/sensu/conf.d/plivosms_handler.json
|
39
|
+
{
|
40
|
+
"handlers": {
|
41
|
+
"plivosms": {
|
42
|
+
"type": "pipe",
|
43
|
+
"command": "/opt/sensu/embedded/bin/handler-plivosms.rb"
|
44
|
+
}
|
45
|
+
},
|
46
|
+
"plivosms":{
|
47
|
+
"id":"098gf09d8fg", // auth id
|
48
|
+
"token":"a9d8ag98daf98ga9fd8g", // auth token
|
49
|
+
"number":"15551112222", // the sms will be sent from this number, include country code
|
50
|
+
"recipients":{
|
51
|
+
|
52
|
+
"11111223333": { // not specifying "subscriptions" is same as 'all'
|
53
|
+
"checks":[ "check_dns", "check_http" ]
|
54
|
+
},
|
55
|
+
"11111224444": {
|
56
|
+
"cutoff": 1 // this guys gets all alerts including warnings
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
If you want to make Plivosms a default handler, meaning any check without a specific handler defined will notify Plivosms when there is an alert, open the default handler configuration file and add Plivosms to the set of handlers:
|
63
|
+
|
64
|
+
/etc/sensu/conf.d/default_handler.json
|
65
|
+
{
|
66
|
+
"handlers": {
|
67
|
+
"default": {
|
68
|
+
"type": "set",
|
69
|
+
"handlers": [
|
70
|
+
"plivosms"
|
71
|
+
]
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
Restart Sensu for your configuration changes to take effect: service sensu-server restart
|
77
|
+
|
78
|
+
```
|
79
|
+
## Installation
|
80
|
+
|
81
|
+
[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
|
82
|
+
|
83
|
+
## Notes
|
@@ -0,0 +1,117 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Sensu Handler: plivo
|
4
|
+
#
|
5
|
+
# This handler formats alerts as SMSes and sends them off to a pre-defined recipient.
|
6
|
+
#
|
7
|
+
# Copyright 2016 Tron Fu <tron@riverwatcher.com>
|
8
|
+
#
|
9
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
10
|
+
# for details.
|
11
|
+
|
12
|
+
require 'sensu-handler'
|
13
|
+
require 'plivo'
|
14
|
+
require 'rest-client'
|
15
|
+
require 'json'
|
16
|
+
|
17
|
+
include Plivo
|
18
|
+
|
19
|
+
class PlivoSMS < Sensu::Handler
|
20
|
+
option :json_config,
|
21
|
+
description: 'Config Name',
|
22
|
+
short: '-j JsonConfig',
|
23
|
+
long: '--json_config JsonConfig',
|
24
|
+
required: false,
|
25
|
+
default: 'plivosms'
|
26
|
+
|
27
|
+
def short_name
|
28
|
+
@event['client']['name'] + '/' + @event['check']['name']
|
29
|
+
end
|
30
|
+
|
31
|
+
def action_to_string
|
32
|
+
@event['action'].eql?('resolve') ? 'RESOLVED' : 'ALERT'
|
33
|
+
end
|
34
|
+
|
35
|
+
def status_to_string
|
36
|
+
case @event['check']['status']
|
37
|
+
when 0
|
38
|
+
'OK'
|
39
|
+
when 1
|
40
|
+
'WARNING'
|
41
|
+
when 2
|
42
|
+
'CRITICAL'
|
43
|
+
else
|
44
|
+
'UNKNOWN'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def json_config
|
49
|
+
@json_config ||= config[:json_config]
|
50
|
+
end
|
51
|
+
|
52
|
+
def interested_in_check?(candidate)
|
53
|
+
(candidate['subscriptions'].nil? || # no subscription attribute specified
|
54
|
+
candidate['subscriptions'].include?('all') ||
|
55
|
+
((candidate['subscriptions'] & @event['check']['subscribers']).size > 0) || # rubocop:disable Style/ZeroLengthPredicate
|
56
|
+
candidate['checks'].nil? || # no checks were specified in the config
|
57
|
+
candidate['checks'].include?(@event['check']['name']))
|
58
|
+
end
|
59
|
+
|
60
|
+
def passed_status_cutoff?(candidate)
|
61
|
+
(@event['action'].eql?('resolve') ||
|
62
|
+
(candidate['cutoff'] || 2) <= @event['check']['status']) # default to only send sms on critical
|
63
|
+
end
|
64
|
+
|
65
|
+
def handle
|
66
|
+
auth_id = settings[json_config]['id']
|
67
|
+
auth_token = settings[json_config]['token']
|
68
|
+
from_number = settings[json_config]['number']
|
69
|
+
candidates = settings[json_config]['recipients']
|
70
|
+
url = settings[json_config]['url']
|
71
|
+
short = settings[json_config]['short'] || false
|
72
|
+
ignore_resolve = settings[json_config]['ignore_resolve'] || false
|
73
|
+
|
74
|
+
return if @event['action'].eql?('resolve') && ignore_resolve
|
75
|
+
|
76
|
+
raise 'Please define a valid Plivo authentication set to use this handler' unless auth_id && auth_token && from_number
|
77
|
+
raise 'Please define a valid set of SMS recipients to use this handler' if candidates.nil? || candidates.empty?
|
78
|
+
|
79
|
+
recipients = []
|
80
|
+
candidates.each do |mobile, candidate|
|
81
|
+
next unless interested_in_check?(candidate) && passed_status_cutoff?(candidate)
|
82
|
+
recipients << mobile
|
83
|
+
end
|
84
|
+
|
85
|
+
message = if short
|
86
|
+
"Sensu #{action_to_string}: #{@event['check']['output']}"
|
87
|
+
else
|
88
|
+
"Sensu #{action_to_string}: #{short_name} (#{@event['client']['address']}) #{@event['check']['output']}"
|
89
|
+
end
|
90
|
+
|
91
|
+
message[157..message.length] = '...' if message.length > 160
|
92
|
+
|
93
|
+
plivo = RestAPI.new(auth_id, auth_token)
|
94
|
+
|
95
|
+
recipients.each do |recipient|
|
96
|
+
params = {
|
97
|
+
'src' => from_number, # Sender's phone number with country code
|
98
|
+
'dst' => recipient, # Receiver's phone Number with country code
|
99
|
+
'text' => message # SMS Text Message
|
100
|
+
}
|
101
|
+
params.merge!(
|
102
|
+
{
|
103
|
+
'url' => url, # The URL to which with the status of the message is sent
|
104
|
+
'method' => 'POST' # The method used to call the url
|
105
|
+
}
|
106
|
+
) unless url.to_s.empty?
|
107
|
+
|
108
|
+
response = plivo.send_message(params)
|
109
|
+
|
110
|
+
if response[1]['error'].nil?
|
111
|
+
puts "Notified #{recipient} for #{action_to_string}"
|
112
|
+
else
|
113
|
+
puts "Failure detected while using Plivo to notify on event: #{response[1]['error']}"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'sensu-plugins-plivo/version'
|
metadata
ADDED
@@ -0,0 +1,238 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-plugins-plivo
|
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: 2016-05-18 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: plivo
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.19
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.3.19
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rest-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.8.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.8.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nori
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.6.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.6.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: codeclimate-test-reporter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.4'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.4'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: github-markup
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.3'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.3'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.10'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.10'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rake
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '10.5'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '10.5'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: redcarpet
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '3.2'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '3.2'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.40.0
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.40.0
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rspec
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '3.4'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '3.4'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: yard
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0.8'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0.8'
|
195
|
+
description: Sensu plugins for plivo
|
196
|
+
email: "<sensu-users@googlegroups.com>"
|
197
|
+
executables:
|
198
|
+
- handler-plivosms.rb
|
199
|
+
extensions: []
|
200
|
+
extra_rdoc_files: []
|
201
|
+
files:
|
202
|
+
- CHANGELOG.md
|
203
|
+
- LICENSE
|
204
|
+
- README.md
|
205
|
+
- bin/handler-plivosms.rb
|
206
|
+
- lib/sensu-plugins-plivo.rb
|
207
|
+
- lib/sensu-plugins-plivo/version.rb
|
208
|
+
homepage: https://github.com/sensu-plugins/sensu-plugins-plivo
|
209
|
+
licenses:
|
210
|
+
- MIT
|
211
|
+
metadata:
|
212
|
+
maintainer: sensu-plugin
|
213
|
+
development_status: active
|
214
|
+
production_status: unstable - testing recommended
|
215
|
+
release_draft: 'false'
|
216
|
+
release_prerelease: 'false'
|
217
|
+
post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
|
218
|
+
in /etc/default/sensu
|
219
|
+
rdoc_options: []
|
220
|
+
require_paths:
|
221
|
+
- lib
|
222
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
223
|
+
requirements:
|
224
|
+
- - ">="
|
225
|
+
- !ruby/object:Gem::Version
|
226
|
+
version: 1.9.3
|
227
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
228
|
+
requirements:
|
229
|
+
- - ">="
|
230
|
+
- !ruby/object:Gem::Version
|
231
|
+
version: '0'
|
232
|
+
requirements: []
|
233
|
+
rubyforge_project:
|
234
|
+
rubygems_version: 2.5.1
|
235
|
+
signing_key:
|
236
|
+
specification_version: 4
|
237
|
+
summary: Sensu plugins for plivo
|
238
|
+
test_files: []
|