Ad Widget

Collapse

low level discovery rule script for ZFS Pools

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neptunus
    Junior Member
    • Jul 2013
    • 7

    #1

    low level discovery rule script for ZFS Pools

    Hello,

    If have been trying to get low level discovery rule script working for ZFS Pools discovery.

    Files located in:
    Code:
    sideswipe: zabbix2_agentd.conf.d # pwd
    /usr/local/etc/zabbix2/zabbix2_agentd.conf.d
    sideswipe: zabbix2_agentd.conf.d # ll
    total 8
    -rwxr-xr-x  1 root  wheel  1463 Aug 20 19:23 zfs-discovery.sh*
    -rw-r--r--  1 root  wheel   304 Aug 20 19:04 zfs.conf
    zfs-discovery.sh
    Code:
    #!/bin/bash
    #################################################################################################
    # Script aimed for zabbix agent(s) of low level discovery rule script for ZFS Pools discovery   #
    #                                                                                               #
    # Author: Neptunus from zabbix forum                                                            #
    #                                                                                               #
    #################################################################################################
    
    
    ################################################
    # PARAMETERS THAT CAN BE MODIFIED BY THE USER
    ################################################
    
    ################################################
    # Path to used utilities
    ################################################
    BIN_ZPOOL="/sbin/zpool"
    
    ################################################
    
    declare -a pools
    #pools=(a b c)
    
    n=0
    #for i in $(/sbin/zpool list -H -o name) ; do
    for i in $($BIN_ZPOOL list -H -o name) ; do
      pools[$n]="$i"
      #echo "Pool: $n = $i"     #to confirm the entry
      let "n= $n + 1"
    done
    
    # Get length of an array
    length=${#pools[@]}
    
    echo "{"
    echo -e "\t\"data\":[\n"
    
    for (( i=0; i<${length}; i++ ))
    do
       if [ $i == $length ]; then
         echo -e "\t{ \"{#ZFSPOOL}\":\"${pools[$i]}\" }"
       else
         echo -e "\t{ \"{#ZFSPOOL}\":\"${pools[$i]}\" },"
       fi
    done
    
    echo -e "\n\t]\n"
    echo "}"
    Example of results(JSON format) when running script standalone (./zfs-discovery.sh):
    Code:
    {
            "data":[
    
            { "{#ZFSPOOL}":"zssddata" },
            { "{#ZFSPOOL}":"zstore" },
    
            ]
    
    }
    zfs.conf
    Code:
    # ZFS checks
    
    # zpool(1M) status, parameters: zpool-name,property
    # parameters eg.: rpool,health
    # see zpool list -o for available properties
    UserParameter=zpool.status[*],zpool list -H -o $2 $1|sed -e 's/%//'
    UserParameter=zpool.discovery, /usr/local/etc/zabbix2/zabbix2_agentd.conf.d/zfs-discovery.sh
    Problems when restarting zabbix agent:
    Code:
    sideswipe: zabbix2_agentd.conf.d # /usr/local/etc/rc.d/zabbix_agentd restart
    zabbix_agentd not running?
    Starting zabbix_agentd.
    zabbix_agentd [29353]: unknown parameter [BIN_ZPOOL] in config file [/usr/local/etc/zabbix2/zabbix2_agentd.conf.d/zfs-discovery.sh], line 17
    /usr/local/etc/rc.d/zabbix_agentd: WARNING: failed to start zabbix_agentd
    When I change:
    Code:
    BIN_ZPOOL="/sbin/zpool"
    
    #for i in $(/sbin/zpool list -H -o name) ; do
    for i in $($BIN_ZPOOL list -H -o name) ; do
    to
    Code:
    #BIN_ZPOOL="/sbin/zpool"
    
    for i in $(/sbin/zpool list -H -o name) ; do
    #for i in $($BIN_ZPOOL list -H -o name) ; do
    The script is running nice standalone but when restarting zabbix agent there are problems:
    Code:
    sideswipe: zabbix2_agentd.conf.d #  /usr/local/etc/rc.d/zabbix_agentd restart                                                                               zabbix_agentd not running?
    Starting zabbix_agentd.
    zabbix_agentd [29374]: invalid entry [declare -a pools] (not following "parameter=value" notation) in config file [/usr/local/etc/zabbix2/zabbix2_agentd.conf.d/zfs-discovery.sh], line 21
    /usr/local/etc/rc.d/zabbix_agentd: WARNING: failed to start zabbix_agentd
    I'm not and expert with bash. Do not know how to proceed, advice is welcome!
  • neptunus
    Junior Member
    • Jul 2013
    • 7

    #2
    Originally posted by neptunus
    Hello,

    If have been trying to get low level discovery rule script working for ZFS Pools discovery.
    Does anyone have a clue how this could be fixed?

    Comment

    • kmaslowski
      Junior Member
      • Sep 2013
      • 4

      #3
      Move script and configutarion file to another directory. Zabbix agent tries to parse them.

      Comment

      • pedrums
        Junior Member
        • Jun 2012
        • 2

        #4
        ZPOOL Discover

        i took your script and it worked ,
        (agent v2.0.8 (revision 38017), Sol 5.10)

        you can test your config without restart the agent:

        zabbix_agentd -c "your Zabbix ConfigFile" -t zpool.discovery

        btw:
        your are under Solaris, i think it's better, you don't use "bash"

        start your scripts with:

        PATH=/usr/xpg4/bin:$PATH:/usr/sbin
        export PATH

        in /usr/xpg4/bin are the better awk and other so on

        #####
        i have this in place (here only the discover-part of the complete script):
        ___________________
        #!/bin/sh

        PATH=/usr/xpg4/bin:$PATH:/usr/sbin
        export PATH

        TYPE=ZPOOL

        discover () {
        printf "{\n\"data\":[\n"
        zpool list -H -o name |awk -v type=$TYPE ' {
        printf "{\n"
        printf "\"{#%s}\":\"%s\",\n",toupper(type),$NF
        printf "},\n"
        } '
        printf "]}"
        }


        discover
        -----------------------

        Comment

        • neptunus
          Junior Member
          • Jul 2013
          • 7

          #5
          Originally posted by pedrums
          i took your script and it worked ,
          (agent v2.0.8 (revision 38017), Sol 5.10)
          discover
          -----------------------
          I'm on BSD.

          I also have it working in zabbix. But with discover it also discovers snapshots. Is it possible to exclude the snapshots?

          Comment

          Working...