Skip to content
Merged
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
24 changes: 24 additions & 0 deletions src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2223,6 +2223,7 @@ gvmd (int argc, char** argv, char *env[])
static gboolean disable_password_policy = FALSE;
static gboolean disable_scheduling = FALSE;
static gboolean dump_vt_verification = FALSE;
static gboolean dump_asset_snapshot_counts = FALSE;
static gchar *encryption_key_type = NULL;
static int encryption_key_length = 0;
static gchar *set_encryption_key = NULL;
Expand Down Expand Up @@ -2407,6 +2408,10 @@ gvmd (int argc, char** argv, char *env[])
&dump_vt_verification,
"Dump the string the VTs verification hash is calculated from.",
NULL },
{ "dump-asset-snapshot-counts", '\0', 0, G_OPTION_ARG_NONE,
&dump_asset_snapshot_counts,
"Dump the string the Asset snapshot counts are calculated from.",
NULL },
{ "encryption-key-length", '\0', 0, G_OPTION_ARG_INT,
&encryption_key_length,
"Set key length to <length> bits when creating a new RSA"
Expand Down Expand Up @@ -3311,6 +3316,25 @@ gvmd (int argc, char** argv, char *env[])
return EXIT_SUCCESS;
}

if (dump_asset_snapshot_counts)
{
int ret;

setproctitle ("--dump-asset-snapshot-counts");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;

ret = manage_dump_asset_snapshot_counts (log_config, &database);
log_config_free ();
if (ret)
{
printf ("Failed to dump Asset snapshot counts.\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

if (create_scanner)
{
int ret;
Expand Down
3 changes: 3 additions & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -3530,6 +3530,9 @@ manage_rebuild (GSList *, const db_conn_info_t *);
int
manage_dump_vt_verification (GSList *, const db_conn_info_t *);

int
manage_dump_asset_snapshot_counts(GSList *, const db_conn_info_t *);


/* Wizards. */

Expand Down
67 changes: 67 additions & 0 deletions src/manage_sql_assets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,73 @@ asset_snapshots_container_image (report_t report, task_t task)
}
#endif /* ENABLE_CONTAINER_SCANNING */

/**
* @brief Dump the string for Asset Snapshot counts to stdout.
*
* @param[in] log_config Log configuration.
* @param[in] database Location of manage database.
*
* @return 0 success, -1 error, -2 database is too old,
* -3 database needs to be initialised from server,
* -5 database is too new.
*/
int
manage_dump_asset_snapshot_counts (GSList *log_config,
const db_conn_info_t *database)
{
int ret;

int total_count = 0;
int target_count = 0;
int agent_count = 0;
int container_image_count = 0;

ret = manage_option_setup (log_config, database,
0 /* avoid_db_check_inserts */);
if (ret)
return ret;

total_count = sql_int (
"SELECT COUNT(DISTINCT asset_key) FROM asset_snapshots;");

target_count = sql_int (
"SELECT COUNT(DISTINCT asset_key) FROM asset_snapshots"
" WHERE asset_type = %d;",
ASSET_TYPE_TARGET);

agent_count = sql_int (
"SELECT COUNT(DISTINCT asset_key) FROM asset_snapshots"
" WHERE asset_type = %d;",
ASSET_TYPE_AGENT);

container_image_count = sql_int (
"SELECT COUNT(DISTINCT asset_key) FROM asset_snapshots"
" WHERE asset_type = %d;",
ASSET_TYPE_CONTAINER_IMAGE);

GString *out = g_string_new (NULL);

g_string_append (out, "Asset Snapshot Counts (distinct asset_key)\n");
g_string_append_printf (
out, " Total: %d\n", total_count);
g_string_append_printf (
out, " Targets (type=%d): %d\n",
ASSET_TYPE_TARGET, target_count);
g_string_append_printf (
out, " Agents (type=%d): %d\n",
ASSET_TYPE_AGENT, agent_count);
g_string_append_printf (
out, " Container images (type=%d): %d\n",
ASSET_TYPE_CONTAINER_IMAGE, container_image_count);

printf ("%s", out->str);

g_string_free (out, TRUE);

manage_option_cleanup ();
return 0;
}

/**
* @brief Setup hosts and their identifiers after a scan, from host details.
*
Expand Down
Loading