class Naginata::Status
Attributes
hostname[RW]
nagios[RW]
status[RW]
Public Class Methods
build(string, nagios_server_hostname)
click to toggle source
Create a new instance from raw status.dat string
@param [String] string raw status.dat text @param [String] nagios_server_hostname hostname to identify status.data data @return [Naginata::Status]
# File lib/naginata/status.rb, line 52 def self.build(string, nagios_server_hostname) instance = new instance.hostname = nagios_server_hostname # @Note NagiosAnalizer::Status.new requires filename, so here # needs to write text data into tempfile. Tempfile.open(["naginata-#{nagios_server_hostname}", ".status.dat"]) do |temp| temp.sync = true temp.write string instance.status = ::NagiosAnalyzer::Status.new(temp.path, include_ok: true) temp.close! end instance end
cache_dir()
click to toggle source
Return a directory path for status.dat caching
@return [String] directory path for status.dat caching
# File lib/naginata/status.rb, line 70 def self.cache_dir dir = (ENV['HOME'] && Dir.exist?(ENV['HOME'])) ? ENV['HOME'] : Dir.pwd dir = File.join(dir, '.naginata/cache/status') FileUtils.mkdir_p dir return dir end
find(nagios_server_hostname)
click to toggle source
Find a instance from cache by nagios server hostname
@return [Naginata::Status]
# File lib/naginata/status.rb, line 80 def self.find(nagios_server_hostname) instance = new instance.hostname = nagios_server_hostname if File.exist?(instance.path) File.open(instance.path) { |f| instance.status = Marshal.load(f) } return instance end end
Public Instance Methods
decorate()
click to toggle source
Returns decorator instance
@return [StatusDecorator]
# File lib/naginata/status.rb, line 43 def decorate @decorator ||= StatusDecorator.new(self) end
path()
click to toggle source
Path of marshal dumped status file
@return [String] path of marshal dumped status file
# File lib/naginata/status.rb, line 35 def path raise "@hostname must be set" if hostname.nil? @path ||= File.join(self.class.cache_dir, "#{hostname}.status.dat") end
purge_cache()
click to toggle source
# File lib/naginata/status.rb, line 26 def purge_cache if File.exist?(path) FileUtils.rm path end end
save()
click to toggle source
Write status.dat into local disk
@return [Naginata::Status] return self @return [false] if @status is nil
# File lib/naginata/status.rb, line 17 def save return false if status.nil? File.open(path, "w") do |f| f.sync = true Marshal.dump(status, f) end self end