- Partial result U from bash script that works fine in a terminal ran as root or cacti user
- Cacti is running as www-data, bash script file ownership and permissions are correct
- Data sources and inputs are defined via GUI
- Tried to rebuild poller cache, remove and create graphs
- Tried different variations of bash scripting
- Results still Invalid
I've made a custom bash script that connects to a printer via SNMP and fetches toner levels data. When I run the script in a terminal, I get the correct result but cacti can't handle it.
This is output from the cacti logfile:
2018/05/08 21:45:03 - POLLER: Poller[Main Poller] WARNING: Invalid Response(s), Errors[1] Device[10] Device[Xerox Phaser 3020] Thread[1] Graphs[Toner percentage, Toner percentage] DS[Get printer toner level]
2018/05/08 21:45:03 - POLLER: Poller[Main Poller] Device[10] Device[Xerox Phaser 3020] Graphs[Toner percentage, Toner percentage] DS[Get printer toner level] CMD: /var/www/html/scripts/xerox_black_toner_level.sh '' '', output: U
2018/05/08 21:45:03 - POLLER: Poller[Main Poller] Device[10] Device[Xerox Phaser 3020] Graphs[Toner percentage, Toner percentage] DS[Get printer toner level] WARNING: Result from CMD not valid. Partial Result: U
Cacti is running as www-data, file is executable and owned by www-data.
File permissions output:
-rwxr-xr-x 1 www-data www-data 793 May 8 21:41 xerox_black_toner_level.sh*
This is the bash script:
Code: Select all
#!/bin/sh
# Tested on Xerox Phaser 3020
# Usage: <path_cacti>/scripts/xerox_black_toner.sh <hostname> <snmp_community>
#Install bc and snmpget for this script to work
BC_PATH="/usr/bin/bc"
# Toner current level
tonerlevel=$(/usr/bin/snmpget -v2c -c $2 $1 1.3.6.1.2.1.43.11.1.1.9.1.1 | awk '{ printf($4) }')
# Toner max level
tonermaxcapacity=$(/usr/bin/snmpget -v2c -c $2 $1 1.3.6.1.2.1.43.11.1.1.8.1.1 | awk '{ printf($4) }')
# Toner left percentage
tonerleft=$(echo "scale=2;$tonerlevel / $tonermaxcapacity *100" | $BC_PATH | cut -f1 -d".")
printf $tonerleft
root@logstation:/var/www/html/scripts# ./xerox_black_toner_level.sh 192.168.0.251 public
98root@logstation:/var/www/html/scripts#
Bash script terminal output as www-data user:
root@logstation:/var/www/html/scripts# sudo -u www-data sh -c "/var/www/html/scripts/xerox_black_toner_level.sh 192.168.0.251 public"
98root@logstation:/var/www/html/scripts#
Data sources, data inputs and graph are created via GUI and are working if I put a direct value into script that is
Code: Select all
printf 98
Code: Select all
printf $tonerleft
Code: Select all
printf "%d" $tonerleft
I've made a simple graph without any templates based on this guide: https://www.cacti.net/downloads/docs/html/how_to.html
GUI settings:
What have I tried already:
- Tried different variations with bash script (echo instead of printf, inputting direct values etc.)
- Rebuilt poller cache many times
- Removed graphs, deleted data and .rrd files, started over
- Went trough similar forum posts and applied their solutions, nothing worked