<?php
date_default_timezone_set("Asia/Shanghai");
error_reporting(0);
class WeblogicJDBCDataSources
{
public function __construct($host_address,$port,$community)
{
$this->host_address = $host_address;
$this->port = $port;
$this->community = $community;
$this->create_data_array();
}
private function create_data_array()
{
//---------- SYSTEM DESCRIPTION STARTS HERE
if(snmpwalk($this->host_address.':'.$this->port, $this->community, '1.3.6.1.4.1.140.625.360.1.65') != FALSE)
{
$this->data_fetched = 'yes';
$data = snmpwalk($this->host_address.':'.$this->port, $this->community, '1.3.6.1.4.1.140.625.360.1.65');
//print_r($data);
if(strlen($data[0]) == 0)
{
$data[0] = '<span id="no_data_received">No data received</span>';
}
else
{
if($data[0] == 'STRING: ')
{
$data[0] = '<span id="no_data_received">No data received</span>';
}
else
{
if(substr_count($data[0], 'STRING: ') > 0)
{
$data[0] = substr($data[0], strlen('STRING: '), strlen($data[0]));
}
else
{
$data[0] = $data[0];
}
$data_lower = strtolower($data[0]);
//print_r($data_lower);
if(substr_count($data_lower, 'weblogic') > 0)
{
$this->operating_system = 'weblogic';
}
if(substr_count($data_lower, '8.1') > 0)
{
$this->version = '8.1';
}
if(substr_count($data_lower, '10.3.6.0') > 0)
{
$this->version = '10.3.6.0';
}
}
}
}
//---------- SYSTEM DESCRIPTION ENDS HERE
$Systems = array();
$result = snmpwalk($this->host_address.':'.$this->port, $this->community, '1.3.6.1.4.1.140.625.191.1');
//print $this->host_address;
//print $this->community;
//print_r($result);
if($this->version == '8.1')
{
$result = array_chunk($result,count($result)/41);
$Name = $result[3];
$LeakedConnectionCount = $result[5];
$Enabled = $result[6];
$State = $result[7];
$ConnectionDelayTime = $result[9];
$ActiveConnectionsCurrentCount = $result[16];
$WaitingForConnectionCurrentCount = $result[17];
$VersionJDBCDriver = $result[18];
$ActiveConnectionsHighCount= $result[19];
$ConnectionsTotalCount= $result[28];
}
if($this->version == '10.3.6.0')
{
$result = array_chunk($result,count($result)/41);
$Name = $result[3];
$LeakedConnectionCount = $result[5];
$Enabled = $result[6];
$State = $result[7];
$ConnectionDelayTime = $result[9];
$ActiveConnectionsCurrentCount = $result[16];
$WaitingForConnectionCurrentCount = $result[17];
$VersionJDBCDriver = $result[18];
$ActiveConnectionsHighCount= $result[19];
$ConnectionsTotalCount= $result[28];
}
//print_r($resultOperStatus);
if(
$Name != FALSE and
$LeakedConnectionCount != FALSE and
$Enabled != FALSE and
$State != FALSE and
$ConnectionDelayTime != FALSE and
$ActiveConnectionsCurrentCount != FALSE and
$WaitingForConnectionCurrentCount != FALSE and
$VersionJDBCDriver != FALSE and
$ActiveConnectionsHighCount != FALSE and
$ConnectionsTotalCount != FALSE
)
{
$length = count($Name);
$count = array();
$count[0] = count($Name);
$count[1] = count($LeakedConnectionCount);
$count[2] = count($Enabled);
$count[3] = count($State);
$count[4] = count($ConnectionDelayTime);
$count[5] = count($ActiveConnectionsCurrentCount);
$count[6] = count($WaitingForConnectionCurrentCount);
$count[7] = count($VersionJDBCDriver);
$count[8] = count($ActiveConnectionsHighCount);
$count[9] = count($ConnectionsTotalCount);
for($i=0; $i<count($count); $i++)
{
if($count[$i] == $length)
{
$this->data_fetched = 'yes';
}
else
{
$this->data_fetched = 'no';
}
}
}
else
{
$this->data_fetched = 'no';
}
//print($this->data_fetched);
if($this->data_fetched == 'yes')
{
//print('before populate');
$this->populate_data_array($Name, $LeakedConnectionCount, $Enabled, $State,$ConnectionDelayTime,$ActiveConnectionsCurrentCount,$WaitingForConnectionCurrentCount,$VersionJDBCDriver,$ActiveConnectionsHighCount,$ConnectionsTotalCount);
}
}
private function populate_data_array($Name, $LeakedConnectionCount, $Enabled, $State,$ConnectionDelayTime,$ActiveConnectionsCurrentCount,$WaitingForConnectionCurrentCount,$VersionJDBCDriver,$ActiveConnectionsHighCount,$ConnectionsTotalCount)
{
$parameter0 = array();
$parameter1 = array();
$parameter2 = array();
$parameter3 = array();
$parameter4 = array();
$parameter5 = array();
$parameter6 = array();
$parameter7 = array();
$parameter8 = array();
$parameter9 = array();
//---------------------------------------------------------------------------------------
$i = 0;
foreach($Name as $key => $value)
{
$data = str_replace('STRING: ', '', $value);
$parameter0[$i] = str_replace('"', '',$data);
//print($data);
$i = $i + 1;
}
$Name = null;
//---------------------------------------------------------------------------------------
$i = 0;
foreach($LeakedConnectionCount as $key => $value)
{
$data = str_replace('INTEGER: ', '', $value);
$parameter1[$i] = $data;
$i = $i + 1;
}
$LeakedConnectionCount = null;
//---------------------------------------------------------------------------------------
$i = 0;
foreach($Enabled as $key => $value)
{
$data = str_replace('INTEGER: ', '', $value);
$parameter2[$i] = $data;
$i = $i + 1;
}
$Enabled = null;
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
$i = 0;
foreach($State as $key => $value)
{
$data = str_replace('STRING: ', '', $value);
$parameter3[$i] = str_replace('"', '',$data);
$i = $i + 1;
}
$State = null;
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
$i = 0;
foreach($ConnectionDelayTime as $key => $value)
{
$data = str_replace('INTEGER: ', '', $value);
$parameter4[$i] = $data;
$i = $i + 1;
}
$ConnectionDelayTime = null;
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
$i = 0;
foreach($ActiveConnectionsCurrentCount as $key => $value)
{
$data = str_replace('INTEGER: ', '', $value);
$parameter5[$i] = $data;
$i = $i + 1;
}
$ActiveConnectionsCurrentCount = null;
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
$i = 0;
foreach($WaitingForConnectionCurrentCount as $key => $value)
{
$data = str_replace('INTEGER: ', '', $value);
$parameter6[$i] = $data;
$i = $i + 1;
}
$WaitingForConnectionCurrentCount = null;
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
$i = 0;
foreach($VersionJDBCDriver as $key => $value)
{
$data = str_replace('STRING: ', '', $value);
$parameter7[$i] = str_replace('"', '',$data);
$i = $i + 1;
}
$VersionJDBCDriver = null;
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
$i = 0;
foreach($ActiveConnectionsHighCount as $key => $value)
{
$data = str_replace('INTEGER: ', '', $value);
$parameter8[$i] = $data;
$i = $i + 1;
}
$ActiveConnectionsHighCount = null;
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
$i = 0;
foreach($ConnectionsTotalCount as $key => $value)
{
$data = str_replace('INTEGER: ', '', $value);
$parameter9[$i] = $data;
$i = $i + 1;
}
$ConnectionsTotalCount = null;
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
$this->data_array[0] = $parameter0;
$this->data_array[1] = $parameter1;
$this->data_array[2] = $parameter2;
$this->data_array[3] = $parameter3;
$this->data_array[4] = $parameter4;
$this->data_array[5] = $parameter5;
$this->data_array[6] = $parameter6;
$this->data_array[7] = $parameter7;
$this->data_array[8] = $parameter8;
$this->data_array[9] = $parameter9;
}
public function get_data_array()
{
return $this->data_array;
}
public function get_operating_system()
{
return $this->operating_system;
}
public function get_version()
{
return $this->version;
}
public function __destruct()
{
/*
* No code needed here
*/
}
public $data_fetched;
private $host_address;
private $port;
private $community;
private $data_array = array();
private $operating_system;
private $version;
}
?>