Patch week calculation required

I have “Patch Week” detail which is updated in the windows registry and location :
“HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of registry in the following format.

G1

I want to start my action based on this value. Basically it has to calculate real patch week with this file value and start their action accordingly . Is that possible ?

Do we have any option to divide the month value by 4 and find the exact week & compare with above pic windows registry :
“HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” value . So that I can start my activity based on that …

Do you want your window on Thursday of the second week of the month, or on the second Thursday of the month (which may not be the same thing).

I highly suggest you check out @brolly33’s blog on the subject at https://www.ibm.com/developerworks/community/blogs/e9d21113-aa93-467e-ac77-a0d20a21eaec/entry/Simple_Answers_Maintenance_Window_related?lang=en

1 Like

Hi Jason ,

Day value will be always different from system to system. Here I have to calculate only week calculation.

Meaning ,

Week 2nd , ‘Thu’ day my action has to start . Another Ex: another system may be having entry as Fri day & week 3rd .

Basically I have to compare with system calendar week & year which suppose to match with week 2nd file entry in the server . Once both match the values, the action has to start particular week & day.

Day calculation is ready . Only week needs to be addressed .

Did you check the blog? There’s a construct for something like first Thursday of current month + 1 * week that should get you there.

1 Like

Thanks Jason . I got the below error again :sob:

