Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/68055.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
log_beacon - remove verbose minion log output
3 changes: 1 addition & 2 deletions salt/beacons/log_beacon.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def __virtual__():
if not salt.utils.platform.is_windows() and HAS_REGEX:
return __virtualname__
err_msg = "Not available for Windows systems or when regex library is missing."
log.error("Unable to load %s beacon: %s", __virtualname__, err_msg)
return False, err_msg


Expand Down Expand Up @@ -117,7 +116,7 @@ def beacon(config):
fp_.seek(loc)

txt = fp_.read()
log.info("txt %s", txt)
log.trace("txt %s", txt)

d = {}
for tag in config.get("tags", {}):
Expand Down
46 changes: 28 additions & 18 deletions tests/pytests/unit/beacons/test_log_beacon.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
log beacon test cases
"""

import logging

import pytest

import salt.beacons.log_beacon as log_beacon
Expand Down Expand Up @@ -38,22 +40,30 @@ def test_empty_config():
assert ret == (False, "Configuration for log beacon must contain file option.")


def test_log_match(stub_log_entry):
def test_log_match(stub_log_entry, caplog):
with patch("salt.utils.files.fopen", mock_open(read_data=stub_log_entry)):
config = [
{"file": "/var/log/auth.log", "tags": {"sshd": {"regex": ".*sshd.*"}}}
]

ret = log_beacon.validate(config)
assert ret == (True, "Valid beacon configuration")

_expected_return = [
{
"error": "",
"match": "yes",
"raw": stub_log_entry.rstrip("\n"),
"tag": "sshd",
}
]
ret = log_beacon.beacon(config)
assert ret == _expected_return
with caplog.at_level(logging.TRACE):
config = [
{"file": "/var/log/auth.log", "tags": {"sshd": {"regex": ".*sshd.*"}}}
]

ret = log_beacon.validate(config)
assert ret == (True, "Valid beacon configuration")

_expected_return = [
{
"error": "",
"match": "yes",
"raw": stub_log_entry.rstrip("\n"),
"tag": "sshd",
}
]

ret = log_beacon.beacon(config)
assert ret == _expected_return
for record in caplog.records:
if record.msg.startswith("txt"):
assert record.levelname == "TRACE"
break
else:
assert False, "expected one TRACE txt log"