jah 0.0.3 → 0.0.5

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.
Files changed (69) hide show
  1. data/README.md +62 -13
  2. data/Rakefile +4 -3
  3. data/VERSION +1 -1
  4. data/bin/jah +4 -2
  5. data/jah.gemspec +73 -21
  6. data/lib/jah/act_pkg/apt.rb +13 -0
  7. data/lib/jah/act_pkg/base.rb +17 -0
  8. data/lib/jah/act_pkg/emerge.rb +4 -0
  9. data/lib/jah/act_pkg/pacman.rb +59 -0
  10. data/lib/jah/act_pkg/pkg.rb +52 -0
  11. data/lib/jah/act_pkg/ports.rb +9 -0
  12. data/lib/jah/act_pkg/slack.rb +8 -0
  13. data/lib/jah/act_pkg/urpm.rb +7 -0
  14. data/lib/jah/act_pkg/yum.rb +31 -0
  15. data/lib/jah/act_pkg/zypp.rb +12 -0
  16. data/lib/jah/act_pkg.rb +41 -0
  17. data/lib/jah/agent.rb +14 -6
  18. data/lib/jah/agents/xmpp.rb +164 -23
  19. data/lib/jah/cli.rb +15 -46
  20. data/lib/jah/command.rb +10 -5
  21. data/lib/jah/commands/cpu.rb +38 -0
  22. data/lib/jah/commands/disk.rb +35 -0
  23. data/lib/jah/commands/mem.rb +49 -0
  24. data/lib/jah/{collectors/net.rb → commands/netstat.rb} +11 -9
  25. data/lib/jah/commands/packages.rb +25 -0
  26. data/lib/jah/commands/prok.rb +97 -0
  27. data/lib/jah/commands/services.rb +14 -0
  28. data/lib/jah/commands/status.rb +1 -41
  29. data/lib/jah/commands/who.rb +27 -0
  30. data/lib/jah/history.rb +25 -0
  31. data/lib/jah/install.rb +12 -18
  32. data/lib/jah/opt.rb +87 -0
  33. data/lib/jah/prayer.rb +75 -0
  34. data/lib/jah.rb +21 -13
  35. data/lib/locales/en_us.yml +9 -1
  36. data/lib/locales/pt_br.yml +9 -1
  37. data/spec/jah/act_pkg/apt_spec.rb +40 -0
  38. data/spec/jah/act_pkg/pacman_spec.rb +141 -0
  39. data/spec/jah/act_pkg/pkg_spec.rb +51 -0
  40. data/spec/jah/act_pkg/ports_spec.rb +36 -0
  41. data/spec/jah/act_pkg/yum_spec.rb +55 -0
  42. data/spec/jah/act_pkg_spec.rb +41 -0
  43. data/spec/jah/agent_spec.rb +8 -0
  44. data/spec/jah/agents/xmpp_spec.rb +8 -0
  45. data/spec/jah/cli_spec.rb +47 -0
  46. data/spec/jah/command_spec.rb +5 -0
  47. data/spec/jah/commands/cpu_spec.rb +51 -0
  48. data/spec/jah/commands/disk_spec.rb +49 -0
  49. data/spec/jah/commands/mem_spec.rb +60 -0
  50. data/spec/jah/commands/netstat_spec.rb +13 -0
  51. data/spec/jah/commands/prok_spec.rb +248 -0
  52. data/spec/jah/commands/who_spec.rb +25 -0
  53. data/spec/jah/history_spec.rb +35 -0
  54. data/spec/jah/install_spec.rb +15 -0
  55. data/spec/jah/opt_spec.rb +37 -0
  56. data/spec/jah/prayer_spec.rb +8 -0
  57. data/spec/jah_spec.rb +4 -2
  58. data/spec/spec_helper.rb +3 -1
  59. metadata +67 -16
  60. data/lib/jah/collector.rb +0 -12
  61. data/lib/jah/collectors/cpu.rb +0 -35
  62. data/lib/jah/collectors/disk.rb +0 -14
  63. data/lib/jah/collectors/mem.rb +0 -51
  64. data/lib/jah/collectors/prok.rb +0 -88
  65. data/lib/jah/collectors/services.rb +0 -13
  66. data/lib/jah/collectors/who.rb +0 -20
  67. data/lib/jah/commands/pub.rb +0 -34
  68. data/lib/jah/god.rb +0 -24
  69. data/lib/jah.yaml.template +0 -26
