vaimo-messages-handler 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 691c1d7faf680a4854849ec97558333fc3658f9d
4
- data.tar.gz: 988c34d23d492b61a5b71117637c566e834c61ed
3
+ metadata.gz: 89b17c68d79f1ef94b034d9f753b5696d2386e14
4
+ data.tar.gz: cf312e17e699da7f6d0c250c6495e3a701c45ec9
5
5
  SHA512:
6
- metadata.gz: b9592305b1c0a20e3699a923b1ada334977915c5d12ba8841d5c379051c5d830831c7143fb1de0030aa19a7747657195002d271c5c976af8482461a61f1b8e90
7
- data.tar.gz: 04720bfa575fd43f8121d3fb733614626cd9b871af54639be541088b7bcf4c1cbc75f6b4312c7635ecd111aa0e2e8d9e95bc6028fc5372eeed5add3c0cffd870
6
+ metadata.gz: 3122e0f06f520700be49bdca317b42581711dbe29292af81cfc9378cea492771a0799b47773e10855f4703401159ffb3240aef744cabab46413cc414d1d6dfd0
7
+ data.tar.gz: d5475a8688ffed4ee848bd3de2b3345eda88c10eec7acae77d006358d4ece8d873dc7c1d0f9ba6b1416c540a76f655ad0c543325d67e114df3607d08bba02f35
@@ -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
data/bin/send-message.rb CHANGED
@@ -30,52 +30,9 @@ require 'date'
30
30
  require 'sensu-handler'
31
31
  require 'timeout'
32
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
-
33
+ # VaimoMessages
34
+ class VaimoMessages < Sensu::Handler
74
35
  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'
36
+ File.open('/tmp/ruby-sensu-data', 'w') { |file| file.write(gets) }
80
37
  end
81
- end
38
+ end
@@ -4,63 +4,12 @@ require 'uri'
4
4
  require 'json'
5
5
 
6
6
  # Messages for Vaimo System
7
- module VaimoMessages
7
+ module VaimoMessagesHandler
8
8
  # Client for Sending data to WebHook
9
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
10
  end
63
11
 
12
+ # Error Handler
64
13
  class ErrorHandler < StandardError
65
14
  end
66
15
  end
@@ -1,8 +1,8 @@
1
- module VaimoMessages
1
+ module VaimoMessagesHandler
2
2
  module Version
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- PATCH = 0
5
+ PATCH = 1
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vaimo-messages-handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Margus Heinmaa
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.2'
19
+ version: 2.6.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.2'
26
+ version: 2.6.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,115 +44,116 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.4'
47
+ version: 1.0.8
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.4'
54
+ version: 1.0.8
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: github-markup
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.3'
61
+ version: 2.0.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.3'
68
+ version: 2.0.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.10'
75
+ version: 0.11.3
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.10'
82
+ version: 0.11.3
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '10.0'
89
+ version: 12.3.1
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '10.0'
96
+ version: 12.3.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: redcarpet
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '3.2'
103
+ version: 3.4.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '3.2'
110
+ version: 3.4.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '3.1'
117
+ version: 3.8.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '3.1'
124
+ version: 3.8.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rubocop
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 0.40.0
131
+ version: 0.58.2
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 0.40.0
138
+ version: 0.58.2
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: yard
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '0.8'
145
+ version: 0.9.16
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '0.8'
152
+ version: 0.9.16
153
153
  description: Sensu Handler Messages
154
154
  email: "<margus.heinmaa@vaimo.com>"
155
155
  executables:
156
+ - copy-send-message.rb
156
157
  - send-message.rb
157
158
  extensions: []
158
159
  extra_rdoc_files: []
@@ -160,17 +161,14 @@ files:
160
161
  - CHANGELOG.md
161
162
  - LICENSE_VAIMO.txt
162
163
  - README.md
164
+ - bin/copy-send-message.rb
163
165
  - bin/send-message.rb
164
166
  - lib/vaimo-messages-handler.rb
165
167
  - lib/vaimo-messages-handler/version.rb
166
168
  homepage: https://bitbucket.org/vaimo/vaimo-messages-handler
167
169
  licenses:
168
170
  - Private
169
- metadata:
170
- development_status: active
171
- production_status: unstable - testing recommended
172
- release_draft: 'false'
173
- release_prerelease: 'false'
171
+ metadata: {}
174
172
  post_install_message:
175
173
  rdoc_options: []
176
174
  require_paths:
@@ -179,7 +177,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
177
  requirements:
180
178
  - - ">="
181
179
  - !ruby/object:Gem::Version
182
- version: 2.1.0
180
+ version: 2.3.0
183
181
  required_rubygems_version: !ruby/object:Gem::Requirement
184
182
  requirements:
185
183
  - - ">="
@@ -187,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
185
  version: '0'
188
186
  requirements: []
189
187
  rubyforge_project:
190
- rubygems_version: 2.5.2.3
188
+ rubygems_version: 2.5.2.1
191
189
  signing_key:
192
190
  specification_version: 4
193
191
  summary: Sensu plugins for Messages handling