sensu-plugins-mailjet 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 45c6dd1615053ce022849415ee93c0e2d25fa81363fb1323f36fd3e2d01953b2
4
+ data.tar.gz: 3914f68374e9c13ffd05b91b69b50af355be66ec7f3e9d608bfc161c39083111
5
+ SHA512:
6
+ metadata.gz: '07881c38454504f8b6f9e52dd2efd9fc207fae2885faf8852138148fae9ca8df2eda62c908518d2c3ae8c80b08408f362fbcf136db26efcdeaf0b14bdfa8d341'
7
+ data.tar.gz: 88165c5cb1b739fbc8233b69d71cebd03768b326d3966c4a30f6bd9d0f9a74cfe56b044c16e11b67f3bf530405f2dcc3e814c454f348ae5d31addb8de2226e76
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2018 about:source GmbH
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ 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,20 @@
1
+ # Sensu::Plugins::Mailjet
2
+
3
+ ## Installation
4
+
5
+ $ gem install sensu-plugins-mailjet
6
+
7
+ ## Usage
8
+
9
+ ```
10
+ {
11
+ "mailjet": {
12
+ "auth_token": <MAILJET AUTH_TOKEN>,
13
+ "phone_numbers": [<PHONE_NUMBER_1>, <PHONE_NUMBER_2>, ...]
14
+ }
15
+ }
16
+ ```
17
+
18
+ ## License
19
+
20
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'sensu/plugins/mailjet'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require 'pry'
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Sensu Handler: mailjet
4
+ #
5
+ # This handler formats alerts and sends them off to the mailjet sms gateway.
6
+ #
7
+ # Copyright 2020 Stefan Walluhn, about source GmbH
8
+ #
9
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
10
+ # for details.
11
+
12
+ require 'sensu-handler'
13
+ require 'timeout'
14
+ require 'rest-client'
15
+
16
+ class HandlerMailjet < Sensu::Handler
17
+ def handle
18
+ apiurl = settings['mailjet']['sms_url'] || 'https://api.mailjet.com/v4/sms-send',
19
+ auth_token = settings['mailjet']['auth_token']
20
+ phone_numbers = settings['mailjet']['phone_numbers']
21
+
22
+ phone_numbers.each do |phone_number|
23
+ response = RestClient.post(
24
+ 'https://api.mailjet.com/v4/sms-send',
25
+ payload(phone_number, message()),
26
+ {
27
+ content_type: :json,
28
+ authorization: "Bearer #{auth_token}",
29
+ },
30
+ )
31
+
32
+ puts format('sent alert %<message>s to number %<number>s',
33
+ message: message(),
34
+ number: phone_number
35
+ )
36
+
37
+ puts format('response: %<response_code>d %<response_body>s',
38
+ response_code: response.code,
39
+ response_body: response.body
40
+ )
41
+ end
42
+ end
43
+
44
+ private
45
+ def message()
46
+ format('%<message>0.159s',
47
+ message: [
48
+ @event['client']['name'],
49
+ @event['check']['name'],
50
+ @event['check']['output']
51
+ ].join(' - '))
52
+ end
53
+
54
+ def payload(phonenumber, message)
55
+ {
56
+ 'Text' => message,
57
+ 'To' => phonenumber,
58
+ 'From' => 'Sensu',
59
+ }.to_json
60
+ end
61
+ end
62
+
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install --path vendor/bundle
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1 @@
1
+ require 'sensu/plugins/mailjet/version'
@@ -0,0 +1,7 @@
1
+ module Sensu
2
+ module Plugins
3
+ module Mailjet
4
+ VERSION = '0.0.1'.freeze
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-mailjet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stefan Walluhn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-01 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: '2.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.5'
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.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.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: 2.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.54'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.54'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.3'
111
+ description: Handler to send alerts using the mailjet sms gateway
112
+ email:
113
+ - stefan.walluhn@aboutsource.net
114
+ executables:
115
+ - handler-mailjet.rb
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - LICENSE
120
+ - README.md
121
+ - bin/console
122
+ - bin/handler-mailjet.rb
123
+ - bin/setup
124
+ - lib/sensu/plugins/mailjet.rb
125
+ - lib/sensu/plugins/mailjet/version.rb
126
+ homepage: https://www.aboutsource.net
127
+ licenses:
128
+ - MIT
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 2.4.0
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubygems_version: 3.1.4
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Sensu handler for mailjet sms gateway
149
+ test_files: []