mirror of
https://github.com/thegeeklab/prometheus-pve-sd.git
synced 2024-11-21 17:00:40 +00:00
feat: add filter option exclude_tags (#159)
This commit is contained in:
parent
7f2dc5a612
commit
b5d362417d
@ -28,6 +28,9 @@ exclude_state: []
|
||||
# needs to be a list of strings
|
||||
exclude_vmid: []
|
||||
|
||||
# can be used to exclude vms by tags (proxmox 6+)
|
||||
exclude_tags: []
|
||||
|
||||
pve:
|
||||
server:
|
||||
user:
|
||||
|
@ -94,6 +94,12 @@ class Config():
|
||||
"file": True,
|
||||
"type": environs.Env().list
|
||||
},
|
||||
"exclude_tags": {
|
||||
"default": [],
|
||||
"env": "EXCLUDE_TAGS",
|
||||
"file": True,
|
||||
"type": environs.Env().list
|
||||
},
|
||||
"pve.server": {
|
||||
"default": "",
|
||||
"env": "PVE_SERVER",
|
||||
|
@ -157,6 +157,12 @@ class Discovery():
|
||||
if str(obj["vmid"]) in self.config.config["exclude_vmid"]:
|
||||
continue
|
||||
|
||||
if (
|
||||
isinstance(obj["tags"], str)
|
||||
and not set(obj["tags"].split(",")).isdisjoint(self.config.config["exclude_tags"])
|
||||
):
|
||||
continue
|
||||
|
||||
filtered.append(item.copy())
|
||||
return filtered
|
||||
|
||||
|
22
prometheuspvesd/test/fixtures/fixtures.py
vendored
22
prometheuspvesd/test/fixtures/fixtures.py
vendored
@ -34,7 +34,8 @@ def qemus():
|
||||
"disk": 0,
|
||||
"status": "running",
|
||||
"netout": 12159205236,
|
||||
"mem": 496179157
|
||||
"mem": 496179157,
|
||||
"tags": "unmonitored,excluded"
|
||||
},
|
||||
{
|
||||
"diskwrite": 0,
|
||||
@ -54,6 +55,25 @@ def qemus():
|
||||
"netout": 12159205236,
|
||||
"mem": 496179157
|
||||
},
|
||||
{
|
||||
"diskwrite": 0,
|
||||
"vmid": "102",
|
||||
"name": "102.example.com",
|
||||
"cpu": 0.0202130478509556,
|
||||
"diskread": 0,
|
||||
"template": "",
|
||||
"uptime": 3101505,
|
||||
"maxdisk": 26843545600,
|
||||
"maxmem": 1073741824,
|
||||
"pid": "1765",
|
||||
"cpus": 1,
|
||||
"netin": 2856071643,
|
||||
"disk": 0,
|
||||
"status": "prelaunch",
|
||||
"netout": 12159205236,
|
||||
"mem": 496179157,
|
||||
"tags": "monitored"
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
|
@ -17,13 +17,31 @@ def get_mock(*args):
|
||||
return False
|
||||
|
||||
|
||||
def test_exclude(discovery_fixture, qemus):
|
||||
discovery_fixture.config.config["exclude_vmid"] = ["100", "101"]
|
||||
def test_exclude_vmid(discovery_fixture, qemus):
|
||||
discovery_fixture.config.config["exclude_vmid"] = ["100", "101", "102"]
|
||||
|
||||
expected = []
|
||||
filtered = discovery_fixture._exclude(qemus)
|
||||
|
||||
assert filtered == expected
|
||||
discovery_fixture.config.config["exclude_vmid"] = []
|
||||
|
||||
|
||||
def test_exclude_state(discovery_fixture, qemus):
|
||||
discovery_fixture.config.config["exclude_state"] = ["prelaunch"]
|
||||
filtered = discovery_fixture._exclude(qemus)
|
||||
|
||||
assert len(filtered) == 2
|
||||
discovery_fixture.config.config["exclude_state"] = []
|
||||
|
||||
|
||||
def test_exclude_tags(discovery_fixture, qemus):
|
||||
discovery_fixture.config.config["exclude_tags"] = ["unmonitored"]
|
||||
|
||||
filtered = discovery_fixture._exclude(qemus)
|
||||
|
||||
assert len(filtered) == 2
|
||||
discovery_fixture.config.config["exclude_tags"] = []
|
||||
|
||||
|
||||
def test_validate_ip(discovery_fixture, addresses):
|
||||
|
Loading…
Reference in New Issue
Block a user