transform_and_wrap

in source/code/plugins/antimalware_lib.rb [13:84]


        def transform_and_wrap(results, hostname, time)
            @log.info "Antimalware lib started..." + results.to_s
            if results.nil?
                @log.error "Antimalware Assessment failed; Empty input for result"
                wrapper = {
                    "DataType"=>"OPERATION_BLOB",
                    "IPName"=>"LogManagement",
                    "DataItems"=>[
                        {
                            "Timestamp" => OMS::Common.format_time(time),
                            "OperationStatus" => "Error",
                            "Computer" => hostname,
                            "Category" => "Antimalware",
                            "Solution" => "Antimalware",
                            "Detail" => "Antimalware Assessment failed: Empty output"
                        }
                    ]
                }
                
                return nil, wrapper
            end

            antimalware_blob = {
                "DataType"=>"PROTECTION_STATUS_BLOB", 
                "IPName"=>"Antimalware",
                "DataItems"=>[
                    {
                        "DeviceName" => hostname,
                        "OSName" => "Linux",
                        "ProtectionStatusRank" => results["ProtectionStatusRank"],
                        "ProtectionStatus" => results["ProtectionStatus"],
                        "ProtectionStatusDetails" => results["ProtectionStatusDetails"],
                        "DetectionId" => results["DetectionId"],
                        "Threat" => results["Threat"],
                        "ThreatStatusRank" => results["ThreatStatusRank"],
                        "ThreatStatus" => results["ThreatStatus"],
                        "ThreatStatusDetails" => results["ThreatStatusDetails"],
                        "Signature" => results["Signature"],
                        "ScanDate" => results["ScanDate"],
                        "DateCollected" => results["DateCollected"],
                        "Tool" => results["Tool"],
                        "AMProductVersion" => results["AMProductVersion"]                                               
                    }                 
                ]
            }    

            if !results["Error"].nil?              
                msg = "Antimalware Assessment encountered some errors but still return the result: " + results["Error"]
                @log.error msg
                wrapper = {
                    "DataType"=>"OPERATION_BLOB",
                    "IPName"=>"LogManagement",
                    "DataItems"=>[
                        {
                            "Timestamp" => OMS::Common.format_time(time),
                            "OperationStatus" => "Error",
                            "Computer" => hostname,
                            "Category" => "Antimalware",
                            "Solution" => "Antimalware",
                            "Detail" => msg
                        }
                    ]
                }                   
                @log.info "Antimalware info collected with error"
                return antimalware_blob, wrapper
            else               
                return antimalware_blob, nil   
            end         
        end 
    end
end