Ad Widget

Collapse

Couple Of UserParameter checks

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • James Wells
    Senior Member
    • Jun 2005
    • 664

    #1

    Couple Of UserParameter checks

    Greetings,

    With the new Host Profiles going into 1.1, I started working to capture some of the information to populate the various fields. At first, I was doing this by hand, but I decided to let Zabbix do it for me. The three bits of data I was most concerned with were MAC Address (Zabbix should really support up to 4 BTW), Linux Distribution, and Linux Kernel Version. To that end, I created the following UserParameter checks that I thought I would share;
    Code:
    UserParameter=custom[oscheck],/usr/bin/head -n1 /etc/redhat-release
    UserParameter=custom[kerncheck],/bin/uname -r
    UserParameter=custom[macaddr0],/sbin/ifconfig eth0 | /usr/bin/head -n1 | awk '{print $5}'
    UserParameter=custom[macaddr1],/sbin/ifconfig eth1 | /usr/bin/head -n1 | awk '{print $5}'
    UserParameter=custom[macaddr2],/sbin/ifconfig eth2 | /usr/bin/head -n1 | awk '{print $5}'
    UserParameter=custom[macaddr3],/sbin/ifconfig eth3 | /usr/bin/head -n1 | awk '{print $5}'
    Unofficial Zabbix Developer
  • primos
    Member
    • Jul 2005
    • 61

    #2
    check oracle

    Nagios check_oracle with Zabbix flavour! copy utils.sh that comes with the official nagios plugins in the same dir as the check! Advise : Make zabbix in the group as oracle (oinstall,dba) client installation(sqlplus):

    need: sqlplus,tnsping (make shure zabbix can execute them)
    I'm sure this can be improved but a good place to start!

    UserParameter=oracletns[db_name],/opt/zabbix/libexec/check_oracle --tns
    UserParameter=oracledb[db_name],/opt/zabbix/libexec/check_oracle --db
    UserParameter=oraclelogin[db_name],/opt/zabbix/libexec/check_oracle --login
    UserParameter=oracletablespace[tablespace_name],/opt/zabbix/libexec/check_oracle --tablespace db_name user user_passwd




    -----------------------------------------------------------------------------------------
    #! /bin/sh
    #
    # [email protected]
    # 01/06/2000
    #
    # This Nagios plugin was created to check Oracle status
    #

    PROGNAME=`basename $0`
    PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
    REVISION=`echo '$Revision: 1.14 $' | sed -e 's/[^0-9.]//g'`

    . $PROGPATH/utils.sh


    print_usage() {
    echo "Usage:"
    echo " $PROGNAME --tns <Oracle Sid or Hostname/IP address>"
    echo " $PROGNAME --db <ORACLE_SID>"
    echo " $PROGNAME --login <ORACLE_SID>"
    echo " $PROGNAME --cache <ORACLE_SID> <USER> <PASS> <CRITICAL> <WARNING>"
    echo " $PROGNAME --tablespace <ORACLE_SID> <USER> <PASS> <TABLESPACE> <CRITICAL> <WARNING>"
    echo " $PROGNAME --oranames <Hostname>"
    echo " $PROGNAME --help"
    echo " $PROGNAME --version"
    }

    print_help() {
    print_revision $PROGNAME $REVISION
    echo ""
    print_usage
    echo ""
    echo "Check Oracle status"
    echo ""
    echo "--tns SID/IP Address"
    echo " Check remote TNS server"
    echo "--db SID"
    echo " Check local database (search /bin/ps for PMON process) and check"
    echo " filesystem for sgadefORACLE_SID.dbf"
    echo "--login SID"
    echo " Attempt a dummy login and alert if not ORA-01017: invalid username/password"
    echo "--cache"
    echo " Check local database for library and buffer cache hit ratios"
    echo " ---> Requires Oracle user/password and SID specified."
    echo " ---> Requires select on v_$sysstat and v_$librarycache"
    echo "--tablespace"
    echo " Check local database for tablespace capacity in ORACLE_SID"
    echo " ---> Requires Oracle user/password specified."
    echo " ---> Requires select on dba_data_files and dba_free_space"
    echo "--oranames Hostname"
    echo " Check remote Oracle Names server"
    echo "--help"
    echo " Print this help screen"
    echo "--version"
    echo " Print version and license information"
    echo ""
    echo "If the plugin doesn't work, check that the ORACLE_HOME environment"
    echo "variable is set, that ORACLE_HOME/bin is in your PATH, and the"
    echo "tnsnames.ora file is locatable and is properly configured."
    echo ""
    echo "When checking local database status your ORACLE_SID is case sensitive."
    echo ""
    echo "If you want to use a default Oracle home, add in your oratab file:"
    echo "*:/opt/app/oracle/product/7.3.4:N"
    echo ""
    support
    }

    case "$1" in
    1)
    cmd='--tns'
    ;;
    2)
    cmd='--db'
    ;;
    *)
    cmd="$1"
    ;;
    esac

    # Information options
    case "$cmd" in
    --help)
    print_help
    exit $STATE_OK
    ;;
    -h)
    print_help
    exit $STATE_OK
    ;;
    --version)
    print_revision $PLUGIN $REVISION
    exit $STATE_OK
    ;;
    -V)
    print_revision $PLUGIN $REVISION
    exit $STATE_OK
    ;;
    esac

    # Hunt down a reasonable ORACLE_HOME
    if [ -z "$ORACLE_HOME" ] ; then
    # Adjust to taste
    for oratab in /var/opt/oracle/oratab /etc/oratab
    do
    [ ! -f $oratab ] && continue
    ORACLE_HOME=`IFS=:
    while read SID ORACLE_HOME junk;
    do
    if [ "$SID" = "$2" -o "$SID" = "*" ] ; then
    echo $ORACLE_HOME;
    exit;
    fi;
    done < $oratab`
    [ -n "$ORACLE_HOME" ] && break
    done
    fi
    # Last resort
    [ -z "$ORACLE_HOME" -a -d $PROGPATH/oracle ] && ORACLE_HOME=$PROGPATH/oracle

    if [ -z "$ORACLE_HOME" -o ! -d "$ORACLE_HOME" ] ; then
    echo "-1"
    exit $STATE_OK
    fi
    PATH=$PATH:$ORACLE_HOME/bin
    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
    export ORACLE_HOME PATH LD_LIBRARY_PATH

    case "$cmd" in
    --tns)
    tnschk=` tnsping $2`
    tnschk2=` echo $tnschk | grep -c OK`
    if [ ${tnschk2} -eq 1 ] ; then
    tnschk3=` echo $tnschk | sed -e 's/.*(//' -e 's/).*//'`
    echo "${tnschk3}"
    exit $STATE_OK
    else
    echo "-1"
    exit $STATE_OK
    fi
    ;;
    --db)
    pmonchk=`ps -ef | grep -v grep | grep -c "ora_pmon_${2}$"`
    if [ ${pmonchk} -ge 1 ] ; then
    echo "${pmonchk}"
    exit $STATE_OK
    #if [ -f $ORACLE_HOME/dbs/sga*${2}* ] ; then
    #if [ ${pmonchk} -eq 1 ] ; then
    #utime=`ls -la $ORACLE_HOME/dbs/sga*$2* | cut -c 43-55`
    #echo "${2} OK - running since ${utime}"
    #exit $STATE_OK
    #fi
    else
    echo "0"
    exit $STATE_OK
    fi
    ;;
    --login)
    loginchk=`sqlplus dummy/user@$2 < /dev/null`
    loginchk2=` echo $loginchk | grep -c ORA-01017`
    if [ ${loginchk2} -eq 1 ] ; then
    echo "1"
    exit $STATE_OK
    else
    loginchk3=` echo "$loginchk" | grep "ORA-" | head -1`
    echo "0"
    exit $STATE_OK
    fi
    ;;

    --tablespace)

    result=`sqlplus -s ${3}/${4}@${2} << EOF
    set pagesize 0
    set numf '9999999.99'
    select b.free,a.total,100 - trunc(b.free/a.total * 1000) / 10 prc
    from (
    select tablespace_name,sum(bytes)/1024/1024 total
    from dba_data_files group by tablespace_name) A,
    ( select tablespace_name,sum(bytes)/1024/1024 free
    from dba_free_space group by tablespace_name) B
    where a.tablespace_name=b.tablespace_name and a.tablespace_name='${5}';
    EOF`

    if [ -n "`echo $result | grep ORA-`" ] ; then
    error=` echo "$result" | grep "ORA-" | head -1`
    echo "-1"
    exit $STATE_OK
    fi

    ts_free=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($1)}'`
    ts_total=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($2)}'`
    ts_pct=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}'`
    ts_pctx=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print $3}'`
    if [ "$ts_free" -eq 0 -a "$ts_total" -eq 0 -a "$ts_pct" -eq 0 ] ; then
    echo "-1"
    exit $STATE_OK
    fi

    echo "$ts_pctx"
    exit $STATE_OK
    ;;
    *)
    print_usage
    exit $STATE_OK
    esac
    Last edited by primos; 18-08-2005, 19:57.

    Comment

    • primos
      Member
      • Jul 2005
      • 61

      #3
      !!Share your checks!!

      I would be nice If we would all share our checks and UserParameters here!

      Comment

      • Alexei
        Founder, CEO
        Zabbix Certified Trainer
        Zabbix Certified SpecialistZabbix Certified Professional
        • Sep 2004
        • 5654

        #4
        Please be aware that if you use 1.1 alpha versions you may take advantage of flexible user parameters. It means that instead of:

        custom[macaddr0]

        you may define

        UserParameter=custom[*], script.sh

        and then use custom[eth0], custom[eth1], custom[whatever]

        The parameter will be passed as command line parameter to the script.
        Alexei Vladishev
        Creator of Zabbix, Product manager
        New York | Tokyo | Riga
        My Twitter

        Comment

        • primos
          Member
          • Jul 2005
          • 61

          #5
          Appeal to all to start dumping there own checks here!
          Last edited by primos; 18-08-2005, 14:41.

          Comment

          • primos
            Member
            • Jul 2005
            • 61

            #6
            IBM mainframe

            Alexei, I've been talking to guys at work, IBM mainframe experts, and they are willing to write a simple agent in kiks. I would really appreciate ANY doc about the protocol that zabbix_agentd uses, to be able to discuss with them further!

            [email protected]

            Comment

            • elkor
              Senior Member
              • Jul 2005
              • 299

              #7
              I created the following parameters and script to pull individual CPU usage percentages out of top (IO/Wait, Idle, etc.). This helps us determine what exactly the server spends it's time doing and what pieces of code could be optimized to improve it. These parameters are really informative when all placed on the same graph for a given host and looked at over time.

              /etc/zabbix/zabbix_agent.conf:
              Code:
              UserParameter=cpupercent[idle],/usr/bin/cat /zabbix/data/CPUusage.idle
              UserParameter=cpupercent[user],/usr/bin/cat /zabbix/data/CPUusage.user
              UserParameter=cpupercent[iowait],/usr/bin/cat /zabbix/data/CPUusage.iowait
              UserParameter=cpupercent[swap],/usr/bin/cat /zabbix/data/CPUusage.swap
              UserParameter=cpupercent[kernel],/usr/bin/cat /zabbix/data/CPUusage.kernel
              /zabbix/scripts/CPUusage: (run out of cron *****)
              Code:
              #!/bin/ksh
              # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
              #
              # Author:       Chris Regenye (SysInfrastructure)
              # Date:         8/1/2005
              # Info:         zabbix agent extention to pull values for CPU usage
              #               breakdown by type.  Note: requires top and may need
              #               modification based on version of top in use.
              #
              # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
              rawstates=$(/usr/local/bin/top -d2 | grep "CPU states" | awk '{print $3$4" " $5$6" " $7$8" " $9$10" " $11$12}')
              for state in $rawstates
              do
                      integerpercent=${state%.*}
                      usagetype=${state#*%}
                      usagetype=${usagetype%,}
                      echo $integerpercent > /zabbix/data/CPUusage.$usagetype
              done
              #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
              Last edited by elkor; 18-08-2005, 15:19.

              Comment

              • marc
                Senior Member
                • Oct 2004
                • 146

                #8
                script to really check http status...

                Description:
                Script checks a Webpage for correct HTTP Return Codes.

                Requires:
                zabbixX
                netcat

                Synopsis:
                UserParameter=httpd[somename], sh /home/www/zabbix/bin/zabbix-www.sh somename URLtoCheck Port Pagetocheck EstimatedReturnStatus

                Example:
                UserParameter=httpd[ino],sh /home/www/zabbix/bin/zabbix-www.sh ino www.inotronic.de 80 /home/index.php 200

                #!/bin/sh
                netcat=/usr/local/bin/nc
                VAR=/home/www/zabbix/var

                if [ ! -x $netcat ] ; then
                echo 42; # netcat not found
                exit 42;
                fi

                request() {
                name="$1"
                host="$2" # host to check
                port="$3" # port to check
                uri="$4" # uri to check
                code="$5" # expected httpcode

                if test -f $VAR/$name.off -o -f $VAR/wwwall.off ; then
                echo "-1" # Don't monitor
                # (because of maintenance for example)
                exit;
                fi

                RETURN=$(printf 'GET '"$uri"' HTTP/1.1\nHost: '"$host"'\n\nQUIT\n' |
                nc -w 5 "$host" "$port" | head -1)

                case "$RETURN" in
                HTTP/1.[10]" "$code" "*)
                echo "0" # good
                ;;
                *)
                echo "1"; # Bad
                ;;
                esac
                }
                request "$@"

                Comment

                • morgolis
                  Member
                  • Oct 2004
                  • 33

                  #9
                  Wasn't this implemented as a core function in zabbix_agentd?

                  Wasn't this implemented as a core function in zabbix_agentd? I read through the online manual / documentation for zabbix alpha 1.1 where it shows that you can get this information with the call function: system.cpu.idle1, system.cpu.system1, etc

                  Originally posted by elkor
                  I created the following parameters and script to pull individual CPU usage percentages out of top (IO/Wait, Idle, etc.). This helps us determine what exactly the server spends it's time doing and what pieces of code could be optimized to improve it. These parameters are really informative when all placed on the same graph for a given host and looked at over time.

                  /etc/zabbix/zabbix_agent.conf:
                  Code:
                  UserParameter=cpupercent[idle],/usr/bin/cat /zabbix/data/CPUusage.idle
                  UserParameter=cpupercent[user],/usr/bin/cat /zabbix/data/CPUusage.user
                  UserParameter=cpupercent[iowait],/usr/bin/cat /zabbix/data/CPUusage.iowait
                  UserParameter=cpupercent[swap],/usr/bin/cat /zabbix/data/CPUusage.swap
                  UserParameter=cpupercent[kernel],/usr/bin/cat /zabbix/data/CPUusage.kernel
                  /zabbix/scripts/CPUusage: (run out of cron *****)
                  Code:
                  #!/bin/ksh
                  # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                  #
                  # Author:       Chris Regenye (SysInfrastructure)
                  # Date:         8/1/2005
                  # Info:         zabbix agent extention to pull values for CPU usage
                  #               breakdown by type.  Note: requires top and may need
                  #               modification based on version of top in use.
                  #
                  # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                  rawstates=$(/usr/local/bin/top -d2 | grep "CPU states" | awk '{print $3$4" " $5$6" " $7$8" " $9$10" " $11$12}')
                  for state in $rawstates
                  do
                          integerpercent=${state%.*}
                          usagetype=${state#*%}
                          usagetype=${usagetype%,}
                          echo $integerpercent > /zabbix/data/CPUusage.$usagetype
                  done
                  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

                  Comment

                  • James Wells
                    Senior Member
                    • Jun 2005
                    • 664

                    #10
                    Originally posted by morgolis
                    Wasn't this implemented as a core function in zabbix_agentd? I read through the online manual / documentation for zabbix alpha 1.1 where it shows that you can get this information with the call function: system.cpu.idle1, system.cpu.system1, etc
                    Yup. This capability is now part of the agent as of 1.1beta1. Please note though that Elkor posted this before the capability existed.
                    Unofficial Zabbix Developer

                    Comment

                    • elkor
                      Senior Member
                      • Jul 2005
                      • 299

                      #11
                      Oh sure morgolis, rain on my parade. thanks a lot

                      yeah, there is support for this now; although.. I didn't see a built in parameter for I/O wait time on the CPU. For those doing datamining or even backups this can be an important metric.

                      Comment

                      • elkor
                        Senior Member
                        • Jul 2005
                        • 299

                        #12
                        A script to set as an action for changes on these items that automatically updates the database with the new values would make the whole thing almost painless....

                        I haven't looked at the host profiles table yet, but is this feasable?


                        Originally posted by James Wells
                        Greetings,

                        With the new Host Profiles going into 1.1, I started working to capture some of the information to populate the various fields. At first, I was doing this by hand, but I decided to let Zabbix do it for me. The three bits of data I was most concerned with were MAC Address (Zabbix should really support up to 4 BTW), Linux Distribution, and Linux Kernel Version. To that end, I created the following UserParameter checks that I thought I would share;
                        Code:
                        UserParameter=custom[oscheck],/usr/bin/head -n1 /etc/redhat-release
                        UserParameter=custom[kerncheck],/bin/uname -r
                        UserParameter=custom[macaddr0],/sbin/ifconfig eth0 | /usr/bin/head -n1 | awk '{print $5}'
                        UserParameter=custom[macaddr1],/sbin/ifconfig eth1 | /usr/bin/head -n1 | awk '{print $5}'
                        UserParameter=custom[macaddr2],/sbin/ifconfig eth2 | /usr/bin/head -n1 | awk '{print $5}'
                        UserParameter=custom[macaddr3],/sbin/ifconfig eth3 | /usr/bin/head -n1 | awk '{print $5}'

                        Comment

                        • James Wells
                          Senior Member
                          • Jun 2005
                          • 664

                          #13
                          Originally posted by elkor
                          A script to set as an action for changes on these items that automatically updates the database with the new values would make the whole thing almost painless....

                          I haven't looked at the host profiles table yet, but is this feasable?
                          Not yet, no, however, this is another thing that I plan to create a patch for. At present, the way I am doing it is using the checks listed previously then doing a simple SQL comand to copy the values I want over to the hosts_profiles table. What I have completed of the hosts_profiles so far, automatically updates the hosts_profiles MAC[0-3] addresses, pulls the machines physical memory for to set the limits on various memory usage graphs, pulls the MAC[0-4] addresses-to-Hostname for use in the network bandiwdth and usage graphs from my switches, auto generates maps which show every server in a 19inch rack, and also generates BTU / AMP / Watt reports for capacity planning.

                          Unfortunately, I just had to take my development machine into the shop, so my ability to turn all of this stuff into a patch against the current system is severely limited right now.
                          Unofficial Zabbix Developer

                          Comment

                          • Alexei
                            Founder, CEO
                            Zabbix Certified Trainer
                            Zabbix Certified SpecialistZabbix Certified Professional
                            • Sep 2004
                            • 5654

                            #14
                            FYI I plan to enhance functionality of host profiles to allow usage of macros. So, most of information displayed in host profiles will be collected by ZABBIX (SNMP, whatever) agents.
                            Alexei Vladishev
                            Creator of Zabbix, Product manager
                            New York | Tokyo | Riga
                            My Twitter

                            Comment

                            • elkor
                              Senior Member
                              • Jul 2005
                              • 299

                              #15
                              Originally posted by James Wells
                              pulls the machines physical memory for to set the limits on various memory usage graphs, pulls the MAC[0-4] addresses-to-Hostname for use in the network bandiwdth and usage graphs from my switches, auto generates maps which show every server in a 19inch rack, and also generates BTU / AMP / Watt reports for capacity planning.
                              That sounds great dude! the autogeneration of server racks along with the cap planning info in particular sounds like quite a bit of work, I'd definately be interested in seeing what you have even if it was just a tarball of the existing files from the alpha build, I have the originals so I could run the diffs here. that could really open up some new functionality for me.

                              The memory graph ceiling is also a killer idea, my plan was just to put the total memory on the graph and set it to autosize but this would remove one item from each graph (haven't done mem graphs yet as I'm still in rollout here and they are looking for "Wow factor" and mem graphs tend to be a bit flat for most of my servers)

                              Originally posted by James Wells
                              Unfortunately, I just had to take my development machine into the shop, so my ability to turn all of this stuff into a patch against the current system is severely limited right now.
                              well that's no good. here's to hoping you get your playground back soon.

                              Comment

                              Working...