Ad Widget

Collapse

Trigger set for unmounted or removed file systems Notification

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ErenYener
    Junior Member
    • Dec 2014
    • 4

    #1

    Trigger set for unmounted or removed file systems Notification

    Hi,
    I can find file systems using low level discovery and I can monitor these file systems.
    but I need to configure a trigger that includes changes in number of the filesystems. For example:
    Assume, discovery found filesystems named c: and d: OR / and /disk1. If any of those discovered filesystem removed, unmounted or added to the system. So, I need to know how to create the trigger that I mentioned above.
  • coreychristian
    Senior Member
    Zabbix Certified Specialist
    • Jun 2012
    • 159

    #2
    I don't think there is anything that can do this out of box. We only do this for UNIX, though I would imagine it would be easy enough to do via powershell as well.

    We have a 3 part script we run on our UNIX hosts via cron which sends data into trapper items in zabbix. Below is the script which you can feel free to use, if you have any questions about the setup let me know.

    Also just to note, we are planning on putting in a kill command in case the script hangs, just haven't had time to get that done.

    parts
    1. Checks that the filesystems can be written to
    2. Checks that the file systems can
    3. Starts the zabbix agent if it's not running

    Zabbix Item Keys.
    filesystem.ro.check
    filesystem.mount.check

    The Zabbix Triggers we use
    if X > 0 trigger for key 1 and 2
    If the host hasn't sent data for these items in 30 minutes


    Code:
    #!/bin/bash
    ########################################
    # Written by Corey Christian 12/05/2014
    ########################################
    HOSTNAME=`hostname`
    CURDATE=`date`
    
    ##################################
    # File System Read Only Check
    ##################################
    
    #Build File List array
    FSROEXTRACT=`cat /etc/fstab| egrep "ext" | grep -v "^#"| awk '{ print  $2 }'`
    FSROLIST=(
            $FSROEXTRACT
            )
    
    #Check if each file system is writeable
    count=0
    FSROCHECKTOTAL=0
    while [ "x${FSROLIST[count]}" != "x" ]
    do
            FSROCHECK=`touch ${FSROLIST[count]}/test.txt 2> /dev/null && { rm ${FSROLIST[count]}/test.txt 2> /dev/null; echo "0"; } || echo "1"`
            FSROCHECKTOTAL=$(( $FSROCHECKTOTAL + $FSROCHECK ))
            if [ "$FSROCHECK" == 1 ] && [ -d "${FSROLIST[count]}" ]; then
                    echo $CURDATE ${FSROLIST[count]} is read only. >> /tmp/fsrocheck.log
            fi
            count=$(( $count + 1 ))
    done
    
    if [ "$FSROCHECKTOTAL" == 0 ]; then
            echo $CURDATE all file systems are writeable. >> /tmp/fsrocheck.log
    fi
    
    #Send the fsrochecktotal to zabbix
    /usr/bin/zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -s $HOSTNAME -k filesystem.ro.check -o $FSROCHECKTOTAL
    
    
    ###############################
    #File System Mounted Check
    ###############################
    
    FSMOUNTEXTRACT=`cat /etc/fstab| egrep "nfs|ext" | grep -v "^#"| awk '{ print  $2 }'`
    FSMOUNTLIST=(
            $FSMOUNTEXTRACT
            )
    
    #Check if each filesystem is mounted
    count=0
    FSMOUNTCHECKTOTAL=0
    while [ "x${FSMOUNTLIST[count]}" != "x" ]
    do
            FSMOUNTCHECK=`df -h ${FSMOUNTLIST[count]} | grep -ic ${FSMOUNTLIST[count]}`
            if [ "$FSMOUNTCHECK" == 0 ]; then
                    echo $CURDATE ${FSMOUNTLIST[count]} is not mounted >> /tmp/fsmountcheck.log
                    FSMOUNTCHECK=1
                    FSMOUNTCHECKTOTAL=$(( $FSMOUNTCHECKTOTAL + $FSMOUNTCHECK ))
            fi
    
            count=$(( $count + 1 ))
    done
    
    if [ "$FSMOUNTCHECKTOTAL" == 0 ]; then
            echo $CURDATE all file systems are mounted >> /tmp/fsmountcheck.log
    fi
    
    #Send the fsmountchecktotal to zabbix
    /usr/bin/zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -s $HOSTNAME -k filesystem.mount.check -o $FSMOUNTCHECKTOTAL
    
    
    ###############################################################
    #Check zabbix agent service, if it's not running start it.
    ###############################################################
    
    ZABBIX_STATUS=`ps -ef | grep -v grep | grep -c zabbix_agentd`
    if [ "$ZABBIX_STATUS" = "0" ]
            then
            /etc/init.d/zabbix_agentd start
            /etc/init.d/zabbix-agent start
    fi

    Comment

    • ErenYener
      Junior Member
      • Dec 2014
      • 4

      #3
      Hi Thanks for your help,
      I will Try this script

      Comment

      Working...