[printer-scraping] This should work now
All checks were successful
Check flake syntax / flake-check (push) Successful in 4m42s
All checks were successful
Check flake syntax / flake-check (push) Successful in 4m42s
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
set -o pipefail
|
||||
set -eo pipefail
|
||||
for command in "jq" "xq" "grep" "curl" "sed"
|
||||
do
|
||||
if ! command -v $command >/dev/null 2>&1
|
||||
@@ -27,8 +27,6 @@ get_cookie () {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#DEBUG; DELETE LATER
|
||||
echo "$cookie" > /home/malobeo/cookie.txt
|
||||
cookie=$(echo "$cookie" | grep Set-Cookie | grep -oP "ID=\K[^.]+" )
|
||||
if [[ $cookie == "" ]]
|
||||
then
|
||||
@@ -95,18 +93,15 @@ system_counter_ScanFaxCounter_keys=("DocumentReadTotal" "DocumentReadLarge" "Fax
|
||||
system_consumables_base_keys=("Toner (Yellow)" "Toner (Magenta)" "Toner (Cyan)" "Toner (Black)" "Drum Cartridge (Cyan)" "Developer Cartridge (Cyan)" "Drum Cartridge (Magenta)" "Developer Cartridge (Magenta)" "Drum Cartridge (Yellow)" "Developer Cartridge (Yellow)" "Drum Cartridge (Black)" "Developer Cartridge (Black)" "Fusing Unit" "Image Transfer Belt Unit" "Transfer Roller Unit")
|
||||
#End Variables-------------
|
||||
|
||||
echo "Start getting cookie"
|
||||
echo "Getting cookie"
|
||||
get_cookie "$@"
|
||||
echo "Cookie got"
|
||||
|
||||
echo "Start extract from system_counter"
|
||||
echo "Start extracting info from system_counter"
|
||||
if [[ $1 == "-d" ]]; then
|
||||
system_counter_data=$(cat system_counter.xml |xq)
|
||||
else
|
||||
system_counter_data=$(curl -s -X GET http://192.168.1.42/wcd/system_counter.xml -H "Cookie: ID=\"$cookie\"" |xq)
|
||||
system_counter_data=$(curl -s -X GET http://192.168.1.42/wcd/system_counter.xml -H "Cookie: ID=$cookie" |xq)
|
||||
fi
|
||||
#DEBUG; DELETE LATER
|
||||
echo "$system_counter_data" > /home/malobeo/system_counter_data.txt
|
||||
|
||||
get_values ".MFP.Count.UserCounterInfo.TotalCounterList.TotalCounter" system_counter_TotalCounter_keys TotalCounter
|
||||
|
||||
@@ -122,21 +117,16 @@ get_values ".MFP.Count.UserCounterInfo.ScanFaxCounterList.ScanFaxCounter" system
|
||||
|
||||
get_values_DeviceStatus system_counter_DeviceStatus_keys DeviceStatus
|
||||
|
||||
echo "Stop extract from system_counter"
|
||||
echo
|
||||
echo "Start extract from system_consumables"
|
||||
echo "Start extracting info from system_consumables"
|
||||
if [[ $1 == "-d" ]]; then
|
||||
system_consumables_data=$(cat system_consumables.xml |xq)
|
||||
else
|
||||
system_consumables_data=$(curl -s -X GET http://192.168.1.42/wcd/system_counter.xml -H "Cookie: ID=\"$cookie\"")
|
||||
system_consumables_data=$(curl -s -X GET http://192.168.1.42/wcd/system_consumable.xml -H "Cookie: ID=$cookie" |xq)
|
||||
fi
|
||||
|
||||
#DEBUG; DELETE LATER
|
||||
echo "$system_consumables_data" > /home/malobeo/system_consumables_data.txt
|
||||
|
||||
get_values_consumables system_consumables_base_keys Consumables
|
||||
|
||||
echo "Stop extract from system_consumables"
|
||||
echo "Sending data to prometheus-pushgateway..."
|
||||
|
||||
echo "$valueStore" | curl -s --data-binary @- http://localhost:9091/metrics/job/printer
|
||||
echo "Success!"
|
||||
|
||||
Reference in New Issue
Block a user