Sha256: 8a4d2e74efd2830bdd59b145b3e06ccb90dd1d9b1070f34ad3f3337126c799fd
Contents?: true
Size: 1.2 KB
Versions: 1
Compression:
Stored size: 1.2 KB
Contents
class ZabbixRubyClient class Store def initialize(dir, server, task, keepdata=false) @dir = dir @server = server @task = task @keepdata = keepdata @basename = "#{@server}-#{@task}-data" end def datafile @datafile ||= if @keepdata unless Dir.exists? File.join(@dir, Time.now.strftime("%Y-%m-%d")) FileUtils.mkdir File.join(@dir, Time.now.strftime("%Y-%m-%d")) end File.join(@dir, Time.now.strftime("%Y-%m-%d"),"#{@basename}_"+Time.now.strftime("%H%M%S")) else File.join(@dir, @basename) end end def record(data) write(data, datafile, pending_content) end def keepdata(file) FileUtils.mv(file, pendingfile) end def pendingfile @pendingfile ||= File.join(@dir, "#{@server}-pending") end def pending_content pending = "" if File.exists? pendingfile pending = File.open(pendingfile,'r').read File.delete(pendingfile) end pending end def write(data, file, prepend = "") File.open(file, "w") do |f| f.write(prepend) data.each do |d| f.puts d end end file end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
zabbix-ruby-client-0.0.15 | lib/zabbix-ruby-client/store.rb |