1
0
mirror of http://git.haproxy.org/git/haproxy.git/ synced 2025-04-10 19:21:37 +00:00

MINOR: add severity information to cli feedback messages

This commit is contained in:
Andjelko Iharos 2017-07-20 16:49:14 +02:00 committed by Willy Tarreau
parent c4df59e914
commit c3680ecdf8
10 changed files with 154 additions and 16 deletions

View File

@ -385,6 +385,7 @@ int cli_has_level(struct appctx *appctx, int level)
struct stream *s = si_strm(si);
if ((strm_li(s)->bind_conf->level & ACCESS_LVL_MASK) < level) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = stats_permission_denied_msg;
appctx->st0 = CLI_ST_PRINT;
return 0;
@ -610,10 +611,14 @@ static void cli_io_handler(struct appctx *appctx)
else if (strcmp(trash.str, "help") == 0 ||
!cli_parse_request(appctx, trash.str)) {
cli_gen_usage_msg();
if (dynamic_usage_msg)
if (dynamic_usage_msg) {
appctx->ctx.cli.severity = LOG_INFO;
appctx->ctx.cli.msg = dynamic_usage_msg;
else
}
else {
appctx->ctx.cli.severity = LOG_INFO;
appctx->ctx.cli.msg = stats_sock_usage_msg;
}
appctx->st0 = CLI_ST_PRINT;
}
/* NB: stats_sock_parse_request() may have put
@ -626,10 +631,14 @@ static void cli_io_handler(struct appctx *appctx)
* prompt and find help.
*/
cli_gen_usage_msg();
if (dynamic_usage_msg)
if (dynamic_usage_msg) {
appctx->ctx.cli.severity = LOG_INFO;
appctx->ctx.cli.msg = dynamic_usage_msg;
else
}
else {
appctx->ctx.cli.severity = LOG_INFO;
appctx->ctx.cli.msg = stats_sock_usage_msg;
}
appctx->st0 = CLI_ST_PRINT;
}
@ -996,6 +1005,7 @@ static int cli_parse_show_env(char **args, struct appctx *appctx, void *private)
break;
}
if (!*var) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Variable not found\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -1035,6 +1045,7 @@ static int cli_parse_set_timeout(char **args, struct appctx *appctx, void *priva
const char *res;
if (!*args[3]) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Expects an integer value.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -1042,6 +1053,7 @@ static int cli_parse_set_timeout(char **args, struct appctx *appctx, void *priva
res = parse_time_err(args[3], &timeout, TIME_UNIT_S);
if (res || timeout < 1) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Invalid timeout value.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -1052,6 +1064,7 @@ static int cli_parse_set_timeout(char **args, struct appctx *appctx, void *priva
return 1;
}
else {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -1067,6 +1080,7 @@ static int cli_parse_set_maxconn_global(char **args, struct appctx *appctx, void
return 1;
if (!*args[3]) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Expects an integer value.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -1074,6 +1088,7 @@ static int cli_parse_set_maxconn_global(char **args, struct appctx *appctx, void
v = atoi(args[3]);
if (v > global.hardmaxconn) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Value out of range.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -1149,6 +1164,7 @@ static int cli_parse_set_ratelimit(char **args, struct appctx *appctx, void *pri
mul = 1024;
}
else {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg =
"'set rate-limit' only supports :\n"
" - 'connections global' to set the per-process maximum connection rate\n"
@ -1162,6 +1178,7 @@ static int cli_parse_set_ratelimit(char **args, struct appctx *appctx, void *pri
}
if (!*args[4]) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Expects an integer value.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -1169,6 +1186,7 @@ static int cli_parse_set_ratelimit(char **args, struct appctx *appctx, void *pri
v = atoi(args[4]);
if (v < 0) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Value out of range.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;

View File

@ -2256,6 +2256,7 @@ static int cli_parse_stat_resolvers(char **args, struct appctx *appctx, void *pr
}
}
if (appctx->ctx.cli.p0 == NULL) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Can't find that resolvers section\n";
appctx->st0 = CLI_ST_PRINT;
return 1;

View File

@ -25,6 +25,7 @@
#include <proto/applet.h>
#include <proto/arg.h>
#include <proto/cli.h>
#include <proto/log.h>
#include <proto/map.h>
#include <proto/pattern.h>
#include <proto/stream_interface.h>
@ -569,10 +570,14 @@ static int cli_parse_get_map(char **args, struct appctx *appctx, void *private)
/* No parameter. */
if (!*args[2] || !*args[3]) {
if (appctx->ctx.map.display_flags == PAT_REF_MAP)
if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Missing map identifier and/or key.\n";
else
}
else {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n";
}
appctx->st0 = CLI_ST_PRINT;
return 1;
}
@ -580,10 +585,14 @@ static int cli_parse_get_map(char **args, struct appctx *appctx, void *private)
/* lookup into the maps */
appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
if (!appctx->ctx.map.ref) {
if (appctx->ctx.map.display_flags == PAT_REF_MAP)
if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
else
}
else {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
}
appctx->st0 = CLI_ST_PRINT;
return 1;
}
@ -596,6 +605,7 @@ static int cli_parse_get_map(char **args, struct appctx *appctx, void *private)
appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1;
appctx->ctx.map.chunk.str = strdup(args[3]);
if (!appctx->ctx.map.chunk.str) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Out of memory error.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -635,10 +645,14 @@ static int cli_parse_show_map(char **args, struct appctx *appctx, void *private)
appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
if (!appctx->ctx.map.ref ||
!(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
if (appctx->ctx.map.display_flags == PAT_REF_MAP)
if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
else
}
else {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
}
appctx->st0 = CLI_ST_PRINT;
return 1;
}
@ -660,6 +674,7 @@ static int cli_parse_set_map(char **args, struct appctx *appctx, void *private)
/* Expect three parameters: map name, key and new value. */
if (!*args[2] || !*args[3] || !*args[4]) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "'set map' expects three parameters: map identifier, key and value.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -668,6 +683,7 @@ static int cli_parse_set_map(char **args, struct appctx *appctx, void *private)
/* Lookup the reference in the maps. */
appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
if (!appctx->ctx.map.ref) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -684,6 +700,7 @@ static int cli_parse_set_map(char **args, struct appctx *appctx, void *private)
/* Convert argument to integer value. */
conv = strtoll(&args[3][1], &error, 16);
if (*error != '\0') {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -692,6 +709,7 @@ static int cli_parse_set_map(char **args, struct appctx *appctx, void *private)
/* Convert and check integer to pointer. */
ref = (struct pat_ref_elt *)(long)conv;
if ((long long int)(long)ref != conv) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -746,6 +764,7 @@ static int cli_parse_add_map(char **args, struct appctx *appctx, void *private)
*/
if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
if (!*args[2] || !*args[3] || !*args[4]) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -753,6 +772,7 @@ static int cli_parse_add_map(char **args, struct appctx *appctx, void *private)
}
else {
if (!*args[2] || !*args[3]) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -762,10 +782,14 @@ static int cli_parse_add_map(char **args, struct appctx *appctx, void *private)
/* Lookup for the reference. */
appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
if (!appctx->ctx.map.ref) {
if (appctx->ctx.map.display_flags == PAT_REF_MAP)
if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
else
}
else {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
}
appctx->st0 = CLI_ST_PRINT;
return 1;
}
@ -775,6 +799,7 @@ static int cli_parse_add_map(char **args, struct appctx *appctx, void *private)
*/
if ((appctx->ctx.map.display_flags & PAT_REF_ACL) &&
(appctx->ctx.map.ref->flags & PAT_REF_SMP)) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. "
"You must use the command 'add map' to add values.\n";
appctx->st0 = CLI_ST_PRINT;
@ -813,6 +838,7 @@ static int cli_parse_del_map(char **args, struct appctx *appctx, void *private)
/* Expect two parameters: map name and key. */
if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
if (!*args[2] || !*args[3]) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -821,6 +847,7 @@ static int cli_parse_del_map(char **args, struct appctx *appctx, void *private)
else {
if (!*args[2] || !*args[3]) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -831,6 +858,7 @@ static int cli_parse_del_map(char **args, struct appctx *appctx, void *private)
appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
if (!appctx->ctx.map.ref ||
!(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -847,6 +875,7 @@ static int cli_parse_del_map(char **args, struct appctx *appctx, void *private)
/* Convert argument to integer value. */
conv = strtoll(&args[3][1], &error, 16);
if (*error != '\0') {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -855,6 +884,7 @@ static int cli_parse_del_map(char **args, struct appctx *appctx, void *private)
/* Convert and check integer to pointer. */
ref = (struct pat_ref_elt *)(long)conv;
if ((long long int)(long)ref != conv) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -863,6 +893,7 @@ static int cli_parse_del_map(char **args, struct appctx *appctx, void *private)
/* Try to delete the entry. */
if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) {
/* The entry is not found, send message. */
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Key not found.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -874,6 +905,7 @@ static int cli_parse_del_map(char **args, struct appctx *appctx, void *private)
*/
if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) {
/* The entry is not found, send message. */
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Key not found.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -897,10 +929,14 @@ static int cli_parse_clear_map(char **args, struct appctx *appctx, void *private
/* no parameter */
if (!*args[2]) {
if (appctx->ctx.map.display_flags == PAT_REF_MAP)
if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Missing map identifier.\n";
else
}
else {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Missing ACL identifier.\n";
}
appctx->st0 = CLI_ST_PRINT;
return 1;
}
@ -909,10 +945,14 @@ static int cli_parse_clear_map(char **args, struct appctx *appctx, void *private
appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
if (!appctx->ctx.map.ref ||
!(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
if (appctx->ctx.map.display_flags == PAT_REF_MAP)
if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
else
}
else {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
}
appctx->st0 = CLI_ST_PRINT;
return 1;
}

View File

@ -13113,6 +13113,7 @@ static int cli_parse_show_errors(char **args, struct appctx *appctx, void *priva
appctx->ctx.errors.iid = atoi(args[2]);
if (!appctx->ctx.errors.iid) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "No such proxy.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;

View File

@ -1351,6 +1351,7 @@ struct proxy *cli_find_frontend(struct appctx *appctx, const char *arg)
struct proxy *px;
if (!*arg) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "A frontend name is expected.\n";
appctx->st0 = CLI_ST_PRINT;
return NULL;
@ -1358,6 +1359,7 @@ struct proxy *cli_find_frontend(struct appctx *appctx, const char *arg)
px = proxy_fe_by_name(arg);
if (!px) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "No such frontend.\n";
appctx->st0 = CLI_ST_PRINT;
return NULL;
@ -1374,6 +1376,7 @@ struct proxy *cli_find_backend(struct appctx *appctx, const char *arg)
struct proxy *px;
if (!*arg) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "A backend name is expected.\n";
appctx->st0 = CLI_ST_PRINT;
return NULL;
@ -1381,6 +1384,7 @@ struct proxy *cli_find_backend(struct appctx *appctx, const char *arg)
px = proxy_be_by_name(arg);
if (!px) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "No such backend.\n";
appctx->st0 = CLI_ST_PRINT;
return NULL;
@ -1403,6 +1407,7 @@ static int cli_parse_show_servers(char **args, struct appctx *appctx, void *priv
px = proxy_be_by_name(args[3]);
if (!px) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Can't find backend.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -1619,6 +1624,7 @@ static int cli_parse_set_dyncookie_key_backend(char **args, struct appctx *appct
return 1;
if (!*args[4]) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "String value expected.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -1626,6 +1632,7 @@ static int cli_parse_set_dyncookie_key_backend(char **args, struct appctx *appct
newkey = strdup(args[4]);
if (!newkey) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Failed to allocate memory.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -1654,6 +1661,7 @@ static int cli_parse_set_maxconn_frontend(char **args, struct appctx *appctx, vo
return 1;
if (!*args[4]) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Integer value expected.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -1661,6 +1669,7 @@ static int cli_parse_set_maxconn_frontend(char **args, struct appctx *appctx, vo
v = atoi(args[4]);
if (v < 0) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Value out of range.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -1695,6 +1704,7 @@ static int cli_parse_shutdown_frontend(char **args, struct appctx *appctx, void
return 1;
if (px->state == PR_STSTOPPED) {
appctx->ctx.cli.severity = LOG_NOTICE;
appctx->ctx.cli.msg = "Frontend was already shut down.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -1721,18 +1731,21 @@ static int cli_parse_disable_frontend(char **args, struct appctx *appctx, void *
return 1;
if (px->state == PR_STSTOPPED) {
appctx->ctx.cli.severity = LOG_NOTICE;
appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
}
if (px->state == PR_STPAUSED) {
appctx->ctx.cli.severity = LOG_NOTICE;
appctx->ctx.cli.msg = "Frontend is already disabled.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
}
if (!pause_proxy(px)) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -1753,18 +1766,21 @@ static int cli_parse_enable_frontend(char **args, struct appctx *appctx, void *p
return 1;
if (px->state == PR_STSTOPPED) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
}
if (px->state != PR_STPAUSED) {
appctx->ctx.cli.severity = LOG_NOTICE;
appctx->ctx.cli.msg = "Frontend is already enabled.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
}
if (!resume_proxy(px)) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n";
appctx->st0 = CLI_ST_PRINT;
return 1;

View File

@ -4346,18 +4346,21 @@ struct server *cli_find_server(struct appctx *appctx, char *arg)
}
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 @@ static int cli_parse_set_server(char **args, struct appctx *appctx, void *privat
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 @@ static int cli_parse_set_server(char **args, struct appctx *appctx, void *privat
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 @@ static int cli_parse_set_server(char **args, struct appctx *appctx, void *privat
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 @@ static int cli_parse_set_server(char **args, struct appctx *appctx, void *privat
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 @@ static int cli_parse_set_server(char **args, struct appctx *appctx, void *privat
}
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 @@ static int cli_parse_set_server(char **args, struct appctx *appctx, void *privat
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 @@ static int cli_parse_set_server(char **args, struct appctx *appctx, void *privat
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 @@ static int cli_parse_set_server(char **args, struct appctx *appctx, void *privat
}
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 @@ static int cli_parse_set_server(char **args, struct appctx *appctx, void *privat
}
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 @@ static int cli_parse_get_weight(char **args, struct appctx *appctx, void *privat
}
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 @@ static int cli_parse_set_weight(char **args, struct appctx *appctx, void *privat
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 @@ static int cli_parse_set_maxconn_server(char **args, struct appctx *appctx, void
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 @@ static int cli_parse_enable_agent(char **args, struct appctx *appctx, void *priv
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;

View File

@ -7801,6 +7801,7 @@ static int cli_parse_show_tlskeys(char **args, struct appctx *appctx, void *priv
} else {
appctx->ctx.cli.p0 = tlskeys_ref_lookup_ref(args[2]);
if (!appctx->ctx.cli.p0) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "'show tls-keys' unable to locate referenced filename\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -7816,6 +7817,7 @@ static int cli_parse_set_tlskeys(char **args, struct appctx *appctx, void *priva
/* Expect two parameters: the filename and the new new TLS key in encoding */
if (!*args[3] || !*args[4]) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "'set ssl tls-key' expects a filename and the new TLS key in base64 encoding.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -7823,6 +7825,7 @@ static int cli_parse_set_tlskeys(char **args, struct appctx *appctx, void *priva
ref = tlskeys_ref_lookup_ref(args[3]);
if (!ref) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "'set ssl tls-key' unable to locate referenced filename\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -7830,6 +7833,7 @@ static int cli_parse_set_tlskeys(char **args, struct appctx *appctx, void *priva
trash.len = base64dec(args[4], strlen(args[4]), trash.str, trash.size);
if (trash.len != sizeof(struct tls_sess_key)) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "'set ssl tls-key' received invalid base64 encoded TLS key.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -7838,6 +7842,7 @@ static int cli_parse_set_tlskeys(char **args, struct appctx *appctx, void *priva
memcpy(ref->tlskeys + ((ref->tls_ticket_enc_index + 2) % TLS_TICKETS_NO), trash.str, trash.len);
ref->tls_ticket_enc_index = (ref->tls_ticket_enc_index + 1) % TLS_TICKETS_NO;
appctx->ctx.cli.severity = LOG_INFO;
appctx->ctx.cli.msg = "TLS ticket key updated!";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -7852,6 +7857,7 @@ static int cli_parse_set_ocspresponse(char **args, struct appctx *appctx, void *
/* Expect one parameter: the new response in base64 encoding */
if (!*args[3]) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -7859,6 +7865,7 @@ static int cli_parse_set_ocspresponse(char **args, struct appctx *appctx, void *
trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size);
if (trash.len < 0) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -7872,10 +7879,12 @@ static int cli_parse_set_ocspresponse(char **args, struct appctx *appctx, void *
}
return 1;
}
appctx->ctx.cli.severity = LOG_INFO;
appctx->ctx.cli.msg = "OCSP Response updated!";
appctx->st0 = CLI_ST_PRINT;
return 1;
#else
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;

View File

@ -3614,6 +3614,7 @@ static int cli_parse_show_stat(char **args, struct appctx *appctx, void *private
appctx->ctx.stats.iid = atoi(args[2]);
if (!appctx->ctx.stats.iid) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "No such proxy.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;

View File

@ -29,6 +29,7 @@
#include <proto/arg.h>
#include <proto/cli.h>
#include <proto/log.h>
#include <proto/proto_http.h>
#include <proto/proto_tcp.h>
#include <proto/proxy.h>
@ -2354,6 +2355,7 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
struct freq_ctr_period *frqp;
if (!*args[4]) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Key value expected\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -2377,6 +2379,7 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
if ((errno == ERANGE && val == ULONG_MAX) ||
(errno != 0 && val == 0) || endptr == args[4] ||
val > 0xffffffff) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Invalid key\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -2393,15 +2396,19 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
default:
switch (appctx->ctx.table.action) {
case STK_CLI_ACT_SHOW:
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Showing keys from tables of type other than ip, ipv6, string and integer is not supported\n";
break;
case STK_CLI_ACT_CLR:
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Removing keys from tables of type other than ip, ipv6, string and integer is not supported\n";
break;
case STK_CLI_ACT_SET:
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Inserting keys into tables of type other than ip, ipv6, string and integer is not supported\n";
break;
default:
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Unknown action\n";
break;
}
@ -2431,6 +2438,7 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
return 1;
if (ts->ref_cnt) {
/* don't delete an entry which is currently referenced */
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -2445,6 +2453,7 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
ts = stksess_new(&px->table, &static_table_key);
if (!ts) {
/* don't delete an entry which is currently referenced */
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Unable to allocate a new entry\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -2454,6 +2463,7 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) {
if (strncmp(args[cur_arg], "data.", 5) != 0) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -2461,18 +2471,21 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
data_type = stktable_get_data_type(args[cur_arg] + 5);
if (data_type < 0) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Unknown data type\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
}
if (!px->table.data_ofs[data_type]) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Data type not stored in this table\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
}
if (!*args[cur_arg+1] || strl2llrc(args[cur_arg+1], strlen(args[cur_arg+1]), &value) != 0) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Require a valid integer value to store\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -2506,6 +2519,7 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
break;
default:
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Unknown action\n";
appctx->st0 = CLI_ST_PRINT;
break;
@ -2519,6 +2533,7 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
static int table_prepare_data_request(struct appctx *appctx, char **args)
{
if (appctx->ctx.table.action != STK_CLI_ACT_SHOW && appctx->ctx.table.action != STK_CLI_ACT_CLR) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -2527,12 +2542,14 @@ static int table_prepare_data_request(struct appctx *appctx, char **args)
/* condition on stored data value */
appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5);
if (appctx->ctx.table.data_type < 0) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Unknown data type\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
}
if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Data type not stored in this table\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -2540,12 +2557,14 @@ static int table_prepare_data_request(struct appctx *appctx, char **args)
appctx->ctx.table.data_op = get_std_op(args[4]);
if (appctx->ctx.table.data_op < 0) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
}
if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Require a valid integer value to compare against\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -2567,6 +2586,7 @@ static int cli_parse_table_req(char **args, struct appctx *appctx, void *private
if (*args[2]) {
appctx->ctx.table.target = proxy_tbl_by_name(args[2]);
if (!appctx->ctx.table.target) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "No such table\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -2590,15 +2610,19 @@ static int cli_parse_table_req(char **args, struct appctx *appctx, void *private
err_args:
switch (appctx->ctx.table.action) {
case STK_CLI_ACT_SHOW:
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Optional argument only supports \"data.<store_data_type>\" <operator> <value> and key <key>\n";
break;
case STK_CLI_ACT_CLR:
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Required arguments: <table> \"data.<store_data_type>\" <operator> <value> or <table> key <key>\n";
break;
case STK_CLI_ACT_SET:
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Required arguments: <table> key <key> [data.<store_data_type> <value>]*\n";
break;
default:
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Unknown action\n";
break;
}

View File

@ -3229,6 +3229,7 @@ static int cli_parse_shutdown_session(char **args, struct appctx *appctx, void *
return 1;
if (!*args[2]) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
@ -3244,6 +3245,7 @@ static int cli_parse_shutdown_session(char **args, struct appctx *appctx, void *
/* do we have the stream ? */
if (strm != ptr) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "No such session (use 'show sess').\n";
appctx->st0 = CLI_ST_PRINT;
return 1;