From c065ef06a762ac555c2e1020a43201172a02ba9f Mon Sep 17 00:00:00 2001 From: jmakar-s1 <103437771+jmakar-s1@users.noreply.github.com> Date: Mon, 22 Jan 2024 07:19:12 -0500 Subject: [PATCH] DTIN-2346: Set monitor attribute when message_log_template is used (#1236) * DTIN-2346: Set monitor attribute when message_log_template is used * DTIN-2346: Update unit tests --- .../builtin_monitors/syslog_monitor.py | 3 ++- .../builtin_monitors/syslog_template_test.py | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/scalyr_agent/builtin_monitors/syslog_monitor.py b/scalyr_agent/builtin_monitors/syslog_monitor.py index b0c2fe1e5..f80eaf2ea 100644 --- a/scalyr_agent/builtin_monitors/syslog_monitor.py +++ b/scalyr_agent/builtin_monitors/syslog_monitor.py @@ -1,4 +1,4 @@ -# Copyright 2017-2023 Scalyr Inc. +# Copyright 2017-2024 Scalyr Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -1768,6 +1768,7 @@ def __handle_syslog_logs(self, data, extra): ) attribs = self.__syslog_attributes.copy() + attribs["monitor"] = "agentSyslog" attribs.update( { k: v diff --git a/tests/unit/builtin_monitors/syslog_template_test.py b/tests/unit/builtin_monitors/syslog_template_test.py index cc1cddbb9..20f7f5f43 100644 --- a/tests/unit/builtin_monitors/syslog_template_test.py +++ b/tests/unit/builtin_monitors/syslog_template_test.py @@ -241,6 +241,7 @@ def test_no_params(self): { "path": "./syslog.log", "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port, @@ -321,6 +322,7 @@ def test_proto_destport_params_one_logconfig(self): { "path": "./syslog-tcp-%d.log" % self.__class__.tcp_port, "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port, @@ -335,6 +337,7 @@ def test_proto_destport_params_one_logconfig(self): { "path": "./syslog-udp-%d.log" % self.__class__.udp_port, "attributes": { + "monitor": "agentSyslog", "proto": "udp", "srcip": "127.0.0.1", "destport": self.__class__.udp_port, @@ -388,6 +391,7 @@ def test_proto_destport_param_two_logconfigs(self): { "path": "./syslog-tcp-%d.log" % self.__class__.tcp_port, "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port, @@ -402,6 +406,7 @@ def test_proto_destport_param_two_logconfigs(self): { "path": "./syslog-tcp-%d.log" % (self.__class__.tcp_port + 1,), "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port + 1, @@ -443,6 +448,7 @@ def test_srcip_param(self): { "path": "./syslog-127.0.0.1.log", "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port, @@ -457,6 +463,7 @@ def test_srcip_param(self): { "path": "./syslog-127.0.1.1.log", "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.2", "destport": self.__class__.tcp_port, @@ -493,6 +500,7 @@ def test_hostname_param_one_logconfig(self): { "path": "./syslog-alpha.log", "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port, @@ -507,6 +515,7 @@ def test_hostname_param_one_logconfig(self): { "path": "./syslog-bravo.log", "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port, @@ -551,6 +560,7 @@ def test_hostname_param_two_explicit_logconfigs(self): { "path": "./syslog-alpha.log", "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port, @@ -565,6 +575,7 @@ def test_hostname_param_two_explicit_logconfigs(self): { "path": "./syslog-bravo.log", "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port, @@ -605,6 +616,7 @@ def test_hostname_param_two_globbed_logconfigs(self): { "path": "./syslog-alpha.log", "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port, @@ -619,6 +631,7 @@ def test_hostname_param_two_globbed_logconfigs(self): { "path": "./syslog-bravo.log", "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port, @@ -661,6 +674,7 @@ def test_hostname_param_two_logconfigs_fallthrough(self): { "path": "./syslog-alpha.log", "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port, @@ -675,6 +689,7 @@ def test_hostname_param_two_logconfigs_fallthrough(self): { "path": "./syslog-bravo.log", "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port, @@ -715,6 +730,7 @@ def test_appname_param_one_logconfig(self): { "path": "./syslog-apiserver.log", "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port, @@ -729,6 +745,7 @@ def test_appname_param_one_logconfig(self): { "path": "./syslog-database.log", "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port, @@ -770,6 +787,7 @@ def test_multiple_attribs(self): { "path": "./syslog-app1.log", "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port, @@ -785,6 +803,7 @@ def test_multiple_attribs(self): { "path": "./syslog-app2.log", "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port, @@ -836,6 +855,7 @@ def test_multiple_attribs_two_logconfigs(self): { "path": "./syslog-app1.log", "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port, @@ -851,6 +871,7 @@ def test_multiple_attribs_two_logconfigs(self): { "path": "./syslog-app2.log", "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port, @@ -890,6 +911,7 @@ def test_max_log_files(self): { "path": "./syslog-app%d.log" % i, "attributes": { + "monitor": "agentSyslog", "proto": "tcp", "srcip": "127.0.0.1", "destport": self.__class__.tcp_port,