Ad Widget

Collapse

Shell script not working with Zabbix 3.4

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lpossamai
    Senior Member
    • Jun 2018
    • 119

    #1

    Shell script not working with Zabbix 3.4

    Hi guys.

    I have a script that checks an API status using curl. When manually executing the script on the Zabbix Server box, it works.

    Code:
    /usr/lib/zabbix/externalscripts/api_services_status.sh "api_check_ping"
    The script:
    Code:
    #!/bin/sh
    
    set -x
    
    api_check_ping=$(curl --cert cert_prod.pem -s https://api.example.com/Ping/1.0 | tr '<|/' '\n' | grep ^service | grep -e $1 | awk '{print $3}')
    
    
    if [ $1 = 'api_check_ping' ];
    then
            if [ "${api_check_ping}" != 'status="up"' ]; then
                    echo "ERROR: $1 is down"
            else
                    echo "SUCCESS: $1 is UP"
            fi
    fi
    Output:
    Code:
     SUCCESS: api_check_ping is UP
    However, when creating an external check and using the same script, the Latest Data reports me the "api_check_ping" function is blank; as follow.

    Output from the Latest Data page:
    Code:
    ++ curl --cert cert_prod.pem -s https://api.example.com/Ping/1.0
     ++ tr '<|/' '\n' ++ awk '{print $3}'
    ++ grep -e api_check_ping
    ++ grep '^service'
    + api_check_ping=
    + '[' api_check_ping = api_check_ping ']'
    + '[' '' '!=' 'status="up"' ']'
    + echo 'ERROR: api_check_ping is down'
    ERROR: api_check_ping is down Zabbix_server log:
    Code:
    20631:20180615:155441.823 In get_value() key:'api_services_status.sh["api_check_ping"]'  
    
    20631:20180615:155441.824 In get_value_external() key:'api_services_status.sh["api_check_ping"]'  
    
    20631:20180615:155441.824 In zbx_popen() command:'/usr/lib/zabbix/externalscripts/api_services_status.sh "api_check_ping"'

    What am I doing wrong? Why does the script work when manually running but the Latest data page reports otherwise? Thanks in advance.
  • Linwood
    Senior Member
    • Dec 2013
    • 398

    #2
    Try running under the zabbix account and make sure you don't have a privilege problem, other common issue (also flushed out that way) are environmental variables.

    Comment

    • lpossamai
      Senior Member
      • Jun 2018
      • 119

      #3
      Originally posted by Linwood
      Try running under the zabbix account and make sure you don't have a privilege problem, other common issue (also flushed out that way) are environmental variables.
      hmm... I can't do su zabbix...

      is there a command where I can use the Zabbix_server to call that script?

      I think I agree with you.. it is probably an environmental variable issue.. but can't find out what it is.

      Comment

      • lpossamai
        Senior Member
        • Jun 2018
        • 119

        #4
        So an UPDATE here: This script is now working. I am, however, trying to get the same result via the Web Scenario... as it would be more easy to maintain and adjust with my needs.

        Final scripts for those who need it is:
        Code:
         
         #!/bin/sh  set -x  api_check_ping=$(curl --cert cert_prod.pem -s https://api.example.com/Ping/1.0 | tr '<|/' '\n' | grep ^service | grep -e $1 | awk '{print $3}')   if [ $1 = 'api_check_ping' ]; then         if [ "${api_check_ping}" != 'status="up"' ]; then                 echo "ERROR: $1 is down"         else                 echo "SUCCESS: $1 is UP"         fi fi

        Comment

        • lpossamai
          Senior Member
          • Jun 2018
          • 119

          #5
          FYI: I was able to get this working via Web Scenario: https://www.zabbix.com/forum/zabbix-...g-web-scenario

          Comment

          Working...