Skip to content

Commit 1a5cd1c

Browse files
printer_supply: support additional languages
Extract the color from the service description in the event that the color code is not available from the data. The following languages are now supported: English, Spanish, German, and French. CMK-22267 Change-Id: I922b5ab2afca6a930be1ed4050249669d5c96cc2
1 parent 6d0d40f commit 1a5cd1c

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

cmk/plugins/collection/agent_based/printer_supply.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
"19": "%",
4545
}
4646

47+
# Supported languages: English, German, French, and Spanish.
48+
VALID_BLACK_WORDS = ("black", "schwarz", "noir", "negra")
49+
VALID_CYAN_WORDS = ("cyan", "zyan", "cian")
50+
VALID_MAGENTA_WORDS = ("magenta",)
51+
VALID_YELLOW_WORDS = ("yellow", "gelb", "jaune", "amarilla")
52+
4753

4854
Unit = NewType("Unit", str)
4955

@@ -106,19 +112,20 @@ def _get_supply_unit(raw_unit: str) -> Unit:
106112
return Unit(unit) if unit in {"", "%"} else Unit(f" {unit}")
107113

108114

109-
def _get_supply_color(raw_color: str) -> Color | None:
115+
def _get_supply_color(raw_color: str, raw_description: str) -> Color | None:
110116
color = raw_color.lower()
117+
description = raw_description.lower()
111118

112-
if color == "black":
119+
if color == "black" or any(word in description for word in VALID_BLACK_WORDS):
113120
return "black"
114121

115-
if color == "cyan":
122+
if color == "cyan" or any(word in description for word in VALID_CYAN_WORDS):
116123
return "cyan"
117124

118-
if color == "magenta":
125+
if color == "magenta" or any(word in description for word in VALID_MAGENTA_WORDS):
119126
return "magenta"
120127

121-
if color == "yellow":
128+
if color == "yellow" or any(word in description for word in VALID_YELLOW_WORDS):
122129
return "yellow"
123130

124131
return None
@@ -182,7 +189,7 @@ def parse_printer_supply(string_table: Sequence[StringTable]) -> Section:
182189
raw_color = raw_color.rstrip("\0")
183190

184191
unit = _get_supply_unit(raw_unit)
185-
color = _get_supply_color(raw_color)
192+
color = _get_supply_color(raw_color, description)
186193
supply_class = _get_supply_class(raw_supply_class)
187194

188195
parsed[description] = PrinterSupply(unit, max_capacity, level, supply_class, color)

0 commit comments

Comments
 (0)