Fixlet/Task Future Date Action by REST API

Hi,

I would like to schedule one of our custom site task, for ex. (AIXHCZ009-Check Status of all Components in Server) via REST API call or by command line, instead of using via BigFix Console. The Execution Constraints like “Starts on” and “Ends on” will be future dates. How to schedule the action.
Thanks and appreciate any help.

Regards
Mendu

Hi, within the XML you post to create the action (documentation) you need to expand the settings element and include the settings you would like - the subelements are StartDateLocalOffset/EndDateLocalOffset or StartDateTimeOffset/EndDateTimeOffset depending if you want it in local time or UTC.

	<Settings>
		<PreActionShowUI>false</PreActionShowUI>
		<HasRunningMessage>false</HasRunningMessage>
		<HasTimeRange>false</HasTimeRange>
		<HasStartTime>true</HasStartTime>
		<StartDateTimeLocalOffset>P1DT9H46M46S</StartDateTimeLocalOffset>
		<HasEndTime>true</HasEndTime>
		<EndDateTimeLocalOffset>P3DT17H46M46S</EndDateTimeLocalOffset>
		<HasDayOfWeekConstraint>false</HasDayOfWeekConstraint>
		<UseUTCTime>false</UseUTCTime>
		<ActiveUserRequirement>NoRequirement</ActiveUserRequirement>
		<ActiveUserType>AllUsers</ActiveUserType>
		<HasWhose>false</HasWhose>
		<PreActionCacheDownload>false</PreActionCacheDownload>
		<Reapply>true</Reapply>
		<HasReapplyLimit>false</HasReapplyLimit>
		<HasReapplyInterval>true</HasReapplyInterval>
		<ReapplyInterval>PT15M</ReapplyInterval>
		<HasRetry>true</HasRetry>
		<RetryCount>999</RetryCount>
		<RetryWait Behavior="WaitForInterval">PT15M</RetryWait>
		<HasTemporalDistribution>false</HasTemporalDistribution>
		<ContinueOnErrors>true</ContinueOnErrors>
		<PostActionBehavior Behavior="Nothing"></PostActionBehavior>
		<IsOffer>false</IsOffer>
	</Settings>
1 Like

I do this same thing with a VBscript that I wrote some time ago.

First, get the offset based on the timezone of the computer running the script:

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For Each objItem In colItems
  strOffset = objItem.CurrentTimeZone / 60
  Exit For
Next

if (strOffset < 0) then
  strOffset = strOffset * -1
  if (strOffset < 10) then
    strOffset = "-0" & left(stroffset & "000", 3)
  else 
    strOffset = "-" & left(stroffset & "0000", 4)
  end if
else
  if (strOffset < 10) then
    strOffset = "+0" & left(stroffset & "000", 3)
  else 
    strOffset = "+" & left(stroffset & "0000", 4)
  end if
end if    

Once the start and end times/dates for the task has been determined, build the start & end strings.

strStartTime = GetDateFormat(right("00" & intStartDay, 2) & " " & MonthName(month(now()), true) & " " & year(now()) & " " & right("00" & intStartHour, 2) & ":" & right("00" & intStartMinute, 2) & ":00 " & strOffset)

strEndTime = GetDateFormat(right("00" & intEndDay, 2) & " " & MonthName(month(now()),true) & " " & year(now()) & " " & right("00" & intEndHour, 2) & ":" & right("00" & intEndMinute, 2) & ":00 " & strOffset)

Function GetDateFormat(ByVal Date1)
    restURL = "https://bigfix:52311/api/query?relevance=" & urlencode("(format " & chr(34) & "P{0}DT{1}H{2}M{3}S" & chr(34) & " + it / (1*day) of it + it mod (1*day) / (1*hour) + it mod (1*hour) / (1*minute) + it mod (1*minute) / (1*second) ) of (" & chr(34) & Date1 & chr(34) & " as time - now)")
    restReq.open "GET", restURL, false, restUsername, restPassword
    restReq.send

    Set strDoc = CreateObject("MSXML2.DOMDocument") 
    strDoc.setProperty "SelectionLanguage", "XPath"
    strDoc.async = False
    strDoc.loadXML(restReq.responseText)

    Set colPatchNodes = strDoc.getElementsByTagName("Answer")

    For Each strValue2 In colPatchNodes
      strValue2 = split(strValue2.text, " ", 2)
      GetDateFormat = strValue2(0)
    next
End Function 

The strStartTime and strEndTime strings are then used in the XML like ageorgiev wrote.

1 Like

Hi,
Thanks for the procedure. I have exported already scheduled action as .bes from BigFix console and renamed as Action**.xml** file. Then updated date and time as “<StartDateTimeLocal>” instead of <StartDateTimeLocalOffset> in <Settings>

<Settings>
    <PreActionShowUI>false</PreActionShowUI>
    <HasRunningMessage>false</HasRunningMessage>
    <HasTimeRange>false</HasTimeRange>
    <HasStartTime>true</HasStartTime>
    <StartDateTimeLocal>2021-09-28 20:00:00</StartDateTimeLocal>
    <HasEndTime>true</HasEndTime>
    <EndDateTimeLocal>2021-09-28 21:00:00</EndDateTimeLocal>
    <HasDayOfWeekConstraint>false</HasDayOfWeekConstraint>
    <UseUTCTime>false</UseUTCTime>
    <ActiveUserRequirement>NoRequirement</ActiveUserRequirement>
    <ActiveUserType>AllUsers</ActiveUserType>
    <HasWhose>false</HasWhose>
    <PreActionCacheDownload>false</PreActionCacheDownload>
    <Reapply>false</Reapply>
    <HasReapplyLimit>true</HasReapplyLimit>
    <ReapplyLimit>3</ReapplyLimit>
    <HasReapplyInterval>false</HasReapplyInterval>
    <HasRetry>false</HasRetry>
    <HasTemporalDistribution>false</HasTemporalDistribution>
    <ContinueOnErrors>true</ContinueOnErrors>
    <PostActionBehavior Behavior="Nothing"></PostActionBehavior>
    <IsOffer>false</IsOffer>
</Settings>

Posted the full Action.xml to BigFix server as below. The Action successfully created to run in future dates.

curl --insecure POST --data-binary @Action.xml --user bigfixadmin:password https://localhost:52311/api/actions

Regards
Mendu.

1 Like

It scheduled properly when using the dates/times in the “YYYY-MM-DD HH:MM:SS” format that you have in your XML?

I have some PowerShell code I use to create the action start/end time in the format for the XML. Say you want to start/end the action on Oct 2nd at 17:00 UTC, this calculates the time offset that needs to be used in the XML

$ActionTimeSpan = new-timespan -start (get-date) -end ([System.Management.ManagementDateTimeConverter]::ToDateTime("20211002170000.000000+000").ToUniversalTime())
$ActionTimeStringForXML = "P$($ActionTimeSpan.Days)DT$($ActionTimeSpan.Hours)H$($ActionTimeSpan.Minutes)M$($ActionTimeSpan.Seconds)S"
write-host $ActionTimeStringForXML
1 Like

Yes. The format is correct for local time. I just tested again with these dates.
2021-10-01 10:00:00
2021-10-01 11:00:00