Skip to content

Commit

Permalink
Merge pull request #633 from timopollmeier/compliance-types
Browse files Browse the repository at this point in the history
Count compliance levels for tasks and reports
  • Loading branch information
mattmundell authored Jul 11, 2019
2 parents 826a1e1 + ddd3a1b commit 994b081
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Document switching between releases when using Postgres. [#563](https://github.com/greenbone/gvmd/pull/563)
- Add vt_refs table. The table is filled with the references of the VTs. [#570](https://github.com/greenbone/gvmd/pull/570)
- Cgreen based unit tests for gvmd has been added. [#579](https://github.com/greenbone/gvmd/pull/579)
- New usage_type property to distinguish normal scan tasks and configs from compliance audits and policies [#613](https://github.com/greenbone/gvmd/pull/613) [#625](https://github.com/greenbone/gvmd/pull/625) [#633](https://github.com/greenbone/gvmd/pull/633)

### Changes
- Check if NVT preferences exist before inserting. [#406](https://github.com/greenbone/gvmd/pull/406)
Expand Down
94 changes: 63 additions & 31 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -18500,37 +18500,69 @@ handle_get_tasks (gmp_parser_t *gmp_parser, GError **error)
scan_start = scan_start_time_uuid (last_report_id);
scan_end = scan_end_time_uuid (last_report_id);

last_report = g_strdup_printf ("<last_report>"
"<report id=\"%s\">"
"<timestamp>%s</timestamp>"
"<scan_start>%s</scan_start>"
"<scan_end>%s</scan_end>"
"<result_count>"
"<debug>%i</debug>"
"<hole>%i</hole>"
"<info>%i</info>"
"<log>%i</log>"
"<warning>%i</warning>"
"<false_positive>"
"%i"
"</false_positive>"
"</result_count>"
"<severity>"
"%1.1f"
"</severity>"
"</report>"
"</last_report>",
last_report_id,
timestamp,
scan_start,
scan_end,
debugs,
holes,
infos,
logs,
warnings,
false_positives,
severity);
if (strcmp (task_iterator_usage_type (&tasks), "audit") == 0)
{
int compliance_yes, compliance_no, compliance_incomplete;

report_compliance_by_uuid (last_report_id,
&compliance_yes,
&compliance_no,
&compliance_incomplete);

last_report
= g_strdup_printf ("<last_report>"
"<report id=\"%s\">"
"<timestamp>%s</timestamp>"
"<scan_start>%s</scan_start>"
"<scan_end>%s</scan_end>"
"<compliance_count>"
"<yes>%d</yes>"
"<no>%d</no>"
"<incomplete>%d</incomplete>"
"</compliance_count>"
"</report>"
"</last_report>",
last_report_id,
timestamp,
scan_start,
scan_end,
compliance_yes,
compliance_no,
compliance_incomplete);
}
else
last_report
= g_strdup_printf ("<last_report>"
"<report id=\"%s\">"
"<timestamp>%s</timestamp>"
"<scan_start>%s</scan_start>"
"<scan_end>%s</scan_end>"
"<result_count>"
"<debug>%i</debug>"
"<hole>%i</hole>"
"<info>%i</info>"
"<log>%i</log>"
"<warning>%i</warning>"
"<false_positive>"
"%i"
"</false_positive>"
"</result_count>"
"<severity>"
"%1.1f"
"</severity>"
"</report>"
"</last_report>",
last_report_id,
timestamp,
scan_start,
scan_end,
debugs,
holes,
infos,
logs,
warnings,
false_positives,
severity);
free (scan_start);
free (scan_end);
g_free (timestamp);
Expand Down
3 changes: 3 additions & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,9 @@ report_path_task_uuid (gchar*);
gboolean
report_task (report_t, task_t*);

void
report_compliance_by_uuid (const char *, int *, int *, int *);

char *
report_slave_task_uuid (report_t);

Expand Down
55 changes: 53 additions & 2 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -19374,8 +19374,8 @@ void
set_task_usage_type (task_t task, const char *usage_type)
{
const char *actual_usage_type;
if (usage_type && strcasecmp (usage_type, "policy") == 0)
actual_usage_type = "policy";
if (usage_type && strcasecmp (usage_type, "audit") == 0)
actual_usage_type = "audit";
else
actual_usage_type = "scan";

Expand Down Expand Up @@ -22507,6 +22507,57 @@ report_task (report_t report, task_t *task)
return FALSE;
}

/**
* @brief Get compliance counts for a report.
*
* @param[in] report_id UUID of the report.
* @param[out] compliance_yes Number of "YES" results.
* @param[out] compliance_no Number of "NO" results.
* @param[out] compliance_incomplete Number of "INCOMPLETE" results.
*/
void
report_compliance_by_uuid (const char *report_id,
int *compliance_yes,
int *compliance_no,
int *compliance_incomplete)
{
report_t report;
gchar *quoted_uuid = sql_quote (report_id);
sql_int64 (&report,
"SELECT id FROM reports WHERE uuid = '%s';",
quoted_uuid);

if (compliance_yes)
{
*compliance_yes
= sql_int ("SELECT count(*) FROM results"
" WHERE report = %llu"
" AND description LIKE 'Compliant:%%YES%%';",
report);
}

if (compliance_no)
{
*compliance_no
= sql_int ("SELECT count(*) FROM results"
" WHERE report = %llu"
" AND description LIKE 'Compliant:%%NO%%';",
report);
}

if (compliance_incomplete)
{
*compliance_incomplete
= sql_int ("SELECT count(*) FROM results"
" WHERE report = %llu"
" AND description LIKE 'Compliant:%%INCOMPLETE%%';",
report);
}

g_free (quoted_uuid);
}


/**
* @brief Return the UUID of a report's slave.
*
Expand Down

0 comments on commit 994b081

Please sign in to comment.