Q: (((value “DayAlpha” of key "HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot"of native registry as string as day_of_week as three letters) of current month_and_year) + week* ((value “Week” of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as string))
E: The operator “times” is not defined.

Hello goperiya1,

Here is your relevance:

Q: (("thu" as string as day_of_week as three letters) of current month_and_year) + week*(2 as string)
E: The operator "times" is not defined.

The 1st addendum has a result type “singular string”:

Q: (("thu" as day_of_week as three letters) of current month_and_year)
A: Thu
I: singular string

The 2nd addendum is a problem here:

Q: week*(2 as string)
E: The operator "times" is not defined.

Removing the “as string” part would get rid of that error:

Q: week*(2)
A: 14 days
I: singular time interval

But now, note that the 1st addendum has a result type “singular string” and the 2nd addendum is “singular time interval”. As a result, you still won’t be able to add those results, while they have different types:

Q: (("thu" as string as day_of_week as three letters) of current month_and_year) + week*(2)
E: The operator "plus" is not defined.

Note: A URL that Jason posted above has some good examples related to maintenance window calculations.

If you want to get a Tuesday of the 1st week of the current month, you might try something like this instead:

q: (first tuesday of current month_and_year)
A: Tue, 05 Mar 2019

If you need the next day of the previous result, you might add a day to it:

q: (first tuesday of current month_and_year) + day
A: Wed, 06 Mar 2019

If you need the next week, you might add a week to the previous result:

q: (first tuesday of current month_and_year) + week
A: Tue, 12 Mar 2019

Regards,
Vitaliy

1 Like

Thanks Vitaliy .

Thanks for your detailed description.

Here my challenge, each & everything I have to refer the file input and make sure my action based on the windows registry value . I have tried almost all options where I am getting only failures :sob:

Now I am trying to change something . Will get back to you .

Is that correct way now ?

((exists key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” whose (conjunction of (exists (it as integer) and it as integer < 5 and it as integer > 0) of substrings separated by “,” of (value “Week” of it as string as trimmed string) AND (exists day_of_week (it)) of (value “DayAlpha” of it as string)) of native registry))

This also not starting the action as per week value :slight_smile:

Hi Jason , Vitaliy ,

I think , I have to break down the current month calendar in to 4 pieces and when it match with 2 week I can start
my action.

May be ,it has to divide in to 4 pieces and assign integer values & based on integer values , we can start the action right ? Somewhat trick here .

I have done something like this . However test is failing still .

(if (not exists key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” whose (exists substrings separated by “,” whose (exists (it as month) OR it as lowercase = “all”) of (value “Months” of it as string) AND exists substrings separated by “,” whose (it as integer < 5 and it as integer > 0) of (value “Week” of it as string) AND exists substrings separated by “,” whose (exists day_of_week (it)) of (value “DayAlpha” of it as string) AND conjunction of (exists time_of_day ((preceding text of it & “:” & it) of last 2 of it)) of (value “WindowStart” of it as string; value “WindowEnd” of it as string)) of native registry) then “not defined” else (if (disjunction of (((it as lowercase = “all” or it as month = current month) of item 0 of it) AND (it as integer - 1 = (current day_of_month as integer - 1) / 7) of item 1 of it AND (if (item 3 of it < item 4 of it) then (day_of_week (item 2 of it) = current day_of_week AND time of current time_of_day >= (item 3 of it - 10minute) AND time of current time_of_day < item 4 of it) else ((day_of_week (item 2 of it) = current day_of_week AND time of current time_of_day >= (item 3 of it - 10minute)) OR (day_of_week (item 2 of it) + day = current day_of_week AND time of current time_of_day < item 4 of it)))) of (substrings separated by “,” whose (exists (it as month) or it as lowercase = “all”) of (value “Months” of it as string) , substrings separated by “,” whose (exists (it as integer)) of (value “Week” of it as string) , substrings separated by “,” whose (exists day_of_week (it)) of (value “DayAlpha” of it as string) , (time_of_day ((preceding text of it & “:” & it) of last 2 of it)) of (value “WindowStart” of it as string) , (time_of_day ((preceding text of it & “:” & it) of last 2 of it)) of (value “WindowEnd” of it as string)) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) AND (exists (((two digit hour of it & “” & two digit minute of it) of current time_of_day) >= ((last 4 of (“0000” & ((it / 60) as string & last 2 of (“00” & ((it mod 60) as string))) of (first 2 of it as integer * 60 + last 2 of it as integer - 10) of it) of ((value “WindowStart” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as string)))) then “yes” else “no”))

Basically I am trying to cover 2 areas.

  1. Patch week , month & year calculation based on the registry value .

  2. 10mins subtracted from “WindowStart” time in order to make sure my action is applicable & action has to start before 10mins of windowstart time .

However the server is not coming applicable list & action not yet started . Not sure where exactly the problem now .

Do you control how the window will be represented in the registry? There are some easier ways to calculate the window if you can alter slightly, like i stead of months “all”, listing out the months individually (and all twelve months listed like “Jan”;“Feb”;… in the case of “all”), and having a window duration like “30” for 30 minutes instead of an end time; especially when you get to edge cases like a window rolling over midnight.

Tried all possibility Jason .

I will post you once I narrow down the problem . Thanks for your support until now.

I was asking, can you change the format of the registry values?

Your relevance can be much easier, if instead of “week” you used “days”, and zero-indexed it (like an array).
That way, “first Thursday of the month” would be represented with “Thu” and “0”. Second Thursday of the month would be “Thu” and “7”. The relevance for that part would just be something like
(first (value "DayAlpha" of it as string as day_of_week) + (value "day" of it as integer * day)) of key "yourpath" of registry

You can also easily change it all to be based off “Patch Tuesday”, as the blog states. “Patch Tuesday” falls on
(first tuesday of current month_and_year) + 7 * day

So you can represent “Thursday after Patch Tuesday” as
(first tuesday of current month_and_year) + 9 * day

Or “The thursday after that” as

(first tuesday of current month_and_year) + 16 * day
And you don’t have to calculate how many weeks are in each month.

1 Like

yaa. Good proposal Jason.

So…do you have control over how the registry values get written? Is that on the table?

I think I see the missing link here…

Q: (("thu" as string as day_of_week as three letters) of current month_and_year) + week*(2 as string)
E: The operator "times" is not defined.

vs

Q: (first ("thu" as day_of_week) of current month_and_year) + week * (2)
A: Thu, 21 Mar 2019

Or, to get the 0 index that @JasonWalker mentioned, just subtract 1

 Q: (first ("thu" as day_of_week) of current month_and_year) + week * (2 - 1)
A: Thu, 14 Mar 2019

and with your reg keys added in

Q: (first (value "DayAlpha" of key "HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot" as string as day_of_week) of current month_and_year) + (week * (value "week" of key "HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot" as string as integer - 1))

And if you want to deal with possibilty of your date being right on the month edge, you could plural out to catch last month, this month and next month

Q: (it + week * (2 - 1)) of (firsts ("thu" as day_of_week) of (it - month; it; it + month) of current month_and_year) 
A: Thu, 14 Feb 2019
A: Thu, 14 Mar 2019
A: Thu, 11 Apr 2019
1 Like