MINOR: add severity information to cli feedback messages
diff --git a/src/server.c b/src/server.c
index c80c987..ec2dbe8 100644
--- a/src/server.c
+++ b/src/server.c
@@ -4346,18 +4346,21 @@
}
if (!*line || !*arg) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Require 'backend/server'.\n";
appctx->st0 = CLI_ST_PRINT;
return NULL;
}
if (!get_backend_server(arg, line, &px, &sv)) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
appctx->st0 = CLI_ST_PRINT;
return NULL;
}
if (px->state == PR_STSTOPPED) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Proxy is disabled.\n";
appctx->st0 = CLI_ST_PRINT;
return NULL;
@@ -4382,6 +4385,7 @@
if (strcmp(args[3], "weight") == 0) {
warning = server_parse_weight_change_request(sv, args[4]);
if (warning) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = warning;
appctx->st0 = CLI_ST_PRINT;
}
@@ -4394,12 +4398,14 @@
else if (strcmp(args[4], "maint") == 0)
srv_adm_set_maint(sv);
else {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n";
appctx->st0 = CLI_ST_PRINT;
}
}
else if (strcmp(args[3], "health") == 0) {
if (sv->track) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "cannot change health on a tracking server.\n";
appctx->st0 = CLI_ST_PRINT;
}
@@ -4416,12 +4422,14 @@
srv_set_stopped(sv, "changed from CLI");
}
else {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n";
appctx->st0 = CLI_ST_PRINT;
}
}
else if (strcmp(args[3], "agent") == 0) {
if (!(sv->agent.state & CHK_ST_ENABLED)) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n";
appctx->st0 = CLI_ST_PRINT;
}
@@ -4434,16 +4442,19 @@
srv_set_stopped(sv, "changed from CLI");
}
else {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n";
appctx->st0 = CLI_ST_PRINT;
}
}
else if (strcmp(args[3], "agent-addr") == 0) {
if (!(sv->agent.state & CHK_ST_ENABLED)) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n";
appctx->st0 = CLI_ST_PRINT;
} else {
if (str2ip(args[4], &sv->agent.addr) == NULL) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "incorrect addr address given for agent.\n";
appctx->st0 = CLI_ST_PRINT;
}
@@ -4451,11 +4462,13 @@
}
else if (strcmp(args[3], "agent-send") == 0) {
if (!(sv->agent.state & CHK_ST_ENABLED)) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n";
appctx->st0 = CLI_ST_PRINT;
} else {
char *nss = strdup(args[4]);
if (!nss) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "cannot allocate memory for new string.\n";
appctx->st0 = CLI_ST_PRINT;
} else {
@@ -4468,20 +4481,24 @@
else if (strcmp(args[3], "check-port") == 0) {
int i = 0;
if (strl2irc(args[4], strlen(args[4]), &i) != 0) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "'set server <srv> check-port' expects an integer as argument.\n";
appctx->st0 = CLI_ST_PRINT;
}
if ((i < 0) || (i > 65535)) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "provided port is not valid.\n";
appctx->st0 = CLI_ST_PRINT;
}
/* prevent the update of port to 0 if MAPPORTS are in use */
if ((sv->flags & SRV_F_MAPPORTS) && (i == 0)) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "can't unset 'port' since MAPPORTS is in use.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
}
sv->check.port = i;
+ appctx->ctx.cli.severity = LOG_NOTICE;
appctx->ctx.cli.msg = "health check port updated.\n";
appctx->st0 = CLI_ST_PRINT;
}
@@ -4489,6 +4506,7 @@
char *addr = NULL;
char *port = NULL;
if (strlen(args[4]) == 0) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "set server <b>/<s> addr requires an address and optionally a port.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@@ -4501,6 +4519,7 @@
}
warning = update_server_addr_port(sv, addr, port, "stats socket command");
if (warning) {
+ appctx->ctx.cli.severity = LOG_WARNING;
appctx->ctx.cli.msg = warning;
appctx->st0 = CLI_ST_PRINT;
}
@@ -4514,11 +4533,13 @@
}
warning = update_server_fqdn(sv, args[4], "stats socket command");
if (warning) {
+ appctx->ctx.cli.severity = LOG_WARNING;
appctx->ctx.cli.msg = warning;
appctx->st0 = CLI_ST_PRINT;
}
}
else {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "'set server <srv>' only supports 'agent', 'health', 'state', 'weight', 'addr', 'fqdn' and 'check-port'.\n";
appctx->st0 = CLI_ST_PRINT;
}
@@ -4541,12 +4562,14 @@
}
if (!*line) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Require 'backend/server'.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
}
if (!get_backend_server(args[2], line, &px, &sv)) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@@ -4575,6 +4598,7 @@
warning = server_parse_weight_change_request(sv, args[3]);
if (warning) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = warning;
appctx->st0 = CLI_ST_PRINT;
}
@@ -4596,6 +4620,7 @@
warning = server_parse_maxconn_change_request(sv, args[4]);
if (warning) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = warning;
appctx->st0 = CLI_ST_PRINT;
}
@@ -4663,6 +4688,7 @@
return 1;
if (!(sv->agent.state & CHK_ST_CONFIGURED)) {
+ appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;