nagios-snmp-plugins/plugins/install.sh

252 lines
7.1 KiB
Bash
Raw Normal View History

2013-11-26 20:27:10 +00:00
#!/bin/bash
2013-11-26 20:27:21 +00:00
############################## install.sh #####################
# Version : 1.4
# Date : Jan 13 2007
2013-11-26 20:27:10 +00:00
# Author : Patrick Proy ( nagios at proy.org)
# Help : http://www.manubulon.com/nagios/
# Licence : GPL - http://www.fsf.org/licenses/gpl.txt
# TODO :
# Contribs :
#################################################################
#
2013-11-26 20:27:21 +00:00
# USAGE : ./install [<perl script name> | AUTO <dir> <tmp_dir> <perl_dir> [<install_location>] ]
2013-11-26 20:27:10 +00:00
# USAGE : by default all scripts will be installed
#
2016-12-04 10:31:25 +00:00
# REQUIREMENTS : /bin/bash and sed
2013-11-26 20:27:10 +00:00
#
2016-12-04 10:31:25 +00:00
# This script will:
2013-11-26 20:27:10 +00:00
# - Check perl binary (and asks for path)
2016-12-04 10:31:25 +00:00
# - Ask for monitoring plugin path (default /usr/local/icinga/libexec)
2013-11-26 20:27:10 +00:00
# - Ask for temporary file location (default /tmp)
2016-12-04 10:31:25 +00:00
# - Check Net::SNMP version
2013-11-26 20:27:10 +00:00
# - Install plugins in the plugins directory and modify paths if necessary.
2013-11-26 20:27:21 +00:00
############################ script list
2013-11-26 20:27:10 +00:00
PLUGINS="check_snmp_boostedge.pl check_snmp_css.pl check_snmp_linkproof_nhr.pl check_snmp_nsbox.pl check_snmp_vrrp.pl check_snmp_cpfw.pl check_snmp_env.pl check_snmp_load.pl check_snmp_process.pl check_snmp_win.pl check_snmp_css_main.pl check_snmp_int.pl check_snmp_mem.pl check_snmp_storage.pl"
2013-11-26 20:27:21 +00:00
############################ get script to install or install type
2013-11-26 20:27:10 +00:00
2013-11-26 20:27:21 +00:00
if [ $# -gt 0 ] ; then INSTSCRIPT=$1 ; else INSTSCRIPT="all" ; fi
2013-11-26 20:27:10 +00:00
2016-12-04 10:31:25 +00:00
if [ $INSTSCRIPT != "AUTO" ] ; then
2013-11-26 20:27:21 +00:00
############################ Manual installation
2016-12-04 10:31:25 +00:00
echo
echo "###### Manubulon snmp scripts installer ######"
echo
2013-11-26 20:27:21 +00:00
echo "Will install $INSTSCRIPT script(s)"
echo
2013-11-26 20:27:10 +00:00
2013-11-26 20:27:21 +00:00
############################ default values
SRCDIR=$PWD
PERLHOME=`which perl 2>&1`
if [ $? -ne 0 ]; then PERLHOME="" ; fi
2016-12-04 10:31:25 +00:00
PLUGHOME=/usr/local/icinga/libexec
2013-11-26 20:27:21 +00:00
TMPDATA=/tmp
############################ Checking Perl
echo -n "What is your perl location ? [$PERLHOME] "
read USERPERL
if [ "ZZ$USERPERL" != "ZZ" ]; then PERLHOME=$USERPERL ; fi
2016-12-04 10:31:25 +00:00
if [ "z$PERLHOME" == "z" ]; then
2013-11-26 20:27:21 +00:00
echo "Can't find perl binary... exiting"
echo "######### ERROR ########"
exit 1
fi
NETSNMP=`$PERLHOME -e 'if (eval "require Net::SNMP") { print "Yes" ;}'`
2016-12-04 10:31:25 +00:00
if [ $? -ne 0 ] ; then
2013-11-26 20:27:21 +00:00
echo "Error while checking Net::SNMP module"
echo "######### ERROR ########"
2016-12-04 10:31:25 +00:00
exit 1;
2013-11-26 20:27:21 +00:00
fi
if [ "zz$NETSNMP" != "zzYes" ]; then
echo "Module Net::SNMP not found!"
echo "Install it with CPAN or manually : http://www.manubulon.com/nagios/faq.html#FAQ2"
echo "######### ERROR ########"
2016-12-04 10:31:25 +00:00
exit 1;
2013-11-26 20:27:21 +00:00
fi
SNMPVER=`$PERLHOME -e 'require Net::SNMP;print Net::SNMP->VERSION'`
echo "Net::SNMP module version is $SNMPVER [OK]"
GETOPT=`$PERLHOME -e 'if (eval "require Getopt::Long") { print "Yes" ;}'`
if [ "zz$GETOPT" != "zzYes" ]; then
echo "Module Getopt::Long not found!"
echo "Install it with CPAN or manually"
echo "######### ERROR ########"
2016-12-04 10:31:25 +00:00
exit 1;
2013-11-26 20:27:21 +00:00
fi
echo "Module Getopt::Long found [OK]"
2016-12-04 10:31:25 +00:00
############################ Check monitoring plugin directory
2013-11-26 20:27:10 +00:00
2013-11-26 20:27:21 +00:00
echo
2016-12-04 10:31:25 +00:00
echo "What is your monitoring plugin location ? "
2013-11-26 20:27:21 +00:00
read USERPLUG
if [ "z$USERPLUG" != "z" ]; then PLUGHOME=$USERPLUG ; fi
2016-12-04 10:31:25 +00:00
if [ ! -d $PLUGHOME ] ; then
2013-11-26 20:27:21 +00:00
echo "Directory $PLUGHOME does not exist !"
echo "######### ERROR ########"
exit 1
fi
############################ Asking for temp directory
2013-11-26 20:27:10 +00:00
2013-11-26 20:27:21 +00:00
echo
echo "Where do you want the plugins to put temporary data (only used by some plugins) ? "
2016-12-04 10:31:25 +00:00
echo -n "Icinga user must be able to write files in it [$TMPDATA] "
2013-11-26 20:27:21 +00:00
read USERTMP
2013-11-26 20:27:10 +00:00
2013-11-26 20:27:21 +00:00
if [ "z$USERTMP" != "z" ]; then TMPDATA=$USERTMP ; fi
2013-11-26 20:27:10 +00:00
2013-11-26 20:27:21 +00:00
if [ ! -d $TMPDATA ] ; then
echo "Directory $TMPDATA does not exist !"
echo "######### ERROR ########"
exit 1
fi
2013-11-26 20:27:10 +00:00
2013-11-26 20:27:21 +00:00
############################ Looks OK, copying with changes if necessary
2013-11-26 20:27:10 +00:00
2013-11-26 20:27:21 +00:00
TRANS=""
2016-12-04 10:31:25 +00:00
# Change '#!/usr/bin/perl -w'
2013-11-26 20:27:21 +00:00
if [ $PERLHOME != "/usr/bin/perl" ] ; then
TRANS="-r -e s#/usr/bin/perl#$PERLHOME#"
fi
2013-11-26 20:27:10 +00:00
2016-12-04 10:31:25 +00:00
# Change 'my $o_base_dir="/tmp/tmp_Icinga_'
2013-11-26 20:27:21 +00:00
if [ $TMPDATA != "/tmp" ] ; then
2016-12-04 10:31:25 +00:00
if [ "z$TRANS" == "z" ]; then TRANS="-r -e s#/tmp/tmp_Icinga#$TMPDATA/tmp_Icinga#"
else TRANS="$TRANS -e s#/tmp/tmp_Icinga#$TMPDATA/tmp_Icinga#";fi
2013-11-26 20:27:21 +00:00
fi
2013-11-26 20:27:10 +00:00
2013-11-26 20:27:21 +00:00
######################### script install
2013-11-26 20:27:10 +00:00
echo
2013-11-26 20:27:21 +00:00
echo "Will now install $INSTSCRIPT script(s) : "
echo "in directory : $PLUGHOME"
echo "perl : $PERLHOME"
echo "temp directory : $TMPDATA"
2016-12-04 10:31:25 +00:00
echo
2013-11-26 20:27:21 +00:00
echo -n "OK ? [Y/n]"
read INSTOK
2016-12-04 10:31:25 +00:00
if [ "$INSTOK" == "n" ]; then
2013-11-26 20:27:21 +00:00
echo "Aborting....."
echo "######### ERROR ########"
exit 1
fi
ERROR=0
2016-12-04 10:31:25 +00:00
if [ $INSTSCRIPT == "all" ] ; then
2013-11-26 20:27:21 +00:00
for i in $PLUGINS ; do
2016-12-04 10:31:25 +00:00
echo
if [ ! -f $i ] ; then
2013-11-26 20:27:21 +00:00
echo "Can't find source file $i : ##### ERROR #####"
else
echo -n "Installing $i : "
2016-12-04 10:31:25 +00:00
if [ "z$TRANS" == "z" ] ; then
2013-11-26 20:27:21 +00:00
cp $i $PLUGHOME/$i 2>&1
else
sed $TRANS $i > $PLUGHOME/$i 2>&1
fi
2016-12-04 10:31:25 +00:00
if [ $? -ne 0 ] ; then
echo "##### ERROR #####";
rm -f $PLUGHOME/$i
2013-11-26 20:27:21 +00:00
ERROR=1
2016-12-04 10:31:25 +00:00
else
echo "OK"
2013-11-26 20:27:21 +00:00
chmod 755 $PLUGHOME/$i 2>&1
fi
fi
done
else
echo
if [ ! -f $INSTSCRIPT ] ; then
echo "Can't find source file $INSTSCRIPT : ##### ERROR #####"
else
echo -n "Installing $INSTSCRIPT : "
2016-12-04 10:31:25 +00:00
if [ "z$TRANS" == "z" ] ; then
2013-11-26 20:27:21 +00:00
cp $INSTSCRIPT > $PLUGHOME/$INSTSCRIPT
else
sed $TRANS $INSTSCRIPT > $PLUGHOME/$INSTSCRIPT 2>&1
fi
if [ $? -ne 0 ] ; then
echo "##### ERROR #####";
rm -f $PLUGHOME/$INSTSCRIPT
ERROR=1
exit 1;
2016-12-04 10:31:25 +00:00
else
echo "OK"
2013-11-26 20:27:21 +00:00
chmod 755 $PLUGHOME/$INSTSCRIPT 2>&1
2016-12-04 10:31:25 +00:00
fi
2013-11-26 20:27:21 +00:00
fi
fi
2013-11-26 20:27:10 +00:00
2013-11-26 20:27:21 +00:00
echo
if [ $ERROR -eq 1 ] ; then
echo "Installation ended with errors. Check output above"
exit 1;
fi
echo "Installation completed OK"
echo "You can delete all the source files and directory"
2016-12-04 10:31:25 +00:00
echo "Remember to look for informtation at http://www.manubulon.com/nagios/"
2013-11-26 20:27:21 +00:00
exit 0;
2016-12-04 10:31:25 +00:00
2013-11-26 20:27:21 +00:00
else
####################### Silent install with parameters ############
# PARAM AUTO <dir> <tmp_dir> <perl_dir> [<install_location>]
if [ $# -ne 4 ] && [ $# -ne 5 ] ; then exit 1; fi
SRCDIR=$PWD
PERLHOME=$4
PLUGHOME=$2
TMPDATA=$3
INSTALLDIR=$5
2016-12-04 10:31:25 +00:00
2013-11-26 20:27:21 +00:00
TRANS=""
2016-12-04 10:31:25 +00:00
# Change '#!/usr/bin/perl -w'
2013-11-26 20:27:21 +00:00
if [ $PERLHOME != "/usr/bin/perl" ] ; then
TRANS="-r -e s#/usr/bin/perl#$PERLHOME#"
fi
2016-12-04 10:31:25 +00:00
# Change 'my $o_base_dir="/tmp/tmp_Icinga_'
2013-11-26 20:27:21 +00:00
if [ $TMPDATA != "/tmp" ] ; then
2016-12-04 10:31:25 +00:00
if [ "z$TRANS" == "z" ]; then TRANS="-r -e s#/tmp/tmp_Icinga#$TMPDATA/tmp_Icinga#"
else TRANS="$TRANS -e s#/tmp/tmp_Icinga#$TMPDATA/tmp_Icinga#";fi
2013-11-26 20:27:21 +00:00
fi
######################### script install
ERROR=0
if [ "z$INSTALLDIR" != "z" ] ; then
PLUGHOME=$INSTALLDIR
fi
for i in $PLUGINS ; do
2016-12-04 10:31:25 +00:00
if [ ! -f $i ] ; then
2013-11-26 20:27:21 +00:00
ERROR=1
else
2016-12-04 10:31:25 +00:00
if [ "z$TRANS" == "z" ] ; then
2013-11-26 20:27:21 +00:00
cp $i $PLUGHOME/$i 2>&1
else
sed $TRANS $i > $PLUGHOME/$i 2>&1
fi
2016-12-04 10:31:25 +00:00
if [ $? -ne 0 ] ; then
rm -f $PLUGHOME/$i
2013-11-26 20:27:21 +00:00
ERROR=1
2016-12-04 10:31:25 +00:00
else
2013-11-26 20:27:21 +00:00
chmod 755 $PLUGHOME/$i 2>&1
fi
fi
done
if [ $ERROR -eq 1 ] ; then
exit 1;
fi
exit 0;
2013-11-26 20:27:10 +00:00
fi