Ad Widget

Collapse

Notify the server when the agent is administratively started or stopped

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alledm
    Member
    • May 2012
    • 84

    #1

    Notify the server when the agent is administratively started or stopped

    Hello,

    Zabbix is very useful for monitoring server availability, and for notifying you when your hosts go down or are unreachable.

    HOWEVER, sometime if you are doing unplanned maintenance you don't want Zabbix to send out emails if YOU are performing the reboot of the server yourself.

    I have modified the (Redhat/Fedora/Centos) init script to allow it to send a "status" to the Zabbix Server so that you can include in your triggers and 'silence' the notification in case the agent was stopped from an Administrator.

    The solution is very simple and can probably be improved.

    The changes to the init script are in the START and STOP Section only

    Code:
     # functions
    start() {
            if [ $RUNNING -eq 1 ]
                    then
                    echo "$0 $ARG: $BINARY_NAME (pid $PID) already running"
            else
                    action $"Starting $BINARY_NAME: " $FULLPATH
    
                    [ ${ENABLE_SENDER} -ne 0 ] && $SENDER -z ${ZABBIX_SERVER} -p ${ZABBIX_PORT} -k ${KEY} -s ${HOSTNAME} -o ${STARTED} >/dev/null
                    touch /var/lock/subsys/$BINARY_NAME
            fi
    }
    
    stop() {
            echo -n $"Shutting down $BINARY_NAME: "
            killproc $BINARY_NAME
            RETVAL=$?
            echo
            if [ $RETVAL -eq 0 ]
                then
                    [ ${ENABLE_SENDER} -ne 0 ] && $SENDER -z ${ZABBIX_SERVER} -p ${ZABBIX_PORT} -k ${KEY} -s ${HOSTNAME} -o ${STOPPED} >/dev/null
                    rm -f /var/lock/subsys/$BINARY_NAME
            fi
            RUNNING=0
    }
    I have also configured these variables in a separate file

    Code:
    vi /etc/sysconfig/zabbix
    
     Default zabbix configuration
    
    # Zabbix-Directory
    BASEDIR=/usr
    
    # Agent Binary File
    BINARY_NAME=zabbix_agentd
    SENDER_NAME=zabbix_sender
    
    # Full Binary File Call
    FULLPATH=${BASEDIR}/sbin/${BINARY_NAME}
    
    # Sender full path
    ENABLE_SENDER=1
    SENDER=${BASEDIR}/bin/${SENDER_NAME}
    KEY=agent_status[]
    STARTED=1
    STOPPED=0
    ZABBIX_SERVER=zabbix-server
    ZABBIX_PORT=10051
    
    # PID file
    PIDFILE=/var/run/zabbix/$BINARY_NAME.pid
    # Establish args
    
    ERROR=0
    STOPPING=0
    All you need to do then is to create an item on the Zabbix_Agent template of type TRAPPER and modify your triggers to include it.


    Let me know what you think
    Regards
    Alessandro
    Last edited by alledm; 10-12-2012, 18:18. Reason: What I wrote before didn't make sense :)
Working...