Skip to content

Commit c065ef0

Browse files
authored
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
1 parent 9aed9f1 commit c065ef0

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

scalyr_agent/builtin_monitors/syslog_monitor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2017-2023 Scalyr Inc.
1+
# Copyright 2017-2024 Scalyr Inc.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -1768,6 +1768,7 @@ def __handle_syslog_logs(self, data, extra):
17681768
)
17691769

17701770
attribs = self.__syslog_attributes.copy()
1771+
attribs["monitor"] = "agentSyslog"
17711772
attribs.update(
17721773
{
17731774
k: v

tests/unit/builtin_monitors/syslog_template_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ def test_no_params(self):
241241
{
242242
"path": "./syslog.log",
243243
"attributes": {
244+
"monitor": "agentSyslog",
244245
"proto": "tcp",
245246
"srcip": "127.0.0.1",
246247
"destport": self.__class__.tcp_port,
@@ -321,6 +322,7 @@ def test_proto_destport_params_one_logconfig(self):
321322
{
322323
"path": "./syslog-tcp-%d.log" % self.__class__.tcp_port,
323324
"attributes": {
325+
"monitor": "agentSyslog",
324326
"proto": "tcp",
325327
"srcip": "127.0.0.1",
326328
"destport": self.__class__.tcp_port,
@@ -335,6 +337,7 @@ def test_proto_destport_params_one_logconfig(self):
335337
{
336338
"path": "./syslog-udp-%d.log" % self.__class__.udp_port,
337339
"attributes": {
340+
"monitor": "agentSyslog",
338341
"proto": "udp",
339342
"srcip": "127.0.0.1",
340343
"destport": self.__class__.udp_port,
@@ -388,6 +391,7 @@ def test_proto_destport_param_two_logconfigs(self):
388391
{
389392
"path": "./syslog-tcp-%d.log" % self.__class__.tcp_port,
390393
"attributes": {
394+
"monitor": "agentSyslog",
391395
"proto": "tcp",
392396
"srcip": "127.0.0.1",
393397
"destport": self.__class__.tcp_port,
@@ -402,6 +406,7 @@ def test_proto_destport_param_two_logconfigs(self):
402406
{
403407
"path": "./syslog-tcp-%d.log" % (self.__class__.tcp_port + 1,),
404408
"attributes": {
409+
"monitor": "agentSyslog",
405410
"proto": "tcp",
406411
"srcip": "127.0.0.1",
407412
"destport": self.__class__.tcp_port + 1,
@@ -443,6 +448,7 @@ def test_srcip_param(self):
443448
{
444449
"path": "./syslog-127.0.0.1.log",
445450
"attributes": {
451+
"monitor": "agentSyslog",
446452
"proto": "tcp",
447453
"srcip": "127.0.0.1",
448454
"destport": self.__class__.tcp_port,
@@ -457,6 +463,7 @@ def test_srcip_param(self):
457463
{
458464
"path": "./syslog-127.0.1.1.log",
459465
"attributes": {
466+
"monitor": "agentSyslog",
460467
"proto": "tcp",
461468
"srcip": "127.0.0.2",
462469
"destport": self.__class__.tcp_port,
@@ -493,6 +500,7 @@ def test_hostname_param_one_logconfig(self):
493500
{
494501
"path": "./syslog-alpha.log",
495502
"attributes": {
503+
"monitor": "agentSyslog",
496504
"proto": "tcp",
497505
"srcip": "127.0.0.1",
498506
"destport": self.__class__.tcp_port,
@@ -507,6 +515,7 @@ def test_hostname_param_one_logconfig(self):
507515
{
508516
"path": "./syslog-bravo.log",
509517
"attributes": {
518+
"monitor": "agentSyslog",
510519
"proto": "tcp",
511520
"srcip": "127.0.0.1",
512521
"destport": self.__class__.tcp_port,
@@ -551,6 +560,7 @@ def test_hostname_param_two_explicit_logconfigs(self):
551560
{
552561
"path": "./syslog-alpha.log",
553562
"attributes": {
563+
"monitor": "agentSyslog",
554564
"proto": "tcp",
555565
"srcip": "127.0.0.1",
556566
"destport": self.__class__.tcp_port,
@@ -565,6 +575,7 @@ def test_hostname_param_two_explicit_logconfigs(self):
565575
{
566576
"path": "./syslog-bravo.log",
567577
"attributes": {
578+
"monitor": "agentSyslog",
568579
"proto": "tcp",
569580
"srcip": "127.0.0.1",
570581
"destport": self.__class__.tcp_port,
@@ -605,6 +616,7 @@ def test_hostname_param_two_globbed_logconfigs(self):
605616
{
606617
"path": "./syslog-alpha.log",
607618
"attributes": {
619+
"monitor": "agentSyslog",
608620
"proto": "tcp",
609621
"srcip": "127.0.0.1",
610622
"destport": self.__class__.tcp_port,
@@ -619,6 +631,7 @@ def test_hostname_param_two_globbed_logconfigs(self):
619631
{
620632
"path": "./syslog-bravo.log",
621633
"attributes": {
634+
"monitor": "agentSyslog",
622635
"proto": "tcp",
623636
"srcip": "127.0.0.1",
624637
"destport": self.__class__.tcp_port,
@@ -661,6 +674,7 @@ def test_hostname_param_two_logconfigs_fallthrough(self):
661674
{
662675
"path": "./syslog-alpha.log",
663676
"attributes": {
677+
"monitor": "agentSyslog",
664678
"proto": "tcp",
665679
"srcip": "127.0.0.1",
666680
"destport": self.__class__.tcp_port,
@@ -675,6 +689,7 @@ def test_hostname_param_two_logconfigs_fallthrough(self):
675689
{
676690
"path": "./syslog-bravo.log",
677691
"attributes": {
692+
"monitor": "agentSyslog",
678693
"proto": "tcp",
679694
"srcip": "127.0.0.1",
680695
"destport": self.__class__.tcp_port,
@@ -715,6 +730,7 @@ def test_appname_param_one_logconfig(self):
715730
{
716731
"path": "./syslog-apiserver.log",
717732
"attributes": {
733+
"monitor": "agentSyslog",
718734
"proto": "tcp",
719735
"srcip": "127.0.0.1",
720736
"destport": self.__class__.tcp_port,
@@ -729,6 +745,7 @@ def test_appname_param_one_logconfig(self):
729745
{
730746
"path": "./syslog-database.log",
731747
"attributes": {
748+
"monitor": "agentSyslog",
732749
"proto": "tcp",
733750
"srcip": "127.0.0.1",
734751
"destport": self.__class__.tcp_port,
@@ -770,6 +787,7 @@ def test_multiple_attribs(self):
770787
{
771788
"path": "./syslog-app1.log",
772789
"attributes": {
790+
"monitor": "agentSyslog",
773791
"proto": "tcp",
774792
"srcip": "127.0.0.1",
775793
"destport": self.__class__.tcp_port,
@@ -785,6 +803,7 @@ def test_multiple_attribs(self):
785803
{
786804
"path": "./syslog-app2.log",
787805
"attributes": {
806+
"monitor": "agentSyslog",
788807
"proto": "tcp",
789808
"srcip": "127.0.0.1",
790809
"destport": self.__class__.tcp_port,
@@ -836,6 +855,7 @@ def test_multiple_attribs_two_logconfigs(self):
836855
{
837856
"path": "./syslog-app1.log",
838857
"attributes": {
858+
"monitor": "agentSyslog",
839859
"proto": "tcp",
840860
"srcip": "127.0.0.1",
841861
"destport": self.__class__.tcp_port,
@@ -851,6 +871,7 @@ def test_multiple_attribs_two_logconfigs(self):
851871
{
852872
"path": "./syslog-app2.log",
853873
"attributes": {
874+
"monitor": "agentSyslog",
854875
"proto": "tcp",
855876
"srcip": "127.0.0.1",
856877
"destport": self.__class__.tcp_port,
@@ -890,6 +911,7 @@ def test_max_log_files(self):
890911
{
891912
"path": "./syslog-app%d.log" % i,
892913
"attributes": {
914+
"monitor": "agentSyslog",
893915
"proto": "tcp",
894916
"srcip": "127.0.0.1",
895917
"destport": self.__class__.tcp_port,

0 commit comments

Comments
 (0)