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

WIP redfishpower: output summary after power cmd #101

Closed
wants to merge 1 commit into from
Closed
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
30 changes: 30 additions & 0 deletions src/redfishpower/redfishpower.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ static struct option longopts[] = {

static time_t cmd_timeout = CMD_TIMEOUT_DEFAULT;

/* global counters for when command is issued, should be re-initialized
* before counting begins.
*/
unsigned int ok_count = 0;
unsigned int timeout_count = 0;
unsigned int error_count = 0;
unsigned int expected_count = 0;

void help(void)
{
printf("Valid commands are:\n");
Expand All @@ -128,6 +136,14 @@ void help(void)
printf(" cycle [nodes]\n");
}

static void init_counters ()
{
ok_count = 0;
timeout_count = 0;
error_count = 0;
expected_count = 0;
}

static size_t output_cb(void *contents, size_t size, size_t nmemb, void *userp)
{
size_t realsize = size * nmemb;
Expand Down Expand Up @@ -329,6 +345,7 @@ static void stat_cmd(List activecmds, CURLM *mh, char **av)
if (!list_append(activecmds, pm))
err_exit(true, "list_append");
free(hostname);
expected_count++;
}
hostlist_iterator_destroy(itr);
hostlist_destroy(lhosts);
Expand Down Expand Up @@ -375,6 +392,7 @@ static void stat_process (struct powermsg *pm)
const char *str;
parse_onoff(pm, &str);
printf("%s: %s\n", pm->hostname, str);
ok_count++;
}

static void stat_cleanup(struct powermsg *pm)
Expand Down Expand Up @@ -440,6 +458,7 @@ static void power_cmd(List activecmds,
if (!list_append(activecmds, pm))
err_exit(true, "list_append");
free(hostname);
expected_count++;
}
hostlist_iterator_destroy(itr);
hostlist_destroy(lhosts);
Expand Down Expand Up @@ -480,6 +499,7 @@ static void on_off_process(List delayedcmds, struct powermsg *pm)
parse_onoff(pm, &str);
if (strcmp(str, pm->cmd) == 0) {
printf("%s: %s\n", pm->hostname, "ok");
ok_count++;
return;
}
/* fallthrough, check again */
Expand All @@ -488,6 +508,7 @@ static void on_off_process(List delayedcmds, struct powermsg *pm)
gettimeofday(&now, NULL);
if (timercmp(&now, &pm->timeout, >)) {
printf("%s: %s\n", pm->hostname, "timeout");
timeout_count++;
return;
}

Expand Down Expand Up @@ -521,6 +542,7 @@ static void off_process(List delayedcmds, struct powermsg *pm)
static void cycle_process(struct powermsg *pm)
{
printf("%s: %s\n", pm->hostname, "ok");
ok_count++;
}

static void power_cleanup(struct powermsg *pm)
Expand Down Expand Up @@ -695,6 +717,11 @@ static void shell(CURLM *mh)
FD_ZERO(&fderror);

if (list_is_empty(activecmds) && list_is_empty(delayedcmds)) {
if (expected_count) {
printf ("summary: ok: %u timeout: %u error: %u\n",
ok_count, timeout_count, error_count);
init_counters();
}
printf("redfishpower> ");
fflush(stdout);

Expand Down Expand Up @@ -835,6 +862,9 @@ static void shell(CURLM *mh)
}
else
printf("%s: %s\n", pm->hostname, "error");

error_count++;

if (verbose)
printf("%s: %s\n", pm->hostname,
curl_easy_strerror(cmsg->data.result));
Expand Down
Loading