apocalypse-client 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/apocalypse-client.rb +13 -10
- data/lib/apocalypse-client/version.rb +1 -1
- data/spec/client_spec.rb +3 -3
- metadata +3 -3
data/lib/apocalypse-client.rb
CHANGED
@@ -18,10 +18,11 @@ end
|
|
18
18
|
|
19
19
|
module Apocalypse
|
20
20
|
class Client
|
21
|
-
|
22
|
-
def self.
|
23
|
-
def self.
|
24
|
-
|
21
|
+
# Was "#{File.dirname(__FILE__)}/../host.yml"
|
22
|
+
def self.host_file; "/etc/apocalypse.yml"; end
|
23
|
+
def self.cron_job_file; "/etc/cron.d/apocalypse"; end
|
24
|
+
def self.rvm?; !`which rvm`.chomp.empty? end
|
25
|
+
|
25
26
|
def self.cron_job_command
|
26
27
|
return rvm? \
|
27
28
|
? " * * * * * root PATH=$PATH:/sbin:/usr/sbin rvm use $RUBY_VERSION ; /usr/local/bin/rvm exec apocalypse-client report > /dev/null" \
|
@@ -35,7 +36,7 @@ module Apocalypse
|
|
35
36
|
Net::HTTP.start(properties[:server_address], properties[:port]) do |http|
|
36
37
|
request.basic_auth(properties[:username], properties[:password])
|
37
38
|
response = http.request(request)
|
38
|
-
|
39
|
+
|
39
40
|
Apocalyse::Client::Response.parse!(response)
|
40
41
|
end
|
41
42
|
end
|
@@ -53,6 +54,7 @@ module Apocalypse
|
|
53
54
|
puts "Everything seems to be in place. You're good to go."
|
54
55
|
else
|
55
56
|
errors.each { |error| puts errors }
|
57
|
+
exit(1)
|
56
58
|
end
|
57
59
|
end
|
58
60
|
|
@@ -66,6 +68,7 @@ module Apocalypse
|
|
66
68
|
end
|
67
69
|
|
68
70
|
def install(options)
|
71
|
+
check(options)
|
69
72
|
installation = Apocalyse::Client::Install.new
|
70
73
|
installation.install!
|
71
74
|
end
|
@@ -143,18 +146,18 @@ module Apocalypse
|
|
143
146
|
'rxbytes' => `/usr/bin/env ifconfig #{device_name} | grep bytes | awk '/RX/ {print $2}' | tr -s ':' ' ' | awk '{print $2}'`.strip,
|
144
147
|
'txbytes' => `/usr/bin/env ifconfig #{device_name} | grep bytes | awk '/TX/ {print $6}' | tr -s ':' ' ' | awk '{print $2}'`.strip,
|
145
148
|
'ipv4address' => `/usr/bin/env ifconfig #{device_name} | egrep -o 'inet addr\:[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | tr -s ':' ' ' | awk '{print $3}'`.strip,
|
146
|
-
'broadcast' => `/usr/bin/env ifconfig #{device_name} | egrep -o Bcast\:[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\} | tr -s ':' ' ' | awk '{print $2}'`.strip,
|
147
|
-
'netmask' => `/usr/bin/env ifconfig #{device_name} | egrep -o Mask\:[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\} | tr -s ':' ' ' | awk '{print $2}'`.strip,
|
149
|
+
'broadcast' => `/usr/bin/env ifconfig #{device_name} | egrep -o 'Bcast\:[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | tr -s ':' ' ' | awk '{print $2}'`.strip,
|
150
|
+
'netmask' => `/usr/bin/env ifconfig #{device_name} | egrep -o 'Mask\:[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | tr -s ':' ' ' | awk '{print $2}'`.strip,
|
148
151
|
'gateway' => `netstat -rn | grep ^0.0.0.0 | grep UG | grep #{device_name} | awk '{print $2}' | head -n1`.strip,
|
149
152
|
'ipv6addr' => `/usr/bin/env ifconfig #{device_name} | egrep -o 'inet6 addr\:\ \([a-fA-F0-9]\{1,4}\:\{1,2\}[a-fA-F0-9]\{1,4}\:\{1,2\}\)+[A-Fa-f0-9\/^\ ]+' | awk '{print $3}'`.strip,
|
150
|
-
'ipv6scope' => `/usr/bin/env ifconfig #{device_name} | egrep -o Scope\:[a-zA-Z]+ | cut -d":" -f2`.strip
|
153
|
+
'ipv6scope' => `/usr/bin/env ifconfig #{device_name} | egrep -o 'Scope\:[a-zA-Z]+' | cut -d":" -f2`.strip
|
151
154
|
}}
|
152
155
|
end
|
153
156
|
end
|
154
|
-
|
157
|
+
|
155
158
|
private
|
156
159
|
def properties
|
157
|
-
throw Exception.new("Host file not found. Please run `
|
160
|
+
throw Exception.new("Host file not found. Please run `apocalypse-client now`") unless File.exists?(self.class.host_file)
|
158
161
|
@properties ||= ::YAML.load(File.open(self.class.host_file))
|
159
162
|
end
|
160
163
|
end
|
data/spec/client_spec.rb
CHANGED
@@ -53,11 +53,11 @@ describe Apocalypse::Client do
|
|
53
53
|
"/usr/bin/env ifconfig eth0 | grep bytes | awk '/RX/ {print $2}' | tr -s ':' ' ' | awk '{print $2}'" => "384735745",
|
54
54
|
"/usr/bin/env ifconfig eth0 | grep bytes | awk '/TX/ {print $6}' | tr -s ':' ' ' | awk '{print $2}'" => "3575372573",
|
55
55
|
"/usr/bin/env ifconfig eth0 | egrep -o 'inet addr\:[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | tr -s ':' ' ' | awk '{print $3}'" => "10.187.234.18",
|
56
|
-
"/usr/bin/env ifconfig eth0 | egrep -o Bcast\:[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\} | tr -s ':' ' ' | awk '{print $2}'" => "10.187.234.254",
|
57
|
-
"/usr/bin/env ifconfig eth0 | egrep -o Mask\:[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\} | tr -s ':' ' ' | awk '{print $2}'" => "255.0.0.0",
|
56
|
+
"/usr/bin/env ifconfig eth0 | egrep -o 'Bcast\:[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | tr -s ':' ' ' | awk '{print $2}'" => "10.187.234.254",
|
57
|
+
"/usr/bin/env ifconfig eth0 | egrep -o 'Mask\:[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | tr -s ':' ' ' | awk '{print $2}'" => "255.0.0.0",
|
58
58
|
"netstat -rn | grep ^0.0.0.0 | grep UG | grep eth0 | awk '{print $2}' | head -n1" => "10.187.234.1",
|
59
59
|
"/usr/bin/env ifconfig eth0 | egrep -o 'inet6 addr\:\ \([a-fA-F0-9]\{1,4}\:\{1,2\}[a-fA-F0-9]\{1,4}\:\{1,2\}\)+[A-Fa-f0-9\/^\ ]+' | awk '{print $3}'" => "fe80::1031:3cff:fe00:bde1/64",
|
60
|
-
"/usr/bin/env ifconfig eth0 | egrep -o Scope\:[a-zA-Z]+ | cut -d\":\" -f2" => "Link"
|
60
|
+
"/usr/bin/env ifconfig eth0 | egrep -o 'Scope\:[a-zA-Z]+' | cut -d\":\" -f2" => "Link"
|
61
61
|
}.each do |command, result|
|
62
62
|
@reporter.should_receive(:`).with(command).and_return(result)
|
63
63
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apocalypse-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ariejan de Vroom
|