informer 0.1.1 → 0.2.0

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.
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{informer}
5
- s.version = "0.1.1"
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-29}
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/led.rb",
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.1
1
+ 0.2.0
@@ -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
- Informer.watch do
5
- process "ruby", :handle => "Ruby"
6
- process "irb"
7
- hostname "en1"
8
- end
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
@@ -5,7 +5,7 @@ require 'informer/basic_watcher'
5
5
  require 'informer/watcher/hostname'
6
6
  require 'informer/watcher/process'
7
7
 
8
- require 'informer/reporter/led'
8
+ require 'informer/reporter/lcd'
9
9
  require 'informer/reporter/standard_output'
10
10
 
11
11
  class Informer
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
- gather
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
- protected
20
-
21
- def gather
22
- @ip = get_ip_address
23
- @hostname = get_hostname
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
- def initialize(process, options = {})
4
- @process = process
5
- @handle = options[:handle] || @process
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 process_match
19
- %r|#{@process}|
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
- USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
6
- root 1 0.0 0.2 5236 576 ? Ss Oct27 0:01 /sbin/init
7
- root 2 0.0 0.0 0 0 ? S< Oct27 0:00 [kthreadd]
8
- root 3 0.0 0.0 0 0 ? S< Oct27 0:00 [migration/0]
9
- root 4 0.0 0.0 0 0 ? S< Oct27 0:00 [ksoftirqd/0]
10
- root 5 0.0 0.0 0 0 ? S< Oct27 0:00 [watchdog/0]
11
- root 6 0.0 0.0 0 0 ? S< Oct27 0:00 [events/0]
12
- root 7 0.0 0.0 0 0 ? S< Oct27 0:00 [khelper]
13
- root 8 0.0 0.0 0 0 ? S< Oct27 0:00 [kstop/0]
14
- root 9 0.0 0.0 0 0 ? S< Oct27 0:00 [kintegrityd/0]
15
- root 10 0.0 0.0 0 0 ? S< Oct27 0:00 [kblockd/0]
16
- root 11 0.0 0.0 0 0 ? S< Oct27 0:00 [kacpid]
17
- root 12 0.0 0.0 0 0 ? S< Oct27 0:00 [kacpi_notify]
18
- root 13 0.0 0.0 0 0 ? S< Oct27 0:00 [cqueue]
19
- root 14 0.0 0.0 0 0 ? S< Oct27 0:17 [ata/0]
20
- root 15 0.0 0.0 0 0 ? S< Oct27 0:00 [ata_aux]
21
- root 16 0.0 0.0 0 0 ? S< Oct27 0:00 [ksuspend_usbd]
22
- root 17 0.0 0.0 0 0 ? S< Oct27 0:00 [khubd]
23
- root 18 0.0 0.0 0 0 ? S< Oct27 0:00 [kseriod]
24
- root 19 0.0 0.0 0 0 ? S< Oct27 0:00 [kmmcd]
25
- root 20 0.0 0.0 0 0 ? S< Oct27 0:00 [btaddconn]
26
- root 21 0.0 0.0 0 0 ? S< Oct27 0:00 [btdelconn]
27
- root 22 0.0 0.0 0 0 ? S Oct27 0:00 [pdflush]
28
- root 23 0.0 0.0 0 0 ? S Oct27 0:00 [pdflush]
29
- root 24 0.0 0.0 0 0 ? S< Oct27 0:00 [kswapd0]
30
- root 25 0.0 0.0 0 0 ? S< Oct27 0:00 [aio/0]
31
- root 26 0.0 0.0 0 0 ? S< Oct27 0:00 [ecryptfs-kthrea]
32
- root 29 0.0 0.0 0 0 ? S< Oct27 0:00 [pciehpd]
33
- root 30 0.0 0.0 0 0 ? S< Oct27 0:00 [scsi_eh_0]
34
- root 31 0.0 0.0 0 0 ? S< Oct27 0:00 [scsi_eh_1]
35
- root 32 0.0 0.0 0 0 ? S< Oct27 0:00 [kstriped]
36
- root 33 0.0 0.0 0 0 ? S< Oct27 0:00 [kmpathd/0]
37
- root 34 0.0 0.0 0 0 ? S< Oct27 0:00 [kmpath_handlerd]
38
- root 35 0.0 0.0 0 0 ? S< Oct27 0:00 [ksnapd]
39
- root 36 0.0 0.0 0 0 ? S< Oct27 0:00 [kondemand/0]
40
- root 37 0.0 0.0 0 0 ? S< Oct27 0:00 [krfcommd]
41
- root 220 0.0 0.0 0 0 ? S< Oct27 0:00 [mpt_poll_0]
42
- root 334 0.0 0.0 0 0 ? S< Oct27 0:00 [scsi_eh_2]
43
- root 753 0.0 0.0 0 0 ? S< Oct27 0:00 [kjournald]
44
- root 873 0.0 0.1 16660 368 ? S<s Oct27 0:00 /sbin/udevd --daemon
45
- root 1056 0.0 0.0 0 0 ? S< Oct27 0:00 [kgameportd]
46
- root 1189 0.0 0.0 0 0 ? S< Oct27 0:00 [kpsmoused]
47
- root 2344 0.0 0.1 3944 488 tty4 Ss+ Oct27 0:00 /sbin/getty 38400 tty4
48
- root 2345 0.0 0.1 3944 488 tty5 Ss+ Oct27 0:00 /sbin/getty 38400 tty5
49
- root 2346 0.0 0.2 4024 608 ? Ss Oct27 0:00 /bin/sh /etc/init.d/rc 2
50
- root 2351 0.0 0.1 3944 488 tty2 Ss+ Oct27 0:00 /sbin/getty 38400 tty2
51
- root 2355 0.0 0.1 3944 488 tty3 Ss+ Oct27 0:00 /sbin/getty 38400 tty3
52
- root 2356 0.0 0.1 3944 488 tty6 Ss+ Oct27 0:00 /sbin/getty 38400 tty6
53
- root 2418 0.0 0.2 3944 576 ? Ss Oct27 0:00 /usr/sbin/acpid -c /etc/acpi/events -s /var/run/acpid.socket
54
- syslog 2452 0.0 0.2 12376 560 ? Ss Oct27 0:00 /sbin/syslogd -u syslog
55
- root 2470 0.0 0.1 8204 460 ? S Oct27 0:00 /bin/dd bs 1 if /proc/kmsg of /var/run/klogd/kmsg
56
- klog 2472 0.0 0.1 6612 468 ? Ss Oct27 0:00 /sbin/klogd -P /var/run/klogd/kmsg
57
- 103 2491 0.0 0.3 21388 944 ? Ss Oct27 0:00 /bin/dbus-daemon --system
58
- lp 2700 0.0 0.1 12432 344 ? Ss Oct27 0:00 /usr/sbin/lpd -s
59
- root 2761 0.0 0.2 66292 648 ? Ss Oct27 0:00 /usr/sbin/winbindd
60
- root 2783 0.0 0.2 66292 552 ? S Oct27 0:00 /usr/sbin/winbindd
61
- root 2791 0.0 1.2 41912 3028 ? Ssl Oct27 0:01 /usr/sbin/console-kit-daemon
62
- avahi 2979 0.0 0.5 31884 1344 ? Ss Oct27 0:00 avahi-daemon: running [minibuntu.local]
63
- avahi 2980 0.0 0.1 31764 436 ? Ss Oct27 0:00 avahi-daemon: chroot helper
64
- daemon 3030 0.0 0.1 16524 432 ? Ss Oct27 0:00 /usr/sbin/atd
65
- root 3055 0.0 0.3 19972 744 ? Ss Oct27 0:00 /usr/sbin/cron
66
- root 3081 0.0 0.2 4024 636 ? S Oct27 0:00 /bin/sh /etc/rc2.d/S99rc.local start
67
- root 3085 0.0 0.2 4024 556 ? S Oct27 0:00 /bin/sh -e /etc/rc.local
68
- scott 3086 0.0 0.3 41904 952 ? S Oct27 0:00 su - scott -c startx
69
- scott 3094 0.0 0.4 10864 1096 ? S Oct27 0:00 /bin/bash /usr/bin/startx
70
- scott 3125 0.0 0.2 15384 732 ? S Oct27 0:00 xinit /etc/X11/xinit/xinitrc -- /etc/X11/xinit/xserverrc :0 -auth /tmp/serverauth.zhFytCmJHA
71
- root 3129 0.0 7.8 113644 19372 tty7 Ss+ Oct27 0:04 /usr/bin/X11/X -nolisten tcp
72
- scott 3285 0.0 1.1 147216 2776 ? S Oct27 0:00 x-session-manager
73
- scott 3300 0.0 2.5 61232 6356 ? S Oct27 0:00 xterm
74
- scott 3309 0.0 0.0 0 0 ? Z Oct27 0:00 [sh] <defunct>
75
- scott 3312 0.0 0.2 35940 604 ? Ss Oct27 0:00 /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session x-session-manager
76
- scott 3315 0.0 0.2 23824 608 ? S Oct27 0:00 /usr/bin/dbus-launch --exit-with-session x-session-manager
77
- scott 3316 0.0 0.2 21256 616 ? Ss Oct27 0:00 //bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
78
- scott 3317 0.0 1.3 20856 3316 pts/0 Ss Oct27 0:00 bash
79
- scott 3331 0.0 0.5 26536 1256 ? S Oct27 0:00 /usr/lib/xfconfd
80
- scott 3343 0.0 3.9 146812 9572 ? S Oct27 0:02 xfwm4
81
- scott 3344 0.0 0.9 121080 2432 ? S Oct27 0:00 xfsettingsd
82
- scott 3346 0.0 1.3 132040 3228 ? S Oct27 0:00 xfce4-panel
83
- scott 3348 0.0 1.3 155268 3204 ? S Oct27 0:00 Thunar --daemon
84
- scott 3350 0.0 6.3 218876 15500 ? S Oct27 0:01 xfdesktop
85
- scott 3365 0.0 1.2 154408 3112 ? S Oct27 0:00 xfce4-settings-helper
86
- scott 3380 0.0 0.3 17544 888 ? S Oct27 0:00 /usr/lib/gamin/gam_server
87
- 105 11449 0.0 1.5 35392 3808 ? Ss Oct27 0:01 /usr/sbin/hald
88
- root 11450 0.0 0.4 15816 1212 ? S Oct27 0:00 hald-runner
89
- root 11481 0.0 0.8 28484 2032 ? S Oct27 0:00 hald-addon-input: Listening on /dev/input/event1 /dev/input/event0 /dev/input/event3
90
- root 11544 0.0 0.8 28484 2044 ? S Oct27 0:01 hald-addon-storage: polling /dev/sr0 (every 2 sec)
91
- root 11547 0.0 0.8 28484 2020 ? S Oct27 0:00 hald-addon-storage: no polling on /dev/fd0 because it is explicitly disabled
92
- 105 11552 0.0 0.8 32392 2016 ? S Oct27 0:00 hald-addon-acpi: listening on acpid socket /var/run/acpid.socket
93
- root 11629 0.0 0.0 0 0 ? S< Oct27 0:00 [vmhgfs]
94
- root 11647 0.0 0.0 0 0 ? S< Oct27 0:00 [vmmemctl]
95
- root 11761 0.0 0.5 23112 1440 ? Ss Oct27 0:19 /usr/lib/vmware-tools/sbin64/vmware-guestd --background /var/run/vmware-guestd.pid
96
- root 29894 0.0 0.2 6488 676 ? Ss 12:36 0:00 dhclient3 -e IF_METRIC=100 -pf /var/run/dhclient.eth0.pid -lf /var/lib/dhcp3/dhclient.eth0.leases eth0
97
- root 29960 0.0 0.8 18964 2020 pts/0 S+ 12:37 0:00 -bash
98
- root 30190 0.0 0.4 48940 1204 ? Ss 12:39 0:00 /usr/sbin/sshd
99
- root 30211 0.0 1.3 80804 3372 ? Ss 12:39 0:00 sshd: scott [priv]
100
- scott 30219 0.0 0.7 80804 1740 ? S 12:39 0:00 sshd: scott@pts/1
101
- scott 30235 0.0 1.4 20860 3672 pts/1 Ss 12:39 0:00 -bash
102
- root 30268 0.0 0.8 18992 2040 pts/1 S 12:39 0:00 -bash
103
- root 31641 2.0 0.4 15172 1136 pts/1 R+ 14:00 0:00 ps aux
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
 
@@ -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("localhost\n192.168.157.129")
17
+ @watcher.report.should eql("my-hostname\n192.168.157.129")
19
18
  end
20
19
  end
21
20
 
22
- describe "private methods" do
23
- describe "get_ip_address method" do
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
- describe "ifconfig method" do
33
-
34
- before(:each) do
35
- @watcher.should_receive(:`).with("ifconfig eth0").and_return(ifconfig_eth0)
36
- end
37
-
38
- it "calls ifconfig with a system call" do
39
- @watcher.send(:ifconfig).should eql(ifconfig_eth0.chomp)
40
- end
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
- describe "get_hostname method" do
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
- before(:each) do
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
@@ -1,8 +1,8 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe Watcher::Process do
3
+ include ProcessHelpers
4
4
 
5
- include ProcessHelpers
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
- describe "privately" do
38
-
39
- it "calls 'ps aux' with a system call" do
40
- @watcher.should_receive(:`).with("ps aux").and_return(ps_aux)
41
- @watcher.send(:processes).should eql(ps_aux.chomp)
42
- end
43
-
44
- it "says that :running? is true when the process exists" do
45
- @watcher.should_receive(:processes).and_return("process-1\nprocess-2\nprocess-name")
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.1.1
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-29 00:00:00 -07:00
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/led.rb
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