Ad Widget

Collapse

How to capture comments returned by script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashuji
    Member
    • Dec 2008
    • 35

    #1

    How to capture comments returned by script

    Hi,

    For custom ITEMs, in zabbix we create ITEM, and ITEM runs a custom scripts and capture value returned by the script (0 or 1 etc.) and store it in its DB. Based on this value returned, zabbix trigger turns ON/OFF.

    But how to configure an ITEM to also capture comments returned by any particular script.

    Suppose if we compose a script which check if perticular file is writable or not by zabbix user, following are the contents:

    ITEM Name: check_file
    TYPE: zabbix_agent
    Type of info: FLOAT
    Interval: 300 (5 mins)

    Script:
    check_writable.sh

    echo "YES Writable" >> /tmp/test_file.txt


    if [ $? == 0 ]
    then
    #File is writable
    Return_value=1
    else
    #File is not writable
    Return_value=0
    fi

    echo $Return_value



    The value returned by above script will be examined by Trigger, and if '0' is returned, trigger will be turned ON to let administrator know that the file is no longer writable.

    Now if the file is not writable, there may be several reasons, like "Disk Space Full" or "Permission Denied" etc. But that reason of not able to write to file is not displayed in zabbix.

    Now suppose we make small modification in script and change to:



    Script:
    check_writable.sh

    echo "YES Writable" >> /tmp/test_file.txt


    if [ $? == 0 ]
    then
    echo File is writable
    Return_value=1
    else
    echo "Disk Space Full"
    Return_value=0
    fi

    echo $Return_value



    The above script will also return some comments like "Disk Space Full".

    Is there any way we can capture these comments and put in COMMENTS in triggers.

    Please suggest.

    Thanks & regards

    Ashwani Jain
  • troffasky
    Senior Member
    • Jul 2008
    • 567

    #2
    Originally posted by ashuji
    But how to configure an ITEM to also capture comments returned by any particular script.
    Why return '1' or '0'? Why not just return the comment?

    Comment

    • ashuji
      Member
      • Dec 2008
      • 35

      #3
      IF so

      If we return complete comment, how will it benefit. How will we setup trigger to analyse the text comment captured take decision to turn ON.

      Comment

      • Calimero
        Senior Member
        • Nov 2006
        • 481

        #4
        Return "OK" when everything is OK and write a trigger that checks that latest value is "OK" ?

        Comment

        • troffasky
          Senior Member
          • Jul 2008
          • 567

          #5
          Surely the only comment the script will be returning is a comment you program into it, ergo, for any comment, you know what the condition is and can create a trigger accordingly.

          Alternatively, you could use a Throw Map to convert the numeric value sent to Zabbix back to a string. Look at Config > General > Value Mapping for some examples.

          Comment

          • ashuji
            Member
            • Dec 2008
            • 35

            #6
            Example

            I tried this, but i could not setup trigger to evaluate the text value stored in ITEM. What formula could be setup in trigger to parse certain strigs from text value and calculate is to decide where to turn on trigger:

            For example, if value returned to ITEM is "no disk space left on /tmp" or "Permission denied" or "No such file or directory found"

            What I wanted is that, trigger should decide ON/OFF by value '1' or '0' returned by script and it should put success/error comments returned by script into COMMENTs field of TRIGGER.
            Last edited by ashuji; 10-03-2009, 12:01.

            Comment

            • Calimero
              Senior Member
              • Nov 2006
              • 481

              #7
              One option is to have the script return "OK" on success and an error message when things go wrong.

              {myhost:my_char_item.str("OK")}#1
              ==> trigger is ON if last value is different from "OK"

              And use {ITEMVALUE} in your action/message.

              Or as troffasky said create various return codes and use zabbix' mapping feature.

              0 = OK
              1 = disk full
              2 = permission denied
              3 = no such file
              ...

              Comment

              • ashuji
                Member
                • Dec 2008
                • 35

                #8
                Does not work

                Hi

                I created following script and ITEM but zabbix showing item "Not Supported":

                [root@SANDBOX2 scripts]# cat /etc/zabbix/bin/check_file.sh
                A="`cat /tmp/test.log`"

                if [ $? == 0 ]
                then
                RET_VAL=OK
                else
                RET_VAL=$A
                fi

                echo $RET_VAL


                [root@SANDBOX2 scripts]# zabbix_agent -t check_file
                check_file [t|OK]

                Item and Trigger configuration in the images attached with this thread. Item was configured but became unsupported, tried to create trigger as suggested but it failed to save. Kindly have a look and suggest solultion.

                Regards

                Ashwani jain
                Attached Files

                Comment

                • trikke
                  Senior Member
                  • Aug 2007
                  • 140

                  #9
                  Hi Try:

                  ....str(OK)}#1 -> No "

                  To get more info on your ERROR, just click the Red-ERROR "BOX"!

                  Greets
                  Patrick

                  Comment

                  • ashuji
                    Member
                    • Dec 2008
                    • 35

                    #10
                    Whats problem with ITEM

                    Thank, I'll try this new formula in TRIGGER but whats problem with the ITEM, the ITEM i configured is shown 'not supported' in zabbix. If I check the KEY on monitored host using 'zabbix_agent -t check_file' it returns OK. Screen shot of config. of ITEM i had attached with the reply.

                    Please check the ITEM config and suggest why is it shown 'not supported' in zabbix ui.

                    Thanks & regards

                    Ashwani Jain

                    Comment

                    • trikke
                      Senior Member
                      • Aug 2007
                      • 140

                      #11
                      OK,

                      first to get a feeling what the Server will receive, try folowing command from the Server: "zabbix_get -s SANDBOX2 -k check_file" as this is the "command" the Server does against the agent ( Agent side seem ok as you checked with agent -t ...)
                      Then just change your item from not supported to aktiv.
                      Check your zabbix_server.log file for possible error messages, check your zabbix_agentd.log file on the agent for possible errors.
                      this should bring u further.
                      As a last thing set your agent to debug=4, restart agent and again check agent logfile for errors or whatever.

                      By the way, how did u embeded the script in the aganets conf??

                      Why don't u just use an item with: system.run[/etc/zabbix/bin/check_file.sh] and leave the Agent "virgin"?

                      Greets
                      Patrick

                      Comment

                      • ashuji
                        Member
                        • Dec 2008
                        • 35

                        #12
                        Tried, strange behaviour

                        Hi,

                        First I checked the agent config on SANDBOX2:

                        [root@SANDBOX2 ~]# tail -n1 /etc/zabbix/zabbix_agent.conf
                        UserParameter=check_file,/etc/zabbix/bin/check_file.sh

                        Now check if the key is working:

                        [root@SANDBOX2 ~]# zabbix_agent -t check_file
                        check_file [t|OK]

                        Check the IP of this monitored host:

                        [root@SANDBOX2 ~]# ifconfig | grep 192
                        inet addr:192.168.90.243 Bcast:192.168.90.255 Mask:255.255.255.0


                        Now checked from Zabbix server:

                        [root@zabbix1 ~]# zabbix_get -s 192.168.90.243 -k check_file
                        ZBX_NOTSUPPORTED


                        See the strange behaviour, on monitored host if we check the key using "zabbix_agent -t <key" the key return desired result. But if we check the same key from Zabbix server using "zabbix_get" it says not supported.

                        Regards

                        Ashwani Jain

                        Comment

                        • trikke
                          Senior Member
                          • Aug 2007
                          • 140

                          #13
                          Hi,

                          please do set debug=4 at agent, restart agent and check logfile for error messages when trying "zabbix_get -s 192.168.90.243 -k check_file" this should give u a clue.
                          Mabybe EnableRemoteCommands=1 in agent conf???

                          Greets
                          Patrick

                          Comment

                          • ashuji
                            Member
                            • Dec 2008
                            • 35

                            #14
                            Not working

                            Hi

                            I enabled remote commands in agent.conf of monitored host but still the problem is same:

                            Here below is the contents of agent.conf:

                            [root@SANDBOX2 ~]# cat /etc/zabbix/zabbix_agent.conf
                            # This is config file for zabbix_agent
                            # To get more information about ZABBIX,
                            # go http://www.zabbix.com

                            # IP address of ZABBIX server
                            # Connections from other hosts will be denied

                            # JSM: This IP will only work in staging for Site A layers
                            # JSM: Correct this if needed
                            Server=192.168.90.98
                            EnableRemoteCommands=1
                            # Spend no more than Timeout seconds on processing
                            # Must be between 1 and 30

                            Timeout=30

                            ####### USER-DEFINED MONITORED PARAMETERS #######
                            #UserParameter=system.test,who|wc -l
                            ### Change -u<username> and add -p<password> if required
                            UserParameter=mysql.ping,mysqladmin -uroot ping|grep alive|wc -l


                            Regards

                            Ashwani Jain

                            Comment

                            • ashuji
                              Member
                              • Dec 2008
                              • 35

                              #15
                              Works

                              OK, this trigger formula is working in case ITEM type is Character or Log but not working if ITEM type is TEXT, is there any alternate for STR to be used with TEXT type ITEMs.

                              Thanks & regards

                              Ashwani Jain

                              Comment

                              Working...