summaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
authorMarkos Fountoulakis <44345837+mfundul@users.noreply.github.com>2019-12-19 11:01:59 +0200
committerAndrew Moss <1043609+amoss@users.noreply.github.com>2019-12-19 10:01:59 +0100
commitce9f70d7b3696a54f099628f3337f5c4d5bd1407 (patch)
treed8f0e7bbdd1a070c2dcf619e62c6e5ff4faaccfc /daemon
parentc1436efd00c5b9afdb3779585eb194ea8388a932 (diff)
Agent claiming (#7525)
Initial infrastructure support for agent claiming. This feature is not currently enabled as we are still finalizing the details of the cloud infrastructure w.r.t. agent claiming. The feature will be enabled when we are ready to release it.
Diffstat (limited to 'daemon')
-rw-r--r--daemon/commands.c21
-rw-r--r--daemon/commands.h1
-rw-r--r--daemon/common.h3
-rw-r--r--daemon/daemon.c6
-rw-r--r--daemon/main.c15
5 files changed, 45 insertions, 1 deletions
diff --git a/daemon/commands.c b/daemon/commands.c
index 5eb22a6693..b12c19216b 100644
--- a/daemon/commands.c
+++ b/daemon/commands.c
@@ -40,6 +40,7 @@ static cmd_status_t cmd_save_database_execute(char *args, char **message);
static cmd_status_t cmd_reopen_logs_execute(char *args, char **message);
static cmd_status_t cmd_exit_execute(char *args, char **message);
static cmd_status_t cmd_fatal_execute(char *args, char **message);
+static cmd_status_t cmd_reload_claiming_state_execute(char *args, char **message);
static cmd_status_t cmd_reload_labels_execute(char *args, char **message);
static command_info_t command_info_array[] = {
@@ -49,6 +50,7 @@ static command_info_t command_info_array[] = {
{"reopen-logs", cmd_reopen_logs_execute, CMD_TYPE_ORTHOGONAL}, // Close and reopen log files
{"shutdown-agent", cmd_exit_execute, CMD_TYPE_EXCLUSIVE}, // exit cleanly
{"fatal-agent", cmd_fatal_execute, CMD_TYPE_HIGH_PRIORITY}, // exit with fatal error
+ {"reload-claiming-state", cmd_reload_claiming_state_execute, CMD_TYPE_ORTHOGONAL}, // reload claiming state
{"reload-labels", cmd_reload_labels_execute, CMD_TYPE_ORTHOGONAL}, // reload the labels
};
@@ -108,7 +110,9 @@ static cmd_status_t cmd_help_execute(char *args, char **message)
"shutdown-agent\n"
" Cleanup and exit the netdata agent.\n"
"fatal-agent\n"
- " Log the state and halt the netdata agent.\n",
+ " Log the state and halt the netdata agent.\n"
+ "reload-claiming-state\n"
+ " Reload agent claiming state from disk.\n",
MAX_COMMAND_LENGTH - 1);
return CMD_STATUS_SUCCESS;
}
@@ -176,6 +180,21 @@ 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;
+
+ info("The claiming feature is still in development and subject to change before the next release");
+ return CMD_STATUS_FAILURE;
+
+ error_log_limit_unlimited();
+ info("COMMAND: Reloading Agent Claiming configuration.");
+ load_claiming_state();
+ error_log_limit_reset();
+ return CMD_STATUS_SUCCESS;
+}
+
static cmd_status_t cmd_reload_labels_execute(char *args, char **message)
{
(void)args;
diff --git a/daemon/commands.h b/daemon/commands.h
index 6de4084217..cb879c2a8c 100644
--- a/daemon/commands.h
+++ b/daemon/commands.h
@@ -19,6 +19,7 @@ typedef enum cmd {
CMD_REOPEN_LOGS,
CMD_EXIT,
CMD_FATAL,
+ CMD_RELOAD_CLAIMING_STATE,
CMD_RELOAD_LABELS,
CMD_TOTAL_COMMANDS
} cmd_t;
diff --git a/daemon/common.h b/daemon/common.h
index 5202a53082..6ac3cb3c87 100644
--- a/daemon/common.h
+++ b/daemon/common.h
@@ -60,6 +60,9 @@
// netdata unit tests
#include "unit_test.h"
+// netdata agent claiming
+#include "claim/claim.h"
+
// the netdata deamon
#include "daemon.h"
#include "main.h"
diff --git a/daemon/daemon.c b/daemon/daemon.c
index 4ad082b95e..77448c0e73 100644
--- a/daemon/daemon.c
+++ b/daemon/daemon.c
@@ -4,6 +4,7 @@
#include <sched.h>
char pidfile[FILENAME_MAX + 1] = "";
+char claimingdirectory[FILENAME_MAX + 1];
static void chown_open_file(int fd, uid_t uid, gid_t gid) {
if(fd == -1) return;
@@ -50,6 +51,7 @@ int become_user(const char *username, int pid_fd) {
create_needed_dir(netdata_configured_cache_dir, uid, gid);
create_needed_dir(netdata_configured_varlib_dir, uid, gid);
+ create_needed_dir(claimingdirectory, uid, gid);
if(pidfile[0]) {
if(chown(pidfile, uid, gid) == -1)
@@ -434,6 +436,9 @@ int become_daemon(int dont_fork, const char *user)
// never become a problem
sched_setscheduler_set();
+ // Set claiming directory based on user config directory with correct ownership
+ snprintfz(claimingdirectory, FILENAME_MAX, "%s/claim.d", netdata_configured_user_config_dir);
+
if(user && *user) {
if(become_user(user, pidfd) != 0) {
error("Cannot become user '%s'. Continuing as we are.", user);
@@ -443,6 +448,7 @@ int become_daemon(int dont_fork, const char *user)
else {
create_needed_dir(netdata_configured_cache_dir, getuid(), getgid());
create_needed_dir(netdata_configured_varlib_dir, getuid(), getgid());
+ create_needed_dir(claimingdirectory, getuid(), getgid());
}
if(pidfd != -1)
diff --git a/daemon/main.c b/daemon/main.c
index b00de00628..1dcdb6edd2 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -351,6 +351,8 @@ int help(int exitcode) {
" set netdata.conf option from the command line.\n\n"
" -W simple-pattern pattern string\n"
" Check if string matches pattern and exit.\n\n"
+ " -W \"claim -token=TOKEN -rooms=ROOM1,ROOM2\"\n"
+ " Claim the agent to the workspace rooms pointed to by TOKEN and ROOM*.\n\n"
);
fprintf(stream, "\n Signals netdata handles:\n\n"
@@ -926,6 +928,7 @@ int main(int argc, char **argv) {
{
char* stacksize_string = "stacksize=";
char* debug_flags_string = "debug_flags=";
+ char* claim_string = "claim";
#ifdef ENABLE_DBENGINE
char* createdataset_string = "createdataset=";
char* stresstest_string = "stresstest=";
@@ -1086,6 +1089,10 @@ int main(int argc, char **argv) {
printf("%s\n", value);
return 0;
}
+ else if(strncmp(optarg, claim_string, strlen(claim_string)) == 0) {
+ /* will trigger a claiming attempt when the agent is initialized */
+ claiming_pending_arguments = optarg + strlen(claim_string);
+ }
else {
fprintf(stderr, "Unknown -W parameter '%s'\n", optarg);
return help(1);
@@ -1271,6 +1278,14 @@ int main(int argc, char **argv) {
get_system_info(system_info);
rrd_init(netdata_configured_hostname, system_info);
+
+ // ------------------------------------------------------------------------
+ // Claim netdata agent to a cloud endpoint
+
+ if (claiming_pending_arguments)
+ claim_agent(claiming_pending_arguments);
+ load_claiming_state();
+
// ------------------------------------------------------------------------
// enable log flood protection