-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
16144 FIX Ignore piggybacked host names starting with a period
SUP-15642 Change-Id: I8544be67055bad6ab9631c4d7411f43587c06615
- Loading branch information
Showing
3 changed files
with
150 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Title: Ignore piggybacked host names starting with a period | ||
Class: fix | ||
Compatible: incomp | ||
Component: core | ||
Date: 1699602114 | ||
Edition: cre | ||
Level: 1 | ||
Version: 2.3.0b1 | ||
|
||
We now skip piggybacked data for hosts names starting | ||
with a period. Examples of such invalid names are ".", | ||
".hostname", and ".hostname.domain.com". | ||
|
||
Users must rename such hosts if they should remain | ||
in the monitoring. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,11 +26,45 @@ | |
from cmk.fetchers.cache import SectionStore | ||
|
||
from cmk.checkengine.parser import AgentParser, AgentRawDataSectionElem, NO_SELECTION, SNMPParser | ||
from cmk.checkengine.parser._agent import is_valid_hostname | ||
from cmk.checkengine.parser._markers import PiggybackMarker, SectionMarker | ||
|
||
StringTable = list[list[str]] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"hostname", | ||
[ | ||
HostName("ec2-11-111-222-333.cd-blahblah-1.compute.amazonaws.com"), | ||
HostName("subdomain.domain.com"), | ||
HostName("domain.com"), | ||
HostName("domain"), | ||
# I don't think the next two are correct but REGEX_HOST_NAME | ||
# would match them as well. | ||
HostName("_"), | ||
HostName("dom_ain.com"), | ||
], | ||
) | ||
def test_is_valid_hostname_positive(hostname: HostName) -> None: | ||
assert is_valid_hostname(hostname) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"hostname", | ||
[ | ||
HostName("."), | ||
HostName(".."), | ||
HostName(".domain"), | ||
HostName(".domain.com"), | ||
HostName("-subdomain.domain.com"), | ||
HostName("[email protected]"), | ||
HostName("@subdomain.domain.com"), | ||
], | ||
) | ||
def test_is_valid_hostname_negative(hostname: HostName) -> None: | ||
assert not is_valid_hostname(hostname) | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def enable_debug_fixture(): | ||
debug_mode = cmk.utils.debug.debug_mode | ||
|
@@ -285,7 +319,7 @@ def test_nameless_piggybacked_sections_are_skipped( | |
raw_data = AgentRawData( | ||
b"\n".join( | ||
( | ||
b"<<<<piggyback header>>>>", | ||
b"<<<<piggyback_header>>>>", | ||
b"<<<a_section>>>", | ||
b"a first line", | ||
b"a second line", | ||
|
@@ -319,6 +353,45 @@ def test_nameless_piggybacked_sections_are_skipped( | |
} | ||
assert not store.load() | ||
|
||
def test_invalid_piggyback_hostnames_are_skipped( | ||
self, | ||
parser: AgentParser, | ||
store: SectionStore[Sequence[AgentRawDataSectionElem]], | ||
monkeypatch: pytest.MonkeyPatch, | ||
) -> None: | ||
monkeypatch.setattr(time, "time", lambda c=itertools.count(1000, 50): next(c)) | ||
monkeypatch.setattr(parser, "cache_piggybacked_data_for", 900) | ||
|
||
raw_data = AgentRawData( | ||
b"\n".join( | ||
( | ||
b"<<<<.>>>>", # <- invalid hostname "." | ||
b"<<<ignored_section>>>", | ||
b"a first line", | ||
b"a second line", | ||
b"<<<ignored_section_2>>>", | ||
b"a third line", | ||
b"a forth line", | ||
b"<<<<>>>>", | ||
b"<<<<piggyback>>>>", | ||
b"<<<keep>>>", | ||
b"first line kept", | ||
b"second line kept", | ||
) | ||
) | ||
) | ||
ahs = parser.parse(raw_data, selection=NO_SELECTION) | ||
assert ahs.sections == {} | ||
assert ahs.cache_info == {} | ||
assert ahs.piggybacked_raw_data == { | ||
"piggyback": [ | ||
b"<<<keep:cached(1000,900)>>>", | ||
b"first line kept", | ||
b"second line kept", | ||
] | ||
} | ||
assert not store.load() | ||
|
||
def test_closing_piggyback_out_of_piggyback_section_closes_section( | ||
self, parser: AgentParser, store: SectionStore[Sequence[AgentRawDataSectionElem]] | ||
) -> None: | ||
|
@@ -364,7 +437,7 @@ def test_piggyback_populates_piggyback_raw_data( | |
raw_data = AgentRawData( | ||
b"\n".join( | ||
( | ||
b"<<<<piggyback header>>>>", # <- space is OK | ||
b"<<<<piggyback_header>>>>", | ||
b"<<<section>>>", | ||
b"first line", | ||
b"second line", | ||
|
@@ -377,9 +450,6 @@ def test_piggyback_populates_piggyback_raw_data( | |
b"third line", | ||
b"forth line", | ||
b"<<<<>>>>", | ||
b"<<<<../b:l*a../>>>>", | ||
b"<<<section>>>", | ||
b"first line", | ||
b"<<<</b_l-u/>>>>", | ||
b"<<<section>>>", | ||
b"first line", | ||
|
@@ -405,10 +475,6 @@ def test_piggyback_populates_piggyback_raw_data( | |
b"third line", | ||
b"forth line", | ||
], | ||
".._b_l_a.._": [ | ||
b"<<<section:cached(1000,900)>>>", | ||
b"first line", | ||
], | ||
"_b_l-u_": [ | ||
b"<<<section:cached(1000,900)>>>", | ||
b"first line", | ||
|