-
Notifications
You must be signed in to change notification settings - Fork 80
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
Add: openvasd_get_performance() #900
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1124,8 +1124,7 @@ | |
goto res_cleanup; | ||
|
||
item = cJSON_GetObjectItem (result_obj, "detail"); | ||
if (item != NULL | ||
&& cJSON_IsObject (item)) | ||
if (item != NULL && cJSON_IsObject (item)) | ||
{ | ||
cJSON *detail_obj = NULL; | ||
|
||
|
@@ -1137,21 +1136,21 @@ | |
{ | ||
detail_source_type = gvm_json_obj_str (detail_obj, "type"); | ||
detail_source_name = gvm_json_obj_str (detail_obj, "name"); | ||
detail_source_description = gvm_json_obj_str (detail_obj, "description"); | ||
detail_source_description = | ||
gvm_json_obj_str (detail_obj, "description"); | ||
} | ||
} | ||
|
||
result = openvasd_result_new (gvm_json_obj_double (result_obj, "id"), | ||
gvm_json_obj_str (result_obj, "type"), | ||
gvm_json_obj_str (result_obj, "ip_address"), | ||
gvm_json_obj_str (result_obj, "hostname"), | ||
gvm_json_obj_str (result_obj, "oid"), | ||
gvm_json_obj_int (result_obj, "port"), | ||
gvm_json_obj_str (result_obj, "protocol"), | ||
gvm_json_obj_str (result_obj, "message"), | ||
detail_name, detail_value, | ||
detail_source_type, detail_source_name, | ||
detail_source_description); | ||
result = openvasd_result_new ( | ||
gvm_json_obj_double (result_obj, "id"), | ||
gvm_json_obj_str (result_obj, "type"), | ||
gvm_json_obj_str (result_obj, "ip_address"), | ||
gvm_json_obj_str (result_obj, "hostname"), | ||
gvm_json_obj_str (result_obj, "oid"), | ||
gvm_json_obj_int (result_obj, "port"), | ||
gvm_json_obj_str (result_obj, "protocol"), | ||
gvm_json_obj_str (result_obj, "message"), detail_name, detail_value, | ||
detail_source_type, detail_source_name, detail_source_description); | ||
|
||
*results = g_slist_append (*results, result); | ||
ret = 200; | ||
|
@@ -1310,8 +1309,7 @@ | |
// read progress of single running hosts | ||
cJSON *scanning; | ||
scanning = cJSON_GetObjectItem (reader, "scanning"); | ||
if (scanning != NULL | ||
&& cJSON_IsObject (scanning)) | ||
if (scanning != NULL && cJSON_IsObject (scanning)) | ||
{ | ||
cJSON *host = scanning->child; | ||
while (host) | ||
|
@@ -1591,6 +1589,56 @@ | |
return response; | ||
} | ||
|
||
openvasd_resp_t | ||
openvasd_get_performance (openvasd_connector_t conn, | ||
openvasd_get_performance_opts_t opts) | ||
{ | ||
openvasd_resp_t response = NULL; | ||
gchar *err = NULL; | ||
CURL *hnd = NULL; | ||
struct curl_slist *customheader = NULL; | ||
time_t now; | ||
time (&now); | ||
|
||
response = g_malloc0 (sizeof (struct openvasd_response)); | ||
|
||
if (!opts.titles || !strcmp (opts.titles, "") || opts.start < 0 | ||
|| opts.start > now || opts.end < 0 || opts.end > now) | ||
{ | ||
response->code = RESP_CODE_ERR; | ||
response->body = | ||
g_strdup ("{\"error\": \"Couldn't send get_performance command " | ||
"to scanner. Bad or missing parameters.\"}"); | ||
return response; | ||
} | ||
gchar *query = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to see more consistency with the declarations. All the others are at the top of the block, even for example Personally I'd also like you to drop the excess inits in general. Like response is set to NULL then it's set again basically straight away. |
||
g_strdup_printf ("/health/performance?start=%d&end=%d&titles=%s", | ||
opts.start, opts.end, opts.titles); | ||
customheader = init_customheader (conn->apikey, FALSE); | ||
hnd = handler (conn, GET, query, NULL, customheader, &err); | ||
if (hnd == NULL) | ||
{ | ||
curl_slist_free_all (customheader); | ||
response->code = RESP_CODE_ERR; | ||
response->body = err; | ||
return response; | ||
} | ||
|
||
openvasd_send_request (hnd, NULL, response); | ||
curl_slist_free_all (customheader); | ||
if (response->code != RESP_CODE_ERR) | ||
response->body = g_strdup (openvasd_vt_stream_str (conn)); | ||
else if (response->code == RESP_CODE_ERR) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could drop the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, this is like this everywhere in this file. I'm happy to do them all as a PR. |
||
{ | ||
response->body = g_strdup ( | ||
"{\"error\": \"Not possible to get performance information.\"}"); | ||
g_warning ("%s: Not possible to get performance information", __func__); | ||
} | ||
|
||
openvasd_reset_vt_stream (conn); | ||
return response; | ||
} | ||
|
||
openvasd_resp_t | ||
openvasd_get_scan_preferences (openvasd_connector_t conn) | ||
{ | ||
|
@@ -1809,12 +1857,11 @@ | |
} | ||
} | ||
|
||
param = | ||
openvasd_param_new (g_strdup (gvm_json_obj_str (param_obj, "id")), | ||
g_strdup (gvm_json_obj_str (param_obj, "name")), | ||
g_strdup (defval), | ||
g_strdup (gvm_json_obj_str (param_obj, "description")), | ||
g_strdup (param_type), mandatory); | ||
param = openvasd_param_new ( | ||
g_strdup (gvm_json_obj_str (param_obj, "id")), | ||
g_strdup (gvm_json_obj_str (param_obj, "name")), g_strdup (defval), | ||
g_strdup (gvm_json_obj_str (param_obj, "description")), | ||
g_strdup (param_type), mandatory); | ||
g_free (defval); | ||
g_free (param_type); | ||
*params = g_slist_append (*params, param); | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -110,6 +110,13 @@ struct openvasd_scan_status | |||||
long response_code; | ||||||
}; | ||||||
|
||||||
typedef struct | ||||||
{ | ||||||
int start; /**< Start interval. */ | ||||||
int end; /**< End interval. */ | ||||||
char *titles; /**< Graph title. */ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} openvasd_get_performance_opts_t; | ||||||
|
||||||
typedef struct openvasd_response *openvasd_resp_t; | ||||||
|
||||||
typedef enum OPENVASD_RESULT_MEMBER_INT openvasd_result_member_int_t; | ||||||
|
@@ -182,6 +189,9 @@ openvasd_resp_t openvasd_get_health_ready (openvasd_connector_t); | |||||
|
||||||
openvasd_resp_t openvasd_get_health_started (openvasd_connector_t); | ||||||
|
||||||
openvasd_resp_t openvasd_get_performance (openvasd_connector_t, | ||||||
openvasd_get_performance_opts_t); | ||||||
|
||||||
/* Scanner preferences */ | ||||||
|
||||||
typedef struct openvasd_param openvasd_param_t; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.