summaryrefslogtreecommitdiffstats
path: root/src/daemon/commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/commands.c')
-rw-r--r--src/daemon/commands.c83
1 files changed, 43 insertions, 40 deletions
diff --git a/src/daemon/commands.c b/src/daemon/commands.c
index f0637ad31..9d716d932 100644
--- a/src/daemon/commands.c
+++ b/src/daemon/commands.c
@@ -47,9 +47,7 @@ static cmd_status_t cmd_ping_execute(char *args, char **message);
static cmd_status_t cmd_aclk_state(char *args, char **message);
static cmd_status_t cmd_version(char *args, char **message);
static cmd_status_t cmd_dumpconfig(char *args, char **message);
-#ifdef ENABLE_ACLK
static cmd_status_t cmd_remove_node(char *args, char **message);
-#endif
static command_info_t command_info_array[] = {
{"help", cmd_help_execute, CMD_TYPE_HIGH_PRIORITY}, // show help menu
@@ -65,9 +63,7 @@ static command_info_t command_info_array[] = {
{"aclk-state", cmd_aclk_state, CMD_TYPE_ORTHOGONAL},
{"version", cmd_version, CMD_TYPE_ORTHOGONAL},
{"dumpconfig", cmd_dumpconfig, CMD_TYPE_ORTHOGONAL},
-#ifdef ENABLE_ACLK
{"remove-stale-node", cmd_remove_node, CMD_TYPE_ORTHOGONAL}
-#endif
};
/* Mutexes for commands of type CMD_TYPE_ORTHOGONAL */
@@ -119,8 +115,6 @@ static cmd_status_t cmd_help_execute(char *args, char **message)
" Reload health configuration.\n\n"
"reload-labels\n"
" Reload all labels.\n\n"
- "save-database\n"
- " Save internal DB to disk for memory mode save.\n\n"
"reopen-logs\n"
" Close and reopen log files.\n\n"
"shutdown-agent\n"
@@ -135,10 +129,8 @@ static cmd_status_t cmd_help_execute(char *args, char **message)
" Returns current state of ACLK and Cloud connection. (optionally in json).\n\n"
"dumpconfig\n"
" Returns the current netdata.conf on stdout.\n\n"
-#ifdef ENABLE_ACLK
"remove-stale-node <node_id | machine_guid | hostname | ALL_NODES>\n"
" Unregisters and removes a node from the cloud.\n\n"
-#endif
"version\n"
" Returns the netdata version.\n",
MAX_COMMAND_LENGTH - 1);
@@ -193,17 +185,42 @@ static cmd_status_t cmd_fatal_execute(char *args, char **message)
return CMD_STATUS_SUCCESS;
}
-static cmd_status_t cmd_reload_claiming_state_execute(char *args, char **message)
-{
- (void)args;
- (void)message;
-#if defined(DISABLE_CLOUD) || !defined(ENABLE_ACLK)
- netdata_log_info("The claiming feature has been explicitly disabled");
- *message = strdupz("This agent cannot be claimed, it was built without support for Cloud");
- return CMD_STATUS_FAILURE;
-#endif
- netdata_log_info("COMMAND: Reloading Agent Claiming configuration.");
- claim_reload_all();
+static cmd_status_t cmd_reload_claiming_state_execute(char *args __maybe_unused, char **message) {
+ char msg[1024];
+
+ CLOUD_STATUS status = claim_reload_and_wait_online();
+ switch(status) {
+ case CLOUD_STATUS_ONLINE:
+ snprintfz(msg, sizeof(msg),
+ "Netdata Agent is claimed to Netdata Cloud and is currently online.");
+ break;
+
+ case CLOUD_STATUS_BANNED:
+ snprintfz(msg, sizeof(msg),
+ "Netdata Agent is claimed to Netdata Cloud, but it is banned.");
+ break;
+
+ default:
+ case CLOUD_STATUS_AVAILABLE:
+ snprintfz(msg, sizeof(msg),
+ "Netdata Agent is not claimed to Netdata Cloud: %s",
+ claim_agent_failure_reason_get());
+ break;
+
+ case CLOUD_STATUS_OFFLINE:
+ snprintfz(msg, sizeof(msg),
+ "Netdata Agent is claimed to Netdata Cloud, but it is currently offline: %s",
+ cloud_status_aclk_offline_reason());
+ break;
+
+ case CLOUD_STATUS_INDIRECT:
+ snprintfz(msg, sizeof(msg),
+ "Netdata Agent is not claimed to Netdata Cloud, but it is currently online via parent.");
+ break;
+ }
+
+ *message = strdupz(msg);
+
return CMD_STATUS_SUCCESS;
}
@@ -242,9 +259,8 @@ static cmd_status_t cmd_read_config_execute(char *args, char **message)
const char *conf_file = temp; /* "cloud" is cloud.conf, otherwise netdata.conf */
struct config *tmp_config = strcmp(conf_file, "cloud") ? &netdata_config : &cloud_config;
- char *value = appconfig_get(tmp_config, temp + offset + 1, temp + offset2 + 1, NULL);
- if (value == NULL)
- {
+ const char *value = appconfig_get(tmp_config, temp + offset + 1, temp + offset2 + 1, NULL);
+ if (value == NULL) {
netdata_log_error("Cannot execute read-config conf_file=%s section=%s / key=%s because no value set",
conf_file,
temp + offset + 1,
@@ -252,13 +268,11 @@ static cmd_status_t cmd_read_config_execute(char *args, char **message)
freez(temp);
return CMD_STATUS_FAILURE;
}
- else
- {
+ else {
(*message) = strdupz(value);
freez(temp);
return CMD_STATUS_SUCCESS;
}
-
}
static cmd_status_t cmd_write_config_execute(char *args, char **message)
@@ -306,17 +320,10 @@ static cmd_status_t cmd_ping_execute(char *args, char **message)
static cmd_status_t cmd_aclk_state(char *args, char **message)
{
netdata_log_info("COMMAND: Reopening aclk/cloud state.");
-#ifdef ENABLE_ACLK
if (strstr(args, "json"))
*message = aclk_state_json();
else
*message = aclk_state();
-#else
- if (strstr(args, "json"))
- *message = strdupz("{\"aclk-available\":false}");
- else
- *message = strdupz("ACLK Available: No");
-#endif
return CMD_STATUS_SUCCESS;
}
@@ -338,14 +345,12 @@ static cmd_status_t cmd_dumpconfig(char *args, char **message)
(void)args;
BUFFER *wb = buffer_create(1024, NULL);
- config_generate(wb, 0);
+ netdata_conf_generate(wb, 0);
*message = strdupz(buffer_tostring(wb));
buffer_free(wb);
return CMD_STATUS_SUCCESS;
}
-#ifdef ENABLE_ACLK
-
static int remove_ephemeral_host(BUFFER *wb, RRDHOST *host, bool report_error)
{
if (host == localhost) {
@@ -362,11 +367,10 @@ static int remove_ephemeral_host(BUFFER *wb, RRDHOST *host, bool report_error)
if (!rrdhost_option_check(host, RRDHOST_OPTION_EPHEMERAL_HOST)) {
rrdhost_option_set(host, RRDHOST_OPTION_EPHEMERAL_HOST);
- sql_set_host_label(&host->host_uuid, "_is_ephemeral", "true");
+ sql_set_host_label(&host->host_id.uuid, "_is_ephemeral", "true");
aclk_host_state_update(host, 0, 0);
unregister_node(host->machine_guid);
- freez(host->node_id);
- host->node_id = NULL;
+ host->node_id = UUID_ZERO;
buffer_sprintf(wb, "Unregistering node with machine guid %s, hostname = %s", host->machine_guid, rrdhost_hostname(host));
rrd_wrlock();
rrdhost_free___while_having_rrd_wrlock(host, true);
@@ -438,7 +442,6 @@ done:
buffer_free(wb);
return CMD_STATUS_SUCCESS;
}
-#endif
static void cmd_lock_exclusive(unsigned index)
{
@@ -509,7 +512,7 @@ static void pipe_write_cb(uv_write_t* req, int status)
static inline void add_char_to_command_reply(BUFFER *reply_string, unsigned *reply_string_size, char character)
{
- buffer_fast_charcat(reply_string, character);
+ buffer_putc(reply_string, character);
*reply_string_size +=1;
}