servicemonitor 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,64 @@
1
+ ServiceMonitor is copyrighted free software by all contributors, see logs in
2
+ revision control for names and email addresses of all of them.
3
+
4
+ You can redistribute it and/or modify it under either the terms of the
5
+ GNU General Public License (GPL) as published by the Free Software
6
+ Foundation (FSF), version {3.0}[http://www.gnu.org/licenses/gpl-3.0.txt]
7
+ or version {2.0}[http://www.gnu.org/licenses/gpl-2.0.txt]
8
+ or the Ruby-specific license terms (see below).
9
+
10
+ The rservicebus project leader (Guy Irvine) reserves the right to add future
11
+ versions of the GPL (and no other licenses) as published by the FSF to
12
+ the licensing terms.
13
+
14
+ === Ruby-specific terms (if you're not using the GPLv2 or GPLv3)
15
+
16
+ 1. You may make and give away verbatim copies of the source form of the
17
+ software without restriction, provided that you duplicate all of the
18
+ original copyright notices and associated disclaimers.
19
+
20
+ 2. You may modify your copy of the software in any way, provided that
21
+ you do at least ONE of the following:
22
+
23
+ a) place your modifications in the Public Domain or otherwise make them
24
+ Freely Available, such as by posting said modifications to Usenet or an
25
+ equivalent medium, or by allowing the author to include your
26
+ modifications in the software.
27
+
28
+ b) use the modified software only within your corporation or
29
+ organization.
30
+
31
+ c) rename any non-standard executables so the names do not conflict with
32
+ standard executables, which must also be provided.
33
+
34
+ d) make other distribution arrangements with the author.
35
+
36
+ 3. You may distribute the software in object code or executable
37
+ form, provided that you do at least ONE of the following:
38
+
39
+ a) distribute the executables and library files of the software,
40
+ together with instructions (in the manual page or equivalent) on where
41
+ to get the original distribution.
42
+
43
+ b) accompany the distribution with the machine-readable source of the
44
+ software.
45
+
46
+ c) give non-standard executables non-standard names, with
47
+ instructions on where to get the original software distribution.
48
+
49
+ d) make other distribution arrangements with the author.
50
+
51
+ 4. You may modify and include the part of the software into any other
52
+ software (possibly commercial). But some files in the distribution
53
+ are not written by the author, so that they are not under this terms.
54
+
55
+ 5. The scripts and library files supplied as input to or produced as
56
+ output from the software do not automatically fall under the
57
+ copyright of the software, but belong to whomever generated them,
58
+ and may be sold commercially, and may be aggregated with this
59
+ software.
60
+
61
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
62
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
63
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
64
+ PURPOSE.
data/README.md ADDED
@@ -0,0 +1,7 @@
1
+ #ServiceMonitor
2
+
3
+ Monitor various parts of the system
4
+
5
+ ##Principles
6
+ #This is aimed at people with computer knowledge
7
+ #The DSL should be clean to read, at the expense of a steeper learning curve
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #Add the currently running directory to the start of the load path
4
+ $:.unshift './'
5
+
6
+ require 'net/smtp'
7
+ require "Alert"
8
+ require "Alert/Email"
9
+ require "MonitorType"
10
+ require "MonitorType/Threshold"
11
+ require "MonitorType/Dir"
12
+ require "MonitorManager"
13
+
14
+
15
+ if ARGV.length == 1 then
16
+ dslName = ARGV[0]
17
+ else
18
+ abort( "Usage: monitor <path to dsl>" )
19
+ end
20
+
21
+
22
+ $a = MonitorManager.new
23
+
24
+ load dslName
25
+
26
+ $a.run
27
+
@@ -0,0 +1,32 @@
1
+ require "net/smtp"
2
+ require "Alert"
3
+
4
+ class Alert_Email
5
+ def initialize( destination, body )
6
+ @destination = destination
7
+ @body = body
8
+ end
9
+
10
+ def Send
11
+
12
+ message = <<MESSAGE_END
13
+ From: Agrimetrics <girvine@lic.co.nz>
14
+ To: #{@destination}
15
+ Subject: Agrimetrics Alert
16
+
17
+ #{@body}
18
+ .
19
+ MESSAGE_END
20
+
21
+ Net::SMTP.start('localhost') do |smtp|
22
+ smtp.send_message message, 'girvine@lic.co.nz',
23
+ @destination
24
+ end
25
+
26
+ rescue Errno::ECONNREFUSED => e
27
+ puts "*** Conection refused while attempting to connect to SMTP server"
28
+ puts "*** Recipient, #{@destination}. Body,"
29
+ puts "*** #{@body}"
30
+ end
31
+ end
32
+
data/lib/Alert.rb ADDED
@@ -0,0 +1,6 @@
1
+
2
+ class Alert
3
+ def Send( destination, body )
4
+ raise "Method needs to be overridden"
5
+ end
6
+ end
@@ -0,0 +1,17 @@
1
+
2
+ class MonitorManager
3
+ def initialize
4
+ @list = Array.new
5
+ end
6
+
7
+ def add( monitor )
8
+ @list.push monitor
9
+ end
10
+
11
+ def run
12
+ @list.each do |m|
13
+ m.run
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,39 @@
1
+ require "MonitorType/Threshold"
2
+
3
+ class MonitorType_Dir<MonitorType_Threshold
4
+
5
+ def sanitise
6
+ inputDir = Dir.new( @path )
7
+ @path = inputDir.path
8
+ if !File.writable?( @path ) then
9
+ puts "*** Warning. Directory is not writable, #{@path}."
10
+ puts "*** Warning. Make the directory, #{@path}, writable and try again."
11
+ end
12
+ 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();
17
+ 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();
22
+ end
23
+
24
+ def initialize( path, params )
25
+ super( params )
26
+ @path = path
27
+ self.sanitise
28
+ end
29
+
30
+ def run
31
+ number_of_files = Dir.glob( "#{@path}/*" ).length
32
+ self.check( number_of_files )
33
+ end
34
+ end
35
+
36
+ def dir( path, params )
37
+ $a.add( MonitorType_Dir.new( path, params ) )
38
+ end
39
+
@@ -0,0 +1,19 @@
1
+
2
+ class MonitorType_Threshold<MonitorType
3
+
4
+ def initialize( params )
5
+ @min = params[:min] ||= 0
6
+ @max = params[:max]
7
+ super( params )
8
+ end
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
+
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+
2
+ class MonitorType
3
+
4
+ def initialize( params )
5
+ @email = params[:email]
6
+ end
7
+
8
+ def run
9
+ raise "Method needs to be overridden"
10
+ end
11
+
12
+ def alert( string )
13
+ if !@email.nil? then
14
+ Alert_Email.new( @email, string ).Send
15
+ puts "Emailed, @email, Body, #{string}"
16
+ else
17
+ puts "*** Alert, no alert destination specified. Body, #{string}"
18
+ end
19
+ end
20
+
21
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: servicemonitor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Guy Irvine
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: parse-cron
16
+ requirement: &70266973839860 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70266973839860
25
+ - !ruby/object:Gem::Dependency
26
+ name: beanstalk-client
27
+ requirement: &70266973838800 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70266973838800
36
+ - !ruby/object:Gem::Dependency
37
+ name: fluiddb
38
+ requirement: &70266973837960 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70266973837960
47
+ description: Monitor various parts of the system
48
+ email: guy@guyirvine.com
49
+ executables:
50
+ - servicemonitor
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - lib/Alert/Email.rb
55
+ - lib/Alert.rb
56
+ - lib/MonitorManager.rb
57
+ - lib/MonitorType/Dir.rb
58
+ - lib/MonitorType/Threshold.rb
59
+ - lib/MonitorType.rb
60
+ - bin/servicemonitor
61
+ - LICENSE
62
+ - README.md
63
+ homepage: http://rubygems.org/gems/servicemonitor
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.11
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: ServiceMonitor
87
+ test_files: []
88
+ has_rdoc: