From 921a4a201b6ec12864a24310d669e07ce0a57c4e Mon Sep 17 00:00:00 2001 From: msil Date: Fri, 7 Sep 2018 11:13:46 +0100 Subject: Add configurable crashfile location and option to use hostnames PR #1506 --- lib/oxidized/config.rb | 3 +++ lib/oxidized/node.rb | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/oxidized') diff --git a/lib/oxidized/config.rb b/lib/oxidized/config.rb index 115e035..25c689a 100644 --- a/lib/oxidized/config.rb +++ b/lib/oxidized/config.rb @@ -35,6 +35,9 @@ module Oxidized asetus.default.models = {} # model level configuration asetus.default.pid = File.join(Oxidized::Config::Root, 'pid') + asetus.default.crash.directory = File.join(Oxidized::Config::Root, 'crashes') + asetus.default.crash.hostnames = false + asetus.default.stats.history_size = 10 asetus.default.input.default = 'ssh, telnet' asetus.default.input.debug = false # or String for session log file diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb index 9dfeb19..e012b23 100644 --- a/lib/oxidized/node.rb +++ b/lib/oxidized/node.rb @@ -74,8 +74,11 @@ module Oxidized Oxidized.logger.send(level, '%s raised %s%s with msg "%s"' % [self.ip, err.class, resc, err.message]) return false rescue => err - file = Oxidized::Config::Crash + '.' + self.ip.to_s - open file, 'w' do |fh| + crashdir = Oxidized.config.crash.directory + crashfile = Oxidized.config.crash.hostnames? ? self.name : self.ip.to_s + FileUtils.mkdir_p(crashdir) unless File.directory?(crashdir) + + open File.join(crashdir, crashfile), 'w' do |fh| fh.puts Time.now.utc fh.puts err.message + ' [' + err.class.to_s + ']' fh.puts '-' * 50 -- cgit v1.2.1