コード例 #1
0
        static void Main(string[] args)
        {
            //监控设备的ip
            string ip = "127.0.0.1";
            //监控设备的社团名
            String community = "public";

            SimpleSnmp snmp = new SimpleSnmp(ip, community);

            //监控项oid和对应的名称
            Dictionary <string, string> Oids = new Dictionary <string, string>();

            Oids.Add("1.3.6.1.2.1.25.2.2.0", "系统物理内存");
            Oids.Add("1.3.6.1.2.1.25.1.5.0", "主机会话数");
            Oids.Add("1.3.6.1.2.1.25.1.6.0", "系统进程数");

            //通过SNMP v2协议获取信息
            Dictionary <Oid, AsnType> results = snmp.Get(SnmpVersion.Ver2, Oids.Keys.ToArray());

            //显示获取到的信息
            foreach (var result in results)
            {
                var oid = result.Key.ToString().Trim('}', '{');
                if (Oids.ContainsKey(oid))
                {
                    Console.WriteLine($"{Oids[result.Key.ToString()]}  {result.Value}");
                }
            }

            Console.ReadKey();
        }
コード例 #2
0
        public static string ShowMarCondTemp()
        {
            string     host      = "10.136.136.41";
            string     community = "public";
            SimpleSnmp snmp      = new SimpleSnmp(host, community);
            string     temperature;

            if (!snmp.Valid)
            {
                temperature = "SNMP agent host name/ip address is invalid.";
            }
            Dictionary <Oid, AsnType> result = snmp.Get(SnmpVersion.Ver2, new string[] { ".1.3.6.1.4.1.476.1.42.3.9.20.1.20.1.2.1.5002" });

            if (result == null)
            {
                temperature = "Result is NULL";
            }

            //foreach (var item in result.Values)
            //{
            //    temperature = float.Parse(item.ToString());

            //}
            temperature = result.Values.ToString();
            return(temperature);
        }
コード例 #3
0
        public static Dictionary <Oid, AsnType> getNextResult(List <string> oids)
        {
            SimpleSnmp snmp;

            try
            {
                snmp = new SimpleSnmp(address, community);
                if (!snmp.Valid)
                {
                    MessageBox.Show("SNMP agent host name/IP address is invalid.");
                    return(null);
                }
                Dictionary <Oid, AsnType> result = snmp.GetNext(SnmpVersion.Ver1, oids.ToArray());
                if (result == null)
                {
                    MessageBox.Show("No results received.");
                    return(null);
                }

                return(result);
            }
            catch (Exception e)
            {
                MessageBox.Show("SNMP agent host name/IP address is invalid.");
                return(null);
            }
        }
コード例 #4
0
ファイル: Snmp.cs プロジェクト: clifu/SNMP_App_Server
        public Snmp()
        {
            string host      = "127.0.0.1";
            string community = "public";

            _snmp = new SimpleSnmp(host, community);
        }
コード例 #5
0
        public string CheckifisSwitchHP(string ip)
        {
            string pc1 = "";

            try
            {
                String     snmpAgent             = ip;
                String     snmpCommunity         = "public";
                SimpleSnmp snmp                  = new SimpleSnmp(snmpAgent, snmpCommunity);
                Dictionary <Oid, AsnType> result = snmp.Walk(SnmpVersion.Ver2, ".1.3.6.1.2.1");
                if (result == null)
                {
                    pc1 = "Request failed.";
                }
                else
                {
                    foreach (KeyValuePair <Oid, AsnType> entry in result)
                    {
                        pc1 = pc1 + entry.Value.ToString();
                    }
                }
                return(pc1);
            }
            catch (Exception ex)
            {
                pc1 = ex.Message + ex.StackTrace;
                return(pc1);
            }
        }
コード例 #6
0
        public void Metoda()
        {
            string     host      = "localhost";
            string     community = "public";
            SimpleSnmp snmp      = new SimpleSnmp(host, community);

            if (!snmp.Valid)
            {
                Console.WriteLine("SNMP agent host name/ip address is invalid.");
                return;
            }
            Dictionary <Oid, AsnType> result = snmp.Get(SnmpVersion.Ver1,
                                                        new string[] { ".1.3.6.1.2.1.1.1" });

            if (result == null)
            {
                Console.WriteLine("No results received.");
                return;
            }

            foreach (KeyValuePair <Oid, AsnType> kvp in result)
            {
                Console.WriteLine("{0}: {1} {2}", kvp.Key.ToString(),
                                  SnmpConstants.GetTypeName(kvp.Value.Type),
                                  kvp.Value.ToString());
            }
        }
コード例 #7
0
    /// <summary>
    /// Send a SetRequest to the agent to start attacking
    /// </summary>
    /// <param name="selected"></param>
    public void SetAttacking(int selected)
    {
        String     snmpAgent     = "127.0.0.1";
        String     snmpCommunity = "public";
        SimpleSnmp snmp          = new SimpleSnmp(snmpAgent, 16100, snmpCommunity, 2000, 2);
        // Create a set Pdu
        Pdu pdu = new Pdu();

        pdu.Type = PduType.Set;

        pdu.VbList.Add(new Oid(baseTreeOid + ".16"), new Counter32((uint)selected));

        PrintPacketSend(pdu);

        Dictionary <Oid, AsnType> result = snmp.Set(SnmpVersion.Ver1, pdu);

        if (result == null)
        {
            Debug.Log("Manager:Set failed.");
        }
        else
        {
            foreach (KeyValuePair <Oid, AsnType> entry in result)
            {
                attacking = int.Parse(entry.Value.ToString());
            }
        }
    }
コード例 #8
0
ファイル: Program.cs プロジェクト: superuser5/SharpPrinter
        static bool getSnmp(string host, string OID)
        {
            bool result = false;

            SimpleSnmp snmpVerb = new SimpleSnmp(host, 161, "public", 500, 0);

            if (!snmpVerb.Valid)
            {
                return(result);
            }

            Oid varbind = new Oid(OID);

            Dictionary <Oid, AsnType> snmpDataS = snmpVerb.Get(SnmpVersion.Ver1, new string[] { varbind.ToString() });

            if (snmpDataS != null)
            {
                string temp = snmpDataS[varbind].ToString();
                // Get MANUFACTURER
                int    startIndex = temp.IndexOf("MFG:");
                int    endIndex   = temp.IndexOf(";", startIndex);
                string mfg        = temp.Substring(startIndex + 4, endIndex - (startIndex + 4));
                // Get MODEL
                startIndex = temp.IndexOf("MDL:");
                endIndex   = temp.IndexOf(";", startIndex);
                string   printerMDL = temp.Substring(startIndex + 4, endIndex - (startIndex + 4));
                Printers data       = new Printers();
                Printers.PrinterList.Add(host + " " + mfg + " " + printerMDL);
            }
            return(result);
        }
コード例 #9
0
ファイル: ManagerWindow.cs プロジェクト: bpasha7/FinalWork
 private long SNMPWALK(List <string> Vals)
 {
     try
     {
         string     host      = Vals[0];
         string     community = Vals[1];
         SimpleSnmp snmp      = new SimpleSnmp(host, community);
         if (!snmp.Valid)
         {
             //Console.WriteLine("SNMP agent host name/ip address is invalid.");
             return(0);
         }
         Dictionary <Oid, AsnType> result = snmp.Walk(SnmpVersion.Ver1, Vals[2]);
         if (result == null)
         {
             //label1.Text = "No results received.";
             return(0);
         }
         ListData.Add(new OIDValueType(Vals[0]));
         foreach (KeyValuePair <Oid, AsnType> kvp in result)
         {
             ListData[ListData.Count - 1].AddOIDValueType(kvp.Key.ToString(), kvp.Value.ToString().Trim(), SnmpConstants.GetTypeName(kvp.Value.Type));
         }
         return((long)GetDllByName("SNMPData").CallFunctions("Initializate", new object[] { Vals[0], Vals[3], ListData[ListData.Count - 1].GetOIDsAsArray, ListData[ListData.Count - 1].GetValuesAsArray, ListData[ListData.Count - 1].GetTypesAsArray, ListData[ListData.Count - 1].Count }));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message.ToString());
         return(0);
     }
 }
コード例 #10
0
    /// <summary>
    /// Update Ammo information
    /// </summary>
    public void UpdateAmmo()
    {
        SimpleSnmp snmp = new SimpleSnmp(snmpAgent, 16100, snmpCommunity, 2000, 2);
        // Create a request Pdu
        Pdu pdu = new Pdu();

        pdu.Type = PduType.Get;

        pdu.VbList.Add(baseTreeOid + ".6.1.1"); //mg ammo 6
        pdu.VbList.Add(baseTreeOid + ".6.2.1"); //missile ammo 8
        pdu.VbList.Add(baseTreeOid + ".6.3.1"); //rail ammo 10

        PrintPacketSend(pdu);

        Dictionary <Oid, AsnType> result = snmp.Get(SnmpVersion.Ver1, pdu);

        if (result == null)
        {
            Debug.Log("Manager:Set failed.");
            return;
        }


        List <AsnType> list = new List <AsnType>(result.Values);

        //guns
        machineGunAmmo      = int.Parse(list[0].ToString());
        missileLauncherAmmo = int.Parse(list[1].ToString());
        railGunAmmo         = int.Parse(list[2].ToString());
    }
コード例 #11
0
        /// <summary>
        /// GetNext;
        /// </summary>
        protected Dictionary <string, string> GetNext(ref List <string> oid)
        {
            SimpleSnmp SnmpMsg = new SimpleSnmp(this.m_DestIPAddr, this.m_Community);
            Dictionary <string, string> Res    = new Dictionary <string, string>();
            List <string>             NextOids = new List <string>();
            Dictionary <Oid, AsnType> TempRes  = new Dictionary <Oid, AsnType>();

            string[] oidargs;

            if (oid.Count != 0)
            {
                oidargs = oid.ToArray();
                TempRes = SnmpMsg.GetNext(this.m_Version, oidargs);
                if (TempRes != null)
                {
                    oid.Clear();
                    foreach (KeyValuePair <Oid, AsnType> entry in TempRes)
                    {
                        Res.Add(entry.Key.ToString(), entry.Value.ToString());
                        oid.Add(entry.Key.ToString());                                // 将Next信息回填;
                    }
                }
                else
                {
                    oid.Clear();
                }
            }

            return(Res);
        }
コード例 #12
0
        public void Marconmon()
        {
            string host      = "10.136.136.41";
            string community = "public";

            label11condTemp.Text = "proccessing";
            SimpleSnmp snmp = new SimpleSnmp(host, community);

            if (!snmp.Valid)
            {
                label1.Text = "SNMP agent host name/ip address is invalid.";
                return;
            }
            Dictionary <Oid, AsnType> result = snmp.Get(SnmpVersion.Ver2, new string[] { ".1.3.6.1.4.1.476.1.42.3.9.20.1.20.1.2.1.5002" });

            if (result == null)
            {
                return;
            }

            foreach (var item in result.Values)
            {
                label11condTemp.Text = item.ToString();
            }
        }
