log machine_guid to access.log
Costa Tsaousis (ktsaou) committed
Sep 19, 2017 at 23:36 UTC
f99dd559fdbfb0e3b605751e990cdf9e91543b2f
1 file changed
+16
-16
src/rrdpush.c
+16
-16
@@ -560,8 +560,8 @@ cleanup:
560
// ----------------------------------------------------------------------------
561
// rrdpush receiver thread
562
563
-static void log_stream_connection(const char *client_ip, const char *client_port, const char *api_key, const char *host, const char *msg) {
564
- log_access("STREAM: %d '[%s]:%s' '%s' host '%s' api key '%s'", gettid(), client_ip, client_port, msg, host, api_key);
563
+static void log_stream_connection(const char *client_ip, const char *client_port, const char *api_key, const char *machine_guid, const char *host, const char *msg) {
564
+ log_access("STREAM: %d '[%s]:%s' '%s' host '%s' api key '%s' machine guid '%s'", gettid(), client_ip, client_port, msg, host, api_key, machine_guid);
565
}
566
567
static int rrdpush_receive(int fd, const char *key, const char *hostname, const char *registry_hostname, const char *machine_guid, const char *os, const char *tags, int update_every, char *client_ip, char *client_port) {
@@ -622,7 +622,7 @@ static int rrdpush_receive(int fd, const char *key, const char *hostname, const
622
623
if(!host) {
624
close(fd);
625
- log_stream_connection(client_ip, client_port, key, hostname, "FAILED - CANNOT ACQUIRE HOST");
625
+ log_stream_connection(client_ip, client_port, key, machine_guid, hostname, "FAILED - CANNOT ACQUIRE HOST");
626
error("STREAM %s [receive from [%s]:%s]: failed to find/create host structure.", hostname, client_ip, client_port);
627
return 1;
628
}
@@ -661,7 +661,7 @@ static int rrdpush_receive(int fd, const char *key, const char *hostname, const
661
662
info("STREAM %s [receive from [%s]:%s]: initializing communication...", host->hostname, client_ip, client_port);
663
if(send_timeout(fd, START_STREAMING_PROMPT, strlen(START_STREAMING_PROMPT), 0, 60) != strlen(START_STREAMING_PROMPT)) {
664
- log_stream_connection(client_ip, client_port, key, host->hostname, "FAILED - CANNOT REPLY");
664
+ log_stream_connection(client_ip, client_port, key, host->machine_guid, host->hostname, "FAILED - CANNOT REPLY");
665
error("STREAM %s [receive from [%s]:%s]: cannot send ready command.", host->hostname, client_ip, client_port);
666
close(fd);
667
return 0;
@@ -674,7 +674,7 @@ static int rrdpush_receive(int fd, const char *key, const char *hostname, const
674
// convert the socket to a FILE *
675
FILE *fp = fdopen(fd, "r");
676
if(!fp) {
677
- log_stream_connection(client_ip, client_port, key, host->hostname, "FAILED - SOCKET ERROR");
677
+ log_stream_connection(client_ip, client_port, key, host->machine_guid, host->hostname, "FAILED - SOCKET ERROR");
678
error("STREAM %s [receive from [%s]:%s]: failed to get a FILE for FD %d.", host->hostname, client_ip, client_port, fd);
679
close(fd);
680
return 0;
@@ -699,11 +699,11 @@ static int rrdpush_receive(int fd, const char *key, const char *hostname, const
699
700
// call the plugins.d processor to receive the metrics
701
info("STREAM %s [receive from [%s]:%s]: receiving metrics...", host->hostname, client_ip, client_port);
702
- log_stream_connection(client_ip, client_port, key, host->hostname, "CONNECTED");
702
+ log_stream_connection(client_ip, client_port, key, host->machine_guid, host->hostname, "CONNECTED");
703
704
size_t count = pluginsd_process(host, &cd, fp, 1);
705
706
- log_stream_connection(client_ip, client_port, key, host->hostname, "DISCONNECTED");
706
+ log_stream_connection(client_ip, client_port, key, host->machine_guid, host->hostname, "DISCONNECTED");
707
error("STREAM %s [receive from [%s]:%s]: disconnected (completed updates %zu).", host->hostname, client_ip, client_port, count);
708
709
rrdhost_wrlock(host);
@@ -825,37 +825,37 @@ int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url
825
}
826
827
if(!key || !*key) {
828
- log_stream_connection(w->client_ip, w->client_port, (key && *key)?key:"-", (hostname && *hostname)?hostname:"-", "ACCESS DENIED - NO KEY");
828
+ log_stream_connection(w->client_ip, w->client_port, (key && *key)?key:"-", (machine_guid && *machine_guid)?machine_guid:"-", (hostname && *hostname)?hostname:"-", "ACCESS DENIED - NO KEY");
829
error("STREAM [receive from [%s]:%s]: request without an API key. Forbidding access.", w->client_ip, w->client_port);
830
return rrdpush_receiver_permission_denied(w);
831
}
832
833
if(!hostname || !*hostname) {
834
- log_stream_connection(w->client_ip, w->client_port, (key && *key)?key:"-", (hostname && *hostname)?hostname:"-", "ACCESS DENIED - NO HOSTNAME");
834
+ log_stream_connection(w->client_ip, w->client_port, (key && *key)?key:"-", (machine_guid && *machine_guid)?machine_guid:"-", (hostname && *hostname)?hostname:"-", "ACCESS DENIED - NO HOSTNAME");
835
error("STREAM [receive from [%s]:%s]: request without a hostname. Forbidding access.", w->client_ip, w->client_port);
836
return rrdpush_receiver_permission_denied(w);
837
}
838
839
if(!machine_guid || !*machine_guid) {
840
- log_stream_connection(w->client_ip, w->client_port, (key && *key)?key:"-", (hostname && *hostname)?hostname:"-", "ACCESS DENIED - NO MACHINE GUID");
840
+ log_stream_connection(w->client_ip, w->client_port, (key && *key)?key:"-", (machine_guid && *machine_guid)?machine_guid:"-", (hostname && *hostname)?hostname:"-", "ACCESS DENIED - NO MACHINE GUID");
841
error("STREAM [receive from [%s]:%s]: request without a machine GUID. Forbidding access.", w->client_ip, w->client_port);
842
return rrdpush_receiver_permission_denied(w);
843
}
844
845
if(regenerate_guid(key, buf) == -1) {
846
- log_stream_connection(w->client_ip, w->client_port, (key && *key)?key:"-", (hostname && *hostname)?hostname:"-", "ACCESS DENIED - INVALID KEY");
846
+ log_stream_connection(w->client_ip, w->client_port, (key && *key)?key:"-", (machine_guid && *machine_guid)?machine_guid:"-", (hostname && *hostname)?hostname:"-", "ACCESS DENIED - INVALID KEY");
847
error("STREAM [receive from [%s]:%s]: API key '%s' is not valid GUID (use the command uuidgen to generate one). Forbidding access.", w->client_ip, w->client_port, key);
848
return rrdpush_receiver_permission_denied(w);
849
}
850
851
if(regenerate_guid(machine_guid, buf) == -1) {
852
- log_stream_connection(w->client_ip, w->client_port, (key && *key)?key:"-", (hostname && *hostname)?hostname:"-", "ACCESS DENIED - INVALID MACHINE GUID");
852
+ log_stream_connection(w->client_ip, w->client_port, (key && *key)?key:"-", (machine_guid && *machine_guid)?machine_guid:"-", (hostname && *hostname)?hostname:"-", "ACCESS DENIED - INVALID MACHINE GUID");
853
error("STREAM [receive from [%s]:%s]: machine GUID '%s' is not GUID. Forbidding access.", w->client_ip, w->client_port, machine_guid);
854
return rrdpush_receiver_permission_denied(w);
855
}
856
857
if(!appconfig_get_boolean(&stream_config, key, "enabled", 0)) {
858
- log_stream_connection(w->client_ip, w->client_port, (key && *key)?key:"-", (hostname && *hostname)?hostname:"-", "ACCESS DENIED - KEY NOT ENABLED");
858
+ log_stream_connection(w->client_ip, w->client_port, (key && *key)?key:"-", (machine_guid && *machine_guid)?machine_guid:"-", (hostname && *hostname)?hostname:"-", "ACCESS DENIED - KEY NOT ENABLED");
859
error("STREAM [receive from [%s]:%s]: API key '%s' is not allowed. Forbidding access.", w->client_ip, w->client_port, key);
860
return rrdpush_receiver_permission_denied(w);
861
}
@@ -865,7 +865,7 @@ int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url
865
if(key_allow_from) {
866
if(!simple_pattern_matches(key_allow_from, w->client_ip)) {
867
simple_pattern_free(key_allow_from);
868
- log_stream_connection(w->client_ip, w->client_port, (key && *key)?key:"-", (hostname && *hostname) ? hostname : "-", "ACCESS DENIED - KEY NOT ALLOWED FROM THIS IP");
868
+ log_stream_connection(w->client_ip, w->client_port, (key && *key)?key:"-", (machine_guid && *machine_guid)?machine_guid:"-", (hostname && *hostname) ? hostname : "-", "ACCESS DENIED - KEY NOT ALLOWED FROM THIS IP");
869
error("STREAM [receive from [%s]:%s]: API key '%s' is not permitted from this IP. Forbidding access.", w->client_ip, w->client_port, key);
870
return rrdpush_receiver_permission_denied(w);
871
}
@@ -874,7 +874,7 @@ int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url
874
}
875
876
if(!appconfig_get_boolean(&stream_config, machine_guid, "enabled", 1)) {
877
- log_stream_connection(w->client_ip, w->client_port, (key && *key)?key:"-", (hostname && *hostname)?hostname:"-", "ACCESS DENIED - MACHINE GUID NOT ENABLED");
877
+ log_stream_connection(w->client_ip, w->client_port, (key && *key)?key:"-", (machine_guid && *machine_guid)?machine_guid:"-", (hostname && *hostname)?hostname:"-", "ACCESS DENIED - MACHINE GUID NOT ENABLED");
878
error("STREAM [receive from [%s]:%s]: machine GUID '%s' is not allowed. Forbidding access.", w->client_ip, w->client_port, machine_guid);
879
return rrdpush_receiver_permission_denied(w);
880
}
@@ -884,7 +884,7 @@ int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url
884
if(machine_allow_from) {
885
if(!simple_pattern_matches(machine_allow_from, w->client_ip)) {
886
simple_pattern_free(machine_allow_from);
887
- log_stream_connection(w->client_ip, w->client_port, (key && *key)?key:"-", (hostname && *hostname) ? hostname : "-", "ACCESS DENIED - MACHINE GUID NOT ALLOWED FROM THIS IP");
887
+ log_stream_connection(w->client_ip, w->client_port, (key && *key)?key:"-", (machine_guid && *machine_guid)?machine_guid:"-", (hostname && *hostname) ? hostname : "-", "ACCESS DENIED - MACHINE GUID NOT ALLOWED FROM THIS IP");
888
error("STREAM [receive from [%s]:%s]: Machine GUID '%s' is not permitted from this IP. Forbidding access.", w->client_ip, w->client_port, machine_guid);
889
return rrdpush_receiver_permission_denied(w);
890
}