Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating unique identifiers for checks to enhance post-processing #675

Open
An-dir opened this issue Feb 19, 2025 · 0 comments
Open

Creating unique identifiers for checks to enhance post-processing #675

An-dir opened this issue Feb 19, 2025 · 0 comments

Comments

@An-dir
Copy link

An-dir commented Feb 19, 2025

When using the generated JSON report for advanced post-processing, it is currently not possible to accurately identify and therefore track some of the checks over time. My suggestion is to assign a unique identifier to each individual test result. Based on your current default checks, they could look like this:

Short ID (generated from current default tests)

  • CIS.1.2.1
  • EIDSCA.AF01
  • MS.AAD.1.1
  • MS.SHAREPOINT.1.1
  • MT.1004
  • MT.1024.9e53e74a-30a5-4cae-932a-f4d7b81ab3cd_passwordHashSync

I have created a workaround that meets my needs for now, but it could break when updating Maester. Therefore I am interested in the extension of the default properties that are returned in the json report by the property "ID" or "MaesterID".

Just to share my workarround here a part of my script that i am currently testing with (not yet finished):

$MaesterVersion = "1.0.0"
$FileForJSONExport = ".\maester\psmodule\Maester\$MaesterVersion\internal\ConvertTo-MtMaesterResults.ps1"
$ExportToolRawData = Get-Content $FileForJSONExport
# DOING MODIFICATIONS TO GET A UNIQUE ID FOR TESTS
$ExportToolRawData = foreach ($line in $ExportToolRawData) {
    if ($line -match "^\s*\`$helpUrl = ''") {
        $line
        "        # Change01`r`n"+
        "        if (`$Name -like `"CIS *`") {`r`n"+
        # CIS Level may not be included as it can't be different within a chapter
        #"        `$TestID = `$Name -replace `"^CIS *([0-9.]*) \((.*?)\).*`",'CIS.`$1.`$2'`r`n"+
        "        `$TestID = `$Name -replace `"^CIS *([0-9.]*) \((.*?)\).*`",'CIS.`$1'`r`n"+
        "        }`r`n"+
        "        if (`$Name -notlike `"CIS *`") {`r`n"+
        "        `$TestID = `$Name -replace `"^(.*?)(:| ).*`$`",'`$1'`r`n"+
        "        }`r`n"+
        "        if (`$null -ne `$test.Block.Data.ID) {`r`n"+
        "        `$TestID += `".`" + `$test.Block.Data.ID`r`n"+
        "        }`r`n"+
        "        # Change01 END`r`n"
        } elseif ($line -match "^\s*helpUrl\s*=\s*\`$helpUrl") {
        $line
        "            #Change02 NewLine:";"$(" "*12)ID$(" "*14)= `$TestID"
        } else {
        $line
    }
}
$ExportToolRawData | Out-File -Encoding utf8BOM -Path $FileForJSONExport

I avoided to directly modify the file to be able to apply updates and eventually have my script updating the new "ConvertTo-MtMaesterResults.ps1" file again.

My workarround works well except with MT.1038 as there is a test with the same number in the "Name" in the default scripts. Of course I could validate that duplicate by checking the "ScriptBlockFile" property in the result, but using this as a secondary identifyer manually is relly not that great. As i have seen this is already addressed here: #604 and here: #583 (comment)

Making an offical requirement for checks to have "ID" as a required parameter and make it unique could be challenging. Maybe a combination of the scriptfoldername, test id and an ID generated from the query if required could work but should be coordinated. Here are some examples about that idea:

Long but duplicate preventing generated ID:

  • "Maester/Entra/MT.1038" (Default: using the tests folder name adding the ID as it is in "Name")
  • "Maester/Entra/MT.1033.60a8a48a-60cd-4069-b84c-99aaabbbdfa0" (Like default example above adding ID from API result)
  • "Maester/Entra/MT.1024.9e53e74a-30a5-4cae-932a-f4d7b81ab3cd_passwordHashSync" (Default + ID from API result)
  • "cis/CIS.1.1.3" (Default, but duplicate "CIS" because the test ist NOT just "CIS 1.1.3" but more "CIS Microsoft 365 1.1.3". A corrected ID would be "CIS/Microsoft.365.1.1.3" or something like that)
  • "EIDSCA/EIDSCA.AF01" (Default but duplicate "EIDSCA" in the name like in "CIS")

With my ID workarround in the code i could almost finish the unique ID generation like that:
$CSAJsonContent.Tests | foreach {($_.ScriptBlockFile -replace [regex]::Escape($repl + "maester-tests\") -replace "test-.*\.ps1" -replace"\\",".") +$_.id}

I'd prefer the shorter version of the ID and I'd prefer not to generate it for myself. So (when) will there be a true "ID"?

And for the people asking "why not use the Name property as a Identifier?" I argue with the challanges of different languages, and sometimes correction of misspelled names.

P.S.: How about an additional parameter for the tables (aka "impactedResources") that are integrated in the "ResultDetail"? In Large reports this is a requirement to have it performant and readable in html and separated in json for postprocessing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant