1#!/bin/bash 2############################## install.sh ##################### 3# Version : 1.4 4# Date : Jan 13 2007 5# Author : Patrick Proy ( nagios at proy.org) 6# Help : http://www.manubulon.com/nagios/ 7# Licence : GPL - http://www.fsf.org/licenses/gpl.txt 8# TODO : 9# Contribs : 10################################################################# 11# 12# USAGE : ./install [<perl script name> | AUTO <dir> <tmp_dir> <perl_dir> [<install_location>] ] 13# USAGE : by default all scripts will be installed 14# 15# REQUIREMENTS : /bin/bash and sed 16# 17# This script will : 18# - Check perl binary (and asks for path) 19# - Ask for nagios plugin path and checks for file "utils.pm" in it (default /usr/local/nagios/libexec) 20# - Ask for temporary file location (default /tmp) 21# - Check Net::SNMP version 22# - Install plugins in the plugins directory and modify paths if necessary. 23 24############################ script list 25PLUGINS="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" 26############################ get script to install or install type 27 28if [ $# -gt 0 ] ; then INSTSCRIPT=$1 ; else INSTSCRIPT="all" ; fi 29 30if [ $INSTSCRIPT != "AUTO" ] ; then 31 ############################ Manual installation 32 echo 33 echo "###### Nagios snmp scripts installer ######" 34 echo 35 echo "Will install $INSTSCRIPT script(s)" 36 echo 37 38 ############################ default values 39 40 SRCDIR=$PWD 41 PERLHOME=`which perl 2>&1` 42 if [ $? -ne 0 ]; then PERLHOME="" ; fi 43 44 PLUGHOME=/usr/local/nagios/libexec 45 TMPDATA=/tmp 46 ############################ Checking Perl 47 48 echo -n "What is your perl location ? [$PERLHOME] " 49 read USERPERL 50 if [ "ZZ$USERPERL" != "ZZ" ]; then PERLHOME=$USERPERL ; fi 51 52 if [ "z$PERLHOME" == "z" ]; then 53 echo "Can't find perl binary... exiting" 54 echo "######### ERROR ########" 55 exit 1 56 fi 57 58 NETSNMP=`$PERLHOME -e 'if (eval "require Net::SNMP") { print "Yes" ;}'` 59 if [ $? -ne 0 ] ; then 60 echo "Error while checking Net::SNMP module" 61 echo "######### ERROR ########" 62 exit 1; 63 fi 64 65 if [ "zz$NETSNMP" != "zzYes" ]; then 66 echo "Module Net::SNMP not found!" 67 echo "Install it with CPAN or manually : http://www.manubulon.com/nagios/faq.html#FAQ2" 68 echo "######### ERROR ########" 69 exit 1; 70 fi 71 72 SNMPVER=`$PERLHOME -e 'require Net::SNMP;print Net::SNMP->VERSION'` 73 echo "Net::SNMP module version is $SNMPVER [OK]" 74 75 GETOPT=`$PERLHOME -e 'if (eval "require Getopt::Long") { print "Yes" ;}'` 76 if [ "zz$GETOPT" != "zzYes" ]; then 77 echo "Module Getopt::Long not found!" 78 echo "Install it with CPAN or manually" 79 echo "######### ERROR ########" 80 exit 1; 81 fi 82 echo "Module Getopt::Long found [OK]" 83 84 ############################ Check nagios plugin directory and utils.pm 85 86 echo 87 echo "What is your nagios plugin location ? " 88 echo -n "Note : file utils.pm must be present in it [$PLUGHOME] " 89 read USERPLUG 90 91 if [ "z$USERPLUG" != "z" ]; then PLUGHOME=$USERPLUG ; fi 92 if [ ! -d $PLUGHOME ] ; then 93 echo "Directory $PLUGHOME does not exist !" 94 echo "######### ERROR ########" 95 exit 1 96 fi 97 if [ ! -f $PLUGHOME/utils.pm ] ; then 98 echo "File $PLUGHOME/utils.pm does not exist !" 99 echo "Install it from nagios plugins" 100 echo "######### ERROR ########" 101 exit 1 102 fi 103 104 ############################ Asking for temp directory 105 106 echo 107 echo "Where do you want the plugins to put temporary data (only used by some plugins) ? " 108 echo -n "Nagios user must be able to write files in it [$TMPDATA] " 109 read USERTMP 110 111 if [ "z$USERTMP" != "z" ]; then TMPDATA=$USERTMP ; fi 112 113 if [ ! -d $TMPDATA ] ; then 114 echo "Directory $TMPDATA does not exist !" 115 echo "######### ERROR ########" 116 exit 1 117 fi 118 119 ############################ Looks OK, copying with changes if necessary 120 121 TRANS="" 122 # Change '#!/usr/bin/perl -w' 123 if [ $PERLHOME != "/usr/bin/perl" ] ; then 124 TRANS="-r -e s#/usr/bin/perl#$PERLHOME#" 125 fi 126 127 # Change 'use lib "/usr/local/nagios/libexec";' 128 if [ $PLUGHOME != "/usr/local/nagios/libexec" ] ; then 129 if [ "z$TRANS" == "z" ]; then TRANS="-r -e s#/usr/local/nagios/libexec#$PLUGHOME#" 130 else TRANS="$TRANS -e s#/usr/local/nagios/libexec#$PLUGHOME#";fi 131 fi 132 133 # Change 'my $o_base_dir="/tmp/tmp_Nagios_' 134 if [ $TMPDATA != "/tmp" ] ; then 135 if [ "z$TRANS" == "z" ]; then TRANS="-r -e s#/tmp/tmp_Nagios#$TMPDATA/tmp_Nagios#" 136 else TRANS="$TRANS -e s#/tmp/tmp_Nagios#$TMPDATA/tmp_Nagios#";fi 137 fi 138 139 ######################### script install 140 141 echo 142 echo "Will now install $INSTSCRIPT script(s) : " 143 echo "in directory : $PLUGHOME" 144 echo "perl : $PERLHOME" 145 echo "temp directory : $TMPDATA" 146 echo 147 echo -n "OK ? [Y/n]" 148 read INSTOK 149 150 if [ "$INSTOK" == "n" ]; then 151 echo "Aborting....." 152 echo "######### ERROR ########" 153 exit 1 154 fi 155 156 ERROR=0 157 158 if [ $INSTSCRIPT == "all" ] ; then 159 for i in $PLUGINS ; do 160 echo 161 if [ ! -f $i ] ; then 162 echo "Can't find source file $i : ##### ERROR #####" 163 else 164 echo -n "Installing $i : " 165 if [ "z$TRANS" == "z" ] ; then 166 cp $i $PLUGHOME/$i 2>&1 167 else 168 sed $TRANS $i > $PLUGHOME/$i 2>&1 169 fi 170 if [ $? -ne 0 ] ; then 171 echo "##### ERROR #####"; 172 rm -f $PLUGHOME/$i 173 ERROR=1 174 else 175 echo "OK" 176 chmod 755 $PLUGHOME/$i 2>&1 177 fi 178 fi 179 done 180 else 181 echo 182 if [ ! -f $INSTSCRIPT ] ; then 183 echo "Can't find source file $INSTSCRIPT : ##### ERROR #####" 184 else 185 echo -n "Installing $INSTSCRIPT : " 186 if [ "z$TRANS" == "z" ] ; then 187 cp $INSTSCRIPT > $PLUGHOME/$INSTSCRIPT 188 else 189 sed $TRANS $INSTSCRIPT > $PLUGHOME/$INSTSCRIPT 2>&1 190 fi 191 if [ $? -ne 0 ] ; then 192 echo "##### ERROR #####"; 193 rm -f $PLUGHOME/$INSTSCRIPT 194 ERROR=1 195 exit 1; 196 else 197 echo "OK" 198 chmod 755 $PLUGHOME/$INSTSCRIPT 2>&1 199 fi 200 fi 201 fi 202 203 echo 204 if [ $ERROR -eq 1 ] ; then 205 echo "Installation ended with errors. Check output above" 206 exit 1; 207 fi 208 209 echo "Installation completed OK" 210 echo "You can delete all the source files and directory" 211 echo "Remember to look for informtation at http://www.manubulon.com/nagios/" 212 exit 0; 213 214else 215####################### Silent install with parameters ############ 216# PARAM AUTO <dir> <tmp_dir> <perl_dir> [<install_location>] 217 if [ $# -ne 4 ] && [ $# -ne 5 ] ; then exit 1; fi 218 219 SRCDIR=$PWD 220 PERLHOME=$4 221 PLUGHOME=$2 222 TMPDATA=$3 223 INSTALLDIR=$5 224 225 TRANS="" 226 # Change '#!/usr/bin/perl -w' 227 if [ $PERLHOME != "/usr/bin/perl" ] ; then 228 TRANS="-r -e s#/usr/bin/perl#$PERLHOME#" 229 fi 230 231 # Change 'use lib "/usr/local/nagios/libexec";' 232 if [ $PLUGHOME != "/usr/local/nagios/libexec" ] ; then 233 if [ "z$TRANS" == "z" ]; then TRANS="-r -e s#/usr/local/nagios/libexec#$PLUGHOME#" 234 else TRANS="$TRANS -e s#/usr/local/nagios/libexec#$PLUGHOME#";fi 235 fi 236 237 # Change 'my $o_base_dir="/tmp/tmp_Nagios_' 238 if [ $TMPDATA != "/tmp" ] ; then 239 if [ "z$TRANS" == "z" ]; then TRANS="-r -e s#/tmp/tmp_Nagios#$TMPDATA/tmp_Nagios#" 240 else TRANS="$TRANS -e s#/tmp/tmp_Nagios#$TMPDATA/tmp_Nagios#";fi 241 fi 242 243 ######################### script install 244 ERROR=0 245 if [ "z$INSTALLDIR" != "z" ] ; then 246 PLUGHOME=$INSTALLDIR 247 fi 248 for i in $PLUGINS ; do 249 if [ ! -f $i ] ; then 250 ERROR=1 251 else 252 if [ "z$TRANS" == "z" ] ; then 253 cp $i $PLUGHOME/$i 2>&1 254 else 255 sed $TRANS $i > $PLUGHOME/$i 2>&1 256 fi 257 if [ $? -ne 0 ] ; then 258 rm -f $PLUGHOME/$i 259 ERROR=1 260 else 261 chmod 755 $PLUGHOME/$i 2>&1 262 fi 263 fi 264 done 265 if [ $ERROR -eq 1 ] ; then 266 exit 1; 267 fi 268 exit 0; 269fi 270 271