From f0683725079035633f7b2e64c99af7e2ce2ad3e5 Mon Sep 17 00:00:00 2001 From: Cyril LAVIER Date: Wed, 3 May 2017 14:05:28 +0200 Subject: Added support for model specific credentials --- README.md | 11 +++++++++++ lib/oxidized/config.rb | 1 + lib/oxidized/config/vars.rb | 6 +++++- lib/oxidized/node.rb | 8 ++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 11231d0..ca70283 100644 --- a/README.md +++ b/README.md @@ -839,6 +839,17 @@ map: name: 1 group: 2 ``` +For model specific credentials + +``` +models: + mikrotik: + username: admin + password: blank + ubiquiti: + username: ubnt + password: ubnt +``` ### Triggered backups diff --git a/lib/oxidized/config.rb b/lib/oxidized/config.rb index aba8b63..23af9c2 100644 --- a/lib/oxidized/config.rb +++ b/lib/oxidized/config.rb @@ -31,6 +31,7 @@ module Oxidized asetus.default.next_adds_job = false # if true, /next adds job, so device is fetched immmeiately asetus.default.vars = {} # could be 'enable'=>'enablePW' asetus.default.groups = {} # group level configuration + asetus.default.models = {} # model level configuration asetus.default.pid = File.join(Oxidized::Config::Root, 'pid') asetus.default.input.default = 'ssh, telnet' diff --git a/lib/oxidized/config/vars.rb b/lib/oxidized/config/vars.rb index 09f9781..d926ee2 100644 --- a/lib/oxidized/config/vars.rb +++ b/lib/oxidized/config/vars.rb @@ -8,8 +8,12 @@ module Oxidized::Config::Vars r ||= Oxidized.config.groups[@node.group].vars[name.to_s] end end + if Oxidized.config.models.has_key?(@node.model.class.name.to_s.downcase) + if Oxidized.config.models[@node.model.class.name.to_s.downcase].vars.has_key?(name.to_s) + r ||= Oxidized.config.models[@node.model.class.name.to_s.downcase].vars[name.to_s] + end + end r ||= Oxidized.config.vars[name.to_s] if Oxidized.config.vars.has_key?(name.to_s) r end end - diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb index cf71e48..8d0d0af 100644 --- a/lib/oxidized/node.rb +++ b/lib/oxidized/node.rb @@ -216,6 +216,14 @@ module Oxidized end end + #model + if Oxidized.config.models.has_key?(@model.class.name.to_s.downcase) + if Oxidized.config.models[@model.class.name.to_s.downcase].has_key?(key_str) + value = Oxidized.config.models[@model.class.name.to_s.downcase][key_str] + Oxidized.logger.debug "node.rb: setting node key '#{key}' to value '#{value}' from model" + end + end + #node value = opt[key_sym] || value Oxidized.logger.debug "node.rb: returning node key '#{key}' with value '#{value}'" -- cgit v1.2.1 From 25d30f8329610b1917fb6513158cc5e2e4542a96 Mon Sep 17 00:00:00 2001 From: Cyril LAVIER Date: Fri, 5 May 2017 13:00:36 +0200 Subject: Updated example for models variable setting --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ca70283..0745577 100644 --- a/README.md +++ b/README.md @@ -843,12 +843,17 @@ For model specific credentials ``` models: - mikrotik: + junos: username: admin - password: blank - ubiquiti: - username: ubnt - password: ubnt + password: password + ironware: + username: admin + password: password + vars: + enable: enablepassword + apc_aos: + username: apc + password: password ``` ### Triggered backups -- cgit v1.2.1