Problem with Prefetch Block

Hi

Help needed regarding Prefetch Block functionality. I am trying to make a fixlet/task to copy a configuration file to our servers, the file varies depending on the domain, i which the server is placed.

ComTradeDomainList.txt holds information needed for prefetch to download the file (sha1, sha256, url)

When we execute the action the ComTradeDomainList.txt is downloaded ok, but then later it fails, because it looks like the configuration file is not downloaded, even though the if sentence is fulfilled. If we then run it again, the configuration file is being downloaded and everything is ok.

Is there something I have misunderstood about how Prefetch Blocks works and how/when parameters and relevance substitutions is being done.

Action script (Prefetch Block part) :

begin prefetch block
parameter “tempfile_pb” = "{pathname of folder “__Download” of client folder of site “CustomSite_XX_Custom_Site”}\ComTradeDomainList.txt"
parameter “domain_pb” = “name={preceding text of first “.” of (following text of first “.” of dns name as lowercase)}”

  add prefetch item name=ComTradeDomainList.txt sha1=123 sha256=123 size=4826 url=http://xxx/xxx/ComTradeDomainList.txt

  collect prefetch items

  if {exists file (parameter "tempfile_pb") and exists lines whose (it contains (parameter "domain_pb")) of file (parameter "tempfile_pb")}
     add prefetch item {lines whose (it contains (parameter "domain_pb")) of file (parameter "tempfile_pb")}
  endif

end prefetch block

Thanks in advance

1 Like

Hi

Nobody who can help me with this one or who have an idea, how to solve this without having to use 2 fixlets or a very large “if” sentence.

Thanks in advance

As you’ve identified, ideally the ComTradeDomainList.txt file should already be available to the Agent for the dynamic download assessment.

How is this file updated on the target web server?

One method you might consider here (aside from 2 separate actions which can certainly work), is to place the ComTradeDomainList.txt file in a custom site (perhaps the same custom site as the Fixlet or Task containing this actionscript). This can be done via the Console, or programmatically via the REST API when the file is updated on the http host.

The ComTradeDomainList.txt is maintained by us and it is placed on the BES Server, which is why I don’t understand why the Prefetch Block isn’t working. Shouldn’t the “Collect prefetch items” download the file and make it available before moving on to the “if” sentence.

I wasn’t aware of the “Adding files to sites” functionality, which could be a way to handle this, but it would copy the files to all 12000 servers in the custom site, where only a few of them would need it at some time.

Are you entering a valid size, sha1, and sha256 value for ComTradeDomainList.txt ? That is required or the download will be rejected as a tampered file.

That’s where the value of “attach file to site” comes in. You can attach a site file to bypass the sha1/sha256/size validation and trust that the file is correct (because the BES infrastructure is enforcing this for you automatically).

Often this site-attached file contains a list of other files that could be downloaded, including their true size, sha1, sha256, and URL values. This is referred to as a Manifest file.

This is how Dynamic Downloads are handled in many deployments. There is a content repository hosted on a server somewhere. Whenever changes are made to the repo (or on a scheduled basis), the Manifest file is regenerated to include all of the correct file information, and then the Manifest is attached to a Bigfix Custom Site. The Manifest contains “every possible dynamic download for every file my deployment hosts”. The BES clients parse the manifest file as part of their action script downloads, and use those results to trigger downloads specific to their action.

If your action already had the correct size/sha1/sha256 values for your file, then your problem may lie elsewhere. Please let us know whether that’s the case.

We have valid values for the ComTradeDomainList.txt and everything works fine, we just have to run the fixlet twice, first time it downloads the ComTradeDomainList.txt and next time the configuration file is downloaded, looks like I am getting a “not exist” on the ComTradeDomainList.txt in my “if” sentence the first time I run the fixlet againt a server.

Ah, ok.

Try moving that second download statement out of the prefetch block, and use the prefetch or download now as statements to parse the file in the actionscript after the prefetch block.

I haven’t used this functionality much, but I agree my impression is that it should have worked as you expected.

I cannot do this, since neither prefetch or download now allows relevance substitution. Even more, I don’t think prefetch is allowed if you are using a prefetch block in your action script, I am not sure about download now.

Apologies again, it’s been a while since I had access to a console to check on this.

I think I found the root cause of your problem, at https://developer.bigfix.com/action-script/guide/dynamic_download.html, and this shouldn’t be too hard to fix. The key is near the end -

No matter which technique is used, after the files have been downloaded, they can be examined with various Inspectors. Before the action runs, these files are collected in a prefetch folder. While the action is running, they are located in the __Download folder.

These Inspectors can be used to locate the files before or while the action runs:

download folder: During the prefetch parsing, this Inspector returns a folder object from the __Global<sitename><actionid>\named folder.

download path “pathname”: This Inspector returns a string containing the full pathname to the specified file, whether it exists or not. The download filename is equivalent to (pathname of download folder) & & filename.

download file “filename”: This Inspector returns a file object from the download folder or another named folder. The download filename is equivalent to file ‘filename’ of download folder.

During the prefetch block the file is not at __BESData\sitename\__Download, it’s stored in a prefetch area specific to the action id; but can be referenced as download file "xyx". I’ve usually referenced my downloads this way, which is probably why I never encountered your issue.

Try changing your prefetch block to

begin prefetch block
// no longer used, at least in prefetch --  parameter “tempfile_pb” = "{pathname of folder “__Download” of client folder of site “CustomSite_XX_Custom_Site”}\ComTradeDomainList.txt"
parameter “domain_pb” = “name={preceding text of first “.” of (following text of first “.” of dns name as lowercase)}”

  add prefetch item name=ComTradeDomainList.txt sha1=123 sha256=123 size=4826 url=http://xxx/xxx/ComTradeDomainList.txt

  collect prefetch items

  if {exists download file "ComTradeDomainList.txt" whose (exists lines containing (parameter "domain_pb") of it)}
     add prefetch item {lines whose (it contains (parameter "domain_pb")) of download file "ComTradeDomainList.txt" }
  endif
end prefetch block
1 Like

Yes, that solved my problem.

Thanks for all your help.