Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not working for multiple DSN #1

Open
saumyajit opened this issue Apr 12, 2020 · 0 comments
Open

not working for multiple DSN #1

saumyajit opened this issue Apr 12, 2020 · 0 comments

Comments

@saumyajit
Copy link

saumyajit commented Apr 12, 2020

Hi nucleusv,

I'm using below code to connect to DSN for fetching oracle tablespaces details. This is working without any issue for single DSN but if we've multiple DSN (reading from array separated by '|') it's failing ... It's not coming under a single JSON root element, rather multiple root elements.

#!/usr/bin/php
<?php

if(!isset($argv[1]) && !isset($argv[2])) exit("ZBX_NOTSUPPORTED");
$argv[1] = (explode("|", $argv[1] ));
foreach ($argv[1] as $value) {

$arry['data'][]=array('{#DSN}'=>"$value",);

$connected_dsn = odbc_connect($value,"","");

  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),'{#DSN}'=>$value);
          }    
        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();
}

?>

[root@tets_server externalscripts]# ./test_oracle.odbc.discovery "KCEPCPRDDB1V-EPCPRDDB|KCEPCPRDDB1V-EPCPVMDB" tablespaces
{"data":[{"{#TBSNAME}":"SYSTEM"},{"{#TBSNAME}":"SYSAUX"},{"{#TBSNAME}":"UNDOTBS1"},{"{#TBSNAME}":"TEMP"},{"{#TBSNAME}":"XDB"},{"{#TBSNAME}":"USERS"},{"{#TBSNAME}":"STATSPACK_DATA"},{"{#TBSNAME}":"WWFDATA"},{"{#TBSNAME}":"IGPDATA"},{"{#TBSNAME}":"EMADATA"},{"{#TBSNAME}":"CRNDATA"},{"{#TBSNAME}":"BATCHDATA"},{"{#TBSNAME}":"NTWKSDATA"},{"{#TBSNAME}":"NWMDATA"},{"{#TBSNAME}":"COMMUSR"},{"{#TBSNAME}":"REPORTSDATA"}]}{"data":[{"{#TBSNAME}":"SYSTEM"},{"{#TBSNAME}":"SYSAUX"},{"{#TBSNAME}":"UNDOTBS1"},{"{#TBSNAME}":"TEMP"},{"{#TBSNAME}":"XDB"},{"{#TBSNAME}":"USERS"},{"{#TBSNAME}":"STATSPACK_DATA"},{"{#TBSNAME}":"WWFDATA"},{"{#TBSNAME}":"IGPDATA"},{"{#TBSNAME}":"EMADATA"},{"{#TBSNAME}":"CRNDATA"},{"{#TBSNAME}":"COMMUSR"},{"{#TBSNAME}":"NTWKSDATA"}]}
> [root@ets_server externalscripts]#

Kindly suggest how can this be fixed.

@saumyajit saumyajit changed the title not working for multiple DNS not working for multiple DSN Apr 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant