diff -Nur nagios-plugins-1.4/config.h.in nagios-plugins-1.4/config.h.in --- nagios-plugins-1.4/config.h.in 2005-02-04 01:47:45.000000000 +0100 +++ nagios-plugins-1.4/config.h.in 2006-02-10 08:42:02.000000000 +0100 @@ -654,6 +654,9 @@ /* path to snmpgetnext binary */ #undef PATH_TO_SNMPGETNEXT +/* path to snmpwalk binary */ +#undef PATH_TO_SNMPWALK + /* path to uptime binary */ #undef PATH_TO_UPTIME diff -Nur nagios-plugins-1.4/configure nagios-plugins-1.4/configure --- nagios-plugins-1.4/configure 2005-02-04 01:48:39.000000000 +0100 +++ nagios-plugins-1.4/configure 2006-02-10 08:42:02.000000000 +0100 @@ -15190,10 +15190,10 @@ #define PATH_TO_SNMPGET "$PATH_TO_SNMPGET" _ACEOF - EXTRAS="$EXTRAS check_hpjd check_snmp" + EXTRAS="$EXTRAS check_hpjd check_printer check_snmp" else - { echo "$as_me:$LINENO: WARNING: Get snmpget from http://net-snmp.sourceforge.net to make check_hpjd and check_snmp plugins" >&5 -echo "$as_me: WARNING: Get snmpget from http://net-snmp.sourceforge.net to make check_hpjd and check_snmp plugins" >&2;} + { echo "$as_me:$LINENO: WARNING: Get snmpget from http://net-snmp.sourceforge.net to make check_hpjd, check_printer and check_snmp plugins" >&5 +echo "$as_me: WARNING: Get snmpget from http://net-snmp.sourceforge.net to make check_hpjd, check_printer and check_snmp plugins" >&2;} fi # Extract the first word of "snmpgetnext", so it can be a program name with args. @@ -15244,6 +15244,55 @@ fi +# Extract the first word of "snmpwalk", so it can be a program name with args. +set dummy snmpwalk; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_path_PATH_TO_SNMPWALK+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + case $PATH_TO_SNMPWALK in + [\\/]* | ?:[\\/]*) + ac_cv_path_PATH_TO_SNMPWALK="$PATH_TO_SNMPWALK" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_PATH_TO_SNMPWALK="$as_dir/$ac_word$ac_exec_ext" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + + ;; +esac +fi +PATH_TO_SNMPWALK=$ac_cv_path_PATH_TO_SNMPWALK + +if test -n "$PATH_TO_SNMPWALK"; then + echo "$as_me:$LINENO: result: $PATH_TO_SNMPWALK" >&5 + echo "${ECHO_T}$PATH_TO_SNMPWALK" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + +if test -x "$PATH_TO_SNMPWALK" +then + +cat >>confdefs.h <<_ACEOF +#define PATH_TO_SNMPWALK "$PATH_TO_SNMPWALK" +_ACEOF + +fi + + if ( $PERL -M"Net::SNMP 3.6" -e 'exit' 2>/dev/null ) then echo "$as_me:$LINENO: checking for Net::SNMP perl module" >&5 @@ -25687,6 +25736,7 @@ s,@PATH_TO_WHO@,$PATH_TO_WHO,;t t s,@PATH_TO_SNMPGET@,$PATH_TO_SNMPGET,;t t s,@PATH_TO_SNMPGETNEXT@,$PATH_TO_SNMPGETNEXT,;t t +s,@PATH_TO_SNMPWALK@,$PATH_TO_SNMPWALK,;t t s,@PATH_TO_QUAKESTAT@,$PATH_TO_QUAKESTAT,;t t s,@PATH_TO_QSTAT@,$PATH_TO_QSTAT,;t t s,@PATH_TO_FPING@,$PATH_TO_FPING,;t t diff -Nur nagios-plugins-1.4/lib/Makefile.in nagios-plugins-1.4/lib/Makefile.in --- nagios-plugins-1.4/lib/Makefile.in 2005-02-04 01:48:30.000000000 +0100 +++ nagios-plugins-1.4/lib/Makefile.in 2006-02-10 08:42:02.000000000 +0100 @@ -194,6 +194,7 @@ PATH_TO_SMBCLIENT = @PATH_TO_SMBCLIENT@ PATH_TO_SNMPGET = @PATH_TO_SNMPGET@ PATH_TO_SNMPGETNEXT = @PATH_TO_SNMPGETNEXT@ +PATH_TO_SNMPWALK = @PATH_TO_SNMPWALK@ PATH_TO_SSH = @PATH_TO_SSH@ PATH_TO_SWAP = @PATH_TO_SWAP@ PATH_TO_SWAPINFO = @PATH_TO_SWAPINFO@ diff -Nur nagios-plugins-1.4/m4/Makefile.in nagios-plugins-1.4/m4/Makefile.in --- nagios-plugins-1.4/m4/Makefile.in 2005-02-04 01:48:31.000000000 +0100 +++ nagios-plugins-1.4/m4/Makefile.in 2006-02-10 08:42:02.000000000 +0100 @@ -157,6 +157,7 @@ PATH_TO_SMBCLIENT = @PATH_TO_SMBCLIENT@ PATH_TO_SNMPGET = @PATH_TO_SNMPGET@ PATH_TO_SNMPGETNEXT = @PATH_TO_SNMPGETNEXT@ +PATH_TO_SNMPWALK = @PATH_TO_SNMPWALK@ PATH_TO_SSH = @PATH_TO_SSH@ PATH_TO_SWAP = @PATH_TO_SWAP@ PATH_TO_SWAPINFO = @PATH_TO_SWAPINFO@ diff -Nur nagios-plugins-1.4/plugins/.deps/check_printer.Po nagios-plugins-1.4/plugins/.deps/check_printer.Po --- nagios-plugins-1.4/plugins/.deps/check_printer.Po 1970-01-01 01:00:00.000000000 +0100 +++ nagios-plugins-1.4/plugins/.deps/check_printer.Po 2006-02-10 08:42:02.000000000 +0100 @@ -0,0 +1 @@ +# dummy diff -Nur nagios-plugins-1.4/plugins/Makefile.am nagios-plugins-1.4/plugins/Makefile.am --- nagios-plugins-1.4/plugins/Makefile.am 2005-02-01 13:30:38.000000000 +0100 +++ nagios-plugins-1.4/plugins/Makefile.am 2006-02-10 08:42:02.000000000 +0100 @@ -22,7 +22,7 @@ EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \ check_swap check_fping check_ldap check_game check_dig \ check_nagios check_by_ssh check_dns check_nt check_ide_smart \ - check_procs + check_procs check_printer EXTRA_DIST = t utils.c netutils.c popen.c utils.h netutils.h popen.h common.h \ getaddrinfo.c getaddrinfo.h gethostbyname.c gethostbyname.h @@ -66,6 +66,7 @@ check_overcr_LDADD = $(NETLIBS) check_pgsql_LDADD = $(NETLIBS) $(PGLIBS) check_ping_LDADD = $(NETLIBS) popen.o +check_printer_LDADD = $(NETLIBS) popen.o check_procs_LDADD = $(BASEOBJS) popen.o check_radius_LDADD = $(NETLIBS) $(RADIUSLIBS) check_real_LDADD = $(NETLIBS) @@ -105,6 +106,7 @@ check_overcr_DEPENDENCIES = check_overcr.c $(NETOBJS) $(DEPLIBS) check_pgsql_DEPENDENCIES = check_pgsql.c $(NETOBJS) $(DEPLIBS) check_ping_DEPENDENCIES = check_ping.c $(NETOBJS) popen.o $(DEPLIBS) +check_printer_DEPENDENCIES = check_printer.c $(NETOBJS) popen.o $(DEPLIBS) check_procs_DEPENDENCIES = check_procs.c $(BASEOBJS) popen.o $(DEPLIBS) check_radius_DEPENDENCIES = check_radius.c $(NETOBJS) $(DEPLIBS) check_real_DEPENDENCIES = check_real.c $(NETOBJS) $(DEPLIBS) diff -Nur nagios-plugins-1.4/plugins/Makefile.in nagios-plugins-1.4/plugins/Makefile.in --- nagios-plugins-1.4/plugins/Makefile.in 2005-02-04 01:48:33.000000000 +0100 +++ nagios-plugins-1.4/plugins/Makefile.in 2006-02-10 08:42:02.000000000 +0100 @@ -14,7 +14,7 @@ @SET_MAKE@ -SOURCES = check_by_ssh.c check_dhcp.c check_dig.c check_disk.c check_dns.c check_dummy.c check_fping.c check_game.c check_hpjd.c check_http.c check_icmp.c check_ide_smart.c check_ldap.c check_load.c check_mrtg.c check_mrtgtraf.c check_mysql.c check_nagios.c check_nt.c check_nwstat.c check_overcr.c check_pgsql.c check_ping.c check_procs.c check_radius.c check_real.c check_smtp.c check_snmp.c check_ssh.c check_swap.c check_tcp.c check_time.c check_udp.c check_ups.c check_users.c negate.c urlize.c +SOURCES = check_by_ssh.c check_dhcp.c check_dig.c check_disk.c check_dns.c check_dummy.c check_fping.c check_game.c check_hpjd.c check_http.c check_icmp.c check_ide_smart.c check_ldap.c check_load.c check_mrtg.c check_mrtgtraf.c check_mysql.c check_nagios.c check_nt.c check_nwstat.c check_overcr.c check_pgsql.c check_ping.c check_printer.c check_procs.c check_radius.c check_real.c check_smtp.c check_snmp.c check_ssh.c check_swap.c check_tcp.c check_time.c check_udp.c check_ups.c check_users.c negate.c urlize.c srcdir = @srcdir@ top_srcdir = @top_srcdir@ @@ -48,7 +48,7 @@ check_swap$(EXEEXT) check_fping$(EXEEXT) check_ldap$(EXEEXT) \ check_game$(EXEEXT) check_dig$(EXEEXT) check_nagios$(EXEEXT) \ check_by_ssh$(EXEEXT) check_dns$(EXEEXT) check_nt$(EXEEXT) \ - check_ide_smart$(EXEEXT) check_procs$(EXEEXT) + check_ide_smart$(EXEEXT) check_printer$(EXEEXT) check_procs$(EXEEXT) subdir = plugins DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -130,6 +130,8 @@ check_pgsql_OBJECTS = check_pgsql.$(OBJEXT) check_ping_SOURCES = check_ping.c check_ping_OBJECTS = check_ping.$(OBJEXT) +check_printer_SOURCES = check_printer.c +check_printer_OBJECTS = check_printer.$(OBJEXT) check_procs_SOURCES = check_procs.c check_procs_OBJECTS = check_procs.$(OBJEXT) check_radius_SOURCES = check_radius.c @@ -182,6 +184,7 @@ @AMDEP_TRUE@ ./$(DEPDIR)/check_overcr.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/check_pgsql.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/check_ping.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/check_printer.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/check_procs.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/check_radius.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/check_real.Po \ @@ -201,7 +204,7 @@ check_hpjd.c check_http.c check_icmp.c check_ide_smart.c \ check_ldap.c check_load.c check_mrtg.c check_mrtgtraf.c \ check_mysql.c check_nagios.c check_nt.c check_nwstat.c \ - check_overcr.c check_pgsql.c check_ping.c check_procs.c \ + check_overcr.c check_pgsql.c check_ping.c check_printer.c check_procs.c \ check_radius.c check_real.c check_smtp.c check_snmp.c \ check_ssh.c check_swap.c check_tcp.c check_time.c check_udp.c \ check_ups.c check_users.c negate.c urlize.c @@ -210,7 +213,7 @@ check_hpjd.c check_http.c check_icmp.c check_ide_smart.c \ check_ldap.c check_load.c check_mrtg.c check_mrtgtraf.c \ check_mysql.c check_nagios.c check_nt.c check_nwstat.c \ - check_overcr.c check_pgsql.c check_ping.c check_procs.c \ + check_overcr.c check_pgsql.c check_ping.c check_printer.c check_procs.c \ check_radius.c check_real.c check_smtp.c check_snmp.c \ check_ssh.c check_swap.c check_tcp.c check_time.c check_udp.c \ check_ups.c check_users.c negate.c urlize.c @@ -313,6 +316,7 @@ PATH_TO_SMBCLIENT = @PATH_TO_SMBCLIENT@ PATH_TO_SNMPGET = @PATH_TO_SNMPGET@ PATH_TO_SNMPGETNEXT = @PATH_TO_SNMPGETNEXT@ +PATH_TO_SNMPWALK = @PATH_TO_SNMPWALK@ PATH_TO_SSH = @PATH_TO_SSH@ PATH_TO_SWAP = @PATH_TO_SWAP@ PATH_TO_SWAPINFO = @PATH_TO_SWAPINFO@ @@ -428,6 +432,7 @@ check_overcr_LDADD = $(NETLIBS) check_pgsql_LDADD = $(NETLIBS) $(PGLIBS) check_ping_LDADD = $(NETLIBS) popen.o +check_printer_LDADD = $(NETLIBS) popen.o check_procs_LDADD = $(BASEOBJS) popen.o check_radius_LDADD = $(NETLIBS) $(RADIUSLIBS) check_real_LDADD = $(NETLIBS) @@ -466,6 +471,7 @@ check_overcr_DEPENDENCIES = check_overcr.c $(NETOBJS) $(DEPLIBS) check_pgsql_DEPENDENCIES = check_pgsql.c $(NETOBJS) $(DEPLIBS) check_ping_DEPENDENCIES = check_ping.c $(NETOBJS) popen.o $(DEPLIBS) +check_printer_DEPENDENCIES = check_printer.c $(NETOBJS) popen.o $(DEPLIBS) check_procs_DEPENDENCIES = check_procs.c $(BASEOBJS) popen.o $(DEPLIBS) check_radius_DEPENDENCIES = check_radius.c $(NETOBJS) $(DEPLIBS) check_real_DEPENDENCIES = check_real.c $(NETOBJS) $(DEPLIBS) @@ -606,6 +612,9 @@ check_ping$(EXEEXT): $(check_ping_OBJECTS) $(check_ping_DEPENDENCIES) @rm -f check_ping$(EXEEXT) $(LINK) $(check_ping_LDFLAGS) $(check_ping_OBJECTS) $(check_ping_LDADD) $(LIBS) +check_printer$(EXEEXT): $(check_printer_OBJECTS) $(check_printer_DEPENDENCIES) + @rm -f check_printer$(EXEEXT) + $(LINK) $(check_printer_LDFLAGS) $(check_printer_OBJECTS) $(check_printer_LDADD) $(LIBS) check_procs$(EXEEXT): $(check_procs_OBJECTS) $(check_procs_DEPENDENCIES) @rm -f check_procs$(EXEEXT) $(LINK) $(check_procs_LDFLAGS) $(check_procs_OBJECTS) $(check_procs_LDADD) $(LIBS) @@ -678,6 +687,7 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_overcr.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_pgsql.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_ping.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_printer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_procs.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_radius.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_real.Po@am__quote@ diff -Nur nagios-plugins-1.4/plugins-scripts/Makefile.in nagios-plugins-1.4/plugins-scripts/Makefile.in --- nagios-plugins-1.4/plugins-scripts/Makefile.in 2005-02-04 01:48:31.000000000 +0100 +++ nagios-plugins-1.4/plugins-scripts/Makefile.in 2006-02-10 08:42:02.000000000 +0100 @@ -162,6 +162,7 @@ PATH_TO_SMBCLIENT = @PATH_TO_SMBCLIENT@ PATH_TO_SNMPGET = @PATH_TO_SNMPGET@ PATH_TO_SNMPGETNEXT = @PATH_TO_SNMPGETNEXT@ +PATH_TO_SNMPWALK = @PATH_TO_SNMPWALK@ PATH_TO_SSH = @PATH_TO_SSH@ PATH_TO_SWAP = @PATH_TO_SWAP@ PATH_TO_SWAPINFO = @PATH_TO_SWAPINFO@ diff -Nur nagios-plugins-1.4/plugins/check_printer.c nagios-plugins-1.4/plugins/check_printer.c --- nagios-plugins-1.4/plugins/check_printer.c 1970-01-01 01:00:00.000000000 +0100 +++ nagios-plugins-1.4/plugins/check_printer.c 2006-03-07 14:43:46.000000000 +0100 @@ -0,0 +1,535 @@ +/****************************************************************************** +* +* 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 2 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, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +* +* $Id: check_printer.c,v 1.31 2004/12/25 23:17:44 opensides Exp $ +*****************************************************************************/ + +const char *progname = "check_printer"; +const char *revision = "$Revision: 0.12 $"; +const char *copyright = "2000-2005"; +const char *email = "csc@fes-aes.de"; + +#include "common.h" +#include "popen.h" +#include "utils.h" +#include "netutils.h" + +#define DEFAULT_COMMUNITY "public" + + +const char *option_summary = "-H host [-C community]\n"; + +#define PTR_CONSOLE_DISPLAY_BUFFER_TEXT ".1.3.6.1.2.1.43.16" +#define PTR_ALERT_TABLE ".1.3.6.1.2.1.43.18" +#define PTR_ALERT_INDEX ".1.3.6.1.2.1.43.18.1.1.1.1" +#define PTR_ALERT_SEVERITY_LEVEL ".1.3.6.1.2.1.43.18.1.1.2.1" +#define PTR_ALERT_TRAINING_LEVEL ".1.3.6.1.2.1.43.18.1.1.3.1" +#define PTR_ALERT_GROUP ".1.3.6.1.2.1.43.18.1.1.4.1" +#define PTR_ALERT_GROUP_INDEX ".1.3.6.1.2.1.43.18.1.1.5.1" +#define PTR_ALERT_LOCATION ".1.3.6.1.2.1.43.18.1.1.6.1" +#define PTR_ALERT_CODE ".1.3.6.1.2.1.43.18.1.1.7.1" +#define PTR_ALERT_DESCRIPTION ".1.3.6.1.2.1.43.18.1.1.8.1" +#define PTR_ALERT_TIME ".1.3.6.1.2.1.43.18.1.1.9.1" + +#define LEVEL_UNTRAINED 3 +#define LEVEL_TRAINED 4 +#define LEVEL_FIELDSERVICE 5 + + +int process_arguments (int, char **); +int validate_arguments (void); +void print_help (void); +void print_usage (void); +char* convert (char*); + +char *community = NULL; +char *address = NULL; +int training_level = LEVEL_TRAINED; + +int main (int argc, char **argv) { + + char command_line[1024]; + int result = STATE_UNKNOWN; + int line = 0; + int index = 0; + int entries = 0; + int id[65535]; + char input_buffer[MAX_INPUT_BUFFER]; + char *errmsg; + char *temp_buffer; + unsigned short int code_mask[2048]; /* specify mask for binary change events which be should considered critical */ + /* other(1) */ + /* unknown(2) */ + /* coverOpen(3) */ + /* coverClosed(4) */ + /* interlockOpen(5) */ + /* interlockClosed(6) */ + /* configurationChange(7) */ + code_mask[8] = TRUE; /* jam(8) */ + code_mask[9] = TRUE; /* subunitMissing(9) -- Not in RFC 1759 */ + /* subunitLifeAlmostOver(10) -- Not in RFC 1759 */ + code_mask[11] = TRUE; /* subunitLifeOver(11) -- Not in RFC 1759 */ + /* subunitAlmostEmpty(12) -- Not in RFC 1759 */ + code_mask[13] = TRUE; /* subunitEmpty(13) -- Not in RFC 1759 */ + /* subunitAlmostFull(14) -- Not in RFC 1759 */ + /* subunitFull(15) -- Not in RFC 1759 */ + /* subunitNearLimit(16) -- Not in RFC 1759 */ + /* subunitAtLimit(17) -- Not in RFC 1759 */ + /* subunitOpened(18) -- Not in RFC 1759 */ + /* subunitClosed(19) -- Not in RFC 1759 */ + /* subunitTurnedOn(20) -- Not in RFC 1759 */ + code_mask[21] = TRUE; /* subunitTurnedOff(21) -- Not in RFC 1759 */ + code_mask[22] = TRUE; /* subunitOffline(22) -- Not in RFC 1759 */ + /* subunitPowerSaver(23) -- Not in RFC 1759 */ + /* subunitWarmingUp(24) -- Not in RFC 1759 */ + /* subunitAdded(25) -- Not in RFC 1759 */ + code_mask[26] = TRUE; /* subunitRemoved(26) -- Not in RFC 1759 */ + /* subunitResourceAdded(27) -- Not in RFC 1759 */ + code_mask[28] = TRUE; /* subunitResourceRemoved(28) -- Not in RFC 1759 */ + /* subunitRecoverableFailure(29) -- Not in RFC 1759 */ + code_mask[30] = TRUE; /* subunitUnrecoverableFailure(30) -- Not in RFC 1759 */ + /* subunitRecoverableStorageError(31) -- Not in RFC 1759 */ + code_mask[32] = TRUE; /* subunitUnrecoverableStorageError(32) -- Not in RFC 1759 */ + code_mask[33] = TRUE; /* subunitMotorFailure(33) -- Not in RFC 1759 */ + code_mask[34] = TRUE; /* subunitMemoryExhausted(34) -- Not in RFC 1759 */ + /* subunitUnderTemperature(35) -- Not in RFC 1759 */ + /* subunitOverTemperature(36) -- Not in RFC 1759 */ + /* subunitTimingFailure(37) -- Not in RFC 1759 */ + /* subunitThermistorFailure(38) -- Not in RFC 1759 */ + + /* doorOpen(501) -- DEPRECATED - Use coverOpened(3) */ + /* doorClosed(502) -- DEPRECATED - Use coverClosed(4) */ + /* powerUp(503) */ + /* powerDown(504) */ + /* printerNMSReset(505) -- Not in RFC 1759 */ + /* printerManualReset(506) -- Not in RFC 1759 */ + /* printerReadyToPrint(507) -- Not in RFC 1759 */ + + code_mask[801] = TRUE; /* inputMediaTrayMissing(801) */ + /* inputMediaSizeChange(802) */ + /* inputMediaWeightChange(803) */ + /* inputMediaTypeChange(804) */ + /* inputMediaColorChange(805) */ + /* inputMediaFormPartsChange(806) */ + /* inputMediaSupplyLow(807) */ + code_mask[808] = TRUE; /* inputMediaSupplyEmpty(808) */ + /* inputMediaChangeRequest(809) -- Not in RFC 1759 */ + /* inputManualInputRequest(810) -- Not in RFC 1759 */ + /* inputTrayPositionFailure(811) -- Not in RFC 1759 */ + /* inputCannotFeedSizeSelected(813) -- Not in RFC 1759 */ + /* inputTrayElevationFailure(812) -- Not in RFC 1759 */ + + code_mask[901] = TRUE; /* outputMediaTrayMissing(901) */ + /* outputMediaTrayAlmostFull(902) */ + code_mask[903] = TRUE; /* outputMediaTrayFull(903) */ + /* outputMailboxSelectFailure(904) -- Not in RFC 1759 */ + + /* markerFuserUnderTemperature(1001) */ + /* markerFuserOverTemperature(1002) */ + /* markerFuserTimingFailure(1003) -- Not in RFC 1759 */ + /* markerFuserThermistorFailure(1004) -- Not in RFC 1759 */ + /* markerAdjustingPrintQuality(1005) -- Not in RFC 1759 */ + code_mask[1101] = TRUE; /* markerTonerEmpty(1101) */ + code_mask[1102] = TRUE; /* markerInkEmpty(1102) */ + /* markerPrintRibbonEmpty(1103) */ + /* markerTonerAlmostEmpty(1104) */ + /* markerInkAlmostEmpty(1105) */ + /* markerPrintRibbonAlmostEmpty(1106) */ + /* markerWasteTonerReceptacleAlmostFull(1107) */ + /* markerWasteInkReceptacleAlmostFull(1108) */ + /* markerWasteTonerReceptacleFull(1109) */ + /* markerWasteInkReceptacleFull(1110) */ + /* markerOpcLifeAlmostOver(1111) */ + code_mask[1112] = TRUE; /* markerOpcLifeOver(1112) */ + /* markerDeveloperAlmostEmpty(1113) */ + code_mask[1114] = TRUE; /* markerDeveloperEmpty(1114) */ + code_mask[1115] = TRUE; /* markerTonerCartridgeMissing(1115) -- Not in RFC 1759 */ + + code_mask[1301] = TRUE; /* mediaPathMediaTrayMissing(1301) */ + /* mediaPathMediaTrayAlmostFull(1302) */ + code_mask[1303] = TRUE; /* mediaPathMediaTrayFull(1303) */ + /* mediaPathCannotDuplexMediaSelected(1304) -- Not in RFC 1759 */ + /* interpreterMemoryIncrease(1501) */ + /* interpreterMemoryDecrease(1502) */ + /* interpreterCartridgeAdded(1503) */ + /* interpreterCartridgeDeleted(1504) */ + /* interpreterResourceAdded(1505) */ + /* interpreterResourceDeleted(1506) */ + /* interpreterResourceUnavailable(1507) */ + /* interpreterComplexPageEncountered(1509) -- Not in RFC 1759 */ + /* alertRemovalOfBinaryChangeEntry(1801) -- Not in RFC 1759 */ + + typedef struct prtTableEntry { + int severity; + int training; + /* int group; */ + /* int group_index; */ + /* int location; */ + int code; + char *descr; + /* int time; */ + } aPrtTableEntry; + + aPrtTableEntry entry[256]; /* should be enough */ + + errmsg = malloc(MAX_INPUT_BUFFER); + + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + + if (process_arguments (argc, argv) == ERROR) + usage4 (_("Could not parse arguments")); + + /* get the command to run */ + #if NETSNMP + sprintf (command_line, "%s -On -Oe -Oq -Oa -v1 -c %s %s %s", + #else + sprintf (command_line, "%s -On -Oe -Oq -v1 -c %s %s %s", + #endif + PATH_TO_SNMPWALK, community, address, PTR_ALERT_TABLE); + + #if DEBUG + printf("command : %s\n",command_line); + #endif + + /* run the command */ + child_process = spopen (command_line); + + if (child_process == NULL) { + printf (_("Could not open pipe: %s\n"), command_line); + return STATE_UNKNOWN; + } + + child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); + if (child_stderr == NULL) { + printf (_("Could not open stderr for %s\n"), command_line); + } + + while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { + + /* strip the newline character from the end of the input */ + if (input_buffer[strlen (input_buffer) - 1] == '\n') + input_buffer[strlen (input_buffer) - 1] = 0; + + #if DEBUG + printf("cmd output: %s\n",input_buffer); + #endif + + temp_buffer = strstr(input_buffer," ") + 1; + sscanf(input_buffer,".1.3.6.1.2.1.43.18.1.1.%*d.1.%d",&index); /* prtAlertIndex */ + + if (strstr(input_buffer,PTR_ALERT_SEVERITY_LEVEL)) { + id[index] = entries++; + entry[id[index]].severity = atoi(temp_buffer); + } + + if (strstr(input_buffer,PTR_ALERT_TRAINING_LEVEL)) + entry[id[index]].training = atoi(temp_buffer); + + if (strstr(input_buffer,PTR_ALERT_CODE)) + entry[id[index]].code = atoi(temp_buffer); + + if (strstr(input_buffer,PTR_ALERT_DESCRIPTION)) { + entry[id[index]].descr = strcpy((char*)malloc(MAX_INPUT_BUFFER),convert(temp_buffer)); + } + + if (!(strstr(input_buffer,PTR_ALERT_TABLE))) { /* AlertDescription is hex and more than one line */ + entry[id[index]].descr = strcat(entry[id[index]].descr,convert(input_buffer)); + } + + } + + for (line=0;line<=entries-1;line++) { + + #if DEBUG + printf(" ==> : line=%d: severity=%d training=%d => \"%s\"\n",line,entry[line].severity,entry[line].training,entry[line].descr); + #endif + + /* only care for states which require intervention of service personal */ + if (training_level <= entry[line].training && entry[line].training <= LEVEL_FIELDSERVICE) { + + /* use the last (latest?) AlarmTableEntry with the highest priority */ + switch (entry[line].severity) { + + case 1: /* other */ + + result = max_state(result,STATE_OK); + if (result == STATE_OK) + if (entry[line].descr) + errmsg = entry[line].descr; + break; + + case 3: /* critical */ + + result = STATE_CRITICAL; + if (entry[line].descr) + errmsg = entry[line].descr; + break; + + case 4: /* warning */ + + result = max_state(result,STATE_WARNING); + if (result == STATE_WARNING) + if (entry[line].descr) + errmsg = entry[line].descr; + break; + + case 5: /* warningBinaryChangeEvent -- New, not in RFC 1759 */ + + result = max_state(result,STATE_WARNING); + if (result == STATE_WARNING) + if (entry[line].descr) + errmsg = entry[line].descr; + if (code_mask[entry[line].code] == TRUE ) { + result = STATE_CRITICAL; + if (entry[line].descr) + errmsg = entry[line].descr; + } + break; + + default: + + result = STATE_UNKNOWN; + if (entry[line].descr) + errmsg = entry[line].descr; + break; + } + + } else { + result = max_state(result,STATE_OK); + if (result == STATE_OK) + if (entry[line].descr) + errmsg = entry[line].descr; + } + } + + /* no entries in prtAlarmTable or no description (KYOCERA), query ptrConsoleDisplayBufferText */ + if (line == 0 || entry[0].descr == NULL) { + + sprintf (command_line, "%s -On -v 1 -c %s %s %s", + PATH_TO_SNMPWALK, community, address, PTR_CONSOLE_DISPLAY_BUFFER_TEXT); + + #if DEBUG + printf("command : %s\n",command_line); + #endif + + child_process = spopen (command_line); + + while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { + + if (input_buffer[strlen (input_buffer) - 1] == '\n') + input_buffer[strlen (input_buffer) - 1] = 0; + + #if DEBUG + printf("cmd output: %s\n",input_buffer); + #endif + + temp_buffer = strtok (input_buffer, "\""); + temp_buffer = strtok (NULL, "\""); + + if (temp_buffer) { + errmsg[strlen(errmsg)] = ' '; + errmsg = strcat(errmsg,temp_buffer); + } + result = max_state(result,STATE_OK); + } + } + + /* UNKNOWN if output found on stderr */ + if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { + + result = STATE_UNKNOWN; + + /* remove CRLF */ + if (input_buffer[strlen (input_buffer) - 1] == '\n') + input_buffer[strlen (input_buffer) - 1] = 0; + sprintf (errmsg, "%s", input_buffer ); + + } + + /* close stderr */ + (void) fclose (child_stderr); + + /* close the pipe */ + if (spclose (child_process)) + result = max_state(result,STATE_UNKNOWN); + + switch (result) { + + case STATE_OK: + printf("OK - Printer ok (\"%s\")\n",errmsg); + break; + + case STATE_WARNING: + printf("WARNING - \"%s\"\n",errmsg); + break; + + case STATE_CRITICAL: + printf("CRITICAL - \"%s\"\n",errmsg); + break; + + default: + printf("UNKNOWN - \"%s\"\n",errmsg); + break; + + } + return result; +} + + +/* process command-line arguments */ +int process_arguments (int argc, char **argv) +{ + int c; + + int option = 0; + static struct option longopts[] = { + {"hostname", required_argument, 0, 'H'}, + {"community", required_argument, 0, 'C'}, +/* {"critical", required_argument,0,'c'}, */ +/* {"warning", required_argument,0,'w'}, */ +/* {"port", required_argument,0,'P'}, */ + {"training-level", required_argument, 0, 'l'}, + {"version", no_argument, 0, 'V'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + + if (argc < 2) + return ERROR; + + while (1) { + c = getopt_long (argc, argv, "+hVH:C:l:", longopts, &option); + + if (c == -1 || c == EOF || c == 1) + break; + + switch (c) { + case 'H': /* hostname */ + if (is_host (optarg)) { + address = strscpy(address, optarg) ; + } + else { + usage2 (_("Invalid hostname/address"), optarg); + } + break; + case 'C': /* community */ + community = strscpy (community, optarg); + break; + case 'l': /* min training level */ + training_level = atoi(optarg); + break; + case 'V': /* version */ + print_revision (progname, revision); + exit (STATE_OK); + case 'h': /* help */ + print_help (); + exit (STATE_OK); + case '?': /* help */ + usage2 (_("Unknown argument"), optarg); + } + } + + c = optind; + if (address == NULL) { + if (is_host (argv[c])) { + address = argv[c++]; + } + else { + usage2 (_("Invalid hostname/address"), argv[c]); + } + } + + if (community == NULL) { + if (argv[c] != NULL ) + community = argv[c]; + else + community = strdup (DEFAULT_COMMUNITY); + } + + return OK; +} + + +void +print_help (void) +{ + print_revision (progname, revision); + + printf ("Copyright (c) 2005 Christian Schoeniger \n"); + printf (COPYRIGHT, copyright, email); + + printf (_("\ +This plugin tests the STATUS of an printer with printmib support.\n\ +ucd-snmp must be installed on the computer running the plugin.\n\n")); + + print_usage (); + + printf (_(UT_HELP_VRSN)); + + printf (_("\ + -C, --community=STRING\n\ + The SNMP community name (default=%s)\n"), DEFAULT_COMMUNITY); + + printf (_(UT_SUPPORT)); +} + + + +void +print_usage (void) +{ + printf ("Usage: %s -H host [-C community]\n", progname); +} + +char* convert (char* str) { /* converts OCTET STRING to DisplayString */ + + char *tmp = malloc(MAX_INPUT_BUFFER); + unsigned int d[4]; + + if (str[0] == '"') + str++; + if (str[strlen(str)-1] == '"') + str[strlen(str)-1] = 0; + + #if DEBUG + printf("\tconvert(\"%s\") ",str); + #endif + + if (sscanf(str,"%d %d %d %d",&d[0],&d[1],&d[2],&d[3])) { + + do { + if (strtoul(str,NULL,16) != 10) + sprintf(tmp,"%s%c",tmp,(int)strtol(str,NULL,16)); + else + sprintf(tmp,"%s%c",tmp,' '); + + } while ((str = (strstr(++str," ")))); + + sprintf(tmp,"%s%c",tmp,0); + + str = tmp; + + } + + #if DEBUG + printf("returns \"%s\"\n",str); + #endif + + return str; + +}