Skip to content

Commit 7fc3a74

Browse files
committed
Add pci slot as unique key to vga card inventory
1 parent 9ebcb4d commit 7fc3a74

File tree

4 files changed

+74
-11
lines changed

4 files changed

+74
-11
lines changed

cmk/plugins/collection/agent_based/inventory_lnx_video.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,18 @@
2424
from collections.abc import Mapping
2525
from dataclasses import dataclass
2626

27-
from cmk.agent_based.v2 import AgentSection, InventoryPlugin, InventoryResult, StringTable, TableRow
27+
from cmk.agent_based.v2 import (
28+
AgentSection,
29+
InventoryPlugin,
30+
InventoryResult,
31+
StringTable,
32+
TableRow,
33+
)
2834

2935

3036
@dataclass
3137
class GraphicsCard:
38+
slot: str
3239
name: str
3340
subsystem: str | None = None
3441
driver: str | None = None
@@ -40,20 +47,24 @@ class GraphicsCard:
4047
def parse_lnx_video(string_table: StringTable) -> Section:
4148
parsed_section: dict[str, GraphicsCard] = {}
4249

50+
current_slot: str = ""
4351
current_name: str = ""
4452
for line in string_table:
4553
if len(line) <= 1:
4654
continue
4755

4856
if "VGA compatible controller" in line[-2]:
57+
current_slot = ":".join(line).split()[0]
4958
current_name = line[-1].strip()
50-
if current_name:
51-
parsed_section.setdefault(current_name, GraphicsCard(name=current_name))
52-
elif current_name:
59+
if current_slot:
60+
parsed_section.setdefault(
61+
current_slot, GraphicsCard(slot=current_slot, name=current_name)
62+
)
63+
elif current_slot:
5364
if line[0] == "Subsystem":
54-
parsed_section[current_name].subsystem = line[1].strip()
65+
parsed_section[current_slot].subsystem = line[1].strip()
5566
elif line[0] == "Kernel driver in use":
56-
parsed_section[current_name].driver = line[1].strip()
67+
parsed_section[current_slot].driver = line[1].strip()
5768

5869
return parsed_section
5970

@@ -70,9 +81,10 @@ def inventory_lnx_video(section: Section) -> InventoryResult:
7081
yield TableRow(
7182
path=["hardware", "video"],
7283
key_columns={
73-
"name": graphics_card.name,
84+
"slot": graphics_card.slot,
7485
},
7586
inventory_columns={
87+
"name": graphics_card.name,
7688
"subsystem": graphics_card.subsystem,
7789
"driver": graphics_card.driver,
7890
},

cmk/plugins/collection/inventory_ui/hardware.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@
454454
title=Title("Graphic cards"),
455455
table=Table(
456456
columns={
457+
"slot": TextField(Title("Slot")),
457458
"name": TextField(Title("Graphic card name")),
458459
"subsystem": TextField(Title("Vendor and device ID")),
459460
"driver": TextField(Title("Driver")),

tests/unit/cmk/gui/views/inventory/test_display_hints.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ def test_paths() -> None:
588588
"physical_volume_free_partitions",
589589
],
590590
("hardware", "video"): [
591+
"slot",
591592
"name",
592593
"subsystem",
593594
"driver",

tests/unit/cmk/plugins/collection/agent_based/test_inventory_lnx_video.py

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030
TableRow(
3131
path=["hardware", "video"],
3232
key_columns={
33-
"name": "Advanced Micro Devices [AMD] nee ATI Cape Verde PRO [Radeon HD 7700 Series] (prog-if 00 [VGA controller])",
33+
"slot": "05:00.0",
3434
},
3535
inventory_columns={
36+
"name": "Advanced Micro Devices [AMD] nee ATI Cape Verde PRO [Radeon HD 7700 Series] (prog-if 00 [VGA controller])",
3637
"subsystem": "Hightech Information System Ltd. Device 200b",
3738
"driver": "fglrx_pci",
3839
},
@@ -53,9 +54,10 @@
5354
TableRow(
5455
path=["hardware", "video"],
5556
key_columns={
56-
"name": "Advanced Micro Devices [AMD] nee ATI Cape Verde PRO [Radeon HD 7700 Series] (prog-if 00 [VGA controller])",
57+
"slot": "05:00.0",
5758
},
5859
inventory_columns={
60+
"name": "Advanced Micro Devices [AMD] nee ATI Cape Verde PRO [Radeon HD 7700 Series] (prog-if 00 [VGA controller])",
5961
"subsystem": None,
6062
"driver": None,
6163
},
@@ -88,9 +90,10 @@
8890
TableRow(
8991
path=["hardware", "video"],
9092
key_columns={
91-
"name": "Intel Corporation Device 9a49 (rev 01) (prog-if 00 [VGA controller])",
93+
"slot": "0000:00:02.0",
9294
},
9395
inventory_columns={
96+
"name": "Intel Corporation Device 9a49 (rev 01) (prog-if 00 [VGA controller])",
9497
"subsystem": "Dell Device 0a38",
9598
"driver": "i915",
9699
},
@@ -99,9 +102,10 @@
99102
TableRow(
100103
path=["hardware", "video"],
101104
key_columns={
102-
"name": "Second graphics card",
105+
"slot": "00:03.0",
103106
},
104107
inventory_columns={
108+
"name": "Second graphics card",
105109
"subsystem": "Some subsystem",
106110
"driver": "Some driver",
107111
},
@@ -110,6 +114,51 @@
110114
],
111115
id="Two graphics cards",
112116
),
117+
pytest.param(
118+
[
119+
[
120+
"00",
121+
"08.0 VGA compatible controller",
122+
" Microsoft Corporation Hyper-V virtual VGA (prog-if 00 [VGA controller])",
123+
],
124+
["Subsystem", " Hightech Information System Ltd. Device 200b"],
125+
["Kernel driver in use", " hyperv_drm"],
126+
[
127+
"00",
128+
"08.1 VGA compatible controller",
129+
" Microsoft Corporation Hyper-V virtual VGA (prog-if 00 [VGA controller])",
130+
],
131+
["Subsystem", " Hightech Information System Ltd. Device 200c"],
132+
["Kernel driver in use", " hyperv_drm"],
133+
],
134+
[
135+
TableRow(
136+
path=["hardware", "video"],
137+
key_columns={
138+
"slot": "00:08.0",
139+
},
140+
inventory_columns={
141+
"name": "Microsoft Corporation Hyper-V virtual VGA (prog-if 00 [VGA controller])",
142+
"subsystem": "Hightech Information System Ltd. Device 200b",
143+
"driver": "hyperv_drm",
144+
},
145+
status_columns={},
146+
),
147+
TableRow(
148+
path=["hardware", "video"],
149+
key_columns={
150+
"slot": "00:08.1",
151+
},
152+
inventory_columns={
153+
"name": "Microsoft Corporation Hyper-V virtual VGA (prog-if 00 [VGA controller])",
154+
"subsystem": "Hightech Information System Ltd. Device 200c",
155+
"driver": "hyperv_drm",
156+
},
157+
status_columns={},
158+
),
159+
],
160+
id="Two identical graphics cards",
161+
),
113162
pytest.param(
114163
[
115164
[

0 commit comments

Comments
 (0)