diff options
Diffstat (limited to 'extra')
-rw-r--r-- | extra/nagios_check_failing_nodes.rb | 22 | ||||
-rw-r--r-- | extra/oxidized.service | 12 | ||||
-rw-r--r-- | extra/syslog.rb | 50 |
3 files changed, 67 insertions, 17 deletions
diff --git a/extra/nagios_check_failing_nodes.rb b/extra/nagios_check_failing_nodes.rb index 1c81f66..27a5c66 100644 --- a/extra/nagios_check_failing_nodes.rb +++ b/extra/nagios_check_failing_nodes.rb @@ -6,20 +6,30 @@ require 'open-uri' require 'json' critical = false +pending = false critical_nodes = [] +pending_nodes = [] json = JSON.load(open("http://localhost:8888/nodes.json")) json.each do |node| - if node['last']['status'] != 'success' - critical_nodes << node['name'] - critical = true + if not node['last'].nil? + if node['last']['status'] != 'success' + critical_nodes << node['name'] + critical = true + end + else + pending_nodes << node['name'] + pending = true end end -if critical - puts 'Unable to backup: ' + critical_nodes.join(' ') +if pending + puts '[WARN] Pending backup: ' + pending_nodes.join(',') + exit 1 +elsif critical + puts '[CRIT] Unable to backup: ' + critical_nodes.join(',') exit 2 else - puts 'Backup of all nodes completed successfully.' + puts '[OK] Backup of all nodes completed successfully.' exit 0 end diff --git a/extra/oxidized.service b/extra/oxidized.service new file mode 100644 index 0000000..65063b7 --- /dev/null +++ b/extra/oxidized.service @@ -0,0 +1,12 @@ +#For debian 8 put it in /lib/systemd/system/ +#and call it with systemctl start oxidized.service + +[Unit] +Description=Oxidized - Network Device Configuration Backup Tool + +[Service] +ExecStart=/usr/local/bin/oxidized +User=root + +[Install] +WantedBy=multi-user.target diff --git a/extra/syslog.rb b/extra/syslog.rb index 20e439e..e364cf9 100644 --- a/extra/syslog.rb +++ b/extra/syslog.rb @@ -8,10 +8,18 @@ # set system syslog host SERVER interactive-commands notice # set system syslog host SERVER match "^mgd\[[0-9]+\]: UI_COMMIT: .*" -# Ports < 1024 need extra privileges, use a port higher than this by passing the first argument a number -# To use the default port for syslog (514) you shouldnt pass an argument, but you will need to allow this with: +# Ports < 1024 need extra privileges, use a port higher than this by setting the port option in your oxidized config file. +# To use the default port for syslog (514) you shouldn't pass an argument, but you will need to allow this with: # sudo setcap 'cap_net_bind_service=+ep' /usr/bin/ruby +# Config options are: +# syslogd +# port (Default = 514) +# file (Default = messages) +# resolve (Default = true) + +# To stop the resolution of IP's to PTR you can set resolve to false + # exit if fork ## TODO: proper daemonize require 'socket' @@ -19,13 +27,30 @@ require 'resolv' require_relative 'rest_client' module Oxidized + + require 'asetus' + class Config + Root = File.join ENV['HOME'], '.config', 'oxidized' + end + + CFGS = Asetus.new :name=>'oxidized', :load=>false, :key_to_s=>true + CFGS.default.syslogd.port = 514 + CFGS.default.syslogd.file = 'messages' + CFGS.default.syslogd.resolve = true + + begin + CFGS.load + rescue => error + raise InvalidConfig, "Error loading config: #{error.message}" + ensure + CFG = CFGS.cfg # convenienence, instead of Config.cfg.password, CFG.password + end + class SyslogMonitor NAME_MAP = { /(.*)\.ip\.tdc\.net/ => '\1', /(.*)\.ip\.fi/ => '\1', } - PORT = 514 - FILE = 'messages' MSG = { :ios => /%SYS-(SW[0-9]+-)?5-CONFIG_I:/, :junos => 'UI_COMMIT:', @@ -34,13 +59,12 @@ module Oxidized } class << self - def udp port=PORT, listen=0 - port ||= PORT + def udp port=Oxidized::CFG.syslogd.port, listen=0 io = UDPSocket.new io.bind listen, port new io, :udp end - def file syslog_file=FILE + def file syslog_file=Oxidized::CFG.syslogd.file io = open syslog_file, 'r' io.seek 0, IO::SEEK_END new io, :file @@ -104,12 +128,16 @@ module Oxidized end def getname ip - name = (Resolv.getname ip.to_s rescue ip) - NAME_MAP.each { |re, sub| name.sub! re, sub } - name + if Oxidized::CFG.syslogd.resolve == false + ip + else + name = (Resolv.getname ip.to_s rescue ip) + NAME_MAP.each { |re, sub| name.sub! re, sub } + name + end end end end -Oxidized::SyslogMonitor.udp ARGV[0] +Oxidized::SyslogMonitor.udp #Oxidized::SyslogMonitor.file '/var/log/poop' |