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

Add osp_get_performance() #262

Merged
merged 2 commits into from
Sep 3, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Change the default path to the redis socket to /run/redis/redis.sock [#256](https://github.com/greenbone/gvm-libs/pull/256)
- Handle EAI_AGAIN in gvm_host_reverse_lookup() IPv6 case and function refactor. [#229](https://github.com/greenbone/gvm-libs/pull/229)
- Prevent g_strsplit to be called with NULL. [#238](https://github.com/greenbone/gvm-libs/pull/238)
- Add osp_get_performance() function. [#262](https://github.com/greenbone/gvm-libs/pull/262)

### Fixed
- Prevent g_strsplit to be called with NULL. [#238](https://github.com/greenbone/gvm-libs/pull/238)
Expand Down
47 changes: 47 additions & 0 deletions osp/osp.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,53 @@ osp_delete_scan (osp_connection_t *connection, const char *scan_id)
return ret;
}

/**
* @brief Get performance graphics from an OSP server.
*
* @param[in] connection Connection to an OSP server.
* @param[in] opts Struct containing the options to apply.
* @param[out] graph Graphic base64 encoded.
* @param[out] error Pointer to error, if any.
mattmundell marked this conversation as resolved.
Show resolved Hide resolved
*
* @return 0 if success, 1 if error.
*/
int
osp_get_performance_ext (osp_connection_t *connection,
osp_get_performance_opts_t opts,
char **graph, char **error)
{
entity_t entity;
int rc;

assert (connection);
rc = osp_send_command (connection, &entity,
"<get_performance start='%d' "
"end='%d' titles='%s'/>",
opts.start, opts.end, opts.titles);

if (rc)
{
if (error)
*error = g_strdup ("Couldn't send get_performance command to scanner");
return 1;
}

if (graph && entity_text (entity) && strcmp (entity_text (entity), "\0"))
*graph = g_strdup (entity_text (entity));
else
{
const char *text = entity_attribute (entity, "status_text");

assert (text);
if (error)
*error = g_strdup (text);
free_entity (entity);
return 1;
}

free_entity (entity);
return 0;
}

/**
* @brief Get a scan status from an OSP server
Expand Down
22 changes: 18 additions & 4 deletions osp/osp.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ typedef enum
OSP_SCAN_STATUS_FINISHED, /**< Finished status. */
} osp_scan_status_t;


typedef struct {
const char *scan_id; ///< UUID of the scan which get the status from.
} osp_get_scan_status_opts_t;

typedef struct {
int start; /**< Start interval. */
int end; /**< End interval. */
char *titles; /**< Graph title. */
} osp_get_performance_opts_t;

typedef struct osp_param osp_param_t;

/* OSP Connection handling */
Expand Down Expand Up @@ -123,10 +134,6 @@ osp_get_scan_pop (osp_connection_t *,
int,
char **);

typedef struct {
const char *scan_id; ///< UUID of the scan which get the status from.
} osp_get_scan_status_opts_t;

osp_scan_status_t
osp_get_scan_status_ext (osp_connection_t *,
osp_get_scan_status_opts_t,
Expand All @@ -141,6 +148,13 @@ osp_stop_scan (osp_connection_t *, const char *, char **);
int
osp_get_scanner_details (osp_connection_t *, char **, GSList **);


int
osp_get_performance_ext (osp_connection_t *,
osp_get_performance_opts_t,
char **,
char **);

/* OSP scanner parameters handling */

osp_param_t *
Expand Down