windows-patch-baseline
windows-patch-baseline copied to clipboard
[enhancement] new method to determine the latest installed date
Hi there
This came up on the #compliance slack channel. The idea is that we create a method that would allow use to write a control where we can check the number of days since the last patch was installed. i.e.
control 'os-patch-date-1.1' do
impact 0.5
title 'Check OS for last patching date - windows'
desc 'This test will check windows applied a patch in the last 90 days'
describe patch_date do
its('days_since_last_patch_installed') { should be <= 90 }
end
end
I've tried having ago to writing this myself but I've hit a gap in my ruby knowledge and would appreciate a steer.
You already did the ground work to get an array of hotfixes installed. I amended that to include InstalledOn
property
I now have an array with items like this
{"Status"=>nil,
"Description"=>"Security Update",
"HotFixId"=>"KB3135173",
"Caption"=>"http://support.microsoft.com/?kbid=3135173",
"InstallDate"=>nil,
"InstalledBy"=>"NT AUTHORITY\\SYSTEM",
"InstalledOn"=>{"value"=>"/Date(1480636800000)/", "DateTime"=>"02 December 2016 00:00:00"}},
{"Status"=>nil,
"Description"=>"Update",
"HotFixId"=>"KB3139907",
"Caption"=>"http://support.microsoft.com/?kbid=3139907",
"InstallDate"=>nil,
"InstalledBy"=>"NT AUTHORITY\\SYSTEM",
"InstalledOn"=>{"value"=>"/Date(1454457600000)/", "DateTime"=>"03 February 2016 00:00:00"}},
....
So I'm trying to find the lastest InstalledOn so I'm thinking I should sort the array and take the first one?
Once I have the date I was going to parse it and return the number of days.
Let me know what you think, I did think of getting powershell to do the sort for me but where's the fun in that :)