Skip to content

Commit ac6c16e

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

File tree

4 files changed

+62
-8
lines changed

4 files changed

+62
-8
lines changed

cmk/plugins/collection/agent_based/inventory_lnx_video.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
@dataclass
3131
class GraphicsCard:
32+
slot: str
3233
name: str
3334
subsystem: str | None = None
3435
driver: str | None = None
@@ -46,14 +47,15 @@ def parse_lnx_video(string_table: StringTable) -> Section:
4647
continue
4748

4849
if "VGA compatible controller" in line[-2]:
50+
current_slot = ":".join(line).split()[0]
4951
current_name = line[-1].strip()
5052
if current_name:
51-
parsed_section.setdefault(current_name, GraphicsCard(name=current_name))
53+
parsed_section.setdefault(current_slot, GraphicsCard(slot=current_slot, name=current_name))
5254
elif current_name:
5355
if line[0] == "Subsystem":
54-
parsed_section[current_name].subsystem = line[1].strip()
56+
parsed_section[current_slot].subsystem = line[1].strip()
5557
elif line[0] == "Kernel driver in use":
56-
parsed_section[current_name].driver = line[1].strip()
58+
parsed_section[current_slot].driver = line[1].strip()
5759

5860
return parsed_section
5961

@@ -70,9 +72,10 @@ def inventory_lnx_video(section: Section) -> InventoryResult:
7072
yield TableRow(
7173
path=["hardware", "video"],
7274
key_columns={
73-
"name": graphics_card.name,
75+
"slot": graphics_card.slot,
7476
},
7577
inventory_columns={
78+
"name": graphics_card.name,
7679
"subsystem": graphics_card.subsystem,
7780
"driver": graphics_card.driver,
7881
},

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 200b",
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)