Tylan / check_snmp_printer

Icinga Plugin for Checking SNMP Printer Status (Trays, Consumables and Pagecounts)
GNU General Public License v3.0
12 stars 4 forks source link

SNMP v3 Support #24

Closed itsechha closed 2 years ago

itsechha commented 2 years ago

Will you ever support SNMP v3?

Tylan commented 2 years ago

I took a stab at it. It's a bit buggy on some select HP printers I've noticed, but give this a try and report any bugs you may encounter.

patch check_snmp_printer < check_snmp_printer_snmpv3.patch.txt

check_snmp_printer_snmpv3.patch.txt

itsechha commented 2 years ago

Thank you! The hp bug is very real, in our case the printer reads tray empty when it's really not, then must be opened and closed manually. Do these issues arise with snmpv2c?

itsechha commented 2 years ago

i cant get the check to work, i think this needs to be added, i get the same error with leonards check w/o it >>> -l {security mode} [-S] [-w] [-c]

Tylan commented 2 years ago

For HP printers I see they force the use of contextname. That is where I believe the bug lies on some OID searches.

What is the exact error message you are receiving?

./check_snmp_printer -v 3 -H 10.15.0.72 -u tech -A test1234 -a sha -x des -X test1234 -n Jetdirect --consum

outputs:

OK: Black Toner is at 39.00% remaining. OK: Maintenance Kit is at 70.00% remaining. |Black_Toner=39.00;;;; Maintenance_Kit=70.00;;;;

Tylan commented 2 years ago

Thank you! The hp bug is very real, in our case the printer reads tray empty when it's really not, then must be opened and closed manually. Do these issues arise with snmpv2c?

No, none of these issues arise on snmpv2c. It appears to be due to the contextname requirement and how Net::SNMP doesn't seem to read it correctly like snmpwalk does. I could experiment with Net-SNMP instead but that would be a rewrite of the entire code. I'm most likely just going to do some other work around that I've been considering. I have some options.

itsechha commented 2 years ago

I was referring too the snmpv3 check by james leonard, sorry if that was confusing. I now think my error is due to live service checks currently running

Speaking of JL's check, I had to add the following in order to add parameter -n context I hope it's of some help

--- /home/rnicksic/check_snmp_printer 2017-02-23 10:08:16.821478951 -0600
+++ check_snmp_printer 2017-02-23 11:53:04.914467280 -0600
@@ -890,7 +890,7 @@ walk_snmp(){
fi

if [[ $SNMPVERSION = 3 ]]; then
- RESULT_TEXT=`snmpwalk -v $SNMPVERSION $OUTPUT_OPTIONS -u $SNMPUSER -l $PRIVILEGELEVEL -x $PRIVACYPROTOCOL -X $PRIVACYPASSWORD -a $AUTHPROTOCOL -A $AUTHPASSWORD $HOST_NAME $1`
+ RESULT_TEXT=`snmpwalk -v $SNMPVERSION $OUTPUT_OPTIONS -u $SNMPUSER -n $CONTEXT -l $PRIVILEGELEVEL -x $PRIVACYPROTOCOL -X $PRIVACYPASSWORD -a $AUTHPROTOCOL -A $AUTHPASSWORD $HOST_NAME $1`
RESULT_CODE=$?
else
# Check if community was also set
@@ -989,6 +989,10 @@ while test -n "$1"; do
PRIVACYPASSWORD=$2
shift
;;
+ --context|-n)
+ CONTEXT=$2
+ shift
+ ;;
--type|-t) # Assign check to perform
CHECK_TYPE=$(echo "$2" | cut -d " " -f1)
PARAMETER=$(echo "$2" | cut -d " " -f2-)
itsechha commented 2 years ago

For HP printers I see they force the use of contextname. That is where I believe the bug lies on some OID searches.

What is the exact error message you are receiving?

./check_snmp_printer -v 3 -H 10.15.0.72 -u tech -A test1234 -a sha -x des -X test1234 -n Jetdirect --consum

outputs:

OK: Black Toner is at 39.00% remaining. OK: Maintenance Kit is at 70.00% remaining. |Black_Toner=39.00;;;; Maintenance_Kit=70.00;;;;

im getting this output

CRITICAL - snmp error: The requested entries are empty or do not exist

but im also getting the same error on james leonards check :/

Tylan commented 2 years ago

im getting this output

CRITICAL - snmp error: The requested entries are empty or do not exist

but im also getting the same error on james leonards check :/

Okay, that's the same error I get on some HP devices. I've noticed that on those when I query the table and it only has one entry the Net::SNMP module doesn't cycle the table at all. I am looking at doing a work around for these where I write a loop to manually cycle the table. When I pull the entries via a manual pull they are there so this should be fixed when I get that implemented. Stand by 😃

itsechha commented 2 years ago

awesome im rooting for you :P

Tylan commented 2 years ago

Hopefully this fixed most of the bugs, apply this patch to your already patched version and let me know:

patch check_snmp_printer < check_snmp_printer_snmpv3.patch2.txt

check_snmp_printer_snmpv3.patch2.txt

itsechha commented 2 years ago

Sorry for the delayed response, I just got back to work,

Well the good news is it worked:

OK: Yellow Toner is at 96.00% remaining.
OK: Black Toner is at 84.00% remaining.
OK: Magenta Toner is at 90.00% remaining.
OK: Cyan Toner is at 88.00% remaining.
|Yellow_Toner=96.00;;;; Black_Toner=84.00;;;; Magenta_Toner=90.00;;;; Cyan_Toner=88.00;;;;

but it's printing that extra info on the bottom. idk if that is intentional, but it's new.

I really cannot thank you enough for all your help. Ill keep you updated if I start experiencing bugs.

itsechha commented 2 years ago

Im actually having an issue with the graphs for the toner check. Graphite is showing eight graphs image

Tylan commented 2 years ago

Sorry for the delayed response, I just got back to work,

Well the good news is it worked:

OK: Yellow Toner is at 96.00% remaining.
OK: Black Toner is at 84.00% remaining.
OK: Magenta Toner is at 90.00% remaining.
OK: Cyan Toner is at 88.00% remaining.
|Yellow_Toner=96.00;;;; Black_Toner=84.00;;;; Magenta_Toner=90.00;;;; Cyan_Toner=88.00;;;;

but it's printing that extra info on the bottom. idk if that is intentional, but it's new.

I really cannot thank you enough for all your help. Ill keep you updated if I start experiencing bugs.

Glad it's working!

You'll see that last line if you run it via command line. That's the line Icinga reads for perf data :)

Tylan commented 2 years ago

Im actually having an issue with the graphs for the toner check. Graphite is showing eight graphs

Go here:

/var/lib/carbon/whisper/icinga2/<NAME_OF_PRINTER>/services/Consumables_Status/snmp_printer/perfdata

and:

sudo rm -rf Black_Cartridge_HP_CF410X
sudo rm -rf Cyan_Cartridge_HP_CF411X
sudo rm -rf Yellow_Cartridge_HP_CF412X
sudo rm -rf Magenta_Cartridge_HP_CF413X

They look to be stale names if you're using my script now.

itsechha commented 2 years ago

i cannot find this directory, I found something similar under /opt/libs/graphite/ but i could not find the command name or printer name. :/

Tylan commented 2 years ago

Interesting. I found this post on the Icinga Forums. Maybe that will assist.

https://community.icinga.com/t/icinga2-graphite-purge-old-data-maintenance/3669

itsechha commented 2 years ago

Thank you for all the help, that link sent me in the right direction.