swiss_admin 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +275 -0
  6. data/Rakefile +8 -0
  7. data/bin/swissadmin +8 -0
  8. data/lib/swiss_admin.rb +9 -0
  9. data/lib/swiss_admin/cli.rb +6 -0
  10. data/lib/swiss_admin/cli/cli.rb +19 -0
  11. data/lib/swiss_admin/cli/hardware_cli.rb +19 -0
  12. data/lib/swiss_admin/cli/host_cli.rb +18 -0
  13. data/lib/swiss_admin/cli/network_cli.rb +19 -0
  14. data/lib/swiss_admin/cli/user_cli.rb +25 -0
  15. data/lib/swiss_admin/cli/web_cli.rb +68 -0
  16. data/lib/swiss_admin/hardware.rb +2 -0
  17. data/lib/swiss_admin/hardware/cpus.rb +11 -0
  18. data/lib/swiss_admin/hardware/memory.rb +36 -0
  19. data/lib/swiss_admin/host.rb +1 -0
  20. data/lib/swiss_admin/host/host.rb +15 -0
  21. data/lib/swiss_admin/network.rb +1 -0
  22. data/lib/swiss_admin/network/network.rb +13 -0
  23. data/lib/swiss_admin/user.rb +1 -0
  24. data/lib/swiss_admin/user/user.rb +18 -0
  25. data/lib/swiss_admin/version.rb +3 -0
  26. data/lib/swiss_admin/web/app.rb +60 -0
  27. data/lib/swiss_admin/web/public/css/base.css +269 -0
  28. data/lib/swiss_admin/web/public/css/layout.css +58 -0
  29. data/lib/swiss_admin/web/public/css/skeleton.css +242 -0
  30. data/lib/swiss_admin/web/public/css/tables.css +46 -0
  31. data/lib/swiss_admin/web/public/images/apple-touch-icon-114x114.png +0 -0
  32. data/lib/swiss_admin/web/public/images/apple-touch-icon-72x72.png +0 -0
  33. data/lib/swiss_admin/web/public/images/apple-touch-icon.png +0 -0
  34. data/lib/swiss_admin/web/public/images/favicon.ico +0 -0
  35. data/lib/swiss_admin/web/public/javascript/jquery-2.1.0.min.js +4 -0
  36. data/lib/swiss_admin/web/views/info.erb +60 -0
  37. data/lib/swiss_admin/web/views/layout.erb +25 -0
  38. data/swiss_admin.gemspec +29 -0
  39. data/test/cli/cli_hardware_test.rb +21 -0
  40. data/test/cli/cli_host_test.rb +20 -0
  41. data/test/cli/cli_network_test.rb +17 -0
  42. data/test/cli/cli_user_test.rb +28 -0
  43. data/test/hardware_test.rb +9 -0
  44. data/test/host_test.rb +12 -0
  45. data/test/network_test.rb +14 -0
  46. data/test/test_helper.rb +28 -0
  47. data/test/user_test.rb +17 -0
  48. data/test/web/test_api.rb +70 -0
  49. data/test/web/test_host_info.rb +44 -0
  50. metadata +216 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 63eff973bde4a3cbdc4db697e985346757472687
