servicemonitor 0.2.7 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/servicemonitor +1 -0
- data/lib/alert/slack.rb +22 -0
- data/lib/monitor_manager.rb +2 -0
- data/lib/monitor_type.rb +13 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 689eb8923455811f44482c650586694cb37a6302
|
4
|
+
data.tar.gz: e3227af2ff329a71a4657ef46ae636f7b66bf4fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4d91d235de19b3a35b31e8dbb1abe7bf70b1333f3a541f2bfc592690968f775cc730c5801ae2bcf59059dc21c81851a0be7f0e6e2ec3bf114db134ed2b93f78
|
7
|
+
data.tar.gz: 148414f9c26302bc5fc9223dbb1dfaf0b72c86902cdbb4eae7e7db075adef27d660aa4786be73803d5e17a2cb55143088fd16e7f3a60c745f085ead22b360dd7
|
data/bin/servicemonitor
CHANGED
data/lib/alert/slack.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
require 'alert'
|
4
|
+
|
5
|
+
# Email alert class
|
6
|
+
# Uses localhost for sending email - Probably need to change this in the future.
|
7
|
+
class AlertSlack
|
8
|
+
def send(slack_url, slack_channel, body)
|
9
|
+
|
10
|
+
payload = Hash[
|
11
|
+
'channel', slack_channel,
|
12
|
+
'text', body.to_json,
|
13
|
+
]
|
14
|
+
|
15
|
+
RestClient.post slack_url, payload.to_json, {content_type: :json}
|
16
|
+
|
17
|
+
rescue Errno::ECONNREFUSED
|
18
|
+
puts "*** Conection refused while attempting to connect to SMTP server\n" \
|
19
|
+
"*** Recipient, #{@destination}. Body,\n" \
|
20
|
+
"*** #{@body}\n"
|
21
|
+
end
|
22
|
+
end
|
data/lib/monitor_manager.rb
CHANGED
data/lib/monitor_type.rb
CHANGED
@@ -36,6 +36,8 @@ class MonitorType
|
|
36
36
|
@name = params[:name]
|
37
37
|
@email = params[:email]
|
38
38
|
@url = params[:url] unless params[:url].nil?
|
39
|
+
@slack_url = params[:slack_url]
|
40
|
+
@slack_channel = params[:slack_channel]
|
39
41
|
|
40
42
|
if !@email.nil?
|
41
43
|
# Sender email address from ENV allows for a single sender across all alerts
|
@@ -102,13 +104,22 @@ class MonitorType
|
|
102
104
|
#
|
103
105
|
# @param [String] string A description of the trip that occurred
|
104
106
|
def alert(string)
|
107
|
+
sent = false
|
105
108
|
body = "#{@name} tripped.\n#{string}"
|
106
109
|
puts '*** '
|
107
110
|
if !@email.nil?
|
108
111
|
AlertEmail.new(@sender_email, @email, body).send
|
109
112
|
puts "Emailed, #{@email}"
|
110
|
-
|
111
|
-
puts body
|
113
|
+
sent = true
|
112
114
|
end
|
115
|
+
|
116
|
+
unless @slack_url.nil?
|
117
|
+
AlertSlack.new.send(@slack_url, @slack_channel, body)
|
118
|
+
puts "Slacked, #{@slack_channel}"
|
119
|
+
sent = true
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
puts body unless sent
|
113
124
|
end
|
114
125
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: servicemonitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guy Irvine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parse-cron
|
@@ -32,6 +32,7 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- lib/alert/email.rb
|
35
|
+
- lib/alert/slack.rb
|
35
36
|
- lib/alert.rb
|
36
37
|
- lib/helper_functions.rb
|
37
38
|
- lib/monitor_manager.rb
|