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

Fix: Use regular expressions to count & filter compliance results #2340

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -938,15 +938,15 @@ manage_create_sql_functions ()
" CASE"
" WHEN (SELECT count(*) FROM results"
" WHERE report = report_id"
" AND description LIKE 'Compliant:%%NO%%') > 0"
" AND description ~ '^Compliant:[\\s]*NO[\\s]*') > 0"
" THEN RETURN 'no';"
" WHEN (SELECT count(*) FROM results"
" WHERE report = report_id"
" AND description LIKE 'Compliant:%%INCOMPLETE%%') > 0"
" AND description ~ '^Compliant:[\\s]*INCOMPLETE[\\s]*') > 0"
" THEN RETURN 'incomplete';"
" WHEN (SELECT count(*) FROM results"
" WHERE report = report_id"
" AND description LIKE 'Compliant:%%YES%%') > 0"
" AND description ~ '^Compliant:[\\s]*YES[\\s]*') > 0"
" THEN RETURN 'yes';"
" ELSE RETURN 'undefined';"
" END CASE;"
Expand All @@ -962,7 +962,7 @@ manage_create_sql_functions ()
" BEGIN"
" WITH compliance_count AS"
" (SELECT count(*) AS total FROM results WHERE report = report_id"
" AND description LIKE 'Compliant:%%' || compliance || '%%')"
" AND description ~ ('^Compliant:[\\s]*' || compliance || '[\\s]*'))"
" SELECT total FROM compliance_count"
" INTO count;"
" RETURN count;"
Expand Down
8 changes: 4 additions & 4 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -22118,7 +22118,7 @@ report_compliance_by_uuid (const char *report_id,
*compliance_yes
= sql_int ("SELECT count(*) FROM results"
" WHERE report = %llu"
" AND description LIKE 'Compliant:%%YES%%';",
" AND description ~ '^Compliant:[\\s]*YES[\\s]*';",
report);
}

Expand All @@ -22127,7 +22127,7 @@ report_compliance_by_uuid (const char *report_id,
*compliance_no
= sql_int ("SELECT count(*) FROM results"
" WHERE report = %llu"
" AND description LIKE 'Compliant:%%NO%%';",
" AND description ~ '^Compliant:[\\s]*NO[\\s]*';",
report);
}

Expand All @@ -22136,15 +22136,15 @@ report_compliance_by_uuid (const char *report_id,
*compliance_incomplete
= sql_int ("SELECT count(*) FROM results"
" WHERE report = %llu"
" AND description LIKE 'Compliant:%%INCOMPLETE%%';",
" AND description ~ '^Compliant:[\\s]*INCOMPLETE[\\s]*';",
report);
}
if (compliance_undefined)
{
*compliance_undefined
= sql_int ("SELECT count(*) FROM results"
" WHERE report = %llu"
" AND description NOT LIKE 'Compliant:%%';",
" AND description !~ '^Compliant:[\\s]*';",
report);
}

Expand Down
Loading