4
+ data.tar.gz: 5daea5b752c885c7539c7289cbb9c9da2bf287c2
5
+ SHA512:
6
+ metadata.gz: 4a469600791cf64ef5d448c4da69a8cdedcb65de6b0afaee0e63e376153451fba0f3be6dda574a77dc4fd021cedc3ad3ac45a1bfed4b2d42ec39dfb70472fc76
7
+ data.tar.gz: abd5c1846b50ea41da4b414720e98e86f702f49b9f62fd2ca27ad5aa0f3a15a8292f14a6c4ca43e6da8af44c0d52fc207e1352e190a1e9514a71a397466bf3e7
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in swiss_admin.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Bradley Smith
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,275 @@
1
+ # SwissAdmin
2
+
3
+ A generous, but not too bloated, system/host helpers for any self respecting system administrator ;)
4
+
5
+ SwissAdmin can either be included in your project or can used from the CLI.
6
+
7
+ I find it best to install swissadmin in your global gemset.
8
+
9
+ ### This only works on Linux
10
+
11
+ ## Things that make swissadmin cool.
12
+
13
+ 1. It offers just the right amount of information about the system/host your are running it on.
14
+ 2. Provides a web server for REST calls.
15
+ 3. Provides a DRb server to query host for information. (see todo)
16
+ 4. Everytime you use it puppies and rainbows shoot into the sky.
17
+
18
+ There a tons of tools that do similar stuff, but I find them to contain way to much information.
19
+ I do not have the brain capacity to remember all those arguments and parsing features.
20
+
21
+
22
+ ## Installation
23
+
24
+ Add this line to your application's Gemfile:
25
+
26
+ gem 'swiss_admin'
27
+
28
+ And then execute:
29
+
30
+ $ bundle
31
+
32
+ Or install it yourself as:
33
+
34
+ $ gem install swiss_admin
35
+
36
+ ## Usage
37
+
38
+ * only commands listed below are funcitonal currenlty
39
+
40
+ ```bash
41
+ Commands:
42
+ swissadmin hardware SUBCOMMAND # Returns information about host hardware
43
+ swissadmin help [COMMAND] # Describe available commands or one specific command
44
+ swissadmin host SUBCOMMAND # Returns information about the host
45
+ swissadmin network SUBCOMMAND # Returns information about host network
46
+ swissadmin user SUBCOMMAND # Returns information about user(s) on host
47
+ ```
48
+
49
+ ### Hardware
50
+ List information about the host's hardware
51
+
52
+ ```bash
53
+ Commands:
54
+ swissadmin hardware cpus # Number of cpu's
55
+ swissadmin hardware help [COMMAND] # Describe subcommands or one specific subcommand
56
+ swissadmin hardware memory # memory for host
57
+ ```
58
+
59
+ ```ruby
60
+ swissadmin hardware cpus #=> 4
61
+ ```
62
+
63
+ ```ruby
64
+ swissadmin hardware memory #=>
65
+ MemTotal 7873568
66
+ MemFree 3731188
67
+ Buffers 164064
68
+ .....
69
+ ```
70
+
71
+ ### Host
72
+
73
+ Returns information about the host
74
+
75
+ ```bash
76
+ commands:
77
+ swissadmin host help [COMMAND] # Describe subcommands or one specific subcommand
78
+ swissadmin host name # Hostname
79
+ swissadmin host loadavg # Current system load
80
+ ```
81
+
82
+ ```ruby
83
+ swissadmin host name #=> foo.local
84
+ ```
85
+
86
+ ```ruby
87
+ # 1,5,15,number of currently running processes/total number of processes, pid
88
+ swissadmin host loadavg #=> 0.10 0.19 0.23 1/742 24553
89
+ ```
90
+
91
+ ### Network
92
+
93
+ Return information about the host's network
94
+
95
+ ```bash
96
+ Commands:
97
+ swissadmin network first_ipv4 # First ipv4 interface
98
+ swissadmin network help [COMMAND] # Describe subcommands or one specific subcommand
99
+ swissadmin network ip_addresses # All the ip addresses on this host
100
+ ```
101
+
102
+ ```ruby
103
+ swissadmin host ip_addresses #=> {:ip_address=>"127.0.0.1", :name=>["localhost", "0"]}
104
+ {:ip_address=>"192.168.4.34", :name=>["bradleyd-900X4C.local", "0"]}
105
+ {:ip_address=>"::1", :name=>["ip6-localhost", "0"]}
106
+ {:ip_address=>"fe80::c685:8ff:fe72:beab%wlan0", :name=>["fe80::c685:8ff:fe72:beab%wlan0", "0"]}
107
+ ```
108
+
109
+ ```ruby
110
+ swissadmin host first_ipv4 #=> 192.168.0.5
111
+ ```
112
+
113
+ ### User
114
+
115
+ Return information about user(s)
116
+
117
+ ```bash
118
+ Commands:
119
+ swissadmin user active # All active users
120
+ swissadmin user current # Current user
121
+ swissadmin user help [COMMAND] # Describe subcommands or one specific subcommand
122
+ swissadmin user home # Current user's home directory
123
+ ```
124
+
125
+ ```ruby
126
+ swissadmin user active #=>
127
+ bradleyd tty7 :0 2days init --user
128
+ bradleyd pts/0 :0 57:24 bash
129
+ bradleyd pts/3 :0 1:06m bash
130
+ bradleyd pts/8 :0.0 4.00s w -s -h
131
+ ```
132
+
133
+ ```ruby
134
+ swissadmin user current #=> bradleyd
135
+ ```
136
+
137
+ ```ruby
138
+ swissadmin user home #=> /home/bradleyd
139
+ ```
140
+
141
+ ### Web
142
+ ```bash
143
+ Commands:
144
+ swissadmin web help [COMMAND] # Describe subcommands or one specific subcommand
145
+ swissadmin web start # Start web server
146
+ Usage:
147
+ swissadmin start
148
+ Options:
149
+ -p, [--port=PORT] # Set port for web companion
150
+ # Default: 8080
151
+
152
+ swissadmin web stop # Stop web server
153
+ swissadmin web status # Status of the web server
154
+ ```
155
+
156
+ ```ruby
157
+ swissadmin web start
158
+ ```
159
+ This also gives you an API which you can query
160
+
161
+ Every CLI command can be accessed via the REST API
162
+
163
+ ```ruby
164
+ curl localhost:8080/api/host/loadavg #=> {"load_average":"0.29 0.29 0.28 2/972 27659\n"}
165
+ ```
166
+ ## Contributing
167
+
168
+ 1. Fork it
169
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
170
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
171
+ 4. Push to the branch (`git push origin my-new-feature`)
172
+ 5. Create new Pull Request
173
+
174
+ ## Add a new command
175
+ ### This is a work in progress and might not be worth a dam
176
+
177
+ To add a new command you must understand the directory structures of ```lib/``` and ```cli/```
178
+
179
+ ### lib/
180
+
181
+ ```bash
182
+ lib/swiss_admin/
183
+ ├── hardware
184
+ │   ├── cpus.rb
185
+ │   └── memory.rb
186
+ ├── host
187
+ │   └── host.rb
188
+ ├── network
189
+ │   └── network.rb
190
+ ├── user
191
+ │   └── user.rb
192
+ ```
193
+
194
+ ### cli/
195
+ ```bash
196
+ lib/swiss_admin/cli/
197
+ ├── cli.rb
198
+ ├── hardware_cli.rb
199
+ ├── host_cli.rb
200
+ ├── network_cli.rb
201
+ └── user_cli.rb
202
+ ```
203
+
204
+ Let's say you have a need for a command called--you guessed it--```foo```
205
+
206
+ ```foo``` will give you the ultimate answer.
207
+
208
+ * I will assume you have written tests for ```foo``` you know who you are!
209
+
210
+ If ```foo``` does not fit in any category from ```lib/``` then you would create a new one.
211
+
212
+ Create a file and directory called foo and adjust to your liking.
213
+
214
+ ```ruby
215
+ # foo/foo.rb
216
+ module SwissAdmin
217
+ class Foo
218
+ def self.answer
219
+ "42"
220
+ end
221
+ end
222
+ end
223
+ ```
224
+
225
+ Run your tests...green I presume.
226
+
227
+ Create another file under ```cli/``` cleverly called ```foo_cli.rb```
228
+
229
+ ```ruby
230
+ module SwissAdmin
231
+ module Commands
232
+ class Foo < Thor
233
+ namespace :foo
234
+
235
+ desc "answer", "ultimate answer"
236
+ def answer
237
+ $stdout.puts SwissAdmin::Foo.answer
238
+ end
239
+
240
+ end
241
+ end
242
+ end
243
+ ```
244
+
245
+ * Note, we are calling ```Foo``` class from ```lib/``` instead of just creating it here
246
+ * This is so we can use ```swissadmin``` as library in another project and forgo the CLI
247
+
248
+
249
+ Next, we need to tell ```CLI``` about this new command.
250
+
251
+ ```ruby
252
+ #lib/cli/cli.rb
253
+
254
+ module SwissAdmin
255
+ class CLI < Thor
256
+ #....snippet....
257
+ desc "foo SUBCOMMAND", "Returns the ultimate answer"
258
+ subcommand "foo", SwissAdmin::Commands::Foo
259
+ end
260
+ end
261
+ ```
262
+
263
+ This will give ```swissadmin``` the ultimate power and bestow it upon you ;)
264
+
265
+ ```ruby
266
+ swissadmin foo answer #=> 42
267
+ ```
268
+
269
+ ### TODO
270
+
271
+ * create DRB server
272
+ * Lock down web server with basic auth or token
273
+ * Show all commands available in CLI
274
+ * Show all commands available in Web
275
+ * Write pid, port file path to `~/.swissadmin/.web.conf
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.options = "-v"
6
+ t.libs << "test"
7
+ t.test_files = FileList["test/*_test.rb", "test/cli/*_test.rb"]
8
+ end
data/bin/swissadmin ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib') unless $LOAD_PATH.include?(File.dirname(__FILE__) + '/../lib')
5
+ require "bundler/setup"
6
+ require 'swiss_admin'
7
+
8
+ SwissAdmin::CLI.start
@@ -0,0 +1,9 @@
1
+ require "swiss_admin/version"
2
+ require "swiss_admin/cli"
3
+ require "swiss_admin/host"
4
+ require "swiss_admin/hardware"
5
+ require "swiss_admin/network"
6
+ require "swiss_admin/user"
7
+
8
+ module SwissAdmin
9
+ end
@@ -0,0 +1,6 @@
1
+ require "swiss_admin/cli/host_cli"
2
+ require "swiss_admin/cli/hardware_cli"
3
+ require "swiss_admin/cli/network_cli"
4
+ require "swiss_admin/cli/user_cli"
5
+ require "swiss_admin/cli/web_cli"
6
+ require "swiss_admin/cli/cli"
@@ -0,0 +1,19 @@
1
+ require "thor"
2
+ module SwissAdmin
3
+ class CLI < Thor
4
+ desc "host SUBCOMMAND", "Returns information about the host"
5
+ subcommand "host", SwissAdmin::Commands::Host
6
+
7
+ desc "hardware SUBCOMMAND", "Returns information about host hardware"
8
+ subcommand "hardware", SwissAdmin::Commands::Hardware
9
+
10
+ desc "network SUBCOMMAND", "Returns information about host network"
11
+ subcommand "network", SwissAdmin::Commands::Network
12
+
13
+ desc "user SUBCOMMAND", "Returns information about user(s) on host"
14
+ subcommand "user", SwissAdmin::Commands::User
15
+
16
+ desc "web SUBCOMMAND", "A basic web ui with all of the hosts information"
17
+ subcommand "web", SwissAdmin::Commands::Web
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "thor"
2
+ module SwissAdmin
3
+ module Commands
4
+ class Hardware < Thor
5
+ namespace :hardware
6
+
7
+ desc "cpus", "Number of cpu's"
8
+ def cpus
9
+ $stdout.puts SwissAdmin::Hardware.cpus
10
+ end
11
+
12
+ desc "memory", "memory for host"
13
+ def memory
14
+ print_table(SwissAdmin::Hardware.memory)
15
+ end
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,18 @@
1
+ require "thor"
2
+ module SwissAdmin
3
+ module Commands
4
+ class Host < Thor
5
+ namespace :host
6
+
7
+ desc "name", "Hostname"
8
+ def name
9
+ $stdout.puts SwissAdmin::Host.name
10
+ end
11
+
12
+ desc "loadavg", "Current system load"
13
+ def loadavg
14
+ $stdout.puts SwissAdmin::Host.loadavg
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ require "thor"
2
+ module SwissAdmin
3
+ module Commands
4
+ class Network < Thor
5
+ namespace :network
6
+
7
+ desc "ip_addresses", "All the ip addresses on this host"
8
+ def ip_addresses
9
+ $stdout.puts SwissAdmin::Network.ip_addresses
10
+ end
11
+
12
+ desc "first_ipv4", "First ipv4 interface"
13
+ def first_ipv4
14
+ $stdout.puts SwissAdmin::Network.first_ipv4
15
+ end
16
+ end
17
+ end
18
+ end
19
+