PHP snmpwalk Weblogic serverRuntimeTable采集服务器运行信息

<?php
date_default_timezone_set("Asia/Shanghai");
error_reporting(0);
    class WeblogicServers
    {
        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.360.1');
            //$udp = array_chunk($result,count($result)/2);
            //print_r($result);
            $Systems = $result;
        
            //$ProcessorLoad        = $processor[0];//snmpwalkoid($this->host_address, $this->community, ".iso.org.dod.internet.mgmt.mib-2.udp.udpTable.udpEntry.udpLocalAddress");
            //$udpLocalPort           = $udp[1];//snmpwalkoid($this->host_address, $this->community, ".iso.org.dod.internet.mgmt.mib-2.udp.udpTable.udpEntry.udpLocalPort");
            if(
                $Systems != FALSE
            )
            {
                
                $length   = count($Systems);
                $count    = array();
                $count[0] = count($Systems);
                //$count[1] = count($udpLocalPort);
                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';
            }
            if($this->data_fetched == 'yes')
            {
                $this->populate_data_array($Systems);
            }
        }
        private function populate_data_array($Systems)
        {
            $Load     = array();
            //$LocalPort       = array();
                        
                        //---------------------------------------------------------------------------------------
            $i = 0;
            foreach($Systems as $key => $value)
            {
                $data       = str_replace('INTEGER: ', '', $value);
                $data       = str_replace('STRING: ', '', $data);
                $data       = str_replace('Gauge32: ', '', $data);
                $data       = str_replace('Counter64: ', '', $data);                
                //$data       = str_replace('"', '', $value);
                $Load[$i] = $data;
                $i = $i + 1;
            }
            $Systems = null;

 
            //---------------------------------------------------------------------------------------

                                    
            //$this->data_array[0] = $Load;
            $this->data_array['Server Name'] = str_replace('"', '',$Load[3]);
            //$this->data_array['Activation Time'] = date('Y-m-d H:i:s', $Load[5]/1000);
            $this->data_array['Activation Time'] = date('Y-m-d H:i:s',str_replace('"', '',$Load[5])/1000);
            $this->data_array['Listen Address'] = str_replace('"', '',$Load[6]);
            $this->data_array['Listen Port'] = str_replace('"', '',$Load[7]);
            if ($this->version == '8.1')
            {
                $this->data_array['Open Sockets'] = str_replace('"', '',$Load[10]);
            }
            if ($this->version == '10.3.6.0')
            {
                $this->data_array['Open Sockets'] = str_replace('"', '',$Load[9]);
            }
            if ($this->version == '8.1')
            {
                $this->data_array['State'] = str_replace('"', '',$Load[12]);
            }
            if ($this->version == '10.3.6.0')
            {
                $this->data_array['State'] = str_replace('"', '',$Load[11]);
            }
            if ($this->version == '8.1')
            { 
                $this->data_array['Weblogic Version'] = str_replace('"', '',$Load[13]);
            }
            if ($this->version == '10.3.6.0')
            {
            $this->data_array['Weblogic Version'] = str_replace('"', '',$Load[12]);
            }
 
        }
        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;
    }
?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值