amiral 0.1.0 → 0.1.1
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.
- data/amiral.gemspec +1 -0
- data/lib/amiral/version.rb +1 -1
- data/lib/amiral.rb +75 -1
- metadata +18 -2
data/amiral.gemspec
CHANGED
data/lib/amiral/version.rb
CHANGED
data/lib/amiral.rb
CHANGED
@@ -18,7 +18,7 @@ module Amiral
|
|
18
18
|
module Providers
|
19
19
|
class Uptime
|
20
20
|
|
21
|
-
PATTERN = /^([0-9:]+) up (.*),[ \t]+([0-9]+) users
|
21
|
+
PATTERN = /^([0-9:]+) up (.*),[ \t]+([0-9]+) users?,[ \t]+load average: ([0-9.]+), ([0-9.]+), ([0-9.]+)/
|
22
22
|
def execute message
|
23
23
|
uptime = `uptime`.strip
|
24
24
|
|
@@ -41,6 +41,77 @@ module Amiral
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
class PuppetAgent
|
45
|
+
def execute message
|
46
|
+
out = err = short = nil
|
47
|
+
status = POpen4::popen4("puppet agent -t"){|stdout,stderr,stdin,pid|
|
48
|
+
out = stdout.read
|
49
|
+
err = stderr.read
|
50
|
+
}
|
51
|
+
short = "unknown status"
|
52
|
+
case status
|
53
|
+
when 0:
|
54
|
+
short = "nothing to do, i'm all good"
|
55
|
+
when 2:
|
56
|
+
short = "successfully applied changes"
|
57
|
+
when 4:
|
58
|
+
short = "encountered catalog application errors"
|
59
|
+
when 6:
|
60
|
+
short = "errors encountered, managed to apply some changes"
|
61
|
+
end
|
62
|
+
|
63
|
+
{
|
64
|
+
:exit => ((status == 0) || (status == 2)) ? 0 : 1,
|
65
|
+
:status => status,
|
66
|
+
:short => short,
|
67
|
+
:out => out,
|
68
|
+
:err => err
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class AptGetUpdate
|
74
|
+
def execute message
|
75
|
+
out = err = nil
|
76
|
+
status = POpen4::popen4("apt-get update"){|stdout,stderr,stdin,pid|
|
77
|
+
out = stdout.read
|
78
|
+
err = stderr.read
|
79
|
+
}
|
80
|
+
{
|
81
|
+
:exit => status,
|
82
|
+
:short => (status == 0) ? "apt-get update ran fine" : "apt-get cannot perform update!",
|
83
|
+
:out => out,
|
84
|
+
:err => err
|
85
|
+
}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class Service
|
90
|
+
def execute message
|
91
|
+
action = "reload"
|
92
|
+
service = message['command']['args'][0]
|
93
|
+
if message['command']['args'].length > 1
|
94
|
+
action = message['command']['args'][1]
|
95
|
+
end
|
96
|
+
|
97
|
+
raise "unknown service command" unless ["stop", "start", "restart", "status", "reload"].include? action
|
98
|
+
|
99
|
+
out = err = nil
|
100
|
+
status = POpen4::popen4("service #{service} #{action}"){|stdout, stderr, stdin, pid|
|
101
|
+
out = stdout.read
|
102
|
+
err = stderr.read
|
103
|
+
|
104
|
+
}
|
105
|
+
{
|
106
|
+
:exit = status,
|
107
|
+
:short = (status == 0) ? "service #{service} #{action} successful" :
|
108
|
+
"service #{service} #{action} failed!",
|
109
|
+
:out => out,
|
110
|
+
:err => err
|
111
|
+
}
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
44
115
|
class Facts
|
45
116
|
def execute message
|
46
117
|
facts = Facter.to_hash
|
@@ -76,6 +147,9 @@ module Amiral
|
|
76
147
|
"facts" => Amiral::Providers::Facts,
|
77
148
|
"provider_list" => Amiral::Providers::ProviderList,
|
78
149
|
"ping" => Amiral::Providers::Ping,
|
150
|
+
"puppet-agent" => Amiral::Providers::PuppetAgent,
|
151
|
+
"apt-update" => Amiral::Providers::AptGetUpdate,
|
152
|
+
"service" => Amiral::Providers::Service,
|
79
153
|
"invalid" => Amiral::Providers::Invalid
|
80
154
|
}
|
81
155
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amiral
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
@@ -107,6 +107,22 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: popen4
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
110
126
|
description: simple command and control based on redis
|
111
127
|
email:
|
112
128
|
- pyr@spootnik.org
|