Custom fact error: Oops, we're sorry but something went wrong No route matches {:action=>"index", :controller=>"

Problem:
I’ve written an external, powershell fact for puppet which uploads to foreman, but I receive an error when trying to view the fact data in the console.

Oops, we’re sorry but something went wrong No route matches {:action=>“index”, :controller=>“fact_values”, :host_id=>“desktop-36nsamj.britanniahome.net”, :parent_fact=>“installed_programs::7-Zip 19.00 (x64)”}, possible unmatched constraints: [:parent_fact]

The JSON format appears to be correct and no errors are displayed when I run puppet agent -t

{
    "Installed_Programs":  {
                               "VMware Tools":  {
                                                    "Publisher":  "VMware, Inc.",
                                                    "Name":  "VMware Tools",
                                                    "Version":  "11.2.6.17901274"
                                                },
                               "Google Update Helper":  {
                                                            "Publisher":  "Google LLC",
                                                            "Name":  "Google Update Helper",
                                                            "Version":  "1.3.35.451"
                                                        },
                               "Microsoft Visual C++ 2019 X64 Additional Runtime - 14.27.29016":  {
                                                                                                      "Publisher":  "Microsoft Corporation",
                                                                                                      "Name":  "Microsoft Visual C++ 2019 X64 Additional Runtime - 14.27.29016",
                                                                                                      "Version":  "14.27.29016"
                                                                                                  },
                               "7-Zip 19.00 (x64)":  {
                                                         "Publisher":  "Igor Pavlov",
                                                         "Name":  "7-Zip 19.00 (x64)",
                                                         "Version":  "19.00"
                                                     },
                               "Puppet Agent (64-bit)":  {
                                                             "Publisher":  "Puppet Inc",
                                                             "Name":  "Puppet Agent (64-bit)",
                                                             "Version":  "7.11.0"
                                                         },
                               "Update for Windows 10 for x64-based Systems (KB5001716)":  {
                                                                                               "Publisher":  "Microsoft Corporation",
                                                                                               "Name":  "Update for Windows 10 for x64-based Systems (KB5001716)",
                                                                                               "Version":  "2.71.0.0"
                                                                                           },
                               "Microsoft Visual C++ 2019 X86 Additional Runtime - 14.27.29016":  {
                                                                                                      "Publisher":  "Microsoft Corporation",
                                                                                                      "Name":  "Microsoft Visual C++ 2019 X86 Additional Runtime - 14.27.29016",
                                                                                                      "Version":  "14.27.29016"
                                                                                                  },
                               "Orca":  {
                                            "Publisher":  "Microsoft Corporation",
                                            "Name":  "Orca",
                                            "Version":  "10.1.19041.685"
                                        },
                               "Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.4148":  {
                                                                                                      "Publisher":  "Microsoft Corporation",
                                                                                                      "Name":  "Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.4148",
                                                                                                      "Version":  "9.0.30729.4148"
                                                                                                  },
                               "Microsoft Update Health Tools":  {
                                                                     "Publisher":  "Microsoft Corporation",
                                                                     "Name":  "Microsoft Update Health Tools",
                                                                     "Version":  "2.83.0.0"
                                                                 },
                               "Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.6161":  {
                                                                                                      "Publisher":  "Microsoft Corporation",
                                                                                                      "Name":  "Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.6161",
                                                                                                      "Version":  "9.0.30729.6161"
                                                                                                  },
                               "Google Chrome":  {
                                                     "Publisher":  "Google LLC",
                                                     "Name":  "Google Chrome",
                                                     "Version":  "94.0.4606.54"
                                                 },
                               "Microsoft Visual C++ 2015-2019 Redistributable (x64) - 14.27.29016":  {
                                                                                                          "Publisher":  "Microsoft Corporation",
                                                                                                          "Name":  "Microsoft Visual C++ 2015-2019 Redistributable (x64) - 14.27.29016",
                                                                                                          "Version":  "14.27.29016.0"
                                                                                                      },
                               "Microsoft Edge":  {
                                                      "Publisher":  "Microsoft Corporation",
                                                      "Name":  "Microsoft Edge",
                                                      "Version":  "93.0.961.52"
                                                  },
                               "Microsoft Visual C++ 2019 X64 Minimum Runtime - 14.27.29016":  {
                                                                                                   "Publisher":  "Microsoft Corporation",
                                                                                                   "Name":  "Microsoft Visual C++ 2019 X64 Minimum Runtime - 14.27.29016",
                                                                                                   "Version":  "14.27.29016"
                                                                                               },
                               "Notepad++ (32-bit x86)":  {
                                                              "Publisher":  "Notepad++ Team",
                                                              "Name":  "Notepad++ (32-bit x86)",
                                                              "Version":  "7.8.1"
                                                          },
                               "VLC media player":  {
                                                        "Publisher":  "VideoLAN",
                                                        "Name":  "VLC media player",
                                                        "Version":  "3.0.8"
                                                    },
                               "Microsoft Edge Update":  {
                                                             "Publisher":  null,
                                                             "Name":  "Microsoft Edge Update",
                                                             "Version":  "1.3.151.27"
                                                         },
                               "Microsoft Visual C++ 2019 X86 Minimum Runtime - 14.27.29016":  {
                                                                                                   "Publisher":  "Microsoft Corporation",
                                                                                                   "Name":  "Microsoft Visual C++ 2019 X86 Minimum Runtime - 14.27.29016",
                                                                                                   "Version":  "14.27.29016"
                                                                                               },
                               "Microsoft Visual C++ 2015-2019 Redistributable (x86) - 14.27.29016":  {
                                                                                                          "Publisher":  "Microsoft Corporation",
                                                                                                          "Name":  "Microsoft Visual C++ 2015-2019 Redistributable (x86) - 14.27.29016",
                                                                                                          "Version":  "14.27.29016.0"
                                                                                                      }
                           }
}


