Ad Widget

Collapse

custom script.. where is the problem?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • michu
    Junior Member
    • Nov 2004
    • 20

    #1

    custom script.. where is the problem?

    hey all

    well i created a nice script, which returns me the % of used space of a disk..
    i saved it in /opt/zabbix/hd_voll:
    ----------------------------------------------------
    #!/bin/bash
    host=$1
    disk=$2

    mulfix=1000000000 #because bash dosnt know floats...

    SUSED=$(snmpget -P e -O q $host public host.hrStorage.hrStorageTable.hrStorageEntry.hrSto rageUsed.$disk | cut -f2 -d" )
    STOTAL=$(snmpget -P e -O q $host public host.hrStorage.hrStorageTable.hrStorageEntry.hrSto rageSize.$disk | cut -f2 -d ")

    #echo "tot: $STOTAL"
    #echo "use: $SUSED"

    if [ "$STOTAL" = "0" ]
    then printf 'ERROR\n'
    else
    if [ "$STOTAL" = "" ]
    then printf 'ERROR\n'
    exit 1;
    fi
    divres=$((100 * $mulfix / $STOTAL))
    resultm=$(($divres * $SUSED))
    resultUnrounded=$(($resultm / ($mulfix/10))) # a primitive rounding algo...
    resultUnroundedA=$(($resultUnrounded + 5))
    result=$(($resultUnroundedA /10))
    echo $result
    ----------------------------------------------------
    when i run it from the command line, it workss fine:

    abcmgmt:/ # /opt/zabbix/hd_voll server01 4
    66

    so i edited /etc/zabbix/agentd.conf, i changed the following:

    a) increased the timeout
    # Spend no more than Timeout seconds on processing
    # Must be between 1 and 30

    Timeout=30

    b)added the user parameter
    UserParameter=DiskFree[SERVER01],/opt/zabbix/hd_voll server01 4

    now i restartet zabbix...

    in the web interface, i add a new item, type is "zabbix_agent" and the key i enter is "DiskFree[SNFSERVER01]", status "monitored", type of information is "numeric"...

    the host is monitored and working fine (other snmp items)... but my script never gets checked... output from latest values:
    DiskFree - - - Graph Trend Compare

    no errors... any hints?

    ps i testet it on zabbix v1.0 and v1.1a2

    regards
    michael
  • johnl
    Junior Member
    • Jan 2005
    • 27

    #2
    have a look at following post.



    you could create cron job to run the script and output value to file and then get zabbix to reference this file. that way you dont have to worry about time scripts take to execute, zabbix permissions to execute scripts etc.

    regards,
    john

    Comment

    • michu
      Junior Member
      • Nov 2004
      • 20

      #3
      hmm

      thanks johnl for your quick reply...

      well i did it the way you desc.

      a) the script is called from a cron job, a file is generated in /opt/zabbix/disk/server014

      in zabbix_Agentd.conf i added the following user parameter

      UserParameter=DiskFree[SERVER014],cat /opt/zabbix/disk/server014

      restart zabbix... now the suckerd.log file show this:

      018116:20050525:110928 Got empty string from [server01]. Parameter [DiskFree[SERVER014]]
      018116:20050525:110928 Assuming that agent dropped connection because of access permissions
      018116:20050525:110928 Got empty string from [server01]. Parameter [DiskFree[SERVER014]]
      018116:20050525:110928 Assuming that agent dropped connection because of access permissions
      018116:20050525:110928 Got empty string from [server01]. Parameter [DiskFree[SERVER014]]
      018116:20050525:110928 Assuming that agent dropped connection because of access permissions


      i also created a script which does the cat /opt/zabbix/disk/server014 and set the suid.. still the same error!?

      perhaps im calling the parameter wrong.. just to be sure:

      agentd.conf:
      UserParameter=DiskFree[SERVER014],cat /opt/zabbix/disk/server014

      on a host i add the following.. (type: zabbix_agent) and key is DiskFree[SERVER014]

      any ideas?

      thanks in advance
      michael

      Comment

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

        #4
        Are you sure your script finds snmpget and other external binaries? You do not have full path to the binaries...
        Alexei Vladishev
        Creator of Zabbix, Product manager
        New York | Tokyo | Riga
        My Twitter

        Comment

        • michu
          Junior Member
          • Nov 2004
          • 20

          #5
          yes... snmpget is not needed anymore, as i create a text file with via cron job... this means i ve a text file with "44\n" in it...

          and a /bin/cat should execute everyone... on the textfile itself everyone has read permission...

          2 questions

          a) when i use a custom script, i had to declare the item as "zabbix_agent", right?
          b) the zabbix agent is just running on the server itself, the other (win) hosts are checked with snmp... so when i create the item, which wants to read the text file, the item needs to specified under the server-host (which runns the agent) or dosnt matter?

          regards
          michael

          Comment

          • johnl
            Junior Member
            • Jan 2005
            • 27

            #6
            so the cron job returns a value to a file eg 1. if you cat this file it should give you

            cat file
            1

            zabbix then needs to have permission to read the contents of this file. your parameters look ok. check that cat file gives you what you think it should and make sure zabbix can read the file.

            your userparameter and item look ok. once you get to the point where zabbix can read the value that is in your file. you need to change cron to mv this file to another file name as the cron job momentarily sets file to empty which will trip zabbix agent to unsupported. let me know if you have any problems. this is example of what we use

            created cron entry for zabbix user
            * * * * * path/script | mv path/outputfile.tmp path/outputfile

            then userparameter in agentd (dont forget to restart zabbix agent after making entry)
            UserParameter=server[test],cat path/outputfile

            item is then
            server[test]

            regards,
            john

            Comment

            • michu
              Junior Member
              • Nov 2004
              • 20

              #7
              hey johnl

              everything is set up right... and a cat is working as expectet...(with the newline) the mv problem issue is solved as alexei wrote in your thread...

              now

              >then userparameter in agentd (dont forget to restart zabbix agent after making entry)
              >UserParameter=server[test],cat path/outputfile

              >item is then
              >server[test]

              but on which host i add now this new item.. on localhost (where the file is and zabbix runns) or, on the server it monitors... or it dosnt matter? well i tried both... without success...

              the status of the item is "Not supported"... which looks like he gets a empty string back...

              i increased the debugging to 4... but there are not alot of informations:

              019320:20050525:115129 zabbix_agentd started
              019321:20050525:115129 zabbix_agentd 19321 started
              019322:20050525:115129 zabbix_agentd 19322 started
              019323:20050525:115129 zabbix_agentd 19323 started
              019324:20050525:115129 zabbix_agentd 19324 started
              019325:20050525:115129 zabbix_agentd 19325 started



              ... im running out of ideas

              regards
              michael

              Comment

              • johnl
                Junior Member
                • Jan 2005
                • 27

                #8
                cant think what could be wrong. i know that when i was trying to get userparameter and script to work it took me a little time (my being stupid didnt help . do the following

                create a file called file1
                put a value of 1 in this file
                create userparameter to check reference this file using cat
                create item on zabbix using userparameter
                set item to monitored.

                you should be able to see this under your latest data, if not something wrong with zabbix. if this works then check your steps for current problem.

                Comment

                • michu
                  Junior Member
                  • Nov 2004
                  • 20

                  #9
                  hey johnl... thanks again for your support... i think i missed 2 important steps:

                  1) i need to add the items on the LOCALHOST (=where zabbix runns)
                  2) restart ALL 3 tasks (suckerd/agentd/trapperd)...

                  regards

                  Comment

                  Working...