1
0
Fork 0
promscripts/printer/epson/et-2720/ink.awk

58 lines
2.1 KiB
Awk

# Parse Epson ET-2720 Advanced Product 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 <http://www.gnu.org/licenses/>.
#
# This will produce a `printer_ink_level` metric for each ink tank.
#
# 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.
#
# This page is reminescant of how one might write a cross-browser vertical
# colored bar in the 90s when you had to maintain compatibility with IE5.
# It contains a colored image with a height in pixels. The height of its
# container is 50px, so we take the height of the image and simply double it
# to get the ink level of that tank.
@include "../../../prom.awk"
BEGIN {
FS = "[ _.']"
count = 0
expected_count = 4
prom_declare_gauge("printer_ink_level",
"Percentage of each ink tank remaining.")
prom_declare_gauge("printer_ink_level_success",
"Whether scraping was successful.")
}
# ex: <img class='color' src='../../IMAGE/Ink_K.PNG' height='23' style=''>
/IMAGE\/Ink_.\.PNG/ {
L["color"] = $11
prom_metric("printer_ink_level", ($15 * 2), L)
count++
}
END {
prom_metric("printer_ink_level_success", (count == expected_count))
}