From 073e0fa95c6dd06a0a12634fb9e785d3aa2d2fc1 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Tue, 16 Sep 2003 14:14:53 +0000 Subject: Support for AIX ps command and cleanup of configure's ps checks git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@731 f882894a-f735-0410-b71e-b25c423dba1c --- configure.in | 70 ++++++++++++++++++++++++++++++--------------------- plugins/Makefile.am | 4 +-- plugins/check_procs.c | 65 ++++++++++++++++++++++++----------------------- 3 files changed, 77 insertions(+), 62 deletions(-) diff --git a/configure.in b/configure.in index 37baafa8..09e8e350 100644 --- a/configure.in +++ b/configure.in @@ -634,7 +634,7 @@ then ac_cv_ps_varlist="[procstat,&procuid,&procppid,&procvsz,&procrss,&procpcpu,procprog,&pos]" ac_cv_ps_command="$PATH_TO_PS -axwo 'stat uid ppid vsz rss pcpu comm args'" ac_cv_ps_format="%s %d %d %d %d %f %s %n" - EXTRAS="$EXTRAS check_nagios" + ac_cv_ps_cols=8 AC_MSG_RESULT([$ac_cv_ps_command]) dnl STAT UCOMM VSZ RSS USER UID PPID COMMAND @@ -644,7 +644,7 @@ then ac_cv_ps_varlist="[procstat,&procuid,&procppid,&procvsz,&procrss,&procpcpu,procprog,&pos]" ac_cv_ps_command="$PATH_TO_PS -weo 'stat uid ppid vsz rss pcpu comm args'" ac_cv_ps_format="%s %d %d %d %d %f %s %n" - EXTRAS="$EXTRAS check_nagios" + ac_cv_ps_cols=8 AC_MSG_RESULT([$ac_cv_ps_command]) dnl FreeBSD @@ -654,7 +654,7 @@ then ac_cv_ps_varlist="[procstat,&procuid,&procppid,&procvsz,&procrss,&procpcpu,procprog,&pos]" ac_cv_ps_command="$PATH_TO_PS waxco 'state uid ppid vsz rss pcpu command command'" ac_cv_ps_format="%s %d %d %d %d %f %s %n" - EXTRAS="$EXTRAS check_nagios" + ac_cv_ps_cols=8 AC_MSG_RESULT([$ac_cv_ps_command]) dnl BSD-like mode in RH 6.1 @@ -664,7 +664,7 @@ then ac_cv_ps_varlist="[procstat,&procuid,&procppid,&procvsz,&procrss,&procpcpu,procprog,&pos]" ac_cv_ps_command="$PATH_TO_PS waxno 'state uid ppid vsz rss pcpu comm args'" ac_cv_ps_format="%s %d %d %d %d %f %s %n" - EXTRAS="$EXTRAS check_nagios" + ac_cv_ps_cols=8 AC_MSG_RESULT([$ac_cv_ps_command]) dnl SunOS 4.1.3: @@ -675,7 +675,7 @@ then ac_cv_ps_varlist="[&procuid,&procppid,&procvsz,&procrss,procstat,&pos,procprog]" ac_cv_ps_command="$PATH_TO_PS -laxnwww" ac_cv_ps_format="%*s %d %*s %d %*s %*s %*s %d %d %*s %s %*s %*s %n%s" - EXTRAS="$EXTRAS check_nagios" + ac_cv_ps_cols=8 AC_MSG_RESULT([$ac_cv_ps_command]) dnl Debian Linux / procps v1.2.9: @@ -688,7 +688,7 @@ then ac_cv_ps_varlist="[&procuid,&procppid,procstat,&procvsz,&procrss,&pos,procprog]" ac_cv_ps_command="$PATH_TO_PS laxnwww" ac_cv_ps_format="%*s %d %*s %d %*s %*s %d %d %*s %s %*s %*s %n%s" - EXTRAS="$EXTRAS check_nagios" + ac_cv_ps_cols=8 AC_MSG_RESULT([$ac_cv_ps_command]) dnl OpenBSD (needs to come early because -exo appears to work, but does not give all procs) @@ -698,17 +698,17 @@ then ac_cv_ps_varlist="[procstat,&procuid,&procppid,&procvsz,&procrss,&procpcpu,procprog,&pos]" ac_cv_ps_command="$PATH_TO_PS -axo 'stat uid ppid vsz rss pcpu comm args'" ac_cv_ps_format="%s %d %d %d %d %f %s %n" - EXTRAS="$EXTRAS check_nagios" + ac_cv_ps_cols=8 AC_MSG_RESULT([$ac_cv_ps_command]) -dnl AIX 4.3.3 - needs verification. This works for Tru64 - needs %*[ +] in PS_FORMAT +dnl Tru64 - needs %*[ +] in PS_FORMAT elif ps -ao 'stat comm vsz rss user uid ppid args' 2>/dev/null | \ egrep -i ["^ *S[TAUES]* +[UCOMDNA]+ +[VSIZE]+ +R[S]+ +U[SER]+ +U[ID]+ +P[PID]+ +[RGSCOMDNA]+"] >/dev/null then ac_cv_ps_varlist="[procstat,&procuid,&procppid,&procvsz,&procrss,&procpcpu,procprog,&pos]" ac_cv_ps_command="$PATH_TO_PS -ao 'stat uid ppid vsz rss pcpu comm args'" ac_cv_ps_format=["%s%*[ +] %d %d %d %d %f %s %n"] - EXTRAS="$EXTRAS check_nagios" + ac_cv_ps_cols=8 AC_MSG_RESULT([$ac_cv_ps_command]) elif ps -eo 's comm vsz rss user uid ppid args' 2>/dev/null | \ @@ -717,16 +717,26 @@ then ac_cv_ps_varlist="[procstat,&procuid,&procppid,&procvsz,&procrss,&procpcpu,procprog,&pos]" ac_cv_ps_command="$PATH_TO_PS -eo 's uid ppid vsz rss pcpu comm args'" ac_cv_ps_format="%s %d %d %d %d %f %s %n" - EXTRAS="$EXTRAS check_nagios" + ac_cv_ps_cols=8 AC_MSG_RESULT([$ac_cv_ps_command]) +dnl AIX 4.3.3 and 5.1 do not have an rss field +elif ps -eo 'stat uid ppid vsz pcpu comm args' 2>/dev/null | \ + egrep -i ["^ *S[TAUES]* +UID +PPID +VSZ +%CPU +COMMAND +COMMAND"] >/dev/null +then + ac_cv_ps_varlist="[procstat,&procuid,&procppid,&procvsz,&procpcpu,procprog,&pos]" + ac_cv_ps_command="$PATH_TO_PS -eo 'stat uid ppid vsz pcpu comm args'" + ac_cv_ps_format="%s %d %d %d %f %s %n" + ac_cv_ps_cols=7 + AC_MSG_RESULT([$ac_cv_ps_command - with no RSS]) + elif ps -Ao 's comm vsz rss uid user ppid args' 2>/dev/null | \ egrep -i ["^S[TAUES]* +C[OMDNA]+ +V[SIZE]+ +RSS +UID +USER +PPID +[RGSCOMDNA]+"] >/dev/null then ac_cv_ps_varlist="[procstat,&procuid,&procppid,&procvsz,&procrss,&procpcpu,procprog,&pos]" ac_cv_ps_command="$PATH_TO_PS -Ao 's uid ppid vsz rss pcpu comm args'" ac_cv_ps_format="%s %d %d %d %d %f %s %n" - EXTRAS="$EXTRAS check_nagios" + ac_cv_ps_cols=8 AC_MSG_RESULT([$ac_cv_ps_command]) elif ps -Ao 'status comm vsz rss uid user ppid args' 2>/dev/null | \ @@ -735,7 +745,7 @@ then ac_cv_ps_varlist="[procstat,&procuid,&procppid,&procvsz,&procrss,&procpcpu,procprog,&pos]" ac_cv_ps_command="$PATH_TO_PS -Ao 'status uid ppid vsz rss pcpu comm args'" ac_cv_ps_format="%s %d %d %d %d %f %s %n" - EXTRAS="$EXTRAS check_nagios" + ac_cv_ps_cols=8 AC_MSG_RESULT([$ac_cv_ps_command]) elif ps -Ao 'state comm vsz rss uid user ppid args' 2>/dev/null | \ @@ -744,7 +754,7 @@ then ac_cv_ps_varlist="[procstat,&procuid,&procppid,&procvsz,&procrss,&procpcpu,procprog,&pos]" ac_cv_ps_command="$PATH_TO_PS -Ao 'state uid ppid vsz rss pcpu comm args'" ac_cv_ps_format="%s %d %d %d %d %f %s %n" - EXTRAS="$EXTRAS check_nagios" + ac_cv_ps_cols=8 AC_MSG_RESULT([$ac_cv_ps_command]) dnl wonder who takes state instead of stat @@ -754,7 +764,7 @@ then ac_cv_ps_varlist="[procstat,&procuid,&procppid,&procvsz,&procrss,&procpcpu,procprog,&pos]" ac_cv_ps_command="$PATH_TO_PS -ao 'state uid ppid vsz rss pcpu command args'" ac_cv_ps_format="%s %d %d %d %d %f %s %n" - EXTRAS="$EXTRAS check_nagios" + ac_cv_ps_cols=7 AC_MSG_RESULT([$ac_cv_ps_command]) dnl IRIX 53 @@ -764,6 +774,7 @@ then ac_cv_ps_varlist="[procstat,&procuid,&procppid,&procvsz,&procrss,&pos,procprog]" ac_cv_ps_command="$PATH_TO_PS -el" ac_cv_ps_format="%*s %s %d %*s %d %*s %*s %*s %*s %d %d %*s %*s %*s %n%s" + ac_cv_ps_cols=7 AC_MSG_RESULT([$ac_cv_ps_command]) dnl IRIX 63 @@ -773,6 +784,7 @@ then ac_cv_ps_varlist="[procstat,&procuid,&procppid,&pos,procprog]" ac_cv_ps_command="$PATH_TO_PS -el" ac_cv_ps_format="%*s %s %d %*s %d %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %n%s" + ac_cv_ps_cols=5 AC_MSG_RESULT([$ac_cv_ps_command]) dnl AIX 4.1: @@ -784,6 +796,7 @@ then ac_cv_ps_varlist="[procstat,&procuid,&procppid,&pos,procprog]" ac_cv_ps_command="$PATH_TO_PS -el" ac_cv_ps_format="%*s %s %d %*s %d %*s %*s %*s %*s %*s %*s %*s %*s %n%s" + ac_cv_ps_cols=7 AC_MSG_RESULT([$ac_cv_ps_command]) dnl AIX? @@ -793,6 +806,7 @@ then ac_cv_ps_varlist="[&procuid,&procppid,&procvsz,&procrss,procstat,&pos,procprog]" ac_cv_ps_command="$PATH_TO_PS glaxen" ac_cv_ps_format="%*s %d %*s %d %*s %*s %d %d %*s %s %*s %*s %n%s" + ac_cv_ps_cols=7 AC_MSG_RESULT([$ac_cv_ps_command]) dnl MacOSX / Darwin @@ -806,7 +820,7 @@ then ac_cv_ps_command="$PATH_TO_PS wwaxo 'state vsz rss uid ppid pcpu ucomm command'" ac_cv_ps_varlist="[procstat,&procvsz,&procrss,&procuid,&procppid,&procpcpu,procprog,&pos]" ac_cv_ps_format="%s %d %d %d %d %f %s %n" - EXTRAS="$EXTRAS check_nagios" + ac_cv_ps_cols=7 AC_MSG_RESULT([$ac_cv_ps_command]) dnl UnixWare @@ -816,24 +830,24 @@ then ac_cv_ps_varlist="[procstat,&procuid,&procppid,&pos,procprog]" ac_cv_ps_command="$PATH_TO_PS -Al" ac_cv_ps_format="%*s %s %d %*s %d %*s %*s %*s %*s %*s %*s %*s %*s %*s %n%s" - #if ps -Ao 'vsz comm' 2>/dev/null | \ - # egrep -i ["^ *VSZ +COMMAND"] >/dev/null - #then - # ac_cv_vsz_command="$PATH_TO_PS -Ao 'vsz comm'" - # ac_cv_vsz_format="%*s %d" - #fi + ac_cv_ps_cols=7 AC_MSG_RESULT([$ac_cv_ps_command]) else - AC_MSG_WARN([unable to find usable ps syntax]) + AC_MSG_WARN([unable to find usable ps syntax - check_procs and check_nagios will not be compiled]) fi -AC_DEFINE_UNQUOTED(PS_VARLIST,$ac_cv_ps_varlist, - [Variable list for sscanf of 'ps' output]) -AC_DEFINE_UNQUOTED(PS_COMMAND,"$ac_cv_ps_command", - [Verbatim command to execute for ps in check_procs]) -AC_DEFINE_UNQUOTED(PS_FORMAT,"$ac_cv_ps_format", - [Format string for scanning ps output in check_procs]) +if test -n $ac_cv_ps_varlist ; then + AC_DEFINE_UNQUOTED(PS_VARLIST,$ac_cv_ps_varlist, + [Variable list for sscanf of 'ps' output]) + AC_DEFINE_UNQUOTED(PS_COMMAND,"$ac_cv_ps_command", + [Verbatim command to execute for ps in check_procs]) + AC_DEFINE_UNQUOTED(PS_FORMAT,"$ac_cv_ps_format", + [Format string for scanning ps output in check_procs]) + AC_DEFINE_UNQUOTED(PS_COLS,$ac_cv_ps_cols, + [Number of columns in ps command]) + EXTRAS="$EXTRAS check_procs check_nagios" +fi dnl jm_AFS jm_LIST_MOUNTED_FILESYSTEMS([list_mounted_fs=yes], [list_mounted_fs=no]) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 683cd51b..ac421e5f 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -12,7 +12,7 @@ LIBS = @LIBINTL@ @LIBS@ libexec_PROGRAMS = check_disk check_dummy check_http check_load \ check_mrtg check_mrtgtraf check_nwstat check_overcr check_ping \ - check_procs check_real check_smtp check_ssh check_tcp check_time \ + check_real check_smtp check_ssh check_tcp check_time \ check_udp check_ups check_users negate urlize \ @EXTRAS@ @@ -21,7 +21,7 @@ check_tcp_programs = check_ftp check_imap check_nntp check_pop check_udp2 \ 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_nagios check_by_ssh check_dns check_nt check_ide-smart check_procs 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 diff --git a/plugins/check_procs.c b/plugins/check_procs.c index e0ee524c..a868fcf9 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c @@ -89,6 +89,7 @@ main (int argc, char **argv) char procstat[8]; char procprog[MAX_INPUT_BUFFER]; char *procargs; + char *temp_string; const char *zombie = "Z"; @@ -97,6 +98,7 @@ main (int argc, char **argv) int procs = 0; /* counter for number of processes meeting filter criteria */ int pos; /* number of spaces before 'args' in `ps` output */ int cols; /* number of columns in ps output */ + int expected_cols = PS_COLS - 1; int warn = 0; /* number of processes in warn state */ int crit = 0; /* number of processes in crit state */ int i = 0; @@ -135,18 +137,35 @@ main (int argc, char **argv) cols = sscanf (input_buffer, PS_FORMAT, PS_VARLIST); /* Zombie processes do not give a procprog command */ - if ( cols == 6 && strstr(procstat, zombie) ) { - cols = 7; + if ( cols == (expected_cols - 1) && strstr(procstat, zombie) ) { + cols = expected_cols; /* Set some value for procargs for the strip command further below Seen to be a problem on some Solaris 7 and 8 systems */ input_buffer[pos] = '\n'; input_buffer[pos+1] = 0x0; } - if ( cols >= 7 ) { + if ( cols >= expected_cols ) { resultsum = 0; asprintf (&procargs, "%s", input_buffer + pos); strip (procargs); + /* Some ps return full pathname for command. This removes path */ + temp_string = strtok ((char *)procprog, "/"); + while (temp_string) { + strcpy(procprog, temp_string); + temp_string = strtok (NULL, "/"); + } + + if (verbose >= 3) + printf ("%d %d %d %d %d %.2f %s %s %s\n", + procs, procuid, procvsz, procrss, + procppid, procpcpu, procstat, procprog, procargs); + + /* Ignore self */ + if (strcmp (procprog, progname) == 0) { + continue; + } + if ((options & STAT) && (strstr (statopts, procstat))) resultsum |= STAT; if ((options & ARGS) && procargs && (strstr (procargs, args) != NULL)) @@ -164,15 +183,6 @@ main (int argc, char **argv) if ((options & PCPU) && (procpcpu >= pcpu)) resultsum |= PCPU; - if (verbose >= 3) - printf ("%d %d %d %d %d %.2f %s %s %s\n", - procs, procuid, procvsz, procrss, - procppid, procpcpu, procstat, procprog, procargs); - - /* Ignore self */ - if (strcmp (procprog, progname) == 0) - continue; - found++; /* Next line if filters not matched */ @@ -192,12 +202,11 @@ main (int argc, char **argv) if (metric != METRIC_PROCS) { if (i == STATE_WARNING) { warn++; - asprintf (&fails, "%s%s%s", fails, (fails == "" ? "" : ", "), procprog); } if (i == STATE_CRITICAL) { crit++; - asprintf (&fails, "%s%s%s", fails, (fails == "" ? "" : ", "), procprog); } + asprintf (&fails, "%s%s%s", fails, (strcmp(fails,"") ? ", " : ""), procprog); result = max_state (result, i); } } @@ -237,33 +246,25 @@ main (int argc, char **argv) } if ( result == STATE_OK ) { - printf (_("%s OK: %d process%s"), - metric_name, procs, ( procs != 1 ? "es" : "") ); + printf ("%s %s: ", metric_name, _("OK")); } else if (result == STATE_WARNING) { - if ( metric == METRIC_PROCS ) { - printf (_("PROCS WARNING: %d process%s"), procs, - ( procs != 1 ? "es" : "")); - } else { - printf (_("%s WARNING: %d warn out of %d process%s"), - metric_name, warn, procs, - ( procs != 1 ? "es" : "")); + printf ("%s %s: ", metric_name, _("WARNING")); + if ( metric != METRIC_PROCS ) { + printf (_("%d warn out of "), warn); } } else if (result == STATE_CRITICAL) { - if (metric == METRIC_PROCS) { - printf (_("PROCS CRITICAL: %d process%s"), procs, - ( procs != 1 ? "es" : "")); - } else { - printf (_("%s CRITICAL: %d crit, %d warn out of %d process%s"), - metric_name, crit, warn, procs, - ( procs != 1 ? "es" : "")); + printf ("%s %s: ", metric_name, _("CRITICAL")); + if (metric != METRIC_PROCS) { + printf (_("%d crit, %d warn out of "), crit, warn); } } + printf (ngettext ("%d process", "%d processes", procs), procs); if (strcmp(fmt,"") != 0) { printf (_(" with %s"), fmt); } - if ( verbose >= 1 && fails != "" ) + if ( verbose >= 1 && strcmp(fails,"") ) printf (" [%s]", fails); printf ("\n"); @@ -631,7 +632,7 @@ Optional Filters:\n\ -a, --argument-array=STRING\n\ Only scan for processes with args that contain STRING.\n\ -C, --command=COMMAND\n\ - Only scan for exact matches to the named COMMAND.\n")); + Only scan for exact matches of COMMAND (without path).\n")); printf(_("\n\ RANGEs are specified 'min:max' or 'min:' or ':max' (or 'max'). If\n\ -- cgit v1.2.3-74-g34f1