Expected outcome:

Fact data is accessible

Foreman and Proxy versions:
3.10 Nightly

Foreman and Proxy plugin versions:
Latest

Distribution and version:
Foreman Stock Nightly + Katello

Other relevant data:

1 Like

Here’s the actual powershell code that generates the .json

# Get-InstalledPrograms
# Script to list installed applications on a system in JSON format for puppet
# Revision 1.00

$InstalledSoftware = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall  -ea SilentlyContinue |Get-ItemProperty|Where-Object {$_.DisplayName -notlike ""} |Select-object -Property DisplayName,Publisher,DisplayVersion,UninstallString

# Create an empty array
$InstalledSoftwareTitles= @{}
foreach ($_ in $InstalledSoftware){

    # Create values with the array properties
    $PackageName = $_.DisplayName
    $PackageVersion = $_.DisplayVersion
    $PackagePublisher = $_.Publisher

    # Create the tables
    $UpdateProperties =@{
        Name = $PackageName
        Version = $PackageVersion
        Publisher = $PackagePublisher
    }

    # Append the data to the array
    $InstalledSoftwareTitles["$PackageName"] = $UpdateProperties
} 

# Create sub tables so that the data is properly structured.
$InventoryFacts = @{
    Installed_Programs = $InstalledSoftwareTitles
}

$InventoryFactsJson = $InventoryFacts |ConvertTo-Json
# $InventoryFactsJson |Out-Host
Set-Content -Encoding Ascii -Path "${PSScriptRoot}/Get-InstalledPrograms.json" -Value $InventoryFactsJson

Figured it out, Fact parents apparently need to be something that’s URL friendly, so no spaces, parenthesis, special characters, etc.

Updated powershell code

# Get-InstalledPrograms
# Script to list installed applications on a system in JSON format for puppet
# Revision 1.00

$InstalledSoftware = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall  -ea SilentlyContinue |Get-ItemProperty|Where-Object {$_.DisplayName -notlike ""} |Select-object -Property DisplayName,Publisher,DisplayVersion,UninstallString

# Create an empty array
$InstalledSoftwareTitles= @{}
foreach ($_ in $InstalledSoftware){

    # Create values with the array properties
    # Remove any Spaces and periods from the Title which would cause a problem for URLs
    $PackageTitle = $_.DisplayName -replace '[!@#$%^&*(),?":{}|<>+() ]','_'
    $PackageName = $_.DisplayName
    $PackageVersion = $_.DisplayVersion
    $PackagePublisher = $_.Publisher

    # Create the tables
    $UpdateProperties =@{
        Name = $PackageName
        Version = $PackageVersion
        Publisher = $PackagePublisher
    }

    # Append the data to the array
    $InstalledSoftwareTitles["$PackageTitle"] = $UpdateProperties} 

# Create sub tables so that the data is properly structured.
$InventoryFacts = @{
    installed_programs = $InstalledSoftwareTitles
}

$InventoryFactsJson = $InventoryFacts |ConvertTo-Json
# $InventoryFactsJson |Out-Host
Set-Content -Encoding Ascii -Path "${PSScriptRoot}/Get-InstalledPrograms.json" -Value $InventoryFactsJson
1 Like

We should drop friendly ids for facts. This is not the first time someone has hit that.

Would the IDs get a randomly generated ID in this case,.which then map to
the fact name, allowing it to have spaces and characters?

Yeah, each fact name already has a unique numerical id. For some reason, we use name in the url on this page, like it was SEO optimized eshop. I guess it would be acceptable to use url like fact_names/3/facts

That would would be preferred, especially as it would allow me to lost
installed applications using their original name.