fix analytics logs (#16462)
Costa Tsaousis committed
Nov 22, 2023 at 22:54 UTC
90d58688d871161867c0df110a69b464d8c81f31
1 file changed
+42
-26
daemon/analytics.c
+42
-26
@@ -824,8 +824,7 @@ void get_system_timezone(void)
824
}
825
}
826
827
-void set_global_environment()
828
-{
827
+void set_global_environment() {
828
{
829
char b[16];
830
snprintfz(b, 15, "%d", default_rrd_update_every);
@@ -922,16 +921,14 @@ void set_global_environment()
921
freez(default_port);
922
923
// set the path we need
925
- char path[1024 + 1], *p = getenv("PATH");
926
- if (!p)
927
- p = "/bin:/usr/bin";
928
- snprintfz(path, 1024, "%s:%s", p, "/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
924
+ char path[4096], *p = getenv("PATH");
925
+ if (!p) p = "/bin:/usr/bin";
926
+ snprintfz(path, sizeof(path), "%s:%s", p, "/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
927
setenv("PATH", config_get(CONFIG_SECTION_ENV_VARS, "PATH", path), 1);
928
929
// python options
930
p = getenv("PYTHONPATH");
933
- if (!p)
934
- p = "";
931
+ if (!p) p = "";
932
setenv("PYTHONPATH", config_get(CONFIG_SECTION_ENV_VARS, "PYTHONPATH", p), 1);
933
934
// disable buffering for python plugins
@@ -941,41 +938,48 @@ void set_global_environment()
938
setenv("LC_ALL", "C", 1);
939
}
940
944
-void send_statistics(const char *action, const char *action_result, const char *action_data)
945
-{
941
+void send_statistics(const char *action, const char *action_result, const char *action_data) {
942
static char *as_script;
943
944
if (netdata_anonymous_statistics_enabled == -1) {
945
char *optout_file = mallocz(
946
sizeof(char) *
947
(strlen(netdata_configured_user_config_dir) + strlen(".opt-out-from-anonymous-statistics") + 2));
948
+
949
sprintf(optout_file, "%s/%s", netdata_configured_user_config_dir, ".opt-out-from-anonymous-statistics");
950
+
951
if (likely(access(optout_file, R_OK) != 0)) {
952
as_script = mallocz(
953
sizeof(char) *
954
(strlen(netdata_configured_primary_plugins_dir) + strlen("anonymous-statistics.sh") + 2));
955
+
956
sprintf(as_script, "%s/%s", netdata_configured_primary_plugins_dir, "anonymous-statistics.sh");
957
+
958
if (unlikely(access(as_script, R_OK) != 0)) {
959
netdata_anonymous_statistics_enabled = 0;
960
- netdata_log_info("Anonymous statistics script %s not found.", as_script);
960
+
961
+ nd_log(NDLS_DAEMON, NDLP_DEBUG,
962
+ "Statistics script '%s' not found.",
963
+ as_script);
964
+
965
freez(as_script);
962
- } else {
963
- netdata_anonymous_statistics_enabled = 1;
966
}
965
- } else {
967
+ else
968
+ netdata_anonymous_statistics_enabled = 1;
969
+ }
970
+ else {
971
netdata_anonymous_statistics_enabled = 0;
972
as_script = NULL;
973
}
974
+
975
freez(optout_file);
976
}
971
- if (!netdata_anonymous_statistics_enabled)
972
- return;
973
- if (!action)
977
+
978
+ if (!netdata_anonymous_statistics_enabled || !action)
979
return;
975
- if (!action_result)
980
+
981
+ if (!action_result || !action_data)
982
action_result = "";
977
- if (!action_data)
978
- action_data = "";
983
984
char *command_to_run = mallocz(
985
sizeof(char) * (strlen(action) + strlen(action_result) + strlen(action_data) + strlen(as_script) +
@@ -1030,7 +1034,9 @@ void send_statistics(const char *action, const char *action_result, const char *
1034
analytics_data.netdata_prebuilt_distro,
1035
analytics_data.netdata_fail_reason);
1036
1033
- netdata_log_info("%s '%s' '%s' '%s'", as_script, action, action_result, action_data);
1037
+ nd_log(NDLS_DAEMON, NDLP_DEBUG,
1038
+ "%s '%s' '%s' '%s'",
1039
+ as_script, action, action_result, action_data);
1040
1041
FILE *fp_child_input;
1042
FILE *fp_child_output = netdata_popen(command_to_run, &command_pid, &fp_child_input);
@@ -1039,11 +1045,21 @@ void send_statistics(const char *action, const char *action_result, const char *
1045
char *s = fgets(buffer, 4, fp_child_output);
1046
int exit_code = netdata_pclose(fp_child_input, fp_child_output, command_pid);
1047
if (exit_code)
1042
- netdata_log_error("Execution of anonymous statistics script returned %d.", exit_code);
1043
- if (s && strncmp(buffer, "200", 3))
1044
- netdata_log_error("Execution of anonymous statistics script returned http code %s.", buffer);
1045
- } else {
1046
- netdata_log_error("Failed to run anonymous statistics script %s.", as_script);
1048
+
1049
+ nd_log(NDLS_DAEMON, NDLP_NOTICE,
1050
+ "Statistics script returned error: %d",
1051
+ exit_code);
1052
+
1053
+ if (s && strncmp(buffer, "200", 3) != 0)
1054
+ nd_log(NDLS_DAEMON, NDLP_NOTICE,
1055
+ "Statistics script returned http code: %s",
1056
+ buffer);
1057
+
1058
}
1059
+ else
1060
+ nd_log(NDLS_DAEMON, NDLP_NOTICE,
1061
+ "Failed to run statistics script: %s.",
1062
+ as_script);
1063
+
1064
freez(command_to_run);
1065
}