Ad Widget

Collapse

How zabbix execute external script?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JoohnyO
    Junior Member
    • Jul 2014
    • 25

    #1

    How zabbix execute external script?

    Hello everyone!
    Im trying to setup LLD for oracleDB, and have some problem with external script i run.
    Here it is:
    PHP Code:
    #!/usr/bin/php
    <?php

      
    if(!isset($argv[1]) && !isset($argv[2])) exit("ZBX_NOTSUPPORTED");

      
    $connected_dsn odbc_connect($argv[1],"","");

      if(!
    $connected_dsn) exit('SQL connection erorr | ZBX_NOTSUPPORTED');

      switch (
    $argv[2]) {
          case 
    "tablespaces":
              
    $result=odbc_exec($connected_dsn,"SELECT tablespace_name FROM dba_tablespaces;");
              
    $tablespaces = array("data"=>array());

              while(
    odbc_fetch_row($result)){
                   
    $tablespaces['data'][]=array('{#TBSNAME}'=>odbc_result($result,1));
              }

              echo 
    json_encode($tablespaces);
              break;

          case 
    "jobs":
              
    $result=odbc_exec($connected_dsn,"SELECT job_name, owner FROM dba_scheduler_jobs WHERE state != 'DISABLED';");

              
    $jobs = array("data"=>array());

              while(
    odbc_fetch_row($result)){
                   
    $jobs['data'][]=array(
                                            
    '{#JOBNAME}'=>odbc_result($result,1),
                                            
    '{#JOBOWNER}'=>odbc_result($result,2));
              }

              echo 
    json_encode($jobs);
              break;
      }

    exit();
    ?>
    when i'm trying to run it myself, it works fine, but when zabbix server trying to execute it, i have this error:
    Code:
    PHP Warning:  odbc_connect(): SQL error: [unixODBC][Oracle][ODBC][Ora]ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA
    , SQL state S1000 in SQLConnect in /etc/zabbix/scripts/oracle.odbc.discovery on line 6
    Oracle variables - oracle_home, oracle_sid, and path is fine, sqlplus and isql is connecting without any problems.
    What did i miss?
  • aib
    Senior Member
    • Jan 2014
    • 1615

    #2
    Try to include all ORACLE variables into the script.
    Somebody told me that Zabbix don't catch all variables from environment.
    Sincerely yours,
    Aleksey

    Comment

    • JoohnyO
      Junior Member
      • Jul 2014
      • 25

      #3
      Im bad at php, and dont really think i've done it right.
      I just added getenv('ORACLE_HOME'); and stuff, and it still the same.

      Comment

      • JoohnyO
        Junior Member
        • Jul 2014
        • 25

        #4
        Found the answer myself. I still don't really understand why zabbix server not exporting variables from /etc/profile etc.
        I've just added export oracle_home with path to /etc/init.d/zabbix_server, and it finally worked fine.

        Comment

        Working...