servicesnapshot 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
+ ServiceSnapshot 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 ServiceSnapshot 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,18 @@
1
+ #ServiceMonitor
2
+
3
+ The fastest way to reliably monitor your 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
8
+ #Tell users what is wrong as precisley as possible, with possible remedy's
9
+
10
+ ##Get it
11
+ #gem install servicemonitor
12
+
13
+ ##Run it
14
+ #Have a look at the dsl's in the Example directory
15
+ #servicemonitor <path to dsl>
16
+
17
+ ##Notes
18
+ #Plays well with upstart and foreman
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #Add the currently running directory to the start of the load path
4
+ $:.unshift './'
5
+
6
+ require "helper_functions"
7
+ require "Snapshot/Ssh"
8
+ require "Snapshot/Beanstalk"
9
+
10
+ #Don't buffer stdout
11
+ $stdout.sync = true
12
+
13
+ abort( "Usage: servicesnapshot <path to dsl>" ) if ARGV.length != 1
14
+
15
+ dslName = ARGV[0]
16
+
17
+ #Need to remove file name extension
18
+ ENV["APP_NAME"] = File.basename( dslName ) if ENV["APP_NAME"].nil?
19
+
20
+ log "Loading dsl, #{dslName}", true
21
+ begin
22
+ load dslName
23
+
24
+ rescue ArgumentError=>e
25
+ puts "*** Your dsl is not formatted correctly"
26
+ puts "*** Ensure each line has the format,"
27
+ puts "*** <command>, [:arg=>value]"
28
+ rescue SystemExit=>e
29
+ # rescue SIGTERM=>e
30
+ rescue Exception=>e
31
+ puts "What the ..."
32
+ puts e.class.name
33
+ puts e.message
34
+ puts e.backtrace
35
+ end
36
+
@@ -0,0 +1,60 @@
1
+ require "beanstalk-client"
2
+
3
+ def beanstalk_queue( params )
4
+
5
+ abort( "*** Incorrect parameters passed for, beanstalk\n*** Usage, ssh :user=><username>, :host=><hostname>, :queue=><queue|[queue1,queue2,...]>" ) if params.class.name != "Hash" || params.keys.length != 3
6
+ abort( "*** User parameter missing for, beanstalk, command\n*** Add, :user=><username>" ) if params[:user].nil?
7
+ abort( "*** Host parameter missing for, beanstalk, command\n*** Add, :host=><host>" ) if params[:host].nil?
8
+ abort( "*** Queue parameter missing for, beanstalk, command\n*** Add, :queue=><queue>" ) if params[:queue].nil?
9
+
10
+ localPort, gateway = open_gateway( params[:user], params[:host] )
11
+
12
+ destinationUrl = "127.0.0.1:#{localPort}"
13
+ log "Opened SSH Gateway to, #{params[:host]}, on, #{destinationUrl}", true
14
+ list = Array.new
15
+ log "Connect to remote beanstalk", true
16
+ beanstalk = Beanstalk::Pool.new([destinationUrl])
17
+ beanstalk.watch( params[:queue] )
18
+ tubeStats = beanstalk.stats_tube( params[:queue] )
19
+ index = tubeStats["current-jobs-ready"].to_i
20
+ log "Current number of msgs in tube, #{index}", true
21
+ jobList = Array.new
22
+ list = Array.new
23
+ 1.upto(index) do
24
+ job = beanstalk.reserve 1
25
+ jobList << job
26
+ list << job.body
27
+ end
28
+
29
+ jobList.each do |job|
30
+ job.release
31
+ end
32
+
33
+ title = "# beanstalk_queue: #{params[:user]}@#{params[:host]} #{params[:queue]}"
34
+ formatOutput( title, "\n==> MSG <==\n\n" + list.join( "\n==> MSG <==\n\n" ) + "\n\n" )
35
+ end
36
+
37
+
38
+ def beanstalk( params )
39
+
40
+ abort( "*** Incorrect parameters passed for, beanstalk\n*** Usage, ssh :user=><username>, :host=><hostname>, :queue=><queue|[queue1,queue2,...]>" ) if params.class.name != "Hash" || params.keys.length < 2 || params.keys.length > 3
41
+ abort( "*** User parameter missing for, beanstalk, command\n*** Add, :user=><username>" ) if params[:user].nil?
42
+ abort( "*** Host parameter missing for, beanstalk, command\n*** Add, :host=><host>" ) if params[:host].nil?
43
+
44
+ localPort, gateway = open_gateway( params[:user], params[:host] )
45
+
46
+ destinationUrl = "127.0.0.1:#{localPort}"
47
+ log "Opened SSH Gateway to, #{params[:host]}, on, #{destinationUrl}", true
48
+ list = Array.new
49
+ log "Connect to remote beanstalk", true
50
+ beanstalk = Beanstalk::Pool.new([destinationUrl])
51
+
52
+ beanstalk.list_tubes[destinationUrl].each do |name|
53
+ tubeStats = beanstalk.stats_tube(name)
54
+ list << name + "(" + tubeStats["current-jobs-ready"].to_s + ")" if params[:queues].nil? or !params[:queues].index( name ).nil?
55
+ end
56
+
57
+ title = "beanstalk: #{params[:user]}@#{params[:host]} #{params[:queues]}"
58
+ formatOutput( title, list.join( "\n" ) )
59
+ end
60
+
@@ -0,0 +1,17 @@
1
+ require "net/ssh"
2
+
3
+ def ssh( params )
4
+
5
+ abort( "*** Incorrect parameters passed for, ssh\n*** Usage, ssh :user=><username>, :host=><hostname>, :cmd=><cmd>" ) if params.class.name != "Hash" || params.keys.length != 3
6
+ abort( "*** User parameter missing for, ssh, command\n*** Add, :user=><username>" ) if params[:user].nil?
7
+ abort( "*** Host parameter missing for, ssh, command\n*** Add, :host=><host>" ) if params[:host].nil?
8
+ abort( "*** Cmd parameter missing for, ssh, command\n*** Add, :cmd=><cmd>" ) if params[:cmd].nil?
9
+
10
+ content = ""
11
+ Net::SSH.start(params[:host], params[:user]) do |ssh|
12
+ content = ssh.exec!(params[:cmd])
13
+ end
14
+
15
+ title = "ssh: #{params[:user]}@#{params[:host]} #{params[:cmd]}"
16
+ formatOutput( title, content )
17
+ end
@@ -0,0 +1,32 @@
1
+ require "net/ssh/gateway"
2
+
3
+ def open_gateway( user, host )
4
+ log "Opening SSH Gateway to, #{host}", true
5
+ gateway = Net::SSH::Gateway.new(host, user)
6
+ localPort = 29000
7
+ opened = false
8
+ while opened==false
9
+ localPort = localPort + 1
10
+ begin
11
+ gateway.open('127.0.0.1', 11300, localPort)
12
+ opened=true
13
+ rescue Errno::EADDRINUSE
14
+ end
15
+ end
16
+ return [localPort,gateway]
17
+ end
18
+
19
+
20
+ def log( string, verbose=false )
21
+ return if ENV["TESTING"]=="true"
22
+
23
+ type = verbose ? "VERB" : "INFO"
24
+ if !ENV["VERBOSE"].nil? || verbose==false then
25
+ timestamp = Time.new.strftime( "%Y-%m-%d %H:%M:%S" )
26
+ puts "[#{type}] #{timestamp} :: #{string}"
27
+ end
28
+ end
29
+
30
+ def formatOutput( title, content )
31
+ puts "\n===> #{title} <===\n#{content}"
32
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: servicesnapshot
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-12-31 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: The fastest way to get a snapshot of your system.
15
+ email: guy@guyirvine.com
16
+ executables:
17
+ - servicesnapshot
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/helper_functions.rb
22
+ - lib/Snapshot/Beanstalk.rb
23
+ - lib/Snapshot/Ssh.rb
24
+ - bin/servicesnapshot
25
+ - LICENSE
26
+ - README.md
27
+ homepage: http://rubygems.org/gems/servicesnapshot
28
+ licenses: []
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 1.8.11
48
+ signing_key:
49
+ specification_version: 3
50
+ summary: ServiceSnapshot
51
+ test_files: []
52
+ has_rdoc: