sensu-plugins-nexmo 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9d9a098025b10df30a305865ea40938cfb3ffa0a
4
+ data.tar.gz: 89c311fe615f5678ce2a51f4303f7ce98ac9baa7
5
+ SHA512:
6
+ metadata.gz: d0fcb135a7a34c299ddd787303f015ddab1313d4eced4a82708948a3a513bdc123bbd4debaea7664e9b63e15a5eb5cf2971edeacd0b4fef3d7a184732602e656
7
+ data.tar.gz: 218d535c1445a07f465421e548691c7b9f004bbc6ae9959f388529efd2f7e681677ae3a2c8188eba2a547f7101d593bb02c7c35fb3710687bef153f22bfd80ae
@@ -0,0 +1 @@
1
+ Can be found at [https://github.com/boutetnico/sensu-plugins-nexmo/releases](https://github.com/boutetnico/sensu-plugins-nexmo/releases).
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Nicolas Boutet
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.
@@ -0,0 +1,39 @@
1
+ ## Sensu-Plugins-nexmo
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/sensu-plugins-nexmo.svg)](https://badge.fury.io/rb/sensu-plugins-nexmo.svg)
4
+ [![Sensu Bonsai Asset](https://img.shields.io/badge/Bonsai-Download%20Me-brightgreen.svg?colorB=89C967&logo=sensu)](https://bonsai.sensu.io/assets/boutetnico/sensu-plugins-nexmo)
5
+
6
+ ## This is an unofficial fork
7
+
8
+ This fork is automatically tested, built and published to [RubyGems](https://rubygems.org/gems/sensu-plugins-nexmo/) and [Bonsai](https://bonsai.sensu.io/assets/boutetnico/sensu-plugins-nexmo).
9
+
10
+ ## Files
11
+
12
+ * bin/check-nexmo-balance.rb
13
+ * bin/handler-nexmo.rb
14
+
15
+ ## Usage
16
+
17
+ **check-nexmo-balance**
18
+ ```bash
19
+ ./check-nexmo-balance.rb -k API_KEY -s API_SECRET
20
+ ./check-nexmo-balance.rb -k API_KEY -s API_SECRET -w 30 -c 15
21
+ ```
22
+
23
+ **handler-nexmo**
24
+ ```json
25
+ {
26
+ "nexmo":{
27
+ "api_key": "ABCDEF",
28
+ "api_secret": "s3cr3t",
29
+ "from": "Sensu",
30
+ "recipients": [
31
+ "00000000000"
32
+ ]
33
+ }
34
+ }
35
+ ```
36
+
37
+ ## Installation
38
+
39
+ [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # check-nexmo-balance.rb
4
+ #
5
+ # DESCRIPTION:
6
+ # Check Nexmo account balance.
7
+ #
8
+ # OUTPUT:
9
+ # plain-text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ # gem: nexmo
17
+ #
18
+ # USAGE:
19
+ # ./check-nexmo-balance.rb -k API_KEY -s API_SECRET
20
+ # ./check-nexmo-balance.rb -k API_KEY -s API_SECRET -w 30 -c 15
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Copyright (c) 2019, Nicolas Boutet amd3002@gmail.com
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'sensu-plugin/check/cli'
31
+ require 'nexmo'
32
+
33
+ class CheckNexmoBalance < Sensu::Plugin::Check::CLI
34
+ option :api_key,
35
+ short: '-k API_KEY',
36
+ long: '--api-key API_KEY',
37
+ description: 'Your Nexmo API Key',
38
+ required: true
39
+
40
+ option :api_secret,
41
+ short: '-s API_SECRET',
42
+ long: '--api-secret API_SECRET',
43
+ description: 'Your Nexmo API Secret',
44
+ required: true
45
+
46
+ option :warning,
47
+ short: '-w N',
48
+ long: '--warning VALUE',
49
+ description: 'Issue a warning if account balance is below VALUE',
50
+ default: 10,
51
+ proc: proc(&:to_i)
52
+
53
+ option :critical,
54
+ short: '-c N',
55
+ long: '--critical VALUE',
56
+ description: 'Issue a critical if account balance is below VALUE',
57
+ default: 5,
58
+ proc: proc(&:to_i)
59
+
60
+ def run
61
+ client = Nexmo::Client.new(
62
+ api_key: config[:api_key],
63
+ api_secret: config[:api_secret]
64
+ )
65
+
66
+ balance = client.account.balance.value.round(2)
67
+
68
+ if config[:critical] > 0 && balance < config[:critical]
69
+ critical "Balance is #{balance} EUR which is below #{config[:critical]} EUR"
70
+ elsif config[:warning] > 0 && balance < config[:warning]
71
+ warning "Balance is #{balance} EUR which is below #{config[:warning]} EUR"
72
+ end
73
+
74
+ ok
75
+ end
76
+ end
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # handler-nexmo.rb
4
+ #
5
+ # DESCRIPTION:
6
+ # Sensu handler for sending SMS through Nexmo provider.
7
+ #
8
+ # OUTPUT:
9
+ # None unless there is an error
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-handler
16
+ # gem: nexmo
17
+ # gem: time
18
+ #
19
+ # USAGE:
20
+ # Configure Nexmo api_key, api_secret, from and recipients in nexmo.json
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Copyright (c) 2019, Nicolas Boutet amd3002@gmail.com
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'sensu-handler'
31
+ require 'nexmo'
32
+ require 'time'
33
+
34
+ class NexmoAlert < Sensu::Handler
35
+ def send_sms(recipient, msg)
36
+ client = Nexmo::Client.new(
37
+ api_key: api_key,
38
+ api_secret: api_secret
39
+ )
40
+ response = client.sms.send(
41
+ from: from,
42
+ to: recipient,
43
+ text: msg
44
+ )
45
+ if response.messages.first.status != '0'
46
+ puts "Error: #{response.messages.first.error_text}"
47
+ exit 1
48
+ end
49
+ end
50
+
51
+ def api_key
52
+ settings['nexmo']['api_key']
53
+ end
54
+
55
+ def api_secret
56
+ settings['nexmo']['api_secret']
57
+ end
58
+
59
+ def action_to_string
60
+ @event['action'].eql?('resolve') ? 'RESOLVED' : 'ALERT'
61
+ end
62
+
63
+ def executed_at
64
+ Time.at(@event['check']['executed']).to_datetime
65
+ end
66
+
67
+ def from
68
+ settings['nexmo']['from']
69
+ end
70
+
71
+ def msg
72
+ "#{action_to_string} - #{short_name}: #{output} #{executed_at}"
73
+ end
74
+
75
+ def output
76
+ @event['check']['output'].strip
77
+ end
78
+
79
+ def recipients
80
+ @event['check']['nexmo']['recipients']
81
+ end
82
+
83
+ def short_name
84
+ @event['client']['name'] + '/' + @event['check']['name']
85
+ end
86
+
87
+ def handle
88
+ recipients.each do |recipient|
89
+ send_sms(recipient, msg)
90
+ end
91
+ end
92
+ end
@@ -0,0 +1 @@
1
+ require 'sensu-plugins-nexmo/version'
@@ -0,0 +1,9 @@
1
+ module SensuPluginsNexmo
2
+ module Version
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ PATCH = 0
6
+
7
+ VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,212 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-nexmo
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Boutet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nexmo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.9.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.9.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: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: codeclimate-test-reporter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: github-markup
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.13'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.13'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '13.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '13.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: redcarpet
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.5'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.5'
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.9'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.9'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.85.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.85.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: yard
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 0.9.25
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 0.9.25
167
+ description: This plugin allows to interact with Nexmo (Vonage) API
168
+ email: "<amd3002@gmail.com>"
169
+ executables:
170
+ - handler-nexmo.rb
171
+ - check-nexmo-balance.rb
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - CHANGELOG.md
176
+ - LICENSE
177
+ - README.md
178
+ - bin/check-nexmo-balance.rb
179
+ - bin/handler-nexmo.rb
180
+ - lib/sensu-plugins-nexmo.rb
181
+ - lib/sensu-plugins-nexmo/version.rb
182
+ homepage: https://github.com/boutetnico/sensu-plugins-nexmo
183
+ licenses:
184
+ - MIT
185
+ metadata:
186
+ maintainer: boutetnico
187
+ development_status: active
188
+ production_status: unstable - testing recommended
189
+ release_draft: 'false'
190
+ release_prerelease: 'false'
191
+ post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
192
+ in /etc/default/sensu
193
+ rdoc_options: []
194
+ require_paths:
195
+ - lib
196
+ required_ruby_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: 2.4.0
201
+ required_rubygems_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ requirements: []
207
+ rubyforge_project:
208
+ rubygems_version: 2.6.14.4
209
+ signing_key:
210
+ specification_version: 4
211
+ summary: Sensu plugins for Nexmo
212
+ test_files: []