diff --git a/nasl/nasl_init.c b/nasl/nasl_init.c index 0c8dab42d..67a65b115 100644 --- a/nasl/nasl_init.c +++ b/nasl/nasl_init.c @@ -78,6 +78,7 @@ static init_func libfuncs[] = { {"script_xref", script_xref}, {"script_tag", script_tag}, {"vendor_version", nasl_vendor_version}, + {"collect_host_stats", nasl_collect_host_stats}, {"update_table_driven_lsc_data", nasl_update_table_driven_lsc_data}, {"get_preference", nasl_get_preference}, {"safe_checks", safe_checks}, diff --git a/nasl/nasl_scanner_glue.c b/nasl/nasl_scanner_glue.c index 0338c7420..b8fb7b566 100644 --- a/nasl/nasl_scanner_glue.c +++ b/nasl/nasl_scanner_glue.c @@ -1053,6 +1053,51 @@ nasl_get_preference (lex_ctxt *lexic) return retc; } +tree_cell * +nasl_collect_host_stats (lex_ctxt *lexic) +{ + tree_cell *retc; + struct script_infos *script_infos = lexic->script_infos; + kb_t kb = script_infos->key; + GString *data = g_string_new (""); + struct kb_item *stats = NULL, *stats_tmp = NULL; + int first = 1; + + stats = kb_item_get_pattern (kb, "general/script_stats*"); + stats_tmp = stats; + + g_string_append_c (data, '['); + while (stats_tmp) + { + char **spl = g_strsplit (stats_tmp->v_str, "/", 0); + char *buf = NULL; + + if (!first) + g_string_append_c (data, ','); + + buf = g_strdup_printf ("{\"%s\": {\"start\": %s, \"stop\": %s}}", spl[0], + spl[1], spl[2]); + + g_string_append (data, buf); + g_strfreev (spl); + g_free (buf); + + stats_tmp = stats_tmp->next; + if (first) + first = 0; + } + g_string_append_c (data, ']'); + + kb_item_free (stats); + + retc = alloc_typed_cell (CONST_STR); + retc->x.str_val = strdup (data->str); + retc->size = data->len; + g_string_free (data, TRUE); + + return retc; +} + tree_cell * nasl_vendor_version (lex_ctxt *lexic) { diff --git a/nasl/nasl_scanner_glue.h b/nasl/nasl_scanner_glue.h index 5ea732f19..6c2308293 100644 --- a/nasl/nasl_scanner_glue.h +++ b/nasl/nasl_scanner_glue.h @@ -118,4 +118,7 @@ nasl_vendor_version (lex_ctxt *); tree_cell * nasl_update_table_driven_lsc_data (lex_ctxt *); +tree_cell * +nasl_collect_host_stats (lex_ctxt *); + #endif diff --git a/src/pluginlaunch.c b/src/pluginlaunch.c index 25880f99d..b054d7c72 100644 --- a/src/pluginlaunch.c +++ b/src/pluginlaunch.c @@ -183,6 +183,7 @@ update_running_processes (kb_t main_kb, kb_t kb) processes[i].start.tv_sec++; now.tv_usec += 1000000; } + if (log_whole) { char *name = nvticache_get_filename (oid); @@ -193,6 +194,14 @@ update_running_processes (kb_t main_kb, kb_t kb) (long) ((now.tv_usec - processes[i].start.tv_usec) / 1000)); g_free (name); + + char msg[2048]; + g_snprintf (msg, sizeof (msg), "%s/%ld/%ld", oid, + (long) ((now.tv_sec * 1000) + + (long) (now.tv_usec / 1000)), + (long) (processes[i].start.tv_sec * 1000 + + processes[i].start.tv_usec / 1000)); + kb_item_push_str (kb, "general/script_stats", msg); } now = old_now; do