diff options
author | Saku Ytti <saku@ytti.fi> | 2014-08-07 13:27:03 +0300 |
---|---|---|
committer | Saku Ytti <saku@ytti.fi> | 2014-08-07 13:27:03 +0300 |
commit | 2a77796a7caf10601ae8edea5bf996f951694985 (patch) | |
tree | e38454fe9e78f16231049ed8c44365b7ea476244 /lib/oxidized/model/model.rb | |
parent | bf299889f54b468412df4822b515cf7c4d60f90d (diff) |
Pass model config as Outputs object instead of str
These objects have some keys, such as 'type' and 'name', which allows
our output model to discriminate on them.
If ios.rb contains this:
cmd 'show ip cef' do |out|
{ output: out, type: 'poop' }
end
cmd 'show process cpu' do |out|
{ output: out, type: 'poop' }
end
cmd 'show memory statistics' do |out|
{ output: out, type: 'poop' }
end
Our git output looks like this:
[ytti@ytti.fi ~/.config/oxidized]% git clone oxidized.git
Cloning into 'oxidized'...
done.
[ytti@ytti.fi ~/.config/oxidized]% git clone poop.git
Cloning into 'poop'...
done.
[ytti@ytti.fi ~/.config/oxidized]% ls poop
bu.ip.fi--show_ip_cef bu.ip.fi--show_memory_statistics bu.ip.fi--show_process_cpu
[ytti@ytti.fi ~/.config/oxidized]% ls oxidized
bu.ip.fi
[ytti@ytti.fi ~/.config/oxidized]%
Where oxidized repo contains standard config for all unspecified types (type is
then 'cfg'), for all specified types instead of collapsing it into single
string, we store them in 'type' repo with filename including 'name' of the
command.
Diffstat (limited to 'lib/oxidized/model/model.rb')
-rw-r--r-- | lib/oxidized/model/model.rb | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/oxidized/model/model.rb b/lib/oxidized/model/model.rb index c3d8760..af86f1d 100644 --- a/lib/oxidized/model/model.rb +++ b/lib/oxidized/model/model.rb @@ -1,3 +1,5 @@ +require_relative 'outputs' + module Oxidized class Model include Oxidized::Config::Vars @@ -87,7 +89,7 @@ module Oxidized end end out = instance_exec out, &block if block - out + process_cmd_output out, string end def output @@ -124,20 +126,20 @@ module Oxidized end def get - data, pre = '', '' + outputs = Outputs.new procs = self.class.procs + procs[:pre].each do |pre_proc| + outputs << instance_eval(&pre_proc) + end self.class.cmds[:cmd].each do |command, block| out = cmd command, &block return false unless out - data << out.to_s - end - procs[:pre].each do |pre_proc| - pre << instance_eval(&pre_proc).to_s + outputs << out end procs[:post].each do |post_proc| - data << instance_eval(&post_proc).to_s + outputs << instance_eval(&post_proc) end - pre + data + outputs end def comment _comment @@ -148,5 +150,15 @@ module Oxidized data end + private + + def process_cmd_output cmd, name + if Hash === cmd + cmd[:name] = name + return cmd + end + {:output=>cmd, :type=>'cfg', :name=>name} + end + end end |