diff --git a/Makefile b/Makefile index f8e778440..9ec7bba64 100755 --- a/Makefile +++ b/Makefile @@ -541,7 +541,7 @@ nxOMSGenerateInventoryMof: nxOMSPlugin: rm -rf output/staging; \ - VERSION="3.67"; \ + VERSION="3.68"; \ PROVIDERS="nxOMSPlugin"; \ STAGINGDIR="output/staging/$@/DSCResources"; \ cat Providers/Modules/$@.psd1 | sed "s@@$${VERSION}@" > intermediate/Modules/$@.psd1; \ diff --git a/Providers/Modules/Plugins/Antimalware/plugin/collectmcafeeinfo.rb b/Providers/Modules/Plugins/Antimalware/plugin/collectmcafeeinfo.rb index 839f1c5f5..b1fdf709b 100644 --- a/Providers/Modules/Plugins/Antimalware/plugin/collectmcafeeinfo.rb +++ b/Providers/Modules/Plugins/Antimalware/plugin/collectmcafeeinfo.rb @@ -91,9 +91,10 @@ def self.getprotectionstatus() if taskcmd[$i].include? "Not Applicable" quickscan = "NA" else - quickscanarray = taskcmd[$i].split(" ") + quickscanarray = taskcmd[$i] + # quickscanarray = "|2 full scan ODS Running 01/05/22 17:23:26 -0800 |" quickscanStatus = 'NA' - quickscan, quickscanStatus = parseMcAfeeDateTime(quickscanarray , @mcafeeVersion) + quickscan, quickscanStatus = parseMcAfeeDateTimeAndScanStatus(quickscanarray) if quickscan == "NA" protectionStatusDetailsArray.push("Fail to parse quickscan date: " + taskcmd[$i]) end @@ -106,9 +107,9 @@ def self.getprotectionstatus() if taskcmd[$i].include? "Not Applicable" fullscan = "NA" else - fullscanarray = taskcmd[$i].split(" ") + fullscanarray = taskcmd[$i] fullscanStatus = 'NA' - fullscan, fullscanStatus = parseMcAfeeDateTime(fullscanarray, @mcafeeVersion) + fullscan, fullscanStatus = parseMcAfeeDateTimeAndScanStatus(fullscanarray) if fullscan == "NA" protectionStatusDetailsArray.push("Fail to parse fullscan date: " + taskcmd[$i]) end @@ -120,9 +121,9 @@ def self.getprotectionstatus() if taskcmd[$i].include? "Not Applicable" datengupdate = "NA" else - datengupdatearray = taskcmd[$i].split(" ") + datengupdatearray = taskcmd[$i] datengupdateStatus = 'NA' - datengupdate, datengupdateStatus = parseMcAfeeDateTime(datengupdatearray, @mcafeeVersion) + datengupdate, datengupdateStatus = parseMcAfeeDateTimeAndScanStatus(datengupdatearray) if datengupdate == "NA" protectionStatusDetailsArray.push("Fail to parse DAT Engine update date: " + taskcmd[$i]) end @@ -249,50 +250,43 @@ def self.getprotectionstatus() return ret end - def self.parseMcAfeeDateTime(datearray , mcafeeVersion) - begin - mcafeeVersionSplit = mcafeeVersion.to_s.split(".") - if (mcafeeVersionSplit[1].to_i > 6) || (mcafeeVersionSplit[1].to_i == 6 && mcafeeVersionSplit[2].to_i >=6 ) - return parseMcAfeeDateTimeForSixPointSixVersionAndNewer(datearray) - else - return parseMcAfeeDateTimeSixPointFiveVersionAndOlder(datearray) - end - # rescue => e - # error += "Getting exception when trying to find mcafee health info: " + e.message + " " + e.backtrace.inspect - # ret["Error"] = error - end + def self.parseMcAfeeDateTimeAndScanStatus(taskcmd) + return parseMcAfeeDateTime(taskcmd) , parseMcAfeeScanStatus(taskcmd) end - def self.parseMcAfeeDateTimeSixPointFiveVersionAndOlder(datearray) - $l = datearray.length - scandate = 'NA' - scanstatus = 'NA' - if $l >= 4 - if(!datearray[$l-3].include? "AM") && (!datearray[$l-3].include? "PM") - scandate = datearray[$l-4] + " " + datearray[$l-3] + " " + datearray[$l-2] - scandate = Time.strptime(scandate, '%d/%m/%y %H:%M:%S %Z') - elsif $l >= 8 - scandate = datearray[$l-7] + " " + datearray[$l-6] + " " + datearray[$l-5] + " " + datearray[$l-4] + " " + datearray[$l-3] + " " + datearray[$l-2] - scandate = Time.strptime(scandate, '%d %b %Y %I:%M:%S %p %Z') - end - if $l >= 5 && (!datearray[4].include? "Not") - scanstatus = datearray[4] - end - if $l >= 10 && (datearray[4].include? "task") && (!datearray[9].include? "Not") - scanstatus = datearray[9] + def self.parseMcAfeeDateTime(taskcmd) + puts "Here in Date time" + begin + # Tue Jan 28 08:42:20 2020 + # Wed 22 Jun 2022 01:00:01 AM UTC + # 05/07/1994 15:15:01 UTC + # 07/05/1994 15:15:01 UTC + # 1994/05/07 15:15:01 UTC + + timeformatVariations = ["%a %b %d %H:%M:%S %Y", "%a %b %-d %H:%M:%S %Y", + "%a %d %b %Y %H:%M:%S %p %Z", "%a %e %b %Y %H:%M:%S %p %Z", "%a %d %b %Y %H:%M:%S %P %Z", "%a %e %b %Y %H:%M:%S %P %Z", + "%d/%m/%y %H:%M:%S %Z", "%e/%-m/%y %H:%M:%S %Z", "%d/%m/%y %H:%M:%S %z", "%e/%-m/%y %H:%M:%S %z", + "%m/%d/%y %H:%M:%S %Z", "%-m/%e/%y %H:%M:%S %Z", "%m/%d/%y %H:%M:%S %z", "%e/%-m/%y %H:%M:%S %z", + "%y/%m/%d %H:%M:%S %Z", "%y/%-m/%e %H:%M:%S %Z", "%y/%m/%d %H:%M:%S %z", "%y/%-m/%e %H:%M:%S %z"] + # above code already handles not applicable + regexForTimeFormat = /(?:\w{3}\s\w{3,}\s+\d{1,2}\s+\d\d:\d\d:\d\d\s\d{4})|(?:\w{3}\s+\d{1,2}\s+\w{3}\s+\d{4}\s+\d\d:\d\d:\d\d\s+((AM|PM|am|pm)*)\s+UTC)|(?:\d{1,4}[\/\-]\d{1,2}[\/\-]\d{1,4}\s\d\d:\d\d:\d\d(\s)*((AM|PM|am|pm)*)(\s)*(UTC|(\-\d{4}))*)/ + + scandatetime = taskcmd.match(regexForTimeFormat).to_s + + timeformatVariations.size.times do |timeformatIndex| + begin + scandate = Time.strptime(scandatetime, timeformatVariations[timeformatIndex]) + return scandate + rescue => e + puts "Time format #{timeformatIndex} : #{timeformatVariations[timeformatIndex]} doesnt match system time format" + end end end - return scandate, scanstatus - end + end - def self.parseMcAfeeDateTimeForSixPointSixVersionAndNewer(datearray) - $l = datearray.length - scandate = 'NA' - scanstatus = 'NA' - scandate = datearray[$l-6] + " " + datearray[$l-5] + " " + datearray[$l-4] + " " + datearray[$l-3] + " " + datearray[$l-2] + " " + datearray[$l-1] - scandate = Time.strptime(scandate, '%a %b %d %H:%M:%S %Y') - scandate.utc.strftime("%d/%m/%y %H:%M:%S %Z") - scanstatus = datearray[9] - return scandate, scanstatus + def self.parseMcAfeeScanStatus(taskcmd) + puts "Here in Scan Status" + regexForMcAfeeScanStatus = /(Not Started|Running|Completed)/ + return taskcmd.match(regexForMcAfeeScanStatus).to_s end end \ No newline at end of file diff --git a/Providers/Modules/Plugins/Antimalware/plugin/collectmcafeetest.rb b/Providers/Modules/Plugins/Antimalware/plugin/collectmcafeetest.rb new file mode 100644 index 000000000..d8a5d5cb2 --- /dev/null +++ b/Providers/Modules/Plugins/Antimalware/plugin/collectmcafeetest.rb @@ -0,0 +1,77 @@ +require 'test/unit' +require_relative 'collectmcafeeinfo' + +class McafeeTest < Test::Unit::TestCase + + timeformatVariations = ["%a %b %d %H:%M:%S %Y", "%a %b %-d %H:%M:%S %Y", + "%a %d %b %Y %H:%M:%S %p %Z", "%a %e %b %Y %H:%M:%S %p %Z", "%a %d %b %Y %H:%M:%S %P %Z", "%a %e %b %Y %H:%M:%S %P %Z", + "%d/%m/%y %H:%M:%S %Z", "%e/%-m/%y %H:%M:%S %Z", "%d/%m/%y %H:%M:%S %z", "%e/%-m/%y %H:%M:%S %z", + "%m/%d/%y %H:%M:%S %Z", "%-m/%e/%y %H:%M:%S %Z", "%m/%d/%y %H:%M:%S %z", "%e/%-m/%y %H:%M:%S %z", + "%y/%m/%d %H:%M:%S %Z", "%y/%-m/%e %H:%M:%S %Z", "%y/%m/%d %H:%M:%S %z", "%y/%-m/%e %H:%M:%S %z"] + + def test_parseMcAfeeScanStatus_Not_Started + taskcmd = "|1 quick scan ODS Not Started 19/01/17 07:43:09 UTC |" + assert_equal("Not Started", McAfee.parseMcAfeeScanStatus(taskcmd)) + end + + def test_parseMcAfeeScanStatus_Running + taskcmd = "|1 quick scan ODS Running 19/01/17 07:43:09 UTC |" + assert_equal("Running", McAfee.parseMcAfeeScanStatus(taskcmd)) + end + + def test_parseMcAfeeScanStatus_Completed + taskcmd = "|1 quick scan ODS Completed 19/01/17 07:43:09 UTC |" + assert_equal("Completed", McAfee.parseMcAfeeScanStatus(taskcmd)) + end + + def test_parseMcAfeeDateTime_timeformatVariations_index_1 + taskcmd = "|2 full scan ODS Running Tue Jan 12 08:42:20 2020 |" + assert_equal("2020-01-12 08:42:20 -0800", McAfee.parseMcAfeeDateTime(taskcmd).to_s) + end + + def test_parseMcAfeeDateTime_timeformatVariations_index_2 + taskcmd = "|2 full scan ODS Running Tue Jan 2 08:42:20 2020 |" + assert_equal("2020-01-02 08:42:20 -0800", McAfee.parseMcAfeeDateTime(taskcmd).to_s) + end + + def test_parseMcAfeeDateTime_timeformatVariations_index_3 + taskcmd = "|2 full scan ODS Running Wed 02 Jun 2022 01:00:01 AM UTC |" + assert_equal("2022-06-02 01:00:01 UTC", McAfee.parseMcAfeeDateTime(taskcmd).to_s) + end + + def test_parseMcAfeeDateTime_timeformatVariations_index_4 + taskcmd = "|2 full scan ODS Running Wed 2 Jun 2022 01:00:01 AM UTC |" + assert_equal("2022-06-02 01:00:01 UTC", McAfee.parseMcAfeeDateTime(taskcmd).to_s) + end + + def test_parseMcAfeeDateTime_timeformatVariations_index_5 + taskcmd = "|2 full scan ODS Running Wed 02 Jun 2022 01:00:01 am UTC |" + assert_equal("2022-06-02 01:00:01 UTC", McAfee.parseMcAfeeDateTime(taskcmd).to_s) + end + + def test_parseMcAfeeDateTime_timeformatVariations_index_6 + taskcmd = "|2 full scan ODS Running Wed 2 Jun 2022 01:00:01 am UTC |" + assert_equal("2022-06-02 01:00:01 UTC", McAfee.parseMcAfeeDateTime(taskcmd).to_s) + end + + def test_parseMcAfeeDateTime_timeformatVariations_index_7 + taskcmd = "|2 full scan ODS Running 01/05/22 17:23:26 UTC |" + assert_equal("2022-05-01 17:23:26 UTC", McAfee.parseMcAfeeDateTime(taskcmd).to_s) + end + + def test_parseMcAfeeDateTime_timeformatVariations_index_8 + taskcmd = "|2 full scan ODS Running 01/05/22 17:23:26 -0800 |" + assert_equal("2022-05-01 17:23:26 -0800", McAfee.parseMcAfeeDateTime(taskcmd).to_s) + end + + def test_parseMcAfeeDateTime_timeformatVariations_index_9 + taskcmd = "|2 full scan ODS Running 1/5/22 17:23:26 UTC |" + assert_equal("2022-05-01 17:23:26 UTC", McAfee.parseMcAfeeDateTime(taskcmd).to_s) + end + + def test_parseMcAfeeDateTime_timeformatVariations_index_10 + taskcmd = "|2 full scan ODS Running 1/5/22 17:23:26 -0800 |" + assert_equal("2022-05-01 17:23:26 -0800", McAfee.parseMcAfeeDateTime(taskcmd).to_s) + end + +end diff --git a/installbuilder/datafiles/Base_DSC.data b/installbuilder/datafiles/Base_DSC.data index b8925c34d..e6e9078f1 100755 --- a/installbuilder/datafiles/Base_DSC.data +++ b/installbuilder/datafiles/Base_DSC.data @@ -102,7 +102,7 @@ SHLIB_EXT: 'so' /opt/microsoft/omsconfig/module_packages/nxOMSContainers_1.0.zip; release/nxOMSContainers_1.0.zip; 755; ${{RUN_AS_USER}}; root /opt/microsoft/omsconfig/module_packages/nxOMSCustomLog_1.0.zip; release/nxOMSCustomLog_1.0.zip; 755; ${{RUN_AS_USER}}; root /opt/microsoft/omsconfig/module_packages/nxOMSGenerateInventoryMof_1.5.zip; release/nxOMSGenerateInventoryMof_1.5.zip; 755; ${{RUN_AS_USER}}; root -/opt/microsoft/omsconfig/module_packages/nxOMSPlugin_3.67.zip; release/nxOMSPlugin_3.67.zip; 755; ${{RUN_AS_USER}}; root +/opt/microsoft/omsconfig/module_packages/nxOMSPlugin_3.68.zip; release/nxOMSPlugin_3.68.zip; 755; ${{RUN_AS_USER}}; root /opt/microsoft/omsconfig/module_packages/nxOMSWLI_1.46.zip; release/nxOMSWLI_1.46.zip; 755; ${{RUN_AS_USER}}; root #endif @@ -418,7 +418,7 @@ if [ "$pythonVersion" = "python3" ]; then su - omsagent -c "/opt/microsoft/omsconfig/Scripts/python3/InstallModule.py /opt/microsoft/omsconfig/module_packages/nxOMSContainers_1.0.zip 0" su - omsagent -c "/opt/microsoft/omsconfig/Scripts/python3/InstallModule.py /opt/microsoft/omsconfig/module_packages/nxOMSCustomLog_1.0.zip 0" su - omsagent -c "/opt/microsoft/omsconfig/Scripts/python3/InstallModule.py /opt/microsoft/omsconfig/module_packages/nxOMSGenerateInventoryMof_1.5.zip 0" - su - omsagent -c "/opt/microsoft/omsconfig/Scripts/python3/InstallModule.py /opt/microsoft/omsconfig/module_packages/nxOMSPlugin_3.67.zip 0" + su - omsagent -c "/opt/microsoft/omsconfig/Scripts/python3/InstallModule.py /opt/microsoft/omsconfig/module_packages/nxOMSPlugin_3.68.zip 0" su - omsagent -c "/opt/microsoft/omsconfig/Scripts/python3/InstallModule.py /opt/microsoft/omsconfig/module_packages/nxOMSWLI_1.46.zip 0" else echo "Running python2 python version is ", $pythonVersion @@ -428,7 +428,7 @@ else su - omsagent -c "/opt/microsoft/omsconfig/Scripts/InstallModule.py /opt/microsoft/omsconfig/module_packages/nxOMSContainers_1.0.zip 0" su - omsagent -c "/opt/microsoft/omsconfig/Scripts/InstallModule.py /opt/microsoft/omsconfig/module_packages/nxOMSCustomLog_1.0.zip 0" su - omsagent -c "/opt/microsoft/omsconfig/Scripts/InstallModule.py /opt/microsoft/omsconfig/module_packages/nxOMSGenerateInventoryMof_1.5.zip 0" - su - omsagent -c "/opt/microsoft/omsconfig/Scripts/InstallModule.py /opt/microsoft/omsconfig/module_packages/nxOMSPlugin_3.67.zip 0" + su - omsagent -c "/opt/microsoft/omsconfig/Scripts/InstallModule.py /opt/microsoft/omsconfig/module_packages/nxOMSPlugin_3.68.zip 0" su - omsagent -c "/opt/microsoft/omsconfig/Scripts/InstallModule.py /opt/microsoft/omsconfig/module_packages/nxOMSWLI_1.46.zip 0" #endif