amiral 0.1.8 → 0.1.9

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/lib/amiral/agent.rb CHANGED
@@ -40,6 +40,9 @@ module Amiral
40
40
  :port => @settings[:port],
41
41
  :driver => :hiredis,
42
42
  :logger => @logger
43
+
44
+ # start a thread which will refresh fact every minute
45
+ FactProvider.refresh
43
46
  end
44
47
 
45
48
  def run args
@@ -62,7 +65,8 @@ module Amiral
62
65
  @logger.debug "incoming message"
63
66
  message = deserialize payload
64
67
 
65
- if agent_matches? message['match']
68
+ if (agent_matches?(message['match']) and
69
+ PROVIDERS.has_key? message['command']['provider'])
66
70
  @logger.info "valid request type: #{message['command']['provider']}"
67
71
  uuid = uuidgen
68
72
  send_ack(:in_reply_to => message['reply_to'],
@@ -0,0 +1,34 @@
1
+ require 'rubygems'
2
+ require 'facter'
3
+
4
+ module Amiral
5
+ class FactProvider
6
+ def self.refresh
7
+ Thread.new do
8
+ while true
9
+ Facter.loadfacts
10
+ if File.exist?("/etc/facts.txt")
11
+ File.readlines("/etc/facts.txt").each do |line|
12
+ if line =~ /^(.+)=(.+)$/
13
+ var = $1; val = $2
14
+
15
+ Facter.add(var) do
16
+ setcode { val }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ sleep 60 # refresh every minute
23
+ end
24
+ end
25
+
26
+ def self.all
27
+ Facter.to_hash
28
+ end
29
+
30
+ def self.[](index)
31
+ Facter.value(index)
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,3 @@
1
- require 'rubygems'
2
- require 'facter'
3
1
 
4
2
  module Amiral
5
3
  class Matcher
@@ -21,7 +19,7 @@ module Amiral
21
19
 
22
20
  if @spec.has_key? :facts
23
21
  @spec[:facts].map do |k,v|
24
- return false unless Facter.value(k).to_s =~ Regexp.new(v)
22
+ return false unless FactProvider[k].to_s =~ Regexp.new(v)
25
23
  end
26
24
  end
27
25
  true
@@ -1,10 +1,9 @@
1
- require 'facter'
2
1
 
3
2
  module Amiral
4
3
  module Providers
5
4
  class Facts
6
5
  def execute message
7
- facts = Facter.to_hash
6
+ facts = Amiral::FactProvider.all
8
7
  {
9
8
  :exit => 0,
10
9
  :facts => facts,
@@ -1,3 +1,3 @@
1
1
  module Amiral
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.9'
3
3
  end
data/lib/amiral.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'amiral/fact_provider'
1
2
  require 'amiral/providers'
2
3
  require 'amiral/matcher'
3
4
  require 'amiral/message'
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.8
4
+ version: 0.1.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -124,6 +124,7 @@ files:
124
124
  - bin/amiral.rb
125
125
  - lib/amiral.rb
126
126
  - lib/amiral/agent.rb
127
+ - lib/amiral/fact_provider.rb
127
128
  - lib/amiral/matcher.rb
128
129
  - lib/amiral/message.rb
129
130
  - lib/amiral/providers.rb