summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e47b74e)
raw | patch | inline | side by side (parent: e47b74e)
author | Ton Voon <tonvoon@users.sourceforge.net> | |
Tue, 16 Sep 2003 14:14:53 +0000 (14:14 +0000) | ||
committer | Ton Voon <tonvoon@users.sourceforge.net> | |
Tue, 16 Sep 2003 14:14:53 +0000 (14:14 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@731 f882894a-f735-0410-b71e-b25c423dba1c
configure.in | patch | blob | history | |
plugins/Makefile.am | patch | blob | history | |
plugins/check_procs.c | patch | blob | history |
diff --git a/configure.in b/configure.in
index 37baafa8e741979d071c4806a8e8c403154669a3..09e8e3504227911c911f4832ef98633e04db630e 100644 (file)
--- a/configure.in
+++ b/configure.in
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
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
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
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:
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:
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)
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 | \
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 | \
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 | \
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
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
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
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:
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?
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
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
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 683cd51bd2ff0b337e96ad37f4df6ce8301b0754..ac421e5fa2897b85d14c60228de74102fe8ae7f7 100644 (file)
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
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@
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 e0ee524c0ec2de46bfb88e6f34fe7fdfa0d4e7fc..a868fcf9ef76b26d544dc5d9508dc23a4a9bcc2e 100644 (file)
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
char procstat[8];
char procprog[MAX_INPUT_BUFFER];
char *procargs;
+ char *temp_string;
const char *zombie = "Z";
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;
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))
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 */
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);
}
}
}
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");
-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\