Пример #1
0
        public string[] RestoreThresholds2Device()
        {
            string failMAC    = "";
            string successDID = "";
            string misMAC     = "";
            SystemThreadPool <SnmpConfiger, bool> systemThreadPool = new SystemLargeThreadPool <SnmpConfiger, bool>(this.snmpConfigs);

            systemThreadPool.GetResults(delegate(System.Collections.ICollection coll, object obj)
            {
                SnmpConfiger snmpConfiger = (SnmpConfiger)obj;
                SnmpExecutor snmpExecutor = new DefaultSnmpExecutor(snmpConfiger);
                try
                {
                    bool flag = false;
                    int num   = snmpExecutor.CheckDeviceMac(snmpConfiger.DeviceMac);
                    if (num >= 0)
                    {
                        flag = snmpExecutor.UpdateDeviceName(snmpConfiger.RestoreThresholds.DeviceName);
                    }
                    else
                    {
                        if (num == -1)
                        {
                            lock (DefaultSnmpExecutors.lockRestore)
                            {
                                misMAC = misMAC + snmpConfiger.DeviceMac + ",";
                            }
                        }
                    }
                    if (flag)
                    {
                        DevicePOPSettings devicePOPSettings = new DevicePOPSettings();
                        devicePOPSettings.copyPOPSetings(snmpConfiger.RestoreThresholds.DeviceThreshold);
                        snmpExecutor.SetDevicePOPSettings(devicePOPSettings);
                        snmpExecutor.SetDeviceThreshold(snmpConfiger.RestoreThresholds.DeviceThreshold);
                        for (int i = 0; i < snmpConfiger.RestoreThresholds.SensorThreshold.Count; i++)
                        {
                            snmpExecutor.SetSensorThreshold(snmpConfiger.RestoreThresholds.SensorThreshold[i + 1]);
                        }
                        for (int j = 0; j < snmpConfiger.RestoreThresholds.BankThreshold.Count; j++)
                        {
                            snmpExecutor.SetBankThreshold(snmpConfiger.RestoreThresholds.BankThreshold[j + 1]);
                        }
                        for (int k = 0; k < snmpConfiger.RestoreThresholds.OutletThreshold.Count; k++)
                        {
                            snmpExecutor.SetOutletThreshold(snmpConfiger.RestoreThresholds.OutletThreshold[k + 1]);
                        }
                        for (int l = 0; l < snmpConfiger.RestoreThresholds.LineThreshold.Count; l++)
                        {
                            snmpExecutor.SetLineThreshold(snmpConfiger.RestoreThresholds.LineThreshold[l + 1]);
                        }
                    }
                    if (!flag)
                    {
                        lock (DefaultSnmpExecutors.lockRestore)
                        {
                            failMAC = failMAC + snmpConfiger.DeviceMac + ",";
                            goto IL_217;
                        }
                    }
                    lock (DefaultSnmpExecutors.lockRestore)
                    {
                        successDID = successDID + snmpConfiger.DeviceID + ",";
                    }
                    IL_217:;
                }
                catch (System.Exception ex)
                {
                    lock (DefaultSnmpExecutors.lockRestore)
                    {
                        failMAC = failMAC + snmpConfiger.DeviceMac + ",";
                    }
                    DebugCenter instance = DebugCenter.GetInstance();
                    instance.appendToFile("Failed to restore config to device: " + snmpConfiger.RestoreThresholds.DeviceName + ", " + ex.Message);
                }
            });
            return(new string[]
            {
                failMAC,
                successDID,
                misMAC
            });
        }
Пример #2
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)
                    {
                    }
                }
            });
        }