Skip to content

Commit

Permalink
Replace "plugins-scripts/subst.in" foo
Browse files Browse the repository at this point in the history
Remove the buggy and complex awk(1) magic in "plugins-scripts/subst.in"
in favor of simple sed(1) substitutions.

The plugins in the "plugins-scripts" directory now always use the PATH
specified via "./configure --trusted-path", or the default PATH
hard-coded in "configure.ac".

Fixes #1242.
  • Loading branch information
weiss committed Feb 28, 2014
1 parent e260efb commit c08d6a4
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 103 deletions.
2 changes: 2 additions & 0 deletions NEWS
Expand Up @@ -25,6 +25,8 @@ This file documents the major additions and syntax changes between releases.
renamed MP_STATE_DIRECTORY. The old variable will continue to work in v1.6.x
check_swap used to allow returning OK on a system without swap when only percent thresholds
were used. This is no longer the case and one must now use -n/--no-swap=<state>
The Perl and Shell plugins now use the PATH specified via ./configure's --trusted-path
option, or "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" by default

1.5 2nd October 2013
ENHANCEMENTS
Expand Down
5 changes: 3 additions & 2 deletions configure.ac
Expand Up @@ -10,6 +10,7 @@ AM_MAINTAINER_MODE([enable])
AC_CONFIG_HEADERS([config.h])
AC_CANONICAL_HOST

DEFAULT_PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
RELEASE=1
AC_SUBST(RELEASE)

Expand Down Expand Up @@ -75,7 +76,8 @@ AC_DEFINE_UNQUOTED(CGIURL,"$CGIURL",[URL of CGI programs])
AC_ARG_WITH(trusted_path,
ACX_HELP_STRING([--with-trusted-path=PATH],
[sets trusted path for executables called by scripts]),
with_trusted_path=$withval)
with_trusted_path=$withval,
with_trusted_path=$DEFAULT_PATH)
AC_SUBST(with_trusted_path)

EXTRAS=
Expand Down Expand Up @@ -1781,7 +1783,6 @@ AC_OUTPUT(
lib/tests/Makefile
plugins-root/Makefile
plugins-scripts/Makefile
plugins-scripts/subst
plugins-scripts/utils.pm
plugins-scripts/utils.sh
perlmods/Makefile
Expand Down
9 changes: 7 additions & 2 deletions plugins-scripts/Makefile.am
Expand Up @@ -23,6 +23,11 @@ EXTRA_DIST=check_breeze.pl check_disk_smb.pl check_flexlm.pl check_ircd.pl \
check_ifstatus.pl check_ifoperstatus.pl check_wave.pl check_mailq.pl check_file_age.pl \
utils.sh.in utils.pm.in t

EDIT = sed \
-e 's|[@]NP_VERSION[@]|$(NP_VERSION)|g' \
-e 's|[@]TRUSTED_PATH[@]|$(with_trusted_path)|g' \
-e 's|[@]PERL[@]|$(PERL)|g'

TESTS_ENVIRONMENT=perl -I $(top_builddir) -I $(top_srcdir)

TESTS = @SCRIPT_TEST@
Expand All @@ -38,11 +43,11 @@ test-debug:
CLEANFILES=$(libexec_SCRIPTS)

.pl :
NP_VERSION=$(NP_VERSION) $(AWK) -f ./subst $< > $@
$(EDIT) $< > $@
chmod +x $@

.sh :
NP_VERSION=$(NP_VERSION) $(AWK) -f ./subst $< > $@
$(EDIT) $< > $@
chmod +x $@

clean-local:
Expand Down
4 changes: 2 additions & 2 deletions plugins-scripts/check_breeze.pl
@@ -1,4 +1,4 @@
#!/usr/bin/perl -wT
#!@PERL@ -wT


use strict;
Expand All @@ -13,7 +13,7 @@
sub print_help ();
sub print_usage ();

$ENV{'PATH'}='@trusted_path@';
$ENV{'PATH'}='@TRUSTED_PATH@';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';

Expand Down
4 changes: 2 additions & 2 deletions plugins-scripts/check_disk_smb.pl
@@ -1,4 +1,4 @@
#!/usr/bin/perl -w
#!@PERL@ -w
#
#
# check_disk.pl <host> <share> <user> <pass> [warn] [critical] [port]
Expand Down Expand Up @@ -33,7 +33,7 @@

$PROGNAME = "check_disk_smb";

$ENV{'PATH'}='@trusted_path@';
$ENV{'PATH'}='@TRUSTED_PATH@';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';

Expand Down
4 changes: 2 additions & 2 deletions plugins-scripts/check_file_age.pl
@@ -1,4 +1,4 @@
#!/bin/perl -w
#!@PERL@ -w

# check_file_age.pl Copyright (C) 2003 Steven Grimm <koreth-nagios@midwinter.com>
#
Expand Down Expand Up @@ -36,7 +36,7 @@

$PROGNAME="check_file_age";

$ENV{'PATH'}='@trusted_path@';
$ENV{'PATH'}='@TRUSTED_PATH@';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';

Expand Down
4 changes: 2 additions & 2 deletions plugins-scripts/check_flexlm.pl
@@ -1,4 +1,4 @@
#!/usr/bin/perl -w
#!@PERL@ -w
#
# usage:
# check_flexlm.pl license_file
Expand Down Expand Up @@ -44,7 +44,7 @@
sub print_help ();
sub print_usage ();

$ENV{'PATH'}='@trusted_path@';
$ENV{'PATH'}='@TRUSTED_PATH@';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';

Expand Down
4 changes: 2 additions & 2 deletions plugins-scripts/check_ifoperstatus.pl
@@ -1,4 +1,4 @@
#!/usr/local/bin/perl -w
#!@PERL@ -w
#
# check_ifoperstatus.pl - monitoring plugin
#
Expand Down Expand Up @@ -49,7 +49,7 @@
sub print_usage ();
sub process_arguments ();

$ENV{'PATH'}='@trusted_path@';
$ENV{'PATH'}='@TRUSTED_PATH@';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';

Expand Down
4 changes: 2 additions & 2 deletions plugins-scripts/check_ifstatus.pl
@@ -1,4 +1,4 @@
#!/usr/local/bin/perl -w
#!@PERL@ -w
#
# check_ifstatus.pl - monitoring plugin
#
Expand Down Expand Up @@ -47,7 +47,7 @@
sub print_usage ();
sub process_arguments ();

$ENV{'PATH'}='@trusted_path@';
$ENV{'PATH'}='@TRUSTED_PATH@';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';

Expand Down
4 changes: 2 additions & 2 deletions plugins-scripts/check_ircd.pl
@@ -1,4 +1,4 @@
#!/usr/bin/perl -wT
#!@PERL@ -wT

# -----------------------------------------------------------------------------
# File Name: check_ircd.pl
Expand Down Expand Up @@ -62,7 +62,7 @@

# -------------------------------------------------------------[ Enviroment ]--

$ENV{'PATH'}='@trusted_path@';
$ENV{'PATH'}='@TRUSTED_PATH@';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';

Expand Down
28 changes: 11 additions & 17 deletions plugins-scripts/check_log.sh
Expand Up @@ -58,18 +58,12 @@
# Paths to commands used in this script. These
# may have to be modified to match your system setup.

GREP="/bin/egrep"
DIFF="/bin/diff"
TAIL="/bin/tail"
CAT="/bin/cat"
RM="/bin/rm"
CHMOD="/bin/chmod"
TOUCH="/bin/touch"

PROGNAME=`/bin/basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION="@NP_VERSION@"
PATH="@trusted_path@"
PATH="@TRUSTED_PATH@"

export PATH

. $PROGPATH/utils.sh

Expand Down Expand Up @@ -177,7 +171,7 @@ fi
# the old diff file and exit

if [ ! -e $oldlog ]; then
$CAT $logfile > $oldlog
cat $logfile > $oldlog
echo "Log check data initialized..."
exit $STATE_OK
fi
Expand All @@ -191,20 +185,20 @@ if [ -x /bin/mktemp ]; then
else
tempdiff=`/bin/date '+%H%M%S'`
tempdiff="/tmp/check_log.${tempdiff}"
$TOUCH $tempdiff
$CHMOD 600 $tempdiff
touch $tempdiff
chmod 600 $tempdiff
fi

$DIFF $logfile $oldlog | $GREP -v "^>" > $tempdiff
diff $logfile $oldlog | grep -v "^>" > $tempdiff

# Count the number of matching log entries we have
count=`$GREP -c "$query" $tempdiff`
count=`grep -c "$query" $tempdiff`

# Get the last matching entry in the diff file
lastentry=`$GREP "$query" $tempdiff | $TAIL -1`
lastentry=`grep "$query" $tempdiff | tail -1`

$RM -f $tempdiff
$CAT $logfile > $oldlog
rm -f $tempdiff
cat $logfile > $oldlog

if [ "$count" = "0" ]; then # no matches, exit with no error
echo "Log check ok - 0 pattern matches found"
Expand Down
4 changes: 2 additions & 2 deletions plugins-scripts/check_mailq.pl
@@ -1,4 +1,4 @@
#!/usr/local/bin/perl -w
#!@PERL@ -w

# check_mailq - check to see how many messages are in the smtp queue awating
# transmittal.
Expand Down Expand Up @@ -40,7 +40,7 @@
sub print_usage ();
sub process_arguments ();

$ENV{'PATH'}='@trusted_path@';
$ENV{'PATH'}='@TRUSTED_PATH@';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';
$PROGNAME = "check_mailq";
Expand Down
4 changes: 2 additions & 2 deletions plugins-scripts/check_mssql.pl
@@ -1,4 +1,4 @@
#!/usr/bin/perl -w
#!@PERL@ -w

#
# Copyright 2003 Roy Sigurd Karlsbakk
Expand Down Expand Up @@ -35,7 +35,7 @@

my $PROGNAME = "check_mssql";

$ENV{'PATH'}='@trusted_path@';
$ENV{'PATH'}='@TRUSTED_PATH@';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';

Expand Down
4 changes: 2 additions & 2 deletions plugins-scripts/check_netdns.pl
@@ -1,4 +1,4 @@
#!/usr/bin/perl -w
#!@PERL@ -w

# Perl version of check_dns plugin which calls DNS directly instead of
# relying on nslookup (which has bugs)
Expand Down Expand Up @@ -33,7 +33,7 @@

my $PROGNAME = "check_netdns";

$ENV{'PATH'}='@trusted_path@';
$ENV{'PATH'}='@TRUSTED_PATH@';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';

Expand Down
4 changes: 2 additions & 2 deletions plugins-scripts/check_ntp.pl
@@ -1,4 +1,4 @@
#!/usr/bin/perl -w
#!@PERL@ -w
#
# (c)1999 Ian Cass, Knowledge Matters Ltd.
# Read the GNU copyright stuff for all the legalese
Expand Down Expand Up @@ -69,7 +69,7 @@
sub print_help ();
sub print_usage ();

$ENV{'PATH'}='@trusted_path@';
$ENV{'PATH'}='@TRUSTED_PATH@';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';

Expand Down
2 changes: 1 addition & 1 deletion plugins-scripts/check_oracle.sh
Expand Up @@ -9,7 +9,7 @@
PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION="@NP_VERSION@"
PATH="@trusted_path@"
PATH="@TRUSTED_PATH@"

. $PROGPATH/utils.sh

Expand Down
4 changes: 2 additions & 2 deletions plugins-scripts/check_rpc.pl
@@ -1,4 +1,4 @@
#!/usr/local/bin/perl -w
#!@PERL@ -w
#
# check_rpc plugin for monitoring
#
Expand Down Expand Up @@ -37,7 +37,7 @@
sub print_usage ();
sub in ($$);

$ENV{'PATH'}='@trusted_path@';
$ENV{'PATH'}='@TRUSTED_PATH@';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';
$ENV{'LC_ALL'}='C';
Expand Down
5 changes: 3 additions & 2 deletions plugins-scripts/check_sensors.sh
Expand Up @@ -3,8 +3,9 @@
PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION="@NP_VERSION@"
TRUSTED_PATH="@trusted_path@"
PATH=${TRUSTED_PATH:-"/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"}
PATH="@TRUSTED_PATH@"

export PATH

. $PROGPATH/utils.sh

Expand Down
4 changes: 2 additions & 2 deletions plugins-scripts/check_wave.pl
@@ -1,4 +1,4 @@
#!/usr/bin/perl -wT
#!@PERL@ -wT
#


Expand All @@ -16,7 +16,7 @@
sub print_help ();
sub print_usage ();

$ENV{'PATH'}='@trusted_path@';
$ENV{'PATH'}='@TRUSTED_PATH@';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';

Expand Down
53 changes: 0 additions & 53 deletions plugins-scripts/subst.in

This file was deleted.

0 comments on commit c08d6a4

Please sign in to comment.