コード例 #13
0
        public static string[] GetPrinters(string IP)
        {
            string[]   Ipaddr                = new string[5];;
            String     snmpAgent             = IP.ToString(); // printer IP
            String     snmpCommunity         = "public";      //printer community
            SimpleSnmp snmp                  = new SimpleSnmp(snmpAgent, snmpCommunity);
            Dictionary <Oid, AsnType> result = snmp.Get(SnmpVersion.Ver2, new string[] { "1.3.6.1.2.1.43.16.5.1.2.1.1" });

            if (result == null)
            {
            }
            else
            {
                List <string> printerInfo = SNMP.GetName(result, IP);
                Ipaddr[0] = printerInfo[0];
                Ipaddr[1] = printerInfo[1];
                Ipaddr[2] = printerInfo[2];
                Ipaddr[3] = "Devices";
                Ipaddr[4] = "Printers";

                // Found Printer Detail
                //listPrintersInformation = new List<string>();
                //listPrintersInformation.Add("Printer IP: " + IP);
                //listPrintersInformation.Add("Printer Name: " + printerInfo[0]);
                //SNMPPrinterInfo(snmp, ip.ToString());

                return(Ipaddr);
            }
            return(Ipaddr);
        }
コード例 #14
0
        public bool SnmpSetTest(string host, string community, string oid, string octetStromg)
        {
            try
            {
                SimpleSnmp snmp = new SimpleSnmp(host, community);
                if (!snmp.Valid)
                {
                    return(false);
                }
                Dictionary <Oid, AsnType> result = snmp.Set(SnmpVersion.Ver1,
                                                            new Vb[] {
                    new Vb(new Oid(oid),
                           new OctetString(octetStromg))
                });
                if (result == null)
                {
                    return(false);
                }

                LogResult(result);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
コード例 #15
0
        ///
        /// <summary>
        /// Executes the installation process on the SNMP agent.
        /// </summary>
        /// <param name="ts">Target's settings</param>
        /// <param name="uploadFolder">Path of folder with exe update within it</param>
        /// <returns>True if installation was executed successfully</returns>
        public static bool setExecute(TargetSettings ts, string uploadFolder)
        {
            SimpleSnmp snmp = new SimpleSnmp(ts.TargetServer, ts.Community);

            if (!snmp.Valid)
            {
                return(false);
            }

            string d            = ts.DestinationFolder.Substring(1);
            int    i            = uploadFolder.LastIndexOf("\\") + 1;
            string relativePath = uploadFolder.Substring(i);
            string destination  = d.Replace("/", "\\");
            string batFile      = ts.RootPath + destination + relativePath + "\\UpdateVersion.bat";

            Dictionary <Oid, AsnType> result = snmp.Set(SnmpVersion.Ver2,
                                                        new Vb[] {
                new Vb(new Oid("1.3.6.1.4.1.2566.127.1.1.157.3.1.1.10.0"),
                       new OctetString(batFile))
            });

            if (result != null)
            {
                return(true);
            }
            return(false);
        }
コード例 #16
0
        ///
        /// <summary>
        /// Finds the site name of the SNMP Agent.  If site name is retreived, then SNMP commands can be issued.
        /// First tries a DVM command, then if it is not DVM, uses a DVMS command to see if it is instead a DVMS device.
        /// </summary>
        /// <param name="strHost">IP address</param>
        /// <param name="strComm">Community String</param>
        /// <returns>SNMP agent's Site Name</returns>
        public static string getSiteName(string strHost, string strComm)
        {
            SimpleSnmp snmp = new SimpleSnmp(strHost, strComm);

            if (!snmp.Valid)
            {
                return(null);
            }

            Dictionary <Oid, AsnType> resultDVM = snmp.Get(SnmpVersion.Ver1, new string[] { ".1.3.6.1.4.1.2566.127.1.1.157.3.1.1.1.0" });

            if (resultDVM != null)
            {
                foreach (KeyValuePair <Oid, AsnType> kvp in resultDVM)
                {
                    return(kvp.Value.ToString());
                }
            }

            //Now tries DVMS command
            Dictionary <Oid, AsnType> resultDVMs = snmp.Get(SnmpVersion.Ver1, new string[] { ".1.3.6.1.4.1.2566.127.1.1.152.3.1.1.1.0" });

            if (resultDVMs != null)
            {
                foreach (KeyValuePair <Oid, AsnType> kvp in resultDVMs)
                {
                    return(kvp.Value.ToString());
                }
            }
            return(null);
        }
コード例 #17
0
        internal async void PrinterInkLevel(string printerName)
        {
            Task T = Task.Run(() =>
            {
                try
                {
                    string all = "";
                    if (printerName.Contains("."))
                    {
                        all = printerName;
                    }
                    else
                    {
                        all = GetPrinterIP(printerName);
                    }
                    simplesnmp = new SimpleSnmp(all, 161, "public", 2000, 3);
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                    return;
                }
                if (simplesnmp != null)
                {
                    GetToner();
                }
            });
            await Task.WhenAny(T);

            InkLevelWindow inkWindow = new InkLevelWindow(Printertoners, printerName);

            inkWindow.ShowDialog();
        }
コード例 #18
0
ファイル: SNMP_Agent.cs プロジェクト: clifu/SNMP_client
        /// <summary>
        /// Konstruktor, ustawia "localhost" i "public"
        /// </summary>
        public SNMP_Agent()
        {
            //Stworzenie nowego obiektu klasy z narzedziami do SNMP, dzialajacej na lokalnym hoscie i w publicznej sieci
            snmp = new SimpleSnmp("localhost", "public");

            //Stworzenie nowego celu UDP
            target = new UdpTarget(snmp.PeerIP, 161, 2000, 1);
        }
コード例 #19
0
 protected override void BeginProcessing()
 {
     base.BeginProcessing();
     _SimpleSnmp           = new SimpleSnmp();
     _SimpleSnmp.Community = _Community;
     _SimpleSnmp.Retry     = _Retry;
     _SimpleSnmp.PeerPort  = _Port;
     _SimpleSnmp.Timeout   = _TimeOut;
 }
コード例 #20
0
    /// <summary>
    /// Send a SetRequest to the agent to select a target
    /// </summary>
    /// <param name="selected"></param>
    public void SetTarget(int selected)
    {
        String     snmpAgent     = "127.0.0.1";
        String     snmpCommunity = "public";
        SimpleSnmp snmp          = new SimpleSnmp(snmpAgent, 16100, snmpCommunity, 2000, 2);
        // Create a set Pdu
        Pdu pdu = new Pdu();

        pdu.Type = PduType.Set;

        pdu.VbList.Add(new Oid(baseTreeOid + ".14"), new Counter32((uint)selected));

        PrintPacketSend(pdu);

        Dictionary <Oid, AsnType> result = snmp.Set(SnmpVersion.Ver1, pdu);

        if (result == null)
        {
            Debug.Log("Manager:Set failed.");
        }
        else
        {
            foreach (KeyValuePair <Oid, AsnType> entry in result)
            {
                selectedTarget = int.Parse(entry.Value.ToString());
            }
        }

        if (selected == 0)
        {
            Enemy1.transform.GetChild(1).gameObject.SetActive(true);
        }
        else
        {
            Enemy1.transform.GetChild(1).gameObject.SetActive(false);
        }

        if (selected == 1)
        {
            Enemy2.transform.GetChild(1).gameObject.SetActive(true);
        }
        else
        {
            Enemy2.transform.GetChild(1).gameObject.SetActive(false);
        }

        if (selected == 2)
        {
            Enemy3.transform.GetChild(1).gameObject.SetActive(true);
        }
        else
        {
            Enemy3.transform.GetChild(1).gameObject.SetActive(false);
        }
    }
コード例 #21
0
        private void SetDataSnrERD(string oid, int data)
        {
            var snmp = new SimpleSnmp(IpAddress, Community);
            Pdu pdu  = new Pdu
            {
                Type = PduType.Set
            };

            pdu.VbList.Add(new Oid(oidTestFlag), new Integer32(data));
            Dictionary <Oid, AsnType> result = snmp.Set(SnmpVersion.Ver1, pdu);
        }
コード例 #22
0
        private void loadSNMPParameters(out SimpleSnmp snmp)
        {
            int timeOut = 10;
            // TODO: timeout by better way
            int    retry     = 3;
            string IpAddress = txtIPAddress.Text;
            int    port      = Convert.ToInt32(txtPort.Text);
            string community = txtCommunityString.Text;

            snmp = new SimpleSnmp(IpAddress, port, community, timeOut, retry);
        }
コード例 #23
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            if (txtOIDValue.Text.Trim().Length <= 0)
            {
                toast.ShowAlert("Xin hãy nhập OID:");
            }
            else
            {
                Pdu pdu = new Pdu();
                Dictionary <Oid, AsnType> dicOID = null;
                SimpleSnmp snmp = null;

                loadSNMPParameters(out snmp);
                SnmpVersion version = SnmpVersion.Ver2;
                if (cbbSNMPVersion.SelectedItem.Equals("1"))
                {
                    version = SnmpVersion.Ver1;
                }

                VbCollection vbList = new VbCollection();
                vbList.Add(txtOIDValue.Text);

                pdu.SetVbList(vbList);

                switch (cbbCommand.SelectedItem)
                {
                case "Get":
                    pdu.Type = PduType.Get;
                    dicOID   = snmp.Get(version, pdu);
                    break;

                case "Get Next":
                    pdu.Type = PduType.GetNext;
                    dicOID   = snmp.Get(version, pdu);
                    break;

                case "Get Bulk":
                    pdu.Type            = PduType.GetBulk;
                    snmp.MaxRepetitions = 20;
                    dicOID = snmp.Get(version, pdu);
                    break;
                }


                if (dicOID != null && dicOID.Count > 0)
                {
                    this.mgResponseQueue.Enqueue(dicOID);
                }
            }
        }
コード例 #24
0
ファイル: SNMP_Agent.cs プロジェクト: clifu/SNMP_client
        /// <summary>
        /// Konstruktor, ustawiający peerName i community. W przypadku błędu ustawi peerName na"localhost" i
        /// community na "public"
        /// </summary>
        /// <param name="peerName"></param>
        /// <param name="community"></param>
        public SNMP_Agent(string peerName, string community)
        {
            try
            {
                snmp = new SimpleSnmp(peerName, community);

                //Stworzenie nowego celu UDP
                target = new UdpTarget(snmp.PeerIP, 161, 2000, 1);
            }
            catch (Exception E)
            {
                Console.WriteLine("SNMP_Agent's constructor: " + E.Message);
                snmp = new SimpleSnmp("localhost", "public");
            }
        }
コード例 #25
0
        private string GetDataSnrERD(string oid)
        {
            string value = "";
            var    snmp  = new SimpleSnmp(IpAddress, Community);
            Dictionary <Oid, AsnType> result = snmp.Get(SnmpVersion.Ver1, new[] { oid });

            if (result == null)
            {
                return(value);
            }
            foreach (var kvp in result)
            {
                value += kvp.Value;
            }
            return(value);
        }
コード例 #26
0
 protected override void BeginProcessing()
 {
     base.BeginProcessing();
     _SimpleSnmp           = new SimpleSnmp();
     _SimpleSnmp.Community = _Community;
     _SimpleSnmp.Retry     = _Retry;
     _SimpleSnmp.PeerPort  = _Port;
     _SimpleSnmp.Timeout   = _TimeOut;
     if (_Force)
     {
         _RootOID = null;
     }
     else
     {
         _RootOID = new Oid(_Oid.ToString());
     }
 }
コード例 #27
0
        public string GetString(string oid)
        {
            Console.WriteLine("weszlo w GetString");
            if (_snmp == null)
            {
                string host      = "127.0.0.1";
                string community = "public";
                _snmp = new SimpleSnmp(host, community);
            }

            string[] value = get(oid);

            string wartosc = value[2];

            //Console.WriteLine(wartosc);
            return(wartosc);
        }
コード例 #28
0
        public SnmpTypeObject Get(SnmpTypeObject snmpObject)
        {
            Console.WriteLine("Weszlo do geta restowego");
            if (_snmp == null)
            {
                string host      = "127.0.0.1";
                string community = "public";
                _snmp = new SimpleSnmp(host, community);
            }

            string[] value = get(snmpObject.Oid);
            // NIE WIEM CO MA BYC ZWRACANE CZY TYLKO VALUE CZY CALA TABLICA
            snmpObject.Oid   = value[0];
            snmpObject.Type  = value[1];
            snmpObject.Value = value[2];
            return(snmpObject);
        }
コード例 #29
0
        private void WaitForCurrentConnectionsToDrain(string farm, string server, string snmpEndpoint, int snmpPort, string snmpCommunity, DateTime timeout)
        {
            if (DateTime.Now > timeout)
            {
                throw new ConDepLoadBalancerException(string.Format("Timed out while taking {0} offline in load balancer.", server));
            }

            Logger.Verbose("Connecting to snmp using " + snmpEndpoint + " on port " + snmpPort + " with community " + snmpCommunity);
            var snmp = new SimpleSnmp(snmpEndpoint, snmpPort, snmpCommunity);

            Logger.Verbose("Getting snmp info about farm " + farm);
            var farmResult = snmp.Walk(SnmpVersion.Ver2, FARM_NAMES_OID);
            var farmOid    = farmResult.Single(x => x.Value.Clone().ToString() == farm);

            var id        = farmOid.Key.ToString();
            var start     = farmOid.Key.ToString().LastIndexOf(".");
            var farmSubId = id.Substring(start + 1, id.Length - start - 1);

            Logger.Verbose("Getting snmp info about server " + server);
            var serverResult = snmp.Walk(SnmpVersion.Ver2, SERVER_NAMES_OID + farmSubId);
            var serverOid    = serverResult.Single(x => x.Value.Clone().ToString() == server);

            var serverId = serverOid.Key.ToString();

            start = serverOid.Key.ToString().LastIndexOf(".");
            var serverSubId = serverId.Substring(start + 1, serverId.Length - start - 1);

            Logger.Verbose("Getting current server sessions for server " + server);
            var pdu = Pdu.GetPdu();

            pdu.VbList.Add(SERVER_CUR_SESSIONS_OID + farmSubId + "." + serverSubId);
            var currentSessionsVal = snmp.Get(SnmpVersion.Ver2, pdu);
            var val = currentSessionsVal.Single().Value.Clone() as Counter64;

            if (val > 0)
            {
                Logger.Verbose("Server " + server + " has " + val + " active sessions.");
                var waitInterval = 3;
                Logger.Warn(string.Format("There are still {0} active connections on server {1}. Waiting {2} second before retry.", val, server, waitInterval));
                Thread.Sleep(1000 * waitInterval);
                WaitForCurrentConnectionsToDrain(farm, server, snmpEndpoint, snmpPort, snmpCommunity, timeout);
            }

            Logger.Verbose("Server " + server + " has 0 active session and is now offline.");
        }
コード例 #30
0
        private void GetSNMPStuff()
        {
            SimpleSnmp snmpVerb = new SimpleSnmp(Address.ToString(), 161, "public");

            if (!snmpVerb.Valid)
            {
                Console.WriteLine("Unable to access community");
                return;
            }
            Dictionary <Oid, AsnType> x = snmpVerb.Walk(SnmpVersion.Ver2, ".1.3.6.1.4.1.2021.11.10.0");

            if (x.Count > 0)
            {
                foreach (Oid xx in x.Keys)
                {
                    Console.WriteLine(xx);
                }
            }
        }