servicemonitor 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/servicemonitor +6 -0
- data/lib/MonitorType.rb +18 -15
- metadata +1 -1
data/bin/servicemonitor
CHANGED
@@ -11,6 +11,11 @@ require "MonitorType/Threshold"
|
|
11
11
|
require "MonitorType/Dir"
|
12
12
|
require "MonitorManager"
|
13
13
|
|
14
|
+
def log( string, verbose=false )
|
15
|
+
if !ENV["VERBOSE"].nil? || verbose==false then
|
16
|
+
puts string
|
17
|
+
end
|
18
|
+
end
|
14
19
|
|
15
20
|
if ARGV.length == 1 then
|
16
21
|
dslName = ARGV[0]
|
@@ -21,6 +26,7 @@ end
|
|
21
26
|
|
22
27
|
$a = MonitorManager.new
|
23
28
|
|
29
|
+
log "Loading dsl, #{dslName}"
|
24
30
|
load dslName
|
25
31
|
|
26
32
|
$a.run
|
data/lib/MonitorType.rb
CHANGED
@@ -7,11 +7,13 @@ class MonitorType
|
|
7
7
|
|
8
8
|
def initialize( name, params )
|
9
9
|
@name = name
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
@email = params[:email]
|
11
|
+
|
12
|
+
cron_string = params[:cron] || "0 1 * * *"
|
13
13
|
@cron = CronParser.new(cron_string)
|
14
|
-
|
14
|
+
@next = Time.now - 1
|
15
|
+
|
16
|
+
log "Loaded Monitor, #{@name}."
|
15
17
|
end
|
16
18
|
|
17
19
|
#Overload this method if any parameters should be checked
|
@@ -23,21 +25,22 @@ class MonitorType
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def run
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
if Time.now > @next then
|
29
|
+
begin
|
30
|
+
@next = @cron.next( Time.now )
|
31
|
+
log "Monitor, #{@name}, next run time, #{@next}"
|
32
|
+
self.sanitise
|
33
|
+
self.process
|
34
|
+
rescue MonitorTypeExceptionHandled => e
|
35
|
+
m.alert( e.message )
|
36
|
+
end
|
34
37
|
end
|
35
38
|
end
|
36
|
-
|
37
|
-
|
39
|
+
|
40
|
+
|
38
41
|
def alert( string )
|
39
42
|
body = "#{@name} tripped.\n#{string}"
|
40
|
-
|
43
|
+
puts "*** "
|
41
44
|
if !@email.nil? then
|
42
45
|
Alert_Email.new( @email, body ).Send
|
43
46
|
puts "Emailed, @email, Body, #{body}"
|