@@ -0,0 +1,35 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe History do
4
+
5
+ before do
6
+ Time.stub!(:now).and_return("NOW")
7
+ end
8
+
9
+ it "should record history" do
10
+ History.set("nofxx", "test")
11
+ History.all[0].should eql(["nofxx", "test", "NOW"])
12
+ end
13
+
14
+ it "should get last one " do
15
+ History.last.should eql(["nofxx", "test", "NOW"])
16
+ end
17
+
18
+ it "should find all" do
19
+ History.set("nofxx", "jah")
20
+ History.all.should eql([["nofxx", "test", "NOW"], ["nofxx", "jah", "NOW"]])
21
+ end
22
+
23
+ it "should filter by user" do
24
+ History.set("foo", "test")
25
+ History.all("foo").should eql([["foo", "test", "NOW"]])
26
+ end
27
+
28
+ it "should clear it" do
29
+ History.clear
30
+ History.should be_empty
31
+ end
32
+
33
+
34
+
35
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Install do
4
+
5
+ it "should write to the correct path" do
6
+ pending
7
+ i = Install.new
8
+ i.stub!(:gets).and_return("")
9
+ File.should_receive(:open).with("jah")
10
+ i.write_down
11
+
12
+ end
13
+
14
+ end
15
+
@@ -0,0 +1,37 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Opt do
4
+
5
+ it "should behave as an hash" do
6
+ Opt[:foo] = 5
7
+ Opt[:foo].should eql(5)
8
+ end
9
+
10
+ it "should be lil more smart" do
11
+ Opt.numero = 5
12
+ Opt.numero.should eql(5)
13
+ end
14
+
15
+ it "should work with booleans" do
16
+ Opt.evil = true
17
+ Opt.evil.should be_true
18
+ end
19
+
20
+ it "should even provide a ?" do
21
+ Opt.evil = true
22
+ Opt.should be_evil
23
+ end
24
+
25
+ it "should get hostname" do
26
+ Opt.should_receive(:"`").with("hostname").and_return("msweet")
27
+ Opt.hostname.should eql("msweet")
28
+ end
29
+
30
+
31
+ it "should get locale" do
32
+ Opt.should_receive(:"`").with("locale | grep LANG").and_return("LANG=en_US.utf8")
33
+ Opt.locale.should eql("en_us")
34
+ end
35
+
36
+
37
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+
4
+ describe Prayer do
5
+
6
+
7
+
8
+ end
data/spec/jah_spec.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Jah" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
4
+
5
+ it "should load the locales fine" do
6
+ I18n.available_locales.should include :pt_br
6
7
  end
8
+
7
9
  end
data/spec/spec_helper.rb CHANGED
@@ -3,7 +3,9 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  require 'jah'
4
4
  require 'spec'
5
5
  require 'spec/autorun'
6
+ include Jah
6
7
 
7
8
  Spec::Runner.configure do |config|
8
-
9
+ #config.mock_with :rr
10
+
9
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jah
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcos Piccinini
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-29 00:00:00 -03:00
12
+ date: 2009-11-26 00:00:00 -02:00
13
13
  default_executable: jah
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: "0"
23
+ version: 0.4.7
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: i18n
@@ -42,7 +42,7 @@ dependencies:
42
42
  - !ruby/object:Gem::Version
43
43
  version: "0"
44
44
  version:
45
- description: talk to your machines
45
+ description: Talk to your machines. Like a God.
46
46
  email: x@nofxx.com
47
47
  executables:
48
48
  - jah
@@ -61,33 +61,64 @@ files:
61
61
  - bin/jah
62
62
  - jah.gemspec
63
63
  - lib/jah.rb
64
- - lib/jah.yaml.template
64
+ - lib/jah/act_pkg.rb
65
+ - lib/jah/act_pkg/apt.rb
66
+ - lib/jah/act_pkg/base.rb
67
+ - lib/jah/act_pkg/emerge.rb
68
+ - lib/jah/act_pkg/pacman.rb
69
+ - lib/jah/act_pkg/pkg.rb
70
+ - lib/jah/act_pkg/ports.rb
71
+ - lib/jah/act_pkg/slack.rb
72
+ - lib/jah/act_pkg/urpm.rb
73
+ - lib/jah/act_pkg/yum.rb
74
+ - lib/jah/act_pkg/zypp.rb
65
75
  - lib/jah/agent.rb
66
76
  - lib/jah/agents/dump.rb
67
77
  - lib/jah/agents/post.rb
68
78
  - lib/jah/agents/xmpp.rb
69
79
  - lib/jah/cli.rb
70
- - lib/jah/collector.rb
71
- - lib/jah/collectors/cpu.rb
72
- - lib/jah/collectors/disk.rb
73
- - lib/jah/collectors/mem.rb
74
- - lib/jah/collectors/net.rb
75
- - lib/jah/collectors/prok.rb
76
- - lib/jah/collectors/services.rb
77
- - lib/jah/collectors/who.rb
78
80
  - lib/jah/command.rb
79
81
  - lib/jah/commands/admin.rb
82
+ - lib/jah/commands/cpu.rb
83
+ - lib/jah/commands/disk.rb
80
84
  - lib/jah/commands/extra.rb
81
- - lib/jah/commands/pub.rb
85
+ - lib/jah/commands/mem.rb
86
+ - lib/jah/commands/netstat.rb
87
+ - lib/jah/commands/packages.rb
88
+ - lib/jah/commands/prok.rb
89
+ - lib/jah/commands/services.rb
82
90
  - lib/jah/commands/status.rb
83
- - lib/jah/god.rb
91
+ - lib/jah/commands/who.rb
92
+ - lib/jah/history.rb
84
93
  - lib/jah/install.rb
94
+ - lib/jah/opt.rb
95
+ - lib/jah/prayer.rb
85
96
  - lib/locales/en_us.yml
86
97
  - lib/locales/pt_br.yml
87
98
  - lib/locales/pt_br_gostosa.yml
88
99
  - lib/locales/pt_br_mano.yml
89
100
  - lib/locales/pt_br_mineiro.yml
90
101
  - spec/console
102
+ - spec/jah/act_pkg/apt_spec.rb
103
+ - spec/jah/act_pkg/pacman_spec.rb
104
+ - spec/jah/act_pkg/pkg_spec.rb
105
+ - spec/jah/act_pkg/ports_spec.rb
106
+ - spec/jah/act_pkg/yum_spec.rb
107
+ - spec/jah/act_pkg_spec.rb
108
+ - spec/jah/agent_spec.rb
109
+ - spec/jah/agents/xmpp_spec.rb
110
+ - spec/jah/cli_spec.rb
111
+ - spec/jah/command_spec.rb
112
+ - spec/jah/commands/cpu_spec.rb
113
+ - spec/jah/commands/disk_spec.rb
114
+ - spec/jah/commands/mem_spec.rb
115
+ - spec/jah/commands/netstat_spec.rb
116
+ - spec/jah/commands/prok_spec.rb
117
+ - spec/jah/commands/who_spec.rb
118
+ - spec/jah/history_spec.rb
119
+ - spec/jah/install_spec.rb
120
+ - spec/jah/opt_spec.rb
121
+ - spec/jah/prayer_spec.rb
91
122
  - spec/jah_spec.rb
92
123
  - spec/spec_helper.rb
93
124
  has_rdoc: true
@@ -117,7 +148,27 @@ rubyforge_project:
117
148
  rubygems_version: 1.3.5
118
149
  signing_key:
119
150
  specification_version: 3
120
- summary: be omnipresent...
151
+ summary: Be omnipresent...
121
152
  test_files:
153
+ - spec/jah/cli_spec.rb
154
+ - spec/jah/agents/xmpp_spec.rb
155
+ - spec/jah/install_spec.rb
156
+ - spec/jah/commands/mem_spec.rb
157
+ - spec/jah/commands/cpu_spec.rb
158
+ - spec/jah/commands/who_spec.rb
159
+ - spec/jah/commands/netstat_spec.rb
160
+ - spec/jah/commands/disk_spec.rb
161
+ - spec/jah/commands/prok_spec.rb
162
+ - spec/jah/agent_spec.rb
163
+ - spec/jah/command_spec.rb
164
+ - spec/jah/act_pkg/yum_spec.rb
165
+ - spec/jah/act_pkg/apt_spec.rb
166
+ - spec/jah/act_pkg/pkg_spec.rb
167
+ - spec/jah/act_pkg/ports_spec.rb
168
+ - spec/jah/act_pkg/pacman_spec.rb
169
+ - spec/jah/opt_spec.rb
170
+ - spec/jah/act_pkg_spec.rb
171
+ - spec/jah/prayer_spec.rb
172
+ - spec/jah/history_spec.rb
122
173
  - spec/jah_spec.rb
123
174
  - spec/spec_helper.rb
data/lib/jah/collector.rb DELETED
@@ -1,12 +0,0 @@
1
- module Jah
2
-
3
- class Collector
4
-
5
-
6
- def self.quick_results
7
- "CPU #{Cpu.get.load}, MEM #{Mem.get.percent}%"
8
- end
9
-
10
-
11
- end
12
- end
@@ -1,35 +0,0 @@
1
- module Jah
2
- class Cpu < Collector
3
- attr_reader :load, :one, :five, :ten, :med
4
- EXEC = "uptime"
5
-
6
- def self.get
7
- new
8
- end
9
-
10
- def initialize
11
- l = cpu_load
12
- @one = l[:one]
13
- @five = l[:five]
14
- @ten = l[:ten]
15
- @load = l.values.join(", ")
16
- @med = @ten / cores
17
- end
18
-
19
- def cpu_load
20
- if `#{EXEC}` =~ /load average(s*): ([\d.]+)(,*) ([\d.]+)(,*) ([\d.]+)\Z/
21
- { :one => $2.to_f,
22
- :five => $4.to_f,
23
- :ten => $6.to_f }
24
- end
25
- end
26
-
27
- def cores
28
- case RUBY_PLATFORM
29
- when /linux/ then `cat /proc/cpuinfo | grep 'model name' | wc -l`.to_i
30
- when /darwin/ then `hwprefs cpu_count`.to_i
31
- else 1
32
- end
33
- end
34
- end
35
- end
@@ -1,14 +0,0 @@
1
- module Jah
2
-
3
- class Disk < Collector
4
- EXEC = "df -h"
5
-
6
- def self.all
7
- @disks = `#{EXEC}`.to_a.reject { |dl| dl =~ /Size|none/ }.map do |l|
8
- l = l.split(" ")
9
- { :path => l[0], :total => l[1], :used => l[2], :avail => l[3], :percent => l[4]}
10
- end
11
- end
12
-
13
- end
14
- end
@@ -1,51 +0,0 @@
1
- module Jah
2
-
3
- class Mem < Collector
4
- attr_reader :total, :free, :used, :percent, :cached, :buffered,
5
- :swap_total, :swap_free, :swap_used, :swap_percent
6
-
7
- EXEC = "cat /proc/meminfo"
8
-
9
- def self.get
10
- new
11
- end
12
-
13
- def initialize
14
- do_something
15
- end
16
-
17
- def do_something
18
- mem_info = {}
19
- `#{EXEC}`.each do |line|
20
- _, key, value = *line.match(/^(\w+):\s+(\d+)\s/)
21
- mem_info[key] = value.to_i
22
- end
23
-
24
- # memory info is empty - operating system may not support it (why doesn't an exception get raised earlier on mac osx?)
25
- raise "No such file or directory" if mem_info.empty?
26
-
27
- @total = mem_info['MemTotal'] / 1024
28
- @free = (mem_info['MemFree'] + mem_info['Buffers'] + mem_info['Cached']) / 1024
29
- @used = @total - @free
30
- @percent = (@used / @total.to_f * 100).to_i
31
-
32
- @swap_total = mem_info['SwapTotal'] / 1024
33
- @swap_free = mem_info['SwapFree'] / 1024
34
- @swap_used = swap_total - swap_free
35
- unless @swap_total == 0
36
- @swap_percent = (@swap_used / @swap_total.to_f * 100).to_i
37
- end
38
- rescue Exception => e
39
- if e.message =~ /No such file or directory/
40
- puts "/proc/meminfo not found.. trying top!"
41
- top = `top -l 1`.to_a[5].split.map!{|m| m[0..-2].to_i}.reject(&:zero?)
42
- @used, @free = top[3,4]
43
- @total = @used + @free
44
- @percent = (@used / @total.to_f * 100).to_i
45
- else
46
- raise e
47
- end
48
- end
49
-
50
- end
51
- end
@@ -1,88 +0,0 @@
1
- module Jah
2
-
3
- class Ps < Collector
4
- COMM = "ps auxww"
5
-
6
- def self.all
7
- `#{COMM}`.to_a[1..-1].map do |l|
8
- Prok.new(l.split)
9
- end
10
- end
11
-
12
- def self.find(name)
13
-
14
- end
15
-
16
-
17
- end
18
-
19
- class Prok
20
- BANLIST = [/^ata/, /^init$/, /^scsi_/, /\/\d$/, /agetty/ ]
21
- attr_reader :pid, :comm, :cpu, :mem, :rss, :vsz, :stat
22
-
23
- def initialize(args) # USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
24
- return unless args[0]
25
- @user = args[0]
26
- @pid = args[1].chomp.to_i
27
- @cpu = args[2].chomp.to_f
28
- @mem = args[3].chomp.to_f
29
- @vsz = args[4].chomp.to_i
30
- @rss = args[5].chomp.to_i
31
- @tty = args[6]
32
- @stat = args[7]
33
- @start = args[8]
34
- @time = args[9]
35
- @comm = args[10]
36
- #@shr = args[6]
37
- end
38
-
39
- def hup!
40
- exec "kill -1 #{pid}"
41
- end
42
-
43
- def kill!
44
- exec "kill #{pid}"
45
- end
46
-
47
- def move_to_acre!
48
- exec "kill -9 #{pid}"
49
- end
50
-
51
- def self.genocide!(ary, f = nil)
52
- for prok in ary
53
- prok.kill
54
- end
55
- end
56
-
57
- def exec(comm)
58
- # SSHWorker.new(@host, @host.user, comm)
59
- end
60
-
61
- def force(f)
62
- { :hup => "-1", :die => "-9"}[f]
63
- end
64
- end
65
-
66
- end
67
-
68
- # COMM = {
69
- # :top => "top -n 1",
70
- # }
71
-
72
-
73
-
74
- # def top
75
- # info, tasks, cpus, mem, swap, n, n, *rest = *@res[:top]
76
- # n, total, used, free, buffered = *mem.match(/(\d*)k\D*(\d*)k\D*(\d*)k\D*(\d*)k.*/)
77
- # cached = swap.match(/(\d*)k cached/)[0]
78
- # proks = rest.map do |r|
79
- # r.split(" ")
80
- # end
81
-
82
- # # fail... top don't show a good stat....
83
- # @proks = proks.reject do |p|
84
- # p[0] == nil || Prok::BANLIST.select{ |pl| pl =~ p[11] }[0]
85
- # end
86
- # rescue => e
87
- # nil
88
- # end
@@ -1,13 +0,0 @@
1
- module Jah
2
- class Services < Collector
3
-
4
-
5
-
6
-
7
-
8
- end
9
-
10
-
11
-
12
-
13
- end
@@ -1,20 +0,0 @@
1
- module Jah
2
-
3
- class Who < Collector
4
- EXEC = "who"
5
-
6
- def self.all
7
- @who = `#{EXEC}`.to_a.map do |l|
8
- l = l.split(" ")
9
-
10
- hash = {}
11
-
12
- hash[:who] = l[0]
13
- hash[:terminal] = l[1]
14
- 2.times{ l.delete(l[0]) }
15
- hash[:date] = l.join(" ")
16
- hash
17
- end
18
- end
19
- end
20
- end
@@ -1,34 +0,0 @@
1
- require "blather/client/dsl"
2
-
3
- module Jah
4
-
5
- class Pub
6
- include Command
7
-
8
- register :create, 'create\spubsub.*'
9
-
10
-
11
- def self.create(_, node)
12
- # pubsub = Blather::DSL::PubSub.new()
13
- request(Blather::Stanza::PubSub::Create.new(:set,
14
- "Jah.host.com", node)) { |n| yield n if block_given? }
15
-
16
-
17
- end
18
-
19
- def self.all
20
-
21
-
22
- end
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
- end
34
- end
data/lib/jah/god.rb DELETED
@@ -1,24 +0,0 @@
1
- # def setup
2
- # DRb.start_service
3
- # @server = DRbObject.new(nil, God::Socket.socket(@config['god_port'])) || nil
4
- # rescue => e
5
- # @config[:god] = false
6
- # end
7
-
8
- # # ping server to ensure that it is responsive
9
- # def ping
10
- # if god?
11
- # tries = 3
12
- # begin
13
- # @server.ping
14
- # rescue Exception => e
15
- # retry if (tries -= 1) > 1
16
- # raise e, "The server is not available (or you do not have permissions to access it)"
17
- # end
18
- # end
19
- # end
20
-
21
-
22
- # def god?
23
- # @config[:god]
24
- # end
@@ -1,26 +0,0 @@
1
- # Jah Config file for 'HOST'
2
- ---
3
- :mode: MODE
4
- :i18n: I18N
5
-
6
- # Auth
7
- :jid: JID
8
- :host: HOST
9
- :key: KEY
10
-
11
- # Access
12
- :acl: ACL
13
- :groups: GROUPS
14
-
15
- # Opts
16
- :eval: EVAL
17
- :god: GOD
18
- :debug: DEBUG
19
- :report: REPORT
20
- :daemon: true
21
-
22
- # Alerts
23
- alerts:
24
- :max_cpu:
25
- :max_mem:
26
- :max_swp: