Skip to content

Commit

Permalink
Merge pull request #132 from bstepankova/log4nut
Browse files Browse the repository at this point in the history
Problem: fty-nut still uses old verbose approach
  • Loading branch information
michal42 committed Jul 19, 2018
2 parents eaec82b + 1d031fc commit ea6d779
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 86 deletions.
1 change: 0 additions & 1 deletion include/alert_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ int alert_actor_commands (
mlm_client_t *client,
mlm_client_t *mb_client,
zmsg_t **message,
bool& verbose,
uint64_t& timeout
);

Expand Down
47 changes: 9 additions & 38 deletions src/actor_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ int
actor_commands (
mlm_client_t *client,
zmsg_t **message_p,
bool& verbose,
uint64_t& timeout,
NUTAgent& nut_agent) {

Expand All @@ -58,10 +57,6 @@ actor_commands (
ret = 1;
}
else
if (streq (cmd, "VERBOSE")) {
verbose = true;
}
else
if (streq (cmd, "CONFIGURE")) {
char *mapping = zmsg_popstr (message);
if (!mapping) {
Expand Down Expand Up @@ -140,16 +135,13 @@ actor_commands_test (bool verbose)
// malamute broker
zactor_t *malamute = zactor_new (mlm_server, (void*) "Malamute");
assert (malamute);
if (verbose)
zstr_send (malamute, "VERBOSE");
zstr_sendx (malamute, "BIND", endpoint, NULL);

mlm_client_t *client = mlm_client_new ();
assert (client);
assert(mlm_client_connect(client, endpoint, 5000, "test-agent") == 0);

zmsg_t *message = NULL;
bool actor_verbose = false;

StateManager manager;
NUTAgent nut_agent(manager.getReader());
Expand All @@ -160,10 +152,9 @@ actor_commands_test (bool verbose)
// empty message - expected fail
message = zmsg_new ();
assert (message);
int rv = actor_commands (client, &message, actor_verbose, actor_polling, nut_agent);
int rv = actor_commands (client, &message, actor_polling, nut_agent);
assert (rv == 0);
assert (message == NULL);
assert (actor_verbose == false);
assert (actor_polling == 0);
assert (nut_agent.isMappingLoaded () == false);
assert (nut_agent.TTL () == 60);
Expand All @@ -176,10 +167,9 @@ actor_commands_test (bool verbose)
message = zmsg_new ();
assert (message);
zmsg_addstr (message, "");
rv = actor_commands (client, &message, actor_verbose, actor_polling, nut_agent);
rv = actor_commands (client, &message, actor_polling, nut_agent);
assert (rv == 0);
assert (message == NULL);
assert (actor_verbose == false);
assert (actor_polling == 0);
assert (nut_agent.isMappingLoaded () == false);
assert (nut_agent.TTL () == 60);
Expand All @@ -192,10 +182,9 @@ actor_commands_test (bool verbose)
message = zmsg_new ();
assert (message);
zmsg_addstr (message, "MAGIC!");
rv = actor_commands (client, &message, actor_verbose, actor_polling, nut_agent);
rv = actor_commands (client, &message, actor_polling, nut_agent);
assert (rv == 0);
assert (message == NULL);
assert (actor_verbose == false);
assert (actor_polling == 0);
assert (nut_agent.isMappingLoaded () == false);
assert (nut_agent.TTL () == 60);
Expand All @@ -209,10 +198,9 @@ actor_commands_test (bool verbose)
assert (message);
zmsg_addstr (message, ACTION_CONFIGURE);
// missing mapping_file here
rv = actor_commands (client, &message, actor_verbose, actor_polling, nut_agent);
rv = actor_commands (client, &message, actor_polling, nut_agent);
assert (rv == 0);
assert (message == NULL);
assert (actor_verbose == false);
assert (actor_polling == 0);
assert (nut_agent.isMappingLoaded () == false);
assert (nut_agent.TTL () == 60);
Expand All @@ -226,10 +214,9 @@ actor_commands_test (bool verbose)
assert (message);
zmsg_addstr (message, ACTION_POLLING);
// missing value here
rv = actor_commands (client, &message, actor_verbose, actor_polling, nut_agent);
rv = actor_commands (client, &message, actor_polling, nut_agent);
assert (rv == 0);
assert (message == NULL);
assert (actor_verbose == false);
assert (actor_polling == 0);
assert (nut_agent.isMappingLoaded () == false);
assert (nut_agent.TTL () == 60);
Expand All @@ -243,10 +230,9 @@ actor_commands_test (bool verbose)
assert (message);
zmsg_addstr (message, ACTION_POLLING);
zmsg_addstr (message, "a14s2"); // Bad value
rv = actor_commands (client, &message, actor_verbose, actor_polling, nut_agent);
rv = actor_commands (client, &message, actor_polling, nut_agent);
assert (rv == 0);
assert (message == NULL);
assert (actor_verbose == false);
assert (actor_polling == 30000);
assert (nut_agent.isMappingLoaded () == false);
assert (nut_agent.TTL () == 60);
Expand All @@ -265,27 +251,14 @@ actor_commands_test (bool verbose)
// Prepare the error logger
fp = freopen ("stderr.txt", "w+", stderr);

// VERBOSE
message = zmsg_new ();
assert (message);
zmsg_addstr (message, "VERBOSE");
rv = actor_commands (client, &message, actor_verbose, actor_polling, nut_agent);
assert (rv == 0);
assert (message == NULL);
assert (actor_verbose == true);
assert (actor_polling == 0);
assert (nut_agent.isMappingLoaded () == false);
assert (nut_agent.TTL () == 60);

// CONFIGURE
message = zmsg_new ();
assert (message);
zmsg_addstr (message, ACTION_CONFIGURE);
zmsg_addstr (message, "src/mapping.conf");
rv = actor_commands (client, &message, actor_verbose, actor_polling, nut_agent);
rv = actor_commands (client, &message, actor_polling, nut_agent);
assert (rv == 0);
assert (message == NULL);
assert (actor_verbose == true);
assert (actor_polling == 0);
assert (nut_agent.isMappingLoaded () == true);
assert (nut_agent.TTL () == 60);
Expand All @@ -294,10 +267,9 @@ actor_commands_test (bool verbose)
message = zmsg_new ();
assert (message);
zmsg_addstr (message, "$TERM");
rv = actor_commands (client, &message, actor_verbose, actor_polling, nut_agent);
rv = actor_commands (client, &message, actor_polling, nut_agent);
assert (rv == 1);
assert (message == NULL);
assert (actor_verbose == true);
assert (actor_polling == 0);
assert (nut_agent.isMappingLoaded () == true);
assert (nut_agent.TTL () == 60);
Expand All @@ -307,10 +279,9 @@ actor_commands_test (bool verbose)
assert (message);
zmsg_addstr (message, ACTION_POLLING);
zmsg_addstr (message, "150");
rv = actor_commands (client, &message, actor_verbose, actor_polling, nut_agent);
rv = actor_commands (client, &message, actor_polling, nut_agent);
assert (rv == 0);
assert (message == NULL);
assert (actor_verbose == true);
assert (actor_polling == 150000);
assert (nut_agent.isMappingLoaded () == true);
assert (nut_agent.TTL () == 300);
Expand Down
4 changes: 0 additions & 4 deletions src/actor_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ class NUTAgent;
// $TERM
// terminate
//
// VERBOSE
// set verbosity of bios_nut_server, malamute in tests
//
// CONNECT/enpoint/name
// connect to malamute broker on 'endpoint' registering as 'name'
//
Expand All @@ -60,7 +57,6 @@ class NUTAgent;
int actor_commands (
mlm_client_t *client,
zmsg_t **message_p,
bool& verbose,
uint64_t& timeout,
NUTAgent& nut_agent);

Expand Down
35 changes: 12 additions & 23 deletions src/alert_actor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ alert_actor_commands (
mlm_client_t *client,
mlm_client_t *mb_client,
zmsg_t **message_p,
bool& verbose,
uint64_t& timeout
)
{
Expand All @@ -55,10 +54,6 @@ alert_actor_commands (
ret = 1;
}
else
if (streq (cmd, "VERBOSE")) {
verbose = true;
}
else
if (streq (cmd, ACTION_POLLING)) {
char *polling = zmsg_popstr (message);
if (!polling) {
Expand Down Expand Up @@ -90,7 +85,6 @@ alert_actor (zsock_t *pipe, void *args)
{

uint64_t polling = 30000;
bool verbose = false;
const char *endpoint = static_cast<const char *>(args);

MlmClientGuard client(mlm_client_new());
Expand Down Expand Up @@ -147,7 +141,7 @@ alert_actor (zsock_t *pipe, void *args)
else if (which == pipe) {
zmsg_t *msg = zmsg_recv (pipe);
if (msg) {
int quit = alert_actor_commands (client, mb_client, &msg, verbose, polling);
int quit = alert_actor_commands (client, mb_client, &msg, polling);
devices.setPollingMs (polling);
zmsg_destroy (&msg);
if (quit) break;
Expand All @@ -161,10 +155,7 @@ alert_actor (zsock_t *pipe, void *args)
}

// --------------------------------------------------------------------------
// Self test of this class

#define verbose_printf if (verbose) printf

// Self test of this
void
alert_actor_test (bool verbose)
{
Expand All @@ -175,8 +166,6 @@ alert_actor_test (bool verbose)
// malamute broker
zactor_t *malamute = zactor_new (mlm_server, (void*) "Malamute");
assert (malamute);
if (verbose)
zstr_send (malamute, "VERBOSE");
zstr_sendx (malamute, "BIND", endpoint, NULL);

fty_proto_t *msg = fty_proto_new(FTY_PROTO_ASSET);
Expand Down Expand Up @@ -229,20 +218,20 @@ alert_actor_test (bool verbose)

// check rule message
{
verbose_printf ("\n recvrule\n");
printf ("\n recvrule\n");
void *which = zpoller_wait (poller, 1000);
assert (which);
zmsg_t *msg = mlm_client_recv (rfc_evaluator);
assert (msg);
assert (streq (mlm_client_subject (rfc_evaluator), "rfc-evaluator-rules"));

verbose_printf (" rule command\n");
printf (" rule command\n");
char *item = zmsg_popstr (msg);
assert (item);
assert (streq (item, "ADD"));
zstr_free (&item);

verbose_printf (" rule json\n");
printf (" rule json\n");
item = zmsg_popstr (msg);
assert (item);
assert (item[0] == '{');
Expand All @@ -253,7 +242,7 @@ alert_actor_test (bool verbose)
// check alert message
devs.publishAlerts (client);
{
verbose_printf (" receive alert\n");
printf (" receive alert\n");
void *which = zpoller_wait (poller, 1000);
assert (which);
zmsg_t *msg = mlm_client_recv (alert_list);
Expand All @@ -262,16 +251,16 @@ alert_actor_test (bool verbose)
fty_proto_t *bp = fty_proto_decode (&msg);
assert (bp);

verbose_printf (" is alert\n");
printf (" is alert\n");
assert (streq (fty_proto_command (bp), "ALERT"));

verbose_printf (" is active\n");
printf (" is active\n");
assert (streq (fty_proto_state (bp), "ACTIVE"));

verbose_printf (" severity\n");
printf (" severity\n");
assert (streq (fty_proto_severity (bp), "CRITICAL"));

verbose_printf (" element\n");
printf (" element\n");
assert (streq (fty_proto_name (bp), "mydevice"));

fty_proto_destroy (&bp);
Expand All @@ -281,7 +270,7 @@ alert_actor_test (bool verbose)
devs.publishAlerts (client);
// check alert message
{
verbose_printf (" receive resolved\n");
printf (" receive resolved\n");
void *which = zpoller_wait (poller, 1000);
assert (which);
zmsg_t *msg = mlm_client_recv (alert_list);
Expand All @@ -291,7 +280,7 @@ alert_actor_test (bool verbose)
assert (bp);
assert (streq (fty_proto_command (bp), "ALERT"));

verbose_printf (" is resolved\n");
printf (" is resolved\n");
assert (streq (fty_proto_state (bp), "RESOLVED"));

fty_proto_destroy (&bp);
Expand Down
11 changes: 2 additions & 9 deletions src/fty_nut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ void usage() {
" --config / -c path to config file\n"
" --mapping-file / -m NUT-to-BIOS mapping file\n"
" --polling / -p polling interval in seconds [30]\n"
" --verbose / -v verbose test output\n"
" --verbose / -v verbose output\n"
" --help / -h this information\n"
);
}


int main(int argc, char *argv []) {
int help = 0;
bool verbose = false;
// int log_level = -1;
std::string mapping_file;
const char* polling = NULL;
Expand Down Expand Up @@ -104,7 +103,6 @@ int main(int argc, char *argv []) {
}
case 'v':
{
verbose = true;
ManageFtyLog::getInstanceFtylog()->setVeboseMode();
break;
}
Expand Down Expand Up @@ -145,7 +143,7 @@ int main(int argc, char *argv []) {

// VERBOSE
if (streq(zconfig_get(config, "server/verbose", "false"), "true")) {
verbose = true;
ManageFtyLog::getInstanceFtylog()->setVeboseMode();
}
// POLLING
polling = zconfig_get(config, CONFIG_POLLING, "30");
Expand All @@ -170,11 +168,6 @@ int main(int argc, char *argv []) {
return -1;
}

if (verbose) {
zstr_sendx(nut_server, "VERBOSE", NULL);
zstr_sendx(nut_device_alert, "VERBOSE", NULL);
zstr_sendx(nut_sensor, "VERBOSE", NULL);
}
zstr_sendx(nut_server, ACTION_CONFIGURE, mapping_file.c_str(), NULL);
zstr_sendx(nut_server, ACTION_POLLING, polling, NULL);

Expand Down
Loading

0 comments on commit ea6d779

Please sign in to comment.