From 1dc3e5ae94a573627e46b5d294680686b3c28e0a Mon Sep 17 00:00:00 2001 From: Andrew Dover Date: Mon, 16 Feb 2026 17:09:21 -0800 Subject: [PATCH] Changed tray empty alert to parse printer page rather than SNMP OID --- printer/modules/collector.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/printer/modules/collector.py b/printer/modules/collector.py index 3b66100..f7dc0ef 100644 --- a/printer/modules/collector.py +++ b/printer/modules/collector.py @@ -23,13 +23,6 @@ class SnmpOid(enum.Enum): INK_CAPACITY = ("ink_capacity", "1.3.6.1.2.1.43.11.1.1.8.1.1") PAGE_COUNT = ("page_count", "1.3.6.1.2.1.43.10.2.1.4.1.1") - TRAY_EMPTY = ("tray_empty", "1.3.6.1.2.1.43.18.1.1.8.1.13", True) - # we observed each printer emitting a different SNMP OID for - # an empty paper tray, the below accounts for this second OID. - # the _2 at the end of this metric does imply that the printer has - # 2 trays. tray_empty_2 is an indication of the same exact issue - # as tray_empty: an empty paper tray. - TRAY_EMPTY_2 = ("tray_empty_2", "1.3.6.1.2.1.43.18.1.1.8.1.2", True) def __init__(self, metric_name, metric_value, is_error=False): self.metric_name = metric_name @@ -75,6 +68,14 @@ def scrape_html(ip: str): soup = BeautifulSoup(response.content, 'html.parser') + status_td = soup.find('td', class_='itemLargeFont') + if status_td: + status_text = status_td.get_text().strip().lower() + is_paper_empty = 1 if "load paper" in status_text else 0 + metrics_handler.snmp_error.labels(name="tray_empty", ip=ip).set(is_paper_empty) + else: + logging.warning(f"Could not find html element on printer page") + ink_td = soup.find('td', string=lambda s: s and '%' in s) if ink_td: try: