Ad Widget

Collapse

Zabbix check if server running

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • redhead
    Junior Member
    • Jun 2006
    • 7

    #1

    Zabbix check if server running

    I made a script to check if the zabbix server is running, not that my zabbix server is sometimes down, now just i now for sure that zabbix is running without checking it manualy. It is posible that the zabbix server is down when I'am testing things, when I'am push it to much.

    Just unzip the attachment, place it in a folder, add a line to cron, run this script every 10-60 minutes, and you're done.

    Zabbix is a great solution, keep up the good work !
    Attached Files
    Last edited by redhead; 15-06-2006, 19:17.
  • weasel
    Junior Member
    • Jul 2006
    • 15

    #2
    Hi redhead

    I like your script - so I "improved" it for my needs.

    -> It only writes the logfile if Zabbix is not running
    -> It tries to (re)start the server.
    -> Also changed sendmail to mail - why? It works for me

    Perhaps one of the functions is useful for someone somehow

    Thanks for the original script

    The code:
    Code:
    [...]
    # Number of retries
    RETRIES=5
    
    # Mail data to send the warning
    MAIL_TO="[email protected]"
    MAIL_FROM="[email protected]"
    MAIL_SUBJECT="Zabbix Check Script"
    
    # Log directory
    LOGDIR="/var/log/zabbixcheck"
    
    # Server binary
    SERVER_BIN="/usr/local/bin/zabbix_server"
    
    # PID file
    SERVER_PID="/var/tmp/zabbix_server.pid"
    
    # Current date
    CURDATE=`/bin/date --date 'today' '+%d-%m-%y-%H-%M'`
    # Logfile
    LOG="$LOGDIR/zabbix_server."$CURDATE".log"
    
    ####### END OF VARIABLES #####################################################
    ########################################################################
    ####### BEGIN WITH SCRIPT ####################################################
    
    COUNTER=1
    
    function delete_pid()
    {
            if test -f $SERVER_PID; then
                    rm $SERVER_PID
            fi
    }
    
    # Make a log directory for (temp) files
    test -d $LOGDIR || mkdir -p $LOGDIR
    pidof zabbix_server
    # Check if there are processes
    
    if [ $? -ne 0 ]; then
            echo -e "\nZabbix Check Script" >> $LOG
            echo -e "\n!! ZABBIX IS NOT RUNNING !!" >> $LOG
    
            while true; do
                    if [ $COUNTER -le $RETRIES ]; then
                            delete_pid
    
                            $SERVER_BIN
                            sleep 15
    
                            pidof zabbix_server
                            if [ $? -ne 0 ]; then
                                    COUNTER=$(($COUNTER+1))
                            else
                                    echo -e "\nZabbix Server automatically restartet!" >> $LOG
                                    echo -e "Tries: "$COUNTER >> $LOG
                                    break 2
                            fi
                    else
                            echo -e "\nZabbix Server not runnning after "$RETRIES" retries" >> $LOG
                            echo "Please start manually!" >> $LOG
                            delete_pid
                            break
                    fi
            done
    
            /usr/bin/mail $MAIL_TO -r $MAIL_FROM -s "$MAIL_SUBJECT" < $LOG
    fi

    Comment

    • mpeide
      Junior Member
      • Jul 2005
      • 21

      #3
      Zabbix Restart Script

      Weasel,

      Thanks for your code contribution. It has helped me immensely.

      Thanks,

      Matt

      Comment

      Working...