Informer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +35 -0
- data/Rakefile +63 -0
- data/VERSION +1 -0
- data/bin/informer +8 -0
- data/features/hostname_watcher.feature +13 -0
- data/features/informer.feature +10 -0
- data/features/step_definitions/hostname_watcher_steps.rb +12 -0
- data/features/step_definitions/informer_steps.rb +11 -0
- data/features/step_definitions/watcher_steps.rb +21 -0
- data/features/support/env.rb +4 -0
- data/features/watcher.feature +12 -0
- data/lib/informer.rb +64 -0
- data/lib/informer/basic_watcher.rb +11 -0
- data/lib/informer/reporter/led.rb +22 -0
- data/lib/informer/reporter/standard_output.rb +9 -0
- data/lib/informer/watcher/hostname.rb +45 -0
- data/lib/informer/watcher/process.rb +27 -0
- data/spec/helpers/host_helpers.rb +16 -0
- data/spec/helpers/process_helpers.rb +107 -0
- data/spec/hostname_spec.rb +57 -0
- data/spec/informer_spec.rb +1 -0
- data/spec/process_spec.rb +58 -0
- data/spec/spec_helper.rb +11 -0
- metadata +86 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Scott Burton
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
= Informer
|
2
|
+
|
3
|
+
Running Informer will watch something, formulate messages about it, and report back somehow. It is useful for extremely simplified reporting the status of a host system.
|
4
|
+
|
5
|
+
Informer is simple and extensible. New arbitrary watchers and reporters just need to be namespaced within the Watcher or Reporter module and respond to #report. See source for details.
|
6
|
+
|
7
|
+
|
8
|
+
== Examples
|
9
|
+
|
10
|
+
* Print the state of two processes, plus the current hostname and ip address for en1, to stdout
|
11
|
+
Informer.watch do
|
12
|
+
process "ruby"
|
13
|
+
process "irb", :handle => "Interactive Ruby"
|
14
|
+
hostname "en1"
|
15
|
+
end
|
16
|
+
|
17
|
+
* Report whether ssh-agent is running on the LCD screen of a Rackable Systems Roamer ILOM device
|
18
|
+
informer = Informer.new("lcd")
|
19
|
+
informer.watchers << Watcher::Process.new("ssh-agent", :handle => "SSH Keychain Agent")
|
20
|
+
informer.report
|
21
|
+
|
22
|
+
== Note on Patches/Pull Requests
|
23
|
+
|
24
|
+
* Fork the project.
|
25
|
+
* Make your feature addition or bug fix.
|
26
|
+
* Add tests for it. This is important so I don't break it in a
|
27
|
+
future version unintentionally.
|
28
|
+
* Commit, do not mess with rakefile, version, or history.
|
29
|
+
(if you want to have your own version, that is fine but
|
30
|
+
bump version in a commit by itself I can ignore when I pull)
|
31
|
+
* Send me a pull request. Bonus points for topic branches.
|
32
|
+
|
33
|
+
== Copyright
|
34
|
+
|
35
|
+
Copyright (c) 2009 Scott Burton. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
$LOAD_PATH << './lib'
|
5
|
+
require 'informer'
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'jeweler'
|
9
|
+
Jeweler::Tasks.new do |gem|
|
10
|
+
gem.name = "Informer"
|
11
|
+
gem.summary = %Q{Informer gathers info and shoots it over the wire}
|
12
|
+
gem.description = %Q{Informer is a flexible information gathering and reporting system.}
|
13
|
+
gem.email = "scottburton11@gmail.com"
|
14
|
+
gem.homepage = "http://github.com/scottburton11/informer"
|
15
|
+
gem.authors = ["Scott Burton"]
|
16
|
+
gem.executables = ["informer"]
|
17
|
+
gem.default_executable = "informer"
|
18
|
+
end
|
19
|
+
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'spec/rake/spectask'
|
25
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
26
|
+
spec.libs << 'lib' << 'spec'
|
27
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
28
|
+
end
|
29
|
+
|
30
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
31
|
+
spec.libs << 'lib' << 'spec'
|
32
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
33
|
+
spec.rcov = true
|
34
|
+
end
|
35
|
+
|
36
|
+
begin
|
37
|
+
require 'cucumber/rake/task'
|
38
|
+
Cucumber::Rake::Task.new(:features)
|
39
|
+
rescue LoadError
|
40
|
+
task :features do
|
41
|
+
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
task :default => :spec
|
48
|
+
|
49
|
+
require 'rake/rdoctask'
|
50
|
+
Rake::RDocTask.new do |rdoc|
|
51
|
+
if File.exist?('VERSION.yml')
|
52
|
+
config = YAML.load(File.read('VERSION.yml'))
|
53
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
54
|
+
else
|
55
|
+
version = ""
|
56
|
+
end
|
57
|
+
|
58
|
+
rdoc.rdoc_dir = 'rdoc'
|
59
|
+
rdoc.title = "Informer #{version}"
|
60
|
+
rdoc.rdoc_files.include('README*')
|
61
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
62
|
+
end
|
63
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/informer
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Feature: The HostnameWatcher gathers the hostname and IP address, and reports back
|
2
|
+
In order to determine which host is reporting
|
3
|
+
As an Informant
|
4
|
+
I want a HostnameWatcher to gather the hostname and IP address of the host system
|
5
|
+
|
6
|
+
Scenario: Gather the hostname and IP
|
7
|
+
Given I have a HostnameWatcher
|
8
|
+
When it gathers info
|
9
|
+
Then it should have a hostname and IP address
|
10
|
+
And it should report the hostname and IP address as a message
|
11
|
+
|
12
|
+
|
13
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Feature: Informant tells you what important stuff is happening
|
2
|
+
In order to protect revenue
|
3
|
+
As a System Administrator
|
4
|
+
I want to be informed about what is happening on my system
|
5
|
+
|
6
|
+
Scenario: Just tell me the message
|
7
|
+
Given I am watching something
|
8
|
+
When the informer runs
|
9
|
+
Then it should report a message
|
10
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Given /^I have a HostnameWatcher$/ do
|
2
|
+
@watcher = HostnameWatcher.new
|
3
|
+
end
|
4
|
+
|
5
|
+
Then /^it should have a hostname and IP address$/ do
|
6
|
+
@watcher.ip.should =~ %r|\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}|
|
7
|
+
@watcher.hostname.should =~ %r|(\w+).(\w+).(\w+)|
|
8
|
+
end
|
9
|
+
|
10
|
+
Then /^it should report the hostname and IP address as a message$/ do
|
11
|
+
pending
|
12
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Given /^I am watching something$/ do
|
2
|
+
@watcher = Watcher.new
|
3
|
+
end
|
4
|
+
|
5
|
+
Given /^I have a watcher$/ do
|
6
|
+
@watcher = Watcher.new
|
7
|
+
end
|
8
|
+
|
9
|
+
When /^the watcher gathers info$/ do
|
10
|
+
@watcher.gather
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
When /^it gathers info$/ do
|
15
|
+
When "the watcher gathers info"
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
Then /^it should have a message$/ do
|
20
|
+
@watcher.message.should be_kind_of(String)
|
21
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Feature: Watchers gather information and report back
|
2
|
+
In order to protect revenue
|
3
|
+
As a System Administrator
|
4
|
+
I want to watch something specific, and formulate a message about it
|
5
|
+
|
6
|
+
Scenario: A watcher gathers info and creates a message
|
7
|
+
Given I have a watcher
|
8
|
+
When the watcher gathers info
|
9
|
+
Then it should have a message
|
10
|
+
|
11
|
+
|
12
|
+
|
data/lib/informer.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
$LOAD_PATH << './lib'
|
2
|
+
|
3
|
+
require 'informer/basic_watcher'
|
4
|
+
|
5
|
+
require 'informer/watcher/hostname'
|
6
|
+
require 'informer/watcher/process'
|
7
|
+
|
8
|
+
require 'informer/reporter/led'
|
9
|
+
require 'informer/reporter/standard_output'
|
10
|
+
|
11
|
+
class Informer
|
12
|
+
|
13
|
+
attr_reader :watchers
|
14
|
+
|
15
|
+
def initialize(reporter)
|
16
|
+
@reporter = get_reporter(reporter)
|
17
|
+
@watchers = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def messages
|
21
|
+
watchers.map {|watcher| watcher.report}
|
22
|
+
end
|
23
|
+
|
24
|
+
def report
|
25
|
+
@reporter.report(messages)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.watch(reporter = "standard_output", &block)
|
29
|
+
informer = Informer.new(reporter)
|
30
|
+
informer.instance_eval(&block)
|
31
|
+
informer.report
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def get_reporter(reporter)
|
37
|
+
begin
|
38
|
+
Reporter.const_get("#{reporter.camelize}")
|
39
|
+
rescue NameError
|
40
|
+
puts "No reporter exists named #{reporter}. We'll use standard output instead."
|
41
|
+
Reporter::StandardOutput
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def method_missing(method, *args, &block)
|
46
|
+
begin
|
47
|
+
watcher = Watcher.const_get("#{method.to_s.camelize}")
|
48
|
+
@watchers << watcher.new(*args, &block)
|
49
|
+
rescue NameError => e
|
50
|
+
puts "No watcher named #{method.to_s}. Error was: #{e}"
|
51
|
+
super
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
class String
|
61
|
+
def camelize
|
62
|
+
self.split(/[^a-z0-9]/).map{|w|w.capitalize}.join("")
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Reporter
|
2
|
+
class Lcd
|
3
|
+
|
4
|
+
LCD_DEV = "/dev/tty" # "/dev/ttyS1"
|
5
|
+
|
6
|
+
def self.report(messages)
|
7
|
+
messages.each do |message|
|
8
|
+
display do |led|
|
9
|
+
led.write "LCD:\n#{message}\n"
|
10
|
+
end
|
11
|
+
sleep 3
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.display(&block)
|
16
|
+
File.open(LCD_DEV, "w+") do |f|
|
17
|
+
yield f
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Watcher
|
2
|
+
class Hostname < BasicWatcher
|
3
|
+
|
4
|
+
attr_reader :ip, :hostname
|
5
|
+
|
6
|
+
def initialize(interface = "eth0")
|
7
|
+
@interface = interface
|
8
|
+
end
|
9
|
+
|
10
|
+
def report
|
11
|
+
gather
|
12
|
+
message
|
13
|
+
end
|
14
|
+
|
15
|
+
def message
|
16
|
+
@message ||= "#{hostname}\n#{ip}"
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def gather
|
22
|
+
@ip = get_ip_address
|
23
|
+
@hostname = get_hostname
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def get_hostname
|
29
|
+
`hostname`.chomp
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_ip_address
|
33
|
+
ip_match.match(ifconfig).to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
def ifconfig
|
37
|
+
`ifconfig #{@interface}`.chomp
|
38
|
+
end
|
39
|
+
|
40
|
+
def ip_match
|
41
|
+
%r|\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}|
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Watcher
|
2
|
+
class Process < BasicWatcher
|
3
|
+
def initialize(process, options = {})
|
4
|
+
@process = process
|
5
|
+
@handle = options[:handle] || @process
|
6
|
+
end
|
7
|
+
|
8
|
+
def report
|
9
|
+
"#{@handle} is #{running? ? '' : 'not '}running"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def processes
|
15
|
+
`ps aux`.chomp
|
16
|
+
end
|
17
|
+
|
18
|
+
def process_match
|
19
|
+
%r|#{@process}|
|
20
|
+
end
|
21
|
+
|
22
|
+
def running?
|
23
|
+
process_match === processes
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module HostHelpers
|
2
|
+
def ifconfig_eth0
|
3
|
+
<<RUBY_HERE
|
4
|
+
eth0 Link encap:Ethernet HWaddr 00:0c:29:14:d1:e9
|
5
|
+
inet addr:192.168.157.129 Bcast:192.168.157.255 Mask:255.255.255.0
|
6
|
+
inet6 addr: fe80::20c:29ff:fe14:d1e9/64 Scope:Link
|
7
|
+
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
8
|
+
RX packets:3436 errors:0 dropped:0 overruns:0 frame:0
|
9
|
+
TX packets:526 errors:0 dropped:0 overruns:0 carrier:0
|
10
|
+
collisions:0 txqueuelen:1000
|
11
|
+
RX bytes:783465 (783.4 KB) TX bytes:70731 (70.7 KB)
|
12
|
+
RUBY_HERE
|
13
|
+
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module ProcessHelpers
|
2
|
+
|
3
|
+
def ps_aux
|
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
|
104
|
+
RUBY_HERE
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Watcher::Hostname do
|
4
|
+
|
5
|
+
include HostHelpers
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@watcher = Watcher::Hostname.new
|
9
|
+
end
|
10
|
+
|
11
|
+
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
|
+
|
17
|
+
it "reports formatted text with the IP and hostname" do
|
18
|
+
@watcher.report.should eql("localhost\n192.168.157.129")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
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
|
31
|
+
|
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
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "get_hostname method" do
|
45
|
+
|
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
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Watcher::Process do
|
4
|
+
|
5
|
+
include ProcessHelpers
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@watcher = Watcher::Process.new('process-name', :handle => 'Process Handle')
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "gathering info about the host system" do
|
12
|
+
|
13
|
+
describe "when the process is running" do
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
@watcher.should_receive(:running?).and_return(true)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "reports the process label and 'is running'" do
|
20
|
+
@watcher.report.should eql("Process Handle is running")
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "when the process isn't running" do
|
26
|
+
|
27
|
+
before(:each) do
|
28
|
+
@watcher.should_receive(:running?).and_return(false)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "reports the process label and 'is not running'" do
|
32
|
+
@watcher.report.should eql("Process Handle is not running")
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
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
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'Informer'
|
4
|
+
require 'spec'
|
5
|
+
require 'spec/autorun'
|
6
|
+
require 'helpers/host_helpers'
|
7
|
+
require 'helpers/process_helpers'
|
8
|
+
|
9
|
+
Spec::Runner.configure do |config|
|
10
|
+
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Informer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Burton
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-29 00:00:00 -07:00
|
13
|
+
default_executable: informer
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Informer is a flexible information gathering and reporting system.
|
17
|
+
email: scottburton11@gmail.com
|
18
|
+
executables:
|
19
|
+
- informer
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- .document
|
27
|
+
- .gitignore
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- bin/informer
|
33
|
+
- features/hostname_watcher.feature
|
34
|
+
- features/informer.feature
|
35
|
+
- features/step_definitions/hostname_watcher_steps.rb
|
36
|
+
- features/step_definitions/informer_steps.rb
|
37
|
+
- features/step_definitions/watcher_steps.rb
|
38
|
+
- features/support/env.rb
|
39
|
+
- features/watcher.feature
|
40
|
+
- lib/informer.rb
|
41
|
+
- lib/informer/basic_watcher.rb
|
42
|
+
- lib/informer/reporter/led.rb
|
43
|
+
- lib/informer/reporter/standard_output.rb
|
44
|
+
- lib/informer/watcher/hostname.rb
|
45
|
+
- lib/informer/watcher/process.rb
|
46
|
+
- spec/helpers/host_helpers.rb
|
47
|
+
- spec/helpers/process_helpers.rb
|
48
|
+
- spec/hostname_spec.rb
|
49
|
+
- spec/informer_spec.rb
|
50
|
+
- spec/process_spec.rb
|
51
|
+
- spec/spec_helper.rb
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://github.com/scottburton11/informer
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options:
|
58
|
+
- --charset=UTF-8
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
requirements: []
|
74
|
+
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.3.5
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Informer gathers info and shoots it over the wire
|
80
|
+
test_files:
|
81
|
+
- spec/helpers/host_helpers.rb
|
82
|
+
- spec/helpers/process_helpers.rb
|
83
|
+
- spec/hostname_spec.rb
|
84
|
+
- spec/informer_spec.rb
|
85
|
+
- spec/process_spec.rb
|
86
|
+
- spec/spec_helper.rb
|