#!/bin/bash # Parse Epson ET-2720 metrics 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 `printer_ink_level` and `printer_pages_count` metrics. # # 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. cd "$(dirname "$0")" et-product-status() { wget -qO- "$1/PRESENTATION/ADVANCED/INFO_PRTINFO/TOP" } et-usage-status() { wget -qO- "$1/PRESENTATION/ADVANCED/INFO_MENTINFO/TOP" } # Add host and URL to metric. # # WARNING: This does _not_ sanitize the URL; do not include double quotes. add-host() { local -r url="${1?Missing URL}" sed 's|}|, url="'"$url"'", model="ET-2720"}|; s/{, /{/' } main() { local url="${1?Missing Epson ET-2720 URL}" url="${url%%/}" local -ri start=$(date +%s) # printer_ink_level et-product-status "$url" | awk -f ink.awk | add-host "$url" # printer_pages_count et-usage-status "$url" | awk -f usage.awk | add-host "$url" local -ri end=$(date +%s) local -ri duration=$((end - start)) echo '# HELP printer_scrape_time_seconds Timestamp of last scrape.' echo '# TYPE printer_scrape_time_seconds counter' echo "printer_scrape_time_seconds $(date +%s)" echo '# HELP printer_scrape_duration_seconds Number of seconds spent scraping data from web interface.' echo '# TYPE printer_scrape_duration_seconds gauge' echo "printer_scrape_duration_seconds $duration" } main "$@"