fix: extract J-code part numbers from ProCurve model strings
parse_system_info() now extracts HPE/HP J-codes (e.g. J9298A, J9777A) from the System Model field and returns them as part_number separately. The model name is cleaned of the J-code and surrounding punctuation: "HP J9298A Switch 2520G-8-PoE" → model="HP 2520G-8-PoE Switch", pn="J9298A" "HP2530-8G Switch(J9777A)" → model="HP2530-8G Switch", pn="J9777A" get_facts() includes part_number in the returned dict so NetOrk can store it on Device.part_number and pass it to NetBox device types. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
f3f70cbf74
commit
2be268a65e
@@ -89,7 +89,23 @@ def parse_system_info(output: str) -> Dict:
|
||||
)
|
||||
serial = get("Serial Number") or get("Serial Num")
|
||||
base_mac = procurve_mac_to_std(get("Base MAC Addr") or get("MAC Address") or "")
|
||||
model = get("System Model") or get("product_model") or ""
|
||||
model_raw = get("System Model") or get("product_model") or ""
|
||||
|
||||
# Extract HPE/HP J-code part numbers (e.g. "J9298A") from the model string.
|
||||
# The J-code is the PN; the remaining text is the clean model name.
|
||||
# Examples:
|
||||
# "HP J9298A Switch 2520G-8-PoE" → model="HP 2520G-8-PoE Switch", pn="J9298A"
|
||||
# "HP2530-8G Switch(J9777A)" → model="HP2530-8G Switch", pn="J9777A"
|
||||
_PN_RE = re.compile(r"\b(J\d{4}[A-Z]{1,2})\b")
|
||||
pn_match = _PN_RE.search(model_raw)
|
||||
part_number = pn_match.group(1) if pn_match else ""
|
||||
if pn_match:
|
||||
clean = _PN_RE.sub("", model_raw)
|
||||
clean = re.sub(r"\(\s*\)", "", clean)
|
||||
clean = re.sub(r"\s{2,}", " ", clean).strip(" -()")
|
||||
model = clean if clean else model_raw
|
||||
else:
|
||||
model = model_raw
|
||||
|
||||
# Parse uptime — ProCurve formats: "5 days 3:14" or "0 days 0:05"
|
||||
# Also: "5 day(s), 3:14:00"
|
||||
@@ -101,6 +117,7 @@ def parse_system_info(output: str) -> Dict:
|
||||
"serial_number": serial,
|
||||
"base_mac": base_mac,
|
||||
"model": model,
|
||||
"part_number": part_number,
|
||||
"uptime_seconds": uptime_seconds,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user