class PaloAlto::XML::Log
Public Class Methods
new(query:, log_type:, nlogs: 20, dir: :backward, show_detail: false, days: 7)
click to toggle source
Calls superclass method
# File lib/palo_alto/log.rb, line 9 def initialize(query:, log_type:, nlogs: 20, dir: :backward, show_detail: false, days: 7) payload = { type: 'log', 'log-type': log_type, nlogs: nlogs, query: !days ? query : query + " AND (receive_time geq '#{(Time.now-days*3600*24).strftime("%Y/%m/%d %H:%M:%S")}')", dir: dir, 'show-detail': show_detail ? 'yes' : 'no' } result = XML.execute(payload) @job_id = result.at_xpath('response/result/job').text @count=nil @skip=0 @first_result = fetch_result super end
Public Instance Methods
count()
click to toggle source
# File lib/palo_alto/log.rb, line 59 def count @count end
each(&block)
click to toggle source
# File lib/palo_alto/log.rb, line 63 def each(&block) # a bit buggy: after #to_a, without calling #rewind, I can't use #next reliable anymore if @skip>0 restore_first end begin @current_result.xpath("/response/result/log/logs/entry").each{|l| result = l.children.inject({}){|h, child| next h if child.is_a?(Nokogiri::XML::Text) h[child.name] = child.text h } block.call(result) } end while fetch_result end
fetch_result()
click to toggle source
# File lib/palo_alto/log.rb, line 37 def fetch_result return nil if @count && @skip == @count payload = { type: 'log', action: 'get', 'job-id': @job_id, skip: @skip } i=0 begin sleep 0.5 if i>0 @current_result = XML.execute(payload) i+=1 end until @current_result.at_xpath("response/result/job/status").text == 'FIN' @count = @current_result.at_xpath("response/result/job/cached-logs").text.to_i @skip += @current_result.at_xpath("response/result/log/logs/@count").value.to_i # skip now shown logs @current_result end
restore_first()
click to toggle source
# File lib/palo_alto/log.rb, line 27 def restore_first @current_result = @first_result @skip = @current_result.at_xpath("response/result/log/logs/@count").value.to_i end
rewind()
click to toggle source
Calls superclass method
# File lib/palo_alto/log.rb, line 32 def rewind restore_first super end