servicemonitor 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/Alert.rb CHANGED
@@ -1,6 +1,7 @@
1
1
 
2
2
  class Alert
3
+
3
4
  def Send( destination, body )
4
- raise "Method needs to be overridden"
5
+ raise "Method needs to be overridden"
5
6
  end
6
7
  end
@@ -10,7 +10,12 @@ class MonitorManager
10
10
 
11
11
  def run
12
12
  @list.each do |m|
13
+ begin
14
+ m.sanitise
13
15
  m.run
16
+ rescue MonitorTypeExceptionHandled => e
17
+ m.alert( )
18
+ end
14
19
  end
15
20
  end
16
21
  end
data/lib/MonitorType.rb CHANGED
@@ -1,20 +1,38 @@
1
1
 
2
+ class MonitorTypeExceptionHandled<StandardError
3
+ end
4
+
2
5
  class MonitorType
3
6
 
4
- def initialize( params )
7
+ def initialize( name, params )
8
+ @name = name
5
9
  @email = params[:email]
6
10
  end
7
11
 
8
- def run
12
+ #Overload this method if any parameters should be checked
13
+ def sanitise
14
+ end
15
+
16
+ def process
9
17
  raise "Method needs to be overridden"
10
18
  end
11
19
 
20
+ def run
21
+ self.sanitise
22
+ self.process
23
+ rescue MonitorTypeExceptionHandled => e
24
+ m.alert( e.message )
25
+ end
26
+
27
+
12
28
  def alert( string )
29
+ body = "#{@name} tripped.\n#{string}"
30
+
13
31
  if !@email.nil? then
14
- Alert_Email.new( @email, string ).Send
15
- puts "Emailed, @email, Body, #{string}"
32
+ Alert_Email.new( @email, body ).Send
33
+ puts "Emailed, @email, Body, #{body}"
16
34
  else
17
- puts "*** Alert, no alert destination specified. Body, #{string}"
35
+ puts body
18
36
  end
19
37
  end
20
38
 
@@ -9,31 +9,35 @@ class MonitorType_Dir<MonitorType_Threshold
9
9
  puts "*** Warning. Directory is not writable, #{@path}."
10
10
  puts "*** Warning. Make the directory, #{@path}, writable and try again."
11
11
  end
12
+
12
13
  rescue Errno::ENOENT => e
13
- puts "***** Directory does not exist, #{@path}."
14
- puts "***** Create the directory, #{@path}, and try again."
15
- puts "***** eg, mkdir #{@path}"
16
- abort();
14
+ string = "***** Directory does not exist, #{@path}.\n"
15
+ string = "#{string}***** Create the directory, #{@path}, and try again.\n"
16
+ string = "#{string}***** eg, mkdir #{@path}"
17
+ raise MonitorTypeExceptionHandled.new(string)
17
18
  rescue Errno::ENOTDIR => e
18
- puts "***** The specified path does not point to a directory, #{@path}."
19
- puts "***** Either repoint path to a directory, or remove, #{@path}, and create it as a directory."
20
- puts "***** eg, rm #{@path} && mkdir #{@path}"
21
- abort();
19
+ string = "***** The specified path does not point to a directory, #{@path}.\n"
20
+ string = "#{string}***** Either repoint path to a directory, or remove, #{@path}, and create it as a directory.\n"
21
+ string = "#{string}***** eg, rm #{@path} && mkdir #{@path}"
22
+ raise MonitorTypeExceptionHandled.new(string)
22
23
  end
23
-
24
- def initialize( path, params )
25
- super( params )
24
+
25
+ def initialize( name, path, params )
26
+ super( name, params )
26
27
  @path = path
27
28
  self.sanitise
29
+ rescue MonitorTypeExceptionHandled => e
30
+ puts e.message
31
+ abort()
28
32
  end
29
-
30
- def run
33
+
34
+ def process
31
35
  number_of_files = Dir.glob( "#{@path}/*" ).length
32
- self.check( number_of_files )
36
+ self.check( number_of_files, "Checking number of files in, #{@path}" )
33
37
  end
34
38
  end
35
39
 
36
- def dir( path, params )
37
- $a.add( MonitorType_Dir.new( path, params ) )
40
+ def dir( name, path, params )
41
+ $a.add( MonitorType_Dir.new( name, path, params ) )
38
42
  end
39
43
 
@@ -1,19 +1,19 @@
1
1
 
2
2
  class MonitorType_Threshold<MonitorType
3
3
 
4
- def initialize( params )
5
- @min = params[:min] ||= 0
6
- @max = params[:max]
7
- super( params )
4
+ def initialize( name, params )
5
+ @min = params[:min] ||= 0
6
+ @max = params[:max]
7
+ super( name, params )
8
8
  end
9
9
 
10
- def check( value )
11
- if !@min.nil? && value < @min then
12
- self.alert( "MIN" )
13
- end
14
- if !@max.nil? && value > @max then
15
- self.alert( "MAX" )
16
- end
17
-
10
+ def check( value, context_sentence )
11
+ if !@min.nil? && value < @min then
12
+ self.alert( "#{context_sentence}\nMinimum threshold exceeded. Minimum: #{@min}, Actual: #{value}" )
13
+ end
14
+ if !@max.nil? && value > @max then
15
+ self.alert( "#{context_sentence}\nMaximum threshold exceeded. Maximum: #{@max}, Actual: #{value}" )
16
+ end
17
+
18
18
  end
19
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servicemonitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parse-cron
16
- requirement: &70266973839860 !ruby/object:Gem::Requirement
16
+ requirement: &70176457205720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70266973839860
24
+ version_requirements: *70176457205720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: beanstalk-client
27
- requirement: &70266973838800 !ruby/object:Gem::Requirement
27
+ requirement: &70176457205260 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70266973838800
35
+ version_requirements: *70176457205260
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: fluiddb
38
- requirement: &70266973837960 !ruby/object:Gem::Requirement
38
+ requirement: &70176457204800 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70266973837960
46
+ version_requirements: *70176457204800
47
47
  description: Monitor various parts of the system
48
48
  email: guy@guyirvine.com
49
49
  executables: