class Hieracles::Formats::Json

format intended to be used for an api server

Public Instance Methods

allparams(args) click to toggle source
# File lib/hieracles/formats/json.rb, line 34
def allparams(args)
  @node.params(false).merge(alerts).to_json
end
build_list(hash, notifications, filter) click to toggle source
# File lib/hieracles/formats/json.rb, line 38
def build_list(hash, notifications, filter)
  if filter[0]
    { 'notifications' => notifications,
      'payload' => hash.select { |k, e| Regexp.new(filter[0]).match k }
    }.to_json
  else
    { 'notifications' => notifications,
      'payload' => hash
    }.to_json
  end
end
facts(args) click to toggle source
# File lib/hieracles/formats/json.rb, line 13
def facts(args)
  filter(@node.facts, args)
  @node.facts.merge(alerts).to_json
end
files(_) click to toggle source
# File lib/hieracles/formats/json.rb, line 18
def files(_)
  { 'files' => @node.files }.merge(alerts).to_json
end
info(args) click to toggle source
# File lib/hieracles/formats/json.rb, line 8
def info(args)
  filter(@node.info, args)
  @node.info.merge(alerts).to_json
end
modules(_) click to toggle source
# File lib/hieracles/formats/json.rb, line 26
def modules(_)
  @node.modules.merge(alerts).to_json
end
params(args) click to toggle source
# File lib/hieracles/formats/json.rb, line 30
def params(args)
  @node.params(true).merge(alerts).to_json
end
paths(_) click to toggle source
# File lib/hieracles/formats/json.rb, line 22
def paths(_)
  { 'paths' => @node.paths }.merge(alerts).to_json
end

Private Instance Methods

alerts() click to toggle source
# File lib/hieracles/formats/json.rb, line 52
def alerts
  if @node.notifications.count > 0
    { 'alerts' => @node.notifications.map(&:to_hash) }
  else
    {}
  end
end
filter(what, args) click to toggle source
# File lib/hieracles/formats/json.rb, line 60
def filter(what, args)
  if args and args[0]
    what.select! { |k, v| Regexp.new(args[0]).match(k.to_s) }
  else
    what
  end
end