servicemonitor 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/bin/servicemonitor CHANGED
@@ -29,7 +29,16 @@ end
29
29
  $a = MonitorManager.new
30
30
 
31
31
  log "Loading dsl, #{dslName}"
32
+ begin
32
33
  load dslName
33
-
34
34
  $a.run
35
+ rescue ArgumentError=>e
36
+ puts "*** Your dsl is not formatted correctly"
37
+ puts "*** Ensure each line has the format,"
38
+ puts "*** <command>, [:arg=>value]"
39
+ rescue SystemExit=>e
40
+ rescue Exception=>e
41
+ puts e.class.name
42
+ puts e.message
43
+ end
35
44
 
data/lib/MonitorType.rb CHANGED
@@ -5,8 +5,13 @@ end
5
5
 
6
6
  class MonitorType
7
7
 
8
- def initialize( name, params )
9
- @name = name
8
+ def initialize( params )
9
+ if params[:name].nil? then
10
+ puts "*** Monitor parameter missing, name"
11
+ puts "*** :name => <name of monitor>"
12
+ abort
13
+ end
14
+ @name = params[:name]
10
15
  @email = params[:email]
11
16
 
12
17
  cron_string = params[:cron] || "0 1 * * *"
@@ -7,10 +7,15 @@ class MonitorType_Beanstalk<MonitorType_Threshold
7
7
  @beanstalk = Beanstalk::Pool.new([@connection_string])
8
8
  end
9
9
 
10
- def initialize( name, queue, params )
11
- super( name, params )
10
+ def initialize( params )
11
+ super( params )
12
12
  @connection_string = params[:beanstalk] || "localhost:11300"
13
- @queue = queue
13
+ if params[:queue].nil? then
14
+ puts "*** Beanstalk parameter missing, queue"
15
+ puts "*** :queue => <queue name>"
16
+ abort
17
+ end
18
+ @queue = params[:queue]
14
19
  self.sanitise
15
20
  rescue MonitorTypeExceptionHandled => e
16
21
  puts e.message
@@ -18,13 +23,18 @@ class MonitorType_Beanstalk<MonitorType_Threshold
18
23
  end
19
24
 
20
25
  def process
26
+ count = 0
27
+ begin
21
28
  tubeStats = @beanstalk.stats_tube(@queue)
29
+ count = tubeStats["current-jobs-ready"]
30
+ rescue Beanstalk::NotFoundError=>e
31
+ end
22
32
 
23
- self.check( tubeStats["current-jobs-ready"], "Checking number of jobs in queue, #{@queue}" )
33
+ self.check( count, "Checking number of jobs in queue, #{@queue}" )
24
34
  end
25
35
  end
26
36
 
27
- def beanstalk( name, queue, params )
28
- $a.add( MonitorType_Beanstalk.new( name, queue, params ) )
37
+ def beanstalk( params )
38
+ $a.add( MonitorType_Beanstalk.new( params ) )
29
39
  end
30
40
 
@@ -22,9 +22,14 @@ class MonitorType_Dir<MonitorType_Threshold
22
22
  raise MonitorTypeExceptionHandled.new(string)
23
23
  end
24
24
 
25
- def initialize( name, path, params )
26
- super( name, params )
27
- @path = path
25
+ def initialize( params )
26
+ super( params )
27
+ if params[:path].nil? then
28
+ puts "*** Dir parameter missing, path"
29
+ puts "*** :path => <path to directory to be monitored>"
30
+ abort
31
+ end
32
+ @path = params[:path]
28
33
  self.sanitise
29
34
  rescue MonitorTypeExceptionHandled => e
30
35
  puts e.message
@@ -37,7 +42,7 @@ class MonitorType_Dir<MonitorType_Threshold
37
42
  end
38
43
  end
39
44
 
40
- def dir( name, path, params )
41
- $a.add( MonitorType_Dir.new( name, path, params ) )
45
+ def dir( params )
46
+ $a.add( MonitorType_Dir.new( params ) )
42
47
  end
43
48
 
@@ -4,13 +4,48 @@ require "MonitorType/Threshold"
4
4
  class MonitorType_FluidDb<MonitorType_Threshold
5
5
 
6
6
  def sanitise
7
- @fluidDb = FluidDb.Db( @uri )
7
+ begin
8
+ @fluidDb = FluidDb.Db( @uri )
9
+ rescue Exception=>e
10
+ puts "*** FluidDb encountered an error while connecting to the db"
11
+ puts "*** Error: #{e.message}"
12
+ puts "*** uri: #{@uri}"
13
+ puts "*** Please fix the error and run again"
14
+ abort()
15
+ end
16
+
17
+ begin
18
+ value = @fluidDb.queryForValue( @sql, [] )
19
+ rescue Exception=>e
20
+ puts "*** FluidDb encountered an error while running the sql"
21
+ puts "*** sql: #{@sql}"
22
+ puts "*** Please fix the query and run again"
23
+ abort()
24
+ end
8
25
  end
9
26
 
10
- def initialize( name, uri, sql, params )
11
- super( name, params )
12
- @uri = URI.parse( uri )
13
- @sql = sql
27
+ def initialize( params )
28
+ super( params )
29
+ if params[:uri].nil? then
30
+ puts "*** FluidDb parameter missing, uri"
31
+ puts "*** :uri => <uri pointing to db to be monitored>"
32
+ abort
33
+ end
34
+ begin
35
+ @uri = URI.parse( params[:uri] )
36
+ rescue URI::InvalidURIError=>e
37
+ puts "*** FluidDb encountered an error while parsing the uri"
38
+ puts "*** uri: #{params[:uri]}"
39
+ puts "*** Please fix the uri and run again"
40
+ abort()
41
+ end
42
+
43
+ if params[:sql].nil? then
44
+ puts "*** FluidDb parameter missing, sql"
45
+ puts "*** :sql => <sql statement, producing a single column, single row which yeidls a number>"
46
+ abort
47
+ end
48
+ @sql = params[:sql]
14
49
  self.sanitise
15
50
  rescue MonitorTypeExceptionHandled => e
16
51
  puts e.message
@@ -24,7 +59,7 @@ class MonitorType_FluidDb<MonitorType_Threshold
24
59
  end
25
60
  end
26
61
 
27
- def fluiddb( name, uri, sql, params )
28
- $a.add( MonitorType_FluidDb.new( name, uri, sql, params ) )
62
+ def fluiddb( params )
63
+ $a.add( MonitorType_FluidDb.new( params ) )
29
64
  end
30
65
 
@@ -1,10 +1,10 @@
1
1
 
2
2
  class MonitorType_Threshold<MonitorType
3
3
 
4
- def initialize( name, params )
4
+ def initialize( params )
5
5
  @min = params[:min] ||= 0
6
6
  @max = params[:max]
7
- super( name, params )
7
+ super( params )
8
8
  end
9
9
 
10
10
  def check( value, context_sentence )
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.6
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-25 00:00:00.000000000 Z
12
+ date: 2013-10-26 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Monitor various parts of the system
15
15
  email: guy@guyirvine.com