informer 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Informer.gemspec +3 -3
- data/VERSION +1 -1
- data/bin/informer +155 -6
- data/lib/informer.rb +1 -1
- data/lib/informer/reporter/{led.rb → lcd.rb} +0 -0
- data/lib/informer/watcher/hostname.rb +9 -7
- data/lib/informer/watcher/process.rb +16 -10
- data/spec/helpers/process_helpers.rb +124 -99
- data/spec/hostname_spec.rb +55 -34
- data/spec/process_spec.rb +40 -20
- metadata +3 -3
data/Informer.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{informer}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.2.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Scott Burton"]
|
9
|
-
s.date = %q{2009-10-
|
9
|
+
s.date = %q{2009-10-31}
|
10
10
|
s.default_executable = %q{informer}
|
11
11
|
s.description = %q{Informer is a flexible information gathering and reporting system.}
|
12
12
|
s.email = %q{scottburton11@gmail.com}
|
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
"features/watcher.feature",
|
34
34
|
"lib/informer.rb",
|
35
35
|
"lib/informer/basic_watcher.rb",
|
36
|
-
"lib/informer/reporter/
|
36
|
+
"lib/informer/reporter/lcd.rb",
|
37
37
|
"lib/informer/reporter/standard_output.rb",
|
38
38
|
"lib/informer/watcher/hostname.rb",
|
39
39
|
"lib/informer/watcher/process.rb",
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/informer
CHANGED
@@ -1,8 +1,157 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
|
4
|
+
# == Synopsis
|
5
|
+
# Running Informer will watch something, formulate messages about it, and report back somehow.
|
6
|
+
# It is useful for extremely simplified reporting on the status of a host system.
|
7
|
+
#
|
8
|
+
# == Examples
|
9
|
+
#
|
10
|
+
# informer -p process-name -p process-name2 -n en1
|
11
|
+
#
|
12
|
+
# == Usage
|
13
|
+
# informer [options]
|
14
|
+
#
|
15
|
+
# For help use: informer -h
|
16
|
+
#
|
17
|
+
# == Options
|
18
|
+
# -p, --process proc Return the status of the process named 'proc'
|
19
|
+
# -n, --hostname if Return the hostname and IP address of interface 'if'. Default is 'eth0'
|
20
|
+
# -l, --lcd Use the LCD display at ttyS1; Default is Rackable Systems Roamer device
|
21
|
+
# -h, --help Displays help message
|
22
|
+
# -v, --version Display the version, then exit
|
23
|
+
# -q, --quiet Output as little as possible, overrides verbose
|
24
|
+
# -V, --verbose Verbose output
|
25
|
+
#
|
26
|
+
# == Author
|
27
|
+
# Scott Burton
|
28
|
+
#
|
29
|
+
# == Copyright
|
30
|
+
# Copyright (c) 2009 Scott Burton. See LICENSE
|
31
|
+
#
|
32
|
+
# Ruby command-line skeleton courtesy of http://blog.infinitered.com/entries/show/5
|
33
|
+
|
34
|
+
require 'optparse'
|
35
|
+
require 'rdoc/usage'
|
36
|
+
require 'ostruct'
|
37
|
+
require 'date'
|
38
|
+
|
2
39
|
require 'lib/informer'
|
3
40
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
41
|
+
class App
|
42
|
+
VERSION = '0.2.0'
|
43
|
+
|
44
|
+
attr_reader :options
|
45
|
+
|
46
|
+
def initialize(arguments, stdin)
|
47
|
+
@arguments = arguments
|
48
|
+
@stdin = stdin
|
49
|
+
|
50
|
+
# Set defaults
|
51
|
+
@options = OpenStruct.new
|
52
|
+
@options.verbose = false
|
53
|
+
@options.quiet = false
|
54
|
+
@options.reporter = "standard_output"
|
55
|
+
|
56
|
+
@options.processes = []
|
57
|
+
end
|
58
|
+
|
59
|
+
# Parse options, check arguments, then process the command
|
60
|
+
def run
|
61
|
+
|
62
|
+
if parsed_options?
|
63
|
+
|
64
|
+
puts "Start at #{DateTime.now}\n\n" if @options.verbose
|
65
|
+
|
66
|
+
output_options if @options.verbose
|
67
|
+
|
68
|
+
process_arguments
|
69
|
+
process_command
|
70
|
+
|
71
|
+
puts "\nFinished at #{DateTime.now}" if @options.verbose
|
72
|
+
|
73
|
+
else
|
74
|
+
output_usage
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
protected
|
80
|
+
|
81
|
+
def parsed_options?
|
82
|
+
|
83
|
+
# Specify options
|
84
|
+
opts = OptionParser.new
|
85
|
+
opts.on('-v', '--version') { output_version ; exit 0 }
|
86
|
+
opts.on('-h', '--help') { output_help }
|
87
|
+
opts.on('-V', '--verbose') { @options.verbose = true }
|
88
|
+
opts.on('-q', '--quiet') { @options.quiet = true }
|
89
|
+
opts.on('-l', '--lcd') { @options.reporter = "lcd"}
|
90
|
+
opts.on('-p label', '--processes label') { |p| @options.processes << p }
|
91
|
+
opts.on('-n iface', '--hostname interface') { |i| @options.hostname = true; @options.interface = i }
|
92
|
+
|
93
|
+
opts.parse!(@arguments) rescue return false
|
94
|
+
|
95
|
+
process_options
|
96
|
+
true
|
97
|
+
end
|
98
|
+
|
99
|
+
# Performs post-parse processing on options
|
100
|
+
def process_options
|
101
|
+
@options.verbose = false if @options.quiet
|
102
|
+
end
|
103
|
+
|
104
|
+
def output_options
|
105
|
+
puts "Options:\n"
|
106
|
+
|
107
|
+
@options.marshal_dump.each do |name, val|
|
108
|
+
puts " #{name} = #{val}"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# True if required arguments were provided
|
113
|
+
def arguments_valid?
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
# Setup the arguments
|
118
|
+
def process_arguments
|
119
|
+
# @interface = ARGV[0]
|
120
|
+
end
|
121
|
+
|
122
|
+
def output_help
|
123
|
+
output_version
|
124
|
+
RDoc::usage() #exits app
|
125
|
+
end
|
126
|
+
|
127
|
+
def output_usage
|
128
|
+
RDoc::usage('usage') # gets usage from comments above
|
129
|
+
end
|
130
|
+
|
131
|
+
def output_version
|
132
|
+
puts "#{File.basename(__FILE__)} version #{VERSION}"
|
133
|
+
end
|
134
|
+
|
135
|
+
def process_command
|
136
|
+
|
137
|
+
informer = Informer.new(@options.reporter)
|
138
|
+
|
139
|
+
@options.processes.each do |process|
|
140
|
+
informer.watchers << Watcher::Process.new(process)
|
141
|
+
end
|
142
|
+
|
143
|
+
informer.watchers << Watcher::Hostname.new(@options.interface) if @options.hostname
|
144
|
+
|
145
|
+
informer.report
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
def process_standard_input
|
150
|
+
input = @stdin.read
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
# Create and run the application
|
156
|
+
app = App.new(ARGV, STDIN)
|
157
|
+
app.run
|
data/lib/informer.rb
CHANGED
File without changes
|
@@ -3,12 +3,13 @@ module Watcher
|
|
3
3
|
|
4
4
|
attr_reader :ip, :hostname
|
5
5
|
|
6
|
-
def initialize(interface = "eth0")
|
6
|
+
def initialize(interface = "eth0", &block)
|
7
|
+
@custom_message = block if block_given?
|
7
8
|
@interface = interface
|
8
9
|
end
|
9
10
|
|
10
11
|
def report
|
11
|
-
|
12
|
+
return @custom_message.call(self) if @custom_message
|
12
13
|
message
|
13
14
|
end
|
14
15
|
|
@@ -16,11 +17,12 @@ module Watcher
|
|
16
17
|
@message ||= "#{hostname}\n#{ip}"
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def ip
|
21
|
+
@ip ||= get_ip_address
|
22
|
+
end
|
23
|
+
|
24
|
+
def hostname
|
25
|
+
@hostname ||= get_hostname
|
24
26
|
end
|
25
27
|
|
26
28
|
private
|
@@ -1,26 +1,32 @@
|
|
1
1
|
module Watcher
|
2
2
|
class Process < BasicWatcher
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
|
4
|
+
attr_reader :handle, :process, :command
|
5
|
+
|
6
|
+
def initialize(command, options = {}, &block)
|
7
|
+
@custom_message = block if block_given?
|
8
|
+
@command = command
|
9
|
+
@handle = options[:handle] || command
|
6
10
|
end
|
7
11
|
|
8
12
|
def report
|
13
|
+
return @custom_message.call(self) if @custom_message
|
9
14
|
"#{@handle} is #{running? ? '' : 'not '}running"
|
10
15
|
end
|
11
16
|
|
17
|
+
def running?
|
18
|
+
process_matcher === processes
|
19
|
+
end
|
20
|
+
|
12
21
|
private
|
13
22
|
|
14
23
|
def processes
|
15
|
-
`ps aux`.chomp
|
24
|
+
# `ps aux`.chomp
|
25
|
+
`ps -o %cpu -o %mem -o comm -o pid -o user -axc`.chomp
|
16
26
|
end
|
17
27
|
|
18
|
-
def
|
19
|
-
%r
|
20
|
-
end
|
21
|
-
|
22
|
-
def running?
|
23
|
-
process_match === processes
|
28
|
+
def process_matcher
|
29
|
+
%r|^\s+(\d+\.\d+)\s+(\d+\.\d+)\s+#{command}\s+(\d+)\s+(\w+)\s+$|
|
24
30
|
end
|
25
31
|
|
26
32
|
end
|
@@ -2,105 +2,130 @@ module ProcessHelpers
|
|
2
2
|
|
3
3
|
def ps_aux
|
4
4
|
<<RUBY_HERE
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
5
|
+
%CPU %MEM COMM PID USER
|
6
|
+
0.0 0.0 launchd 1 root
|
7
|
+
0.0 0.1 kextd 10 root
|
8
|
+
0.0 0.1 DirectoryService 11 root
|
9
|
+
0.0 0.0 notifyd 12 root
|
10
|
+
0.0 0.1 configd 15 root
|
11
|
+
0.0 0.0 distnoted 20 daemon
|
12
|
+
0.0 0.0 mDNSResponder 27 _mdnsresponder
|
13
|
+
0.0 0.1 securityd 37 root
|
14
|
+
0.0 0.0 ntpd 66 root
|
15
|
+
0.0 0.1 httpd 67 root
|
16
|
+
0.0 0.0 usbmuxd 68 _usbmuxd
|
17
|
+
0.0 0.0 update 69 root
|
18
|
+
0.0 0.0 SystemStarter 70 root
|
19
|
+
0.0 9.4 mds 74 root
|
20
|
+
13.9 0.2 loginwindow 75 scott
|
21
|
+
0.0 0.0 KernelEventAgent 76 root
|
22
|
+
0.0 0.0 kdcmond 77 root
|
23
|
+
0.0 0.0 hidd 79 root
|
24
|
+
0.0 0.0 fseventsd 80 root
|
25
|
+
0.0 0.0 dynamic_pager 82 root
|
26
|
+
0.0 0.0 diskarbitrationd 85 root
|
27
|
+
0.0 0.1 blued 89 root
|
28
|
+
0.0 0.0 autofsd 90 root
|
29
|
+
0.0 0.0 socketfilterfw 92 root
|
30
|
+
0.0 0.0 daemondo 94 root
|
31
|
+
0.0 0.0 daemondo 95 root
|
32
|
+
0.0 0.0 sh 97 _mysql
|
33
|
+
0.0 0.0 DigidesignFireWi 98 root
|
34
|
+
0.0 0.0 memcached 111 nobody
|
35
|
+
1.9 3.2 WindowServer 117 _windowserver
|
36
|
+
0.0 0.0 krb5kdc 124 root
|
37
|
+
0.0 0.9 coreservicesd 128 root
|
38
|
+
0.0 0.0 postgres 130 postgres
|
39
|
+
0.0 1.4 mysqld 156 _mysql
|
40
|
+
0.0 0.0 Mbox2CS 434 root
|
41
|
+
0.0 0.0 globalSAN 441 root
|
42
|
+
0.0 0.1 qmasterd 446 root
|
43
|
+
0.0 0.0 hpusbmond 654 root
|
44
|
+
0.0 0.1 qmasterd 685 root
|
45
|
+
0.0 0.0 HPIO Trap Monito 694 root
|
46
|
+
0.0 0.0 vmnet-natd 740 root
|
47
|
+
0.0 0.0 vmnet-dhcpd 750 root
|
48
|
+
0.0 0.0 ApplicationPoolS 757 root
|
49
|
+
0.2 0.4 Passenger spawn 758 root
|
50
|
+
0.0 0.1 httpd 759 _www
|
51
|
+
0.0 0.0 vmnet-netifup 760 root
|
52
|
+
0.0 0.0 vmnet-netifup 763 root
|
53
|
+
0.0 0.0 vmnet-dhcpd 766 root
|
54
|
+
0.0 0.0 vmnet-bridge 770 root
|
55
|
+
0.0 0.1 aksusbd 781 root
|
56
|
+
0.0 0.0 postgres: writer 799 postgres
|
57
|
+
0.0 0.0 postgres: wal wr 800 postgres
|
58
|
+
0.0 0.0 postgres: autova 801 postgres
|
59
|
+
0.0 0.0 postgres: stats 802 postgres
|
60
|
+
0.0 0.0 launchd 805 scott
|
61
|
+
0.0 0.5 Spotlight 815 scott
|
62
|
+
0.0 0.1 UserEventAgent 816 scott
|
63
|
+
0.0 0.0 pboard 817 scott
|
64
|
+
0.0 0.3 Dock 818 scott
|
65
|
+
0.0 0.2 ATSServer 819 scott
|
66
|
+
0.0 0.2 coreaudiod 821 root
|
67
|
+
1.7 0.5 SystemUIServer 822 scott
|
68
|
+
0.0 1.2 Finder 824 scott
|
69
|
+
0.0 0.1 HPEventHandler 830 scott
|
70
|
+
0.0 0.1 iTunesHelper 838 scott
|
71
|
+
0.0 1.0 Quicksilver 926 scott
|
72
|
+
0.0 0.4 GrowlHelperApp 1140 scott
|
73
|
+
0.0 0.0 check_afp 1252 root
|
74
|
+
0.0 0.1 AppleSpell 1679 scott
|
75
|
+
0.0 0.8 Preview 1899 scott
|
76
|
+
0.0 1.3 TextMate 2404 scott
|
77
|
+
0.0 0.0 ssh-agent 2590 scott
|
78
|
+
0.0 0.0 ssh-agent 2687 scott
|
79
|
+
0.0 0.0 ssh-agent 2773 scott
|
80
|
+
0.0 0.0 ssh-agent 2872 scott
|
81
|
+
0.0 0.0 ssh-agent 2906 scott
|
82
|
+
0.0 0.0 ssh-agent 2950 scott
|
83
|
+
0.0 0.0 ssh-agent 2965 scott
|
84
|
+
0.0 0.0 ssh-agent 2998 scott
|
85
|
+
0.0 0.0 ssh-agent 3086 scott
|
86
|
+
0.0 0.0 ssh-agent 3167 scott
|
87
|
+
0.0 0.0 ssh-agent 3190 scott
|
88
|
+
0.0 0.0 ssh-agent 3658 scott
|
89
|
+
0.0 0.0 ssh-agent 3701 scott
|
90
|
+
0.0 0.0 ssh-agent 3724 scott
|
91
|
+
0.0 0.0 ssh-agent 4302 scott
|
92
|
+
0.0 0.0 ssh-agent 4354 scott
|
93
|
+
0.0 0.0 ssh-agent 4829 scott
|
94
|
+
0.0 0.0 ssh-agent 4843 scott
|
95
|
+
0.0 0.0 syslogd 5096 root
|
96
|
+
0.0 0.0 ssh-agent 5309 scott
|
97
|
+
0.0 0.1 httpd 7996 _www
|
98
|
+
0.0 0.6 compressord 8793 scott
|
99
|
+
0.0 0.3 qmasterqd 8794 scott
|
100
|
+
0.0 0.0 ssh-agent 8956 scott
|
101
|
+
1.0 0.5 Terminal 10296 scott
|
102
|
+
0.0 0.1 mdworker 10336 _spotlight
|
103
|
+
0.0 2.8 firefox-bin 10719 scott
|
104
|
+
0.0 0.3 mdworker 10882 scott
|
105
|
+
0.0 0.6 backupd 10890 root
|
106
|
+
0.5 0.1 diskimages-helpe 11032 root
|
107
|
+
0.0 2.1 iTunes 11039 scott
|
108
|
+
0.0 0.0 hdiejectd 11044 root
|
109
|
+
0.0 0.1 AppleMobileDevic 11057 scott
|
110
|
+
0.0 0.1 PlugSuit Agent 11616 scott
|
111
|
+
0.0 0.0 ssh-agent 11870 scott
|
112
|
+
0.0 0.0 login 11520 root
|
113
|
+
0.0 0.0 -zsh 11521 scott
|
114
|
+
1.4 0.5 ruby 12093 scott
|
115
|
+
0.0 0.0 login 10297 root
|
116
|
+
0.0 0.0 -zsh 10299 scott
|
117
|
+
0.0 0.0 login 10300 root
|
118
|
+
0.0 0.0 -zsh 10303 scott
|
119
|
+
0.0 0.0 login 12043 root
|
120
|
+
0.0 0.0 -zsh 12045 scott
|
121
|
+
0.0 0.0 man 12058 scott
|
122
|
+
0.0 0.0 sh 12061 scott
|
123
|
+
0.0 0.0 sh 12062 scott
|
124
|
+
0.0 0.0 sh 12067 scott
|
125
|
+
0.0 0.0 less 12068 scott
|
126
|
+
0.0 0.0 login 12071 root
|
127
|
+
0.0 0.0 -zsh 12072 scott
|
128
|
+
0.0 0.0 ps 12100 root
|
104
129
|
RUBY_HERE
|
105
130
|
end
|
106
131
|
|
data/spec/hostname_spec.rb
CHANGED
@@ -1,57 +1,78 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
+
include HostHelpers
|
4
|
+
|
5
|
+
|
3
6
|
describe Watcher::Hostname do
|
4
7
|
|
5
|
-
include HostHelpers
|
6
|
-
|
7
8
|
before(:each) do
|
8
9
|
@watcher = Watcher::Hostname.new
|
10
|
+
@watcher.stub!(:ip).and_return("192.168.157.129")
|
11
|
+
@watcher.stub!(:hostname).and_return("my-hostname")
|
9
12
|
end
|
10
13
|
|
11
14
|
describe "gathering info on the host system" do
|
12
|
-
before(:each) do
|
13
|
-
@watcher.should_receive(:get_ip_address).and_return("192.168.157.129")
|
14
|
-
@watcher.should_receive(:get_hostname).and_return("localhost")
|
15
|
-
end
|
16
15
|
|
17
16
|
it "reports formatted text with the IP and hostname" do
|
18
|
-
@watcher.report.should eql("
|
17
|
+
@watcher.report.should eql("my-hostname\n192.168.157.129")
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
before(:each) do
|
25
|
-
@watcher.should_receive(:ifconfig).and_return(ifconfig_eth0)
|
26
|
-
end
|
27
|
-
it "calls ifconfig with a system call" do
|
28
|
-
@watcher.send(:get_ip_address).should eql("192.168.157.129")
|
29
|
-
end
|
30
|
-
end
|
21
|
+
end
|
22
|
+
|
31
23
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
24
|
+
describe Watcher::Hostname, "with a custom message" do
|
25
|
+
|
26
|
+
before(:each) do
|
27
|
+
@watcher = Watcher::Hostname.new { |w| "The hostname is #{w.hostname}\nand the IP address is #{w.ip}"}
|
28
|
+
@watcher.stub!(:ip).and_return("192.168.157.129")
|
29
|
+
@watcher.stub!(:hostname).and_return("my-hostname")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "allows access to the instance data" do
|
33
|
+
@watcher.report.should eql("The hostname is my-hostname\nand the IP address is 192.168.157.129")
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
describe "private methods" do
|
40
|
+
|
41
|
+
before(:each) do
|
42
|
+
@watcher = Watcher::Hostname.new
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "get_ip_address method" do
|
46
|
+
before(:each) do
|
47
|
+
@watcher.should_receive(:ifconfig).and_return(ifconfig_eth0)
|
48
|
+
end
|
49
|
+
it "calls ifconfig with a system call" do
|
50
|
+
@watcher.send(:get_ip_address).should eql("192.168.157.129")
|
42
51
|
end
|
52
|
+
end
|
43
53
|
|
44
|
-
|
54
|
+
describe "ifconfig method" do
|
55
|
+
|
56
|
+
before(:each) do
|
57
|
+
@watcher.should_receive(:`).with("ifconfig eth0").and_return(ifconfig_eth0)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "calls ifconfig with a system call" do
|
61
|
+
@watcher.send(:ifconfig).should eql(ifconfig_eth0.chomp)
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
45
65
|
|
46
|
-
|
47
|
-
@watcher.should_receive(:`).with("hostname").and_return("localhost")
|
48
|
-
end
|
49
|
-
|
50
|
-
it "calls hostname with a system call" do
|
51
|
-
@watcher.send(:get_hostname).should eql("localhost")
|
52
|
-
end
|
66
|
+
describe "get_hostname method" do
|
53
67
|
|
68
|
+
before(:each) do
|
69
|
+
@watcher.should_receive(:`).with("hostname").and_return("localhost")
|
54
70
|
end
|
55
71
|
|
72
|
+
it "calls hostname with a system call" do
|
73
|
+
@watcher.send(:get_hostname).should eql("localhost")
|
74
|
+
end
|
75
|
+
|
56
76
|
end
|
77
|
+
|
57
78
|
end
|
data/spec/process_spec.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
|
3
|
+
include ProcessHelpers
|
4
4
|
|
5
|
-
|
5
|
+
describe Watcher::Process do
|
6
6
|
|
7
7
|
before(:each) do
|
8
8
|
@watcher = Watcher::Process.new('process-name', :handle => 'Process Handle')
|
@@ -34,25 +34,45 @@ describe Watcher::Process do
|
|
34
34
|
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
@watcher.should be_running
|
47
|
-
end
|
48
|
-
|
49
|
-
it "says that :running? is false when the process doesn't exist" do
|
50
|
-
@watcher.should_receive(:processes).and_return("process-1\nprocess-2")
|
51
|
-
@watcher.should_not be_running
|
52
|
-
end
|
53
|
-
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe Watcher::Process, "with a custom message" do
|
42
|
+
|
43
|
+
before(:each) do
|
44
|
+
@watcher = Watcher::Process.new('process-name', :handle => 'Process Handle') do |p|
|
45
|
+
"#{p.handle}: #{p.running? ? %q{Active}: %q{Inactive}}"
|
54
46
|
end
|
55
|
-
|
47
|
+
@watcher.stub!(:running?).and_return(true)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "has access to instance data" do
|
51
|
+
@watcher.report.should eql("Process Handle: Active")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
describe Watcher::Process, "privately" do
|
58
|
+
|
59
|
+
before(:each) do
|
60
|
+
@watcher = Watcher::Process.new('process-name', :handle => 'Process Handle')
|
61
|
+
end
|
62
|
+
|
63
|
+
it "calls 'ps aux' with a system call" do
|
64
|
+
@watcher.should_receive(:`).with("ps -o %cpu -o %mem -o comm -o pid -o user -axc").and_return(ps_aux)
|
65
|
+
@watcher.send(:processes).should eql(ps_aux.chomp)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "says that :running? is true when the process exists" do
|
69
|
+
@watcher.stub!(:command).and_return("ruby")
|
70
|
+
@watcher.should be_running
|
71
|
+
end
|
72
|
+
|
73
|
+
it "says that :running? is false when the process doesn't exist" do
|
74
|
+
@watcher.stub!(:command).and_return("not-ruby")
|
75
|
+
@watcher.should_not be_running
|
56
76
|
end
|
57
77
|
|
58
78
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: informer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Burton
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-31 00:00:00 -07:00
|
13
13
|
default_executable: informer
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -40,7 +40,7 @@ files:
|
|
40
40
|
- features/watcher.feature
|
41
41
|
- lib/informer.rb
|
42
42
|
- lib/informer/basic_watcher.rb
|
43
|
-
- lib/informer/reporter/
|
43
|
+
- lib/informer/reporter/lcd.rb
|
44
44
|
- lib/informer/reporter/standard_output.rb
|
45
45
|
- lib/informer/watcher/hostname.rb
|
46
46
|
- lib/informer/watcher/process.rb
|