Management framework: add a helper for rendering result vectors to a string

This commit is contained in:
Christian Kreibich 2022-06-17 22:31:10 -07:00
parent d367f1bad9
commit a2525e44ba
3 changed files with 17 additions and 10 deletions

View file

@ -695,7 +695,8 @@ event Management::Agent::API::notify_log(instance: string, msg: string, node: st
event Management::Agent::API::deploy_response(reqid: string, results: Management::ResultVec)
{
Management::Log::info(fmt("rx Management::Agent::API::deploy_response %s", reqid));
Management::Log::info(fmt("rx Management::Agent::API::deploy_response %s %s",
reqid, Management::result_vec_to_string(results)));
# Retrieve state for the request we just got a response to
local areq = Management::Request::lookup(reqid);

View file

@ -146,20 +146,12 @@ function is_null(request: Request): bool
function to_string(request: Request): string
{
local results: string_vec;
local res: Management::Result;
local parent_id = "";
if ( request?$parent_id )
parent_id = fmt(" (via %s)", request$parent_id);
for ( idx in request$results )
{
res = request$results[idx];
results[|results|] = Management::result_to_string(res);
}
return fmt("[request %s%s %s, results: %s]", request$id, parent_id,
request$finished ? "finished" : "pending",
join_string_vec(results, ", "));
Management::result_vec_to_string(request$results));
}

View file

@ -124,6 +124,10 @@ export {
## Given a :zeek:see:`Management::Result` record,
## this function returns a string summarizing it.
global result_to_string: function(res: Result): string;
## Given a vector of :zeek:see:`Management::Result` records,
## this function returns a string summarizing them.
global result_vec_to_string: function(res: ResultVec): string;
}
function result_to_string(res: Result): string
@ -151,3 +155,13 @@ function result_to_string(res: Result): string
return result;
}
function result_vec_to_string(res: ResultVec): string
{
local ret: vector of string;
for ( idx in res )
ret += result_to_string(res[idx]);;
return join_string_vec(ret, ", ");
}