lib/hieracles/formats/json.rb in hieracles-0.2.0 vs lib/hieracles/formats/json.rb in hieracles-0.2.1

- old
+ new

@@ -4,31 +4,44 @@ module Formats # format intended to be used for an api server class Json < Hieracles::Format def info(_) - @node.info.to_json + @node.info.merge(alerts).to_json end + def facts(_) + @node.facts.merge(alerts).to_json + end + def files(_) - @node.files.to_json + { 'files' => @node.files }.merge(alerts).to_json end def paths(_) - @node.paths.to_json + { 'paths' => @node.paths }.merge(alerts).to_json end def modules(_) - @node.modules.to_json + @node.modules.merge(alerts).to_json end def params(args) - @node.params(true).to_json + @node.params(true).merge(alerts).to_json end def allparams(args) - @node.params(false).to_json + @node.params(false).merge(alerts).to_json end + private + + def alerts + if @node.notifications.count > 0 + { 'alerts' => @node.notifications.map(&:to_hash) } + else + {} + end + end end end end