# Parse Epson ET-2720 Advanced Usage Status page from web interface # # Copyright (C) 2021 Mike Gerwitz # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # This will produce a `printer_pages_count` metric for each available color # and source. # # Note that this script is hardly robust and relies on many different # assumptions about the strucutre of the sloppy HTML on the page, beacuse # I do not permit the printer to access the Internet, and therefore the # firmware can never upgrade and make changes to the layout of this page. # Consequently, you may find that this script does not work for your # printer, even if it is the same model. @include "../../../prom.awk" # Rather than parsing start and end tags, we'll set the field separator to # any opening angled bracket and the record separator to any closing. This # leaves us with the node names, attributes, and cdata. BEGIN { FS = "<" RS = ">" count = 0 expected_count = 8 prom_declare_counter("printer_pages_count", "Number of pages."); prom_declare_gauge("printer_pages_count_success", "Whether scraping was successful.") } # Simplify matching. { gsub(/B&(amp;)?W/, "BW") gsub(/ /, " ") } # Lines that mention BW or Color indicate a metric. /BW|Color/ { color = "CMYK" source = "" if ($1 ~ /BW/) color="K" # Whitelist metrics. switch ($1) { case /Copy :$/: source = "copy" break case /Scan :$/: source = "scan" break case /Print from Computer or Mobile Device :$/: source = "print" break case /Print from Memory Device or Other Functions :$/: source = "internal" break default: next } # Assume that the next line beginning with a number is the value. while (!($1 ~ /^[0-9]/)) getline L["color"] = color L["source"] = source prom_metric("printer_pages_count", $1, L) count++ } END { prom_metric("printer_pages_count_success", (count == expected_count)) }