summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/oxidized/input/ssh.rb4
-rw-r--r--lib/oxidized/model/panos.rb26
-rw-r--r--lib/oxidized/model/screenos.rb9
-rw-r--r--lib/oxidized/output/git.rb25
-rw-r--r--lib/oxidized/source/csv.rb2
-rw-r--r--lib/oxidized/source/http.rb54
-rw-r--r--lib/oxidized/worker.rb4
7 files changed, 110 insertions, 14 deletions
diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb
index ec33d37..b1f109b 100644
--- a/lib/oxidized/input/ssh.rb
+++ b/lib/oxidized/input/ssh.rb
@@ -23,7 +23,9 @@ module Oxidized
@log = File.open(CFG.input.debug?.to_s + '-ssh', 'w') if CFG.input.debug?
@ssh = Net::SSH.start @node.ip, @node.auth[:username],
:password => @node.auth[:password], :timeout => CFG.timeout,
- :paranoid => secure
+ :paranoid => secure,
+ :auth_methods => %w(none publickey password keyboard-interactive),
+ :number_of_password_prompts => 0
unless @exec
shell_open @ssh
begin
diff --git a/lib/oxidized/model/panos.rb b/lib/oxidized/model/panos.rb
new file mode 100644
index 0000000..35624b7
--- /dev/null
+++ b/lib/oxidized/model/panos.rb
@@ -0,0 +1,26 @@
+class PanOS < Oxidized::Model
+
+ # PaloAlto PAN-OS model #
+
+ comment '! '
+
+ prompt /^[\w.\@:\(\)-]+>\s?$/
+
+ cmd :all do |cfg|
+ cfg.each_line.to_a[2..-3].join
+ end
+
+ cmd 'show system info' do |cfg|
+ cfg.gsub! /^(up)?time:\ .*\n/, ''
+ comment cfg
+ end
+
+ cmd 'show config running' do |cfg|
+ cfg
+ end
+
+ cfg :ssh do
+ post_login 'set cli pager off'
+ pre_logout 'exit'
+ end
+end
diff --git a/lib/oxidized/model/screenos.rb b/lib/oxidized/model/screenos.rb
index 922f401..7ee9d9f 100644
--- a/lib/oxidized/model/screenos.rb
+++ b/lib/oxidized/model/screenos.rb
@@ -4,7 +4,7 @@ class ScreenOS < Oxidized::Model
comment '! '
- prompt '/^([\w.-\(\)]+->\s?)$/'
+ prompt /^[\w.:\(\)-]+->\s?$/
cmd :all do |cfg|
cfg.each_line.to_a[2..-2].join
@@ -18,6 +18,8 @@ class ScreenOS < Oxidized::Model
end
cmd 'get system' do |cfg|
+ cfg.gsub! /^Date\ .*\n/, ''
+ cfg.gsub! /^Up\ .*\n/, ''
comment cfg
end
@@ -33,7 +35,10 @@ class ScreenOS < Oxidized::Model
cfg :telnet, :ssh do
post_login 'set console page 0'
- pre_logout 'exit'
+ pre_logout do
+ send "exit\n"
+ send "n"
+ end
end
end
diff --git a/lib/oxidized/output/git.rb b/lib/oxidized/output/git.rb
index e9256e8..57b6f62 100644
--- a/lib/oxidized/output/git.rb
+++ b/lib/oxidized/output/git.rb
@@ -2,7 +2,6 @@ module Oxidized
class Git < Output
class GitError < OxidizedError; end
begin
- gem 'rugged', '~> 0.21.0'
require 'rugged'
rescue LoadError
raise OxidizedError, 'rugged not found: sudo gem install rugged'
@@ -68,17 +67,23 @@ class Git < Output
def update repo, file, data
return if data.empty?
if @opt[:group]
- repo = File.join File.dirname(repo), @opt[:group] + '.git'
+ if @cfg.single_repo?
+ file = File.join @opt[:group], file
+ else
+ repo = File.join File.dirname(repo), @opt[:group] + '.git'
+ end
end
- repo = Rugged::Repository.new repo
- update_repo repo, file, data, @msg, @user, @email
- rescue Rugged::OSError, Rugged::RepositoryError => open_error
begin
- Rugged::Repository.init_at repo, :bare
- rescue => create_error
- raise GitError, "first '#{open_error.message}' was raised while opening git repo, then '#{create_error.message}' was while trying to create git repo"
+ repo = Rugged::Repository.new repo
+ update_repo repo, file, data, @msg, @user, @email
+ rescue Rugged::OSError, Rugged::RepositoryError => open_error
+ begin
+ Rugged::Repository.init_at repo, :bare
+ rescue => create_error
+ raise GitError, "first '#{open_error.message}' was raised while opening git repo, then '#{create_error.message}' was while trying to create git repo"
+ end
+ retry
end
- retry
end
def update_repo repo, file, data, msg, user, email
@@ -99,7 +104,9 @@ class Git < Output
:parents => repo.empty? ? [] : [repo.head.target].compact,
:update_ref => 'HEAD',
)
+
index.write
+ true
end
end
end
diff --git a/lib/oxidized/source/csv.rb b/lib/oxidized/source/csv.rb
index 3b66e65..5064e5e 100644
--- a/lib/oxidized/source/csv.rb
+++ b/lib/oxidized/source/csv.rb
@@ -18,7 +18,7 @@ class CSV < Source
def load
nodes = []
- open(@cfg.file).each_line do |line|
+ open(File.expand_path @cfg.file).each_line do |line|
next if line.match /^\s*#/
data = line.chomp.split @cfg.delimiter
next if data.empty?
diff --git a/lib/oxidized/source/http.rb b/lib/oxidized/source/http.rb
new file mode 100644
index 0000000..d2e3ea6
--- /dev/null
+++ b/lib/oxidized/source/http.rb
@@ -0,0 +1,54 @@
+module Oxidized
+class HTTP < Source
+ def initialize
+ @cfg = CFG.source.http
+ super
+ end
+
+ def setup
+ if @cfg.url.empty?
+ raise NoConfig, 'no source http url config, edit ~/.config/oxidized/config'
+ end
+ end
+
+ require "net/http"
+ require "uri"
+ require "json"
+
+ def load
+ nodes = []
+ uri = URI.parse(@cfg.url)
+ http = Net::HTTP.new(uri.host, uri.port)
+ http.use_ssl = true if uri.scheme == 'https'
+
+ # map headers
+ headers = {}
+ @cfg.headers.each do |header, value|
+ headers[header] = value
+ end
+
+ request = Net::HTTP::Get.new(uri.request_uri, headers)
+
+ response = http.request(request)
+ data = JSON.parse(response.body)
+ data.each do |line|
+ next if line.empty?
+ # map node parameters
+ keys = {}
+ @cfg.map.each do |key, position|
+ keys[key.to_sym] = line[position]
+ end
+ keys[:model] = map_model keys[:model] if keys.key? :model
+
+ # map node specific vars, empty value is considered as nil
+ vars = {}
+ @cfg.vars_map.each { |key, position| vars[key.to_sym] = line[position].to_s.empty? ? nil : line[position] }
+ keys[:vars] = vars unless vars.empty?
+
+ nodes << keys
+ end
+ nodes
+ end
+
+end
+end
diff --git a/lib/oxidized/worker.rb b/lib/oxidized/worker.rb
index 7ed70ac..6bb2a22 100644
--- a/lib/oxidized/worker.rb
+++ b/lib/oxidized/worker.rb
@@ -37,8 +37,10 @@ module Oxidized
msg = "update #{node.name}"
msg += " from #{node.from}" if node.from
msg += " with message '#{node.msg}'" if node.msg
- node.output.new.store node.name, job.config,
+ if node.output.new.store node.name, job.config,
:msg => msg, :user => node.user, :group => node.group
+ Log.info "Configuration updated for #{node.group}/#{node.name}"
+ end
node.reset
else
msg = "#{node.name} status #{job.status}"