GetBulk() public method

SNMP GET-BULK request
GetBulk request type is only available with SNMP v2c agents. SNMP v3 also supports the request itself but that version of the protocol is not supported by SimpleSnmp. GetBulk method will return a dictionary of Oid to value mapped values as returned form a single GetBulk request to the agent. You can change how the request itself is made by changing the SimpleSnmp.NonRepeaters and SimpleSnmp.MaxRepetitions values. SimpleSnmp properties are only used when values in the parameter Pdu are set to 0.
public GetBulk ( Pdu pdu ) : AsnType>.Dictionary
pdu Pdu Request Protocol Data Unit
return AsnType>.Dictionary
示例#1
0
       public bool SnmpBulkGetTest(string host, string community, string[] oids)
       {

           try
           {
               SimpleSnmp snmp = new SimpleSnmp(host, community);
               if (!snmp.Valid)
               {
                   return false;
               }
               Dictionary<Oid, AsnType> result = snmp.GetBulk(oids);
               if (result == null)
               {
                   return false;
               }

               LogResult(result);
               return true;
           }
           catch (Exception)
           {
               return false;
           }
       }
示例#2
0
        private void SNMPGetInfo()
        {
            if (this.krbSNMP.Checked)
            {
                try
                {
                    SimpleSnmp snmp = new SimpleSnmp(Properties.Settings.Default.ip, this.kcbCommunity.SelectedItem.ToString());
                    snmp.Retry = 5;
                    snmp.Timeout = 60000;
                    snmp.SuppressExceptions = false;
                    string oid = Properties.Settings.Default.oid;
                    Dictionary<Oid, AsnType> result = null;
                    if (this.kcbMethod.SelectedItem.ToString() == "Get NEXT")
                    {
                        Pdu pdu = new Pdu();
                        pdu.Type = PduType.GetNext;
                        pdu.VbList.Add(oid);
                        result = snmp.GetNext(SnmpVersion.Ver1, pdu);
                    }
                    else if (this.kcbMethod.SelectedItem.ToString() == "GET")
                    {
                        // Create a request Pdu
                        Pdu pdu = new Pdu();
                        pdu.Type = PduType.Get;
                        pdu.VbList.Add(oid);
                        result = snmp.GetNext(SnmpVersion.Ver1, pdu);
                    }
                    else if (this.kcbMethod.SelectedItem.ToString() == "Walk")
                    {
                        result = snmp.Walk(SnmpVersion.Ver2, oid);
                    }
                    else if (this.kcbMethod.SelectedItem.ToString() == "Get BULK")
                    {
                        //Using GetBulk
                        Pdu pdu = new Pdu();
                        pdu.Type = PduType.GetBulk;
                        pdu.VbList.Add(oid);
                        pdu.NonRepeaters = 0;
                        pdu.MaxRepetitions = Convert.ToInt32(this.krypTxtBxRepeaters.Text);
                        result = snmp.GetBulk(pdu);
                    }

                    ktbResult.SuspendLayout();
                    ktbResult.Clear();
                    if (result == null)
                    {
                        ktbResult.AppendText("Request failed.\r\n");
                    }
                    else
                    {
                        ktbResult.SuspendLayout();
                        foreach (KeyValuePair<Oid, AsnType> entry in result)
                        {
                            ktbResult.AppendText(String.Format("{0} = {1}: {2}\r\n", entry.Key.ToString(), SnmpConstants.GetTypeName(entry.Value.Type),
                              entry.Value.ToString()));
                        }
                        ktbResult.ResumeLayout();
                    }
                }
                catch (Exception snmpEx)
                {
                    ComponentFactory.Krypton.Toolkit.KryptonMessageBox.Show(snmpEx.Message,
                        "SNMP Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                ktbResult.Focus();
                ktbResult.SelectionStart = 0;
                ktbResult.SelectionLength = 0;
                ktbResult.ScrollToCaret();
                ktbResult.ResumeLayout();
            }
        }