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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8741fedf212a5f413ae48b7c4ca2ef30eadd8e75
4
- data.tar.gz: 3e4280d175d63e406411425a79281ddd9ec3da2c
3
+ metadata.gz: 689eb8923455811f44482c650586694cb37a6302
4
+ data.tar.gz: e3227af2ff329a71a4657ef46ae636f7b66bf4fc
5
5
  SHA512:
6
- metadata.gz: 554afa3807766adeb9d0cda26e98e876fb4dd9c56f3e36ec0ad973c6dfacd1226d10645bcff5bb8601d405d86974f4dc7185bfb220394f8b51eee54a993e85a0
7
- data.tar.gz: b4582c275fca6f3e5a89b4523b0eb512898a04ed73f61440ee4aeb67e70f74c00a0c31c750f872da05b0d15e288d5c011ca8278ee716b22c8a89d13524f7810b
6
+ metadata.gz: f4d91d235de19b3a35b31e8dbb1abe7bf70b1333f3a541f2bfc592690968f775cc730c5801ae2bcf59059dc21c81851a0be7f0e6e2ec3bf114db134ed2b93f78
7
+ data.tar.gz: 148414f9c26302bc5fc9223dbb1dfaf0b72c86902cdbb4eae7e7db075adef27d660aa4786be73803d5e17a2cb55143088fd16e7f3a60c745f085ead22b360dd7
@@ -6,6 +6,7 @@ $:.unshift './'
6
6
  require 'net/smtp'
7
7
  require 'alert'
8
8
  require 'alert/email'
9
+ require 'alert/slack'
9
10
  require 'monitor_type'
10
11
  require 'monitor_type/threshold'
11
12
  require 'monitor_type/beanstalk'
@@ -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
@@ -19,6 +19,8 @@ class MonitorManager
19
19
  end
20
20
  end
21
21
  sleep 0.2
22
+
23
+ exit unless ENV['RUN_ONCE'].nil?
22
24
  end
23
25
 
24
26
  rescue Interrupt
@@ -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
- else
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.2.7
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: 2016-11-02 00:00:00.000000000 Z
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