151 lines
4.7 KiB
Bash
Executable File
151 lines
4.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Startup script for Pandora SNMP Console
|
|
# Sancho Lerena, <slerena@gmail.com>
|
|
# Linux Version (generic)
|
|
# v1.3 BUILD 070802
|
|
|
|
# Compatible with NetSNMP 5.1 or higher
|
|
|
|
# Configurable path and filenames
|
|
PANDORA_HOME="/etc/pandora/pandora_server.conf"
|
|
PANDORA_PID_PATH="/var/run/pandora"
|
|
PANDORA_PID=$PANDORA_PID_PATH/pandora_snmp.pid
|
|
PANDORA_DAEMON=/usr/local/bin/pandora_snmpconsole
|
|
|
|
DAEMON_LOG="/var/log/pandora/pandora_snmptrap.log"
|
|
DAEMON_PID="$PANDORA_PID_PATH/pandora_snmptrapd.pid"
|
|
DAEMON_PATH=/usr/sbin/snmptrapd
|
|
|
|
# Dont touch this call unless you know are doing. For different versions of NetSNMP Trap daemon, it's possible you need to change some options
|
|
# Please refer NetSNMP documentation in that case.
|
|
DAEMON_OPTIONS="-t -On -n -a -Lf $DAEMON_LOG -p $DAEMON_PID -F %4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]%a[**]%N[**]%w[**]%W[**]%q[**]%v\n"
|
|
DAEMON="$DAEMON_PATH $DAEMON_OPTIONS"
|
|
|
|
if [ ! -d "$PANDORA_PID_PATH" ]
|
|
then
|
|
echo "Pandora FMS cannot write it's PID file in $PANDORA_PID_PATH. Please create that directory"
|
|
exit
|
|
fi
|
|
|
|
if [ ! -f "$DAEMON_PATH" ]
|
|
then
|
|
echo "NetSNMP snmptrapd not found at $DAEMON_PATH, please check setup and read manual"
|
|
exit
|
|
fi
|
|
|
|
case "$1" in
|
|
start)
|
|
if [ -f $DAEMON_PID ]
|
|
then
|
|
CHECK_PID=`cat $DAEMON_PID`
|
|
CHECK_PID_RESULT=`ps aux | grep -v grep | grep "$CHECK_PID" | grep "snmp" | wc -l`
|
|
if [ $CHECK_PID_RESULT == 1 ]
|
|
then
|
|
echo "NetSNMP Trap daemon is currently running on this machine with PID ($CHECK_PID). Aborting now..."
|
|
exit
|
|
fi
|
|
fi
|
|
|
|
SNMP_WARNING=`ps aux | grep "$DAEMON_PATH" | grep -v grep | wc -l`
|
|
if [ $SNMP_WARNING == 1 ]
|
|
then
|
|
echo "WARNING: Seems to be already running a SNMP trap daemon on this system not associated with Pandora FMS"
|
|
echo "Check manually if their output logfile is been used for Pandora FMS and it's format is correct"
|
|
fi
|
|
|
|
# Launch SNMP TRAP Daemon
|
|
$DAEMON
|
|
|
|
sleep 1
|
|
if [ ! -f $DAEMON_LOG ]
|
|
then
|
|
echo "Problem with NetSNMP Trap daemon (Logfile $DAEMON_LOG not found!). Aborting"
|
|
exit
|
|
fi
|
|
|
|
if [ -f $DAEMON_PID ]
|
|
then
|
|
CHECK_PID=`cat $DAEMON_PID`
|
|
CHECK_PID_RESULT=`ps aux | grep -v grep | grep "$CHECK_PID" | grep "snmp" | wc -l`
|
|
if [ $CHECK_PID_RESULT != 1 ]
|
|
then
|
|
echo "Problem starting NetSNMP Trap daemon on this machine (PID File not correct). Aborting now..."
|
|
exit
|
|
fi
|
|
else
|
|
echo "Problem starting NetSNMP Trap daemon on this machine (Cannot get PID File). Aborting now..."
|
|
exit
|
|
fi
|
|
|
|
RESULT="`cat $DAEMON_LOG | grep 'errno 13' 2> /dev/null`"
|
|
if [ -z "$RESULT" ]
|
|
then
|
|
echo "NetSNMP Trap daemon is now running with PID `cat $DAEMON_PID 2> /dev/null`"
|
|
else
|
|
echo "NetSNMP cannot open port (udp/162). Please execute as root user"
|
|
rm -f $DAEMON_PID 2> /dev/null
|
|
fi
|
|
|
|
if [ -f $PANDORA_PID ]
|
|
then
|
|
CHECK_PID=`cat $PANDORA_PID`
|
|
CHECK_PID_RESULT=`ps aux | grep -v grep | grep "$CHECK_PID" | grep "pandora_snmpconsole" | wc -l`
|
|
if [ $CHECK_PID_RESULT == 1 ]
|
|
then
|
|
echo "Pandora FMS SNMP Server is currently running on this machine with PID ($CHECK_PID). Aborting now..."
|
|
exit
|
|
fi
|
|
fi
|
|
|
|
$PANDORA_DAEMON $PANDORA_HOME -D
|
|
sleep 1
|
|
|
|
MYPID=`ps aux | grep "$PANDORA_DAEMON" | grep -v grep | tail -1 | awk '{print $2}'`
|
|
if [ ! -z "$MYPID" ]
|
|
then
|
|
echo $MYPID > $PANDORA_PID
|
|
echo "Pandora FMS SNMP Server is now running with PID $MYPID"
|
|
else
|
|
echo "Cannot start Pandora FMS SNMP Server. Aborted"
|
|
fi
|
|
cd "$OLD_PATH"
|
|
;;
|
|
stop)
|
|
if [ -f $DAEMON_PID ]
|
|
then
|
|
echo "Stopping NetSNMP Trap daemon"
|
|
PID_1=`cat $DAEMON_PID`
|
|
if [ ! -z "`ps -F -p $PID_1 | grep -v grep | grep 'snmptrapd'`" ]
|
|
then
|
|
kill -9 `cat $DAEMON_PID 2> /dev/null`
|
|
fi
|
|
rm -f $DAEMON_PID 2> /dev/null > /dev/null
|
|
rm -f $DAEMON_LOG 2> /dev/null > /dev/null
|
|
else
|
|
echo "NetSNMP Trap daemon is not running, cannot stop it."
|
|
fi
|
|
|
|
if [ -f $PANDORA_PID ]
|
|
then
|
|
echo "Stopping Pandora SNMP Console"
|
|
PID_2=`cat $PANDORA_PID`
|
|
if [ ! -z "`ps -F -p $PID_2 | grep -v grep | grep 'pandora_snmpconsole'`" ]
|
|
then
|
|
kill `cat $PANDORA_PID` 2> /dev/null > /dev/null
|
|
fi
|
|
rm -f $PANDORA_PID
|
|
else
|
|
echo "Pandora FMS SNMP Console is not running, cannot stop it."
|
|
fi
|
|
;;
|
|
force-reload|restart)
|
|
$0 stop
|
|
$0 start
|
|
;;
|
|
*)
|
|
echo "Usage: pandora_snmpconsole {start|stop|restart}"
|
|
exit 1
|
|
esac
|
|
|