예제 #1
0
        public void UpdateTrapReceiver(Sys_Para pSys, TrapEnabled open)
        {
            if (pSys.TrapPort <= 0 || pSys.TrapPort > 65535)
            {
                return;
            }
            DebugCenter debug = DebugCenter.GetInstance();

            debug.appendToFile("*****=====***** Begin to send trap receiver config to device *****=====*****");
            SystemThreadPool <SnmpConfiger, bool> systemThreadPool = new SystemLargeThreadPool <SnmpConfiger, bool>(this.snmpConfigs);

            systemThreadPool.GetResults(delegate(System.Collections.ICollection coll, object obj)
            {
                System.Collections.Generic.List <System.Net.IPAddress> managerLocalIpAddress = this.getManagerLocalIpAddress();
                System.Net.IPAddress iPAddress = managerLocalIpAddress[0];
                SnmpConfiger snmpConfiger      = (SnmpConfiger)obj;
                SnmpExecutor snmpExecutor      = new DefaultSnmpExecutor(snmpConfiger);
                if (snmpConfiger.DevModelConfig.commonThresholdFlag != Constant.EatonPDU_M2 && snmpConfiger.DevModelConfig.commonThresholdFlag != Constant.APC_PDU && !snmpConfiger.SnmpConfig.AgentIp.Equals("127.0.0.1"))
                {
                    try
                    {
                        if (managerLocalIpAddress.Count > 1)
                        {
                            iPAddress = this.getLocalSameNetworkIP(snmpConfiger.SnmpConfig.AgentIp);
                            if (iPAddress.ToString().Equals("127.0.0.1"))
                            {
                                int deviceHttpPort = snmpExecutor.DeviceHttpPort;
                                if (deviceHttpPort > 0)
                                {
                                    iPAddress = this.getLocalConnectibleIP(snmpConfiger.SnmpConfig.AgentIp, deviceHttpPort);
                                    if (iPAddress.ToString().Equals("127.0.0.1"))
                                    {
                                        debug.appendToFile("Failed to get connectiable IP, Device IP: " + snmpConfiger.SnmpConfig.AgentIp);
                                        if (iPAddress.ToString().Equals("127.0.0.1"))
                                        {
                                            iPAddress = managerLocalIpAddress[0];
                                        }
                                    }
                                }
                                else
                                {
                                    debug.appendToFile(string.Concat(new object[]
                                    {
                                        "Failed to get device http port: ",
                                        deviceHttpPort,
                                        ", Device IP: ",
                                        snmpConfiger.SnmpConfig.AgentIp
                                    }));
                                    iPAddress = managerLocalIpAddress[0];
                                }
                            }
                        }
                        TrapReceiverConfiguration trapReceiverConfig = snmpExecutor.GetTrapReceiverConfig(1);
                        if (trapReceiverConfig != null && (trapReceiverConfig.Enabled != open || trapReceiverConfig.TrapVersion != pSys.TrapSnmpVersion || trapReceiverConfig.TrapPort != pSys.TrapPort || trapReceiverConfig.ReceiverIp.ToString() != iPAddress.ToString()))
                        {
                            snmpExecutor.ConfigTrapReceiver(new TrapReceiverConfiguration(1)
                            {
                                AgentVersion = (int)snmpConfiger.SnmpConfig.Version,
                                Enabled      = open,
                                ReceiverIp   = iPAddress,
                                TrapPort     = pSys.TrapPort,
                                TrapVersion  = pSys.TrapSnmpVersion,
                                Community    = pSys.TrapUserName,
                                Username     = pSys.TrapUserName,
                                AuthPassword = pSys.TrapAuthenPwd,
                                PrivPassword = pSys.TrapPrivacyPwd
                            });
                        }
                    }
                    catch (System.Exception)
                    {
                    }
                }
            });
        }