diff options
author | Emmanuel Vasilakis <mrzammler@mm.st> | 2021-05-31 10:42:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-31 10:42:25 +0300 |
commit | 1d493f5f85d1cfae858f4ecc0aec423135618411 (patch) | |
tree | 9dee3c7411dece656b3f3636f440771a4bf3825c | |
parent | c9c9d9299396f674700c0fc37980ff9aa9baec82 (diff) |
Check return status of execution of anonymous statistics script (#11188)
* check return of execution of anonymous statistics script
* break check into two parts
-rw-r--r-- | daemon/analytics.c | 13 | ||||
-rwxr-xr-x | daemon/anonymous-statistics.sh.in | 5 |
2 files changed, 12 insertions, 6 deletions
diff --git a/daemon/analytics.c b/daemon/analytics.c index 08923a3cb7..86d2807507 100644 --- a/daemon/analytics.c +++ b/daemon/analytics.c @@ -876,10 +876,15 @@ void send_statistics(const char *action, const char *action_result, const char * FILE *fp = mypopen(command_to_run, &command_pid); if (fp) { - char buffer[100 + 1]; - while (fgets(buffer, 100, fp) != NULL) - ; - mypclose(fp, command_pid); + char buffer[4 + 1]; + char *s = fgets(buffer, 4, fp); + int exit_code = mypclose(fp, command_pid); + if (exit_code) + error("Execution of anonymous statistics script returned %s.", strerror(exit_code)); + if (s && strncmp(buffer, "200", 3)) + error("Execution of anonymous statistics script returned http code %s.", buffer); + } else { + error("Failed to run anonymous statistics script %s.", as_script); } freez(command_to_run); } diff --git a/daemon/anonymous-statistics.sh.in b/daemon/anonymous-statistics.sh.in index bd22963d93..03efea3e7e 100755 --- a/daemon/anonymous-statistics.sh.in +++ b/daemon/anonymous-statistics.sh.in @@ -148,12 +148,13 @@ EOF # send the anonymous statistics to the Netdata PostHog if [ -n "$(command -v curl 2> /dev/null)" ]; then - curl -X POST --max-time 2 --header "Content-Type: application/json" -d "${REQ_BODY}" https://posthog.netdata.cloud/capture/ > /dev/null 2>&1 + curl --silent -o /dev/null --write-out '%{http_code}' -X POST --max-time 2 --header "Content-Type: application/json" -d "${REQ_BODY}" https://posthog.netdata.cloud/capture/ else wget -q -O - --no-check-certificate \ + --server-response \ --method POST \ --timeout=1 \ --header 'Content-Type: application/json' \ --body-data "${REQ_BODY}" \ - 'https://posthog.netdata.cloud/capture/' > /dev/null 2>&1 + 'https://posthog.netdata.cloud/capture/' 2>&1 | awk '/^ HTTP/{print $2}' fi |