Ejemplo n.º 1
0
 private void ShowData(IOIDSettingDTO data)
 {
     if (data != null)
     {
         ViewHelper.RedirectConsoleToFile(true);
         Console.WriteLine($"OID setting {data.ID} with this definition:\n" +
                           $"\t-Initial OID: {data.InitialOID}\n" +
                           $"\t-Final OID: {data.FinalOID}\n" +
                           $"\t-Inclusive: {data.InclusiveInterval}\n");
         ViewHelper.RedirectConsoleToFile(false);
     }
 }
Ejemplo n.º 2
0
        private void SNMPRunAgent(OctetString Community, IOIDSettingDTO OIDSetting, ISNMPDeviceDataDTO SNMPDeviceData)
        {
            bool            nextEntry = true;
            AgentParameters AgParam;
            Pdu             pdu;
            SnmpV2Packet    Result;
            Oid             indexOid = new Oid(OIDSetting.InitialOID); //Walk control
            Oid             finalOid = new Oid(OIDSetting.FinalOID);

            AgParam         = new AgentParameters(Community);
            AgParam.Version = SnmpVersion.Ver2; // Set SNMP version to 2 (GET-BULK only works with SNMP ver 2 and 3)

            pdu = new Pdu(PduType.GetBulk);
            pdu.NonRepeaters   = 0; //NonRepeaters tells how many OID asociated values (leafs of this object) get. 0 is all
            pdu.MaxRepetitions = 5; // MaxRepetitions tells the agent how many Oid/Value pairs to return in the response packet.
            pdu.RequestId      = 1;

            using (UdpTarget UDPtarget = new UdpTarget(SNMPDeviceData.TargetIP, DefaultPort, DefaultTimeout, DefaultRetries))
            {
                while (nextEntry)
                {
                    pdu.VbList.Add(indexOid); //Add starting OID for request

                    try
                    {
                        Result    = (SnmpV2Packet)UDPtarget.Request(pdu, AgParam);
                        nextEntry = SNMPDecodeData(Result, indexOid, finalOid, OIDSetting.InclusiveInterval, SNMPDeviceData);
                    }
                    catch //(SnmpException e)
                    {
                        throw;
                    }
                    finally
                    {
                        //Prepare PDU object for iteration. Otherwise, wipe contents of pdu
                        pdu.RequestId++;
                        pdu.VbList.Clear();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static void OIDEntryProcessor(ISNMPDeviceDataDTO Device, object StrategyDTOobject, IOIDSettingDTO SelectedSetting, IList <Action <IList <string>, string, object> > MappingHandler)
        {
            string[] RootEntries = SelectedSetting.IndexedOIDSettings.Keys.ToArray();

            //Loop of each subset
            for (int i = 0; i < RootEntries.Length; i++)
            {
                //1) select OID data subset
                IList <ISNMPRawEntryDTO> SelectedDeviceOID = OIDDataSelector(Device, RootEntries[i], i + 1 == RootEntries.Length ? RootEntries[i] : RootEntries[i + 1]);

                if (SelectedDeviceOID != null)
                {
                    //2) apply specific handle on entryparser
                    OIDEntryParser(SelectedDeviceOID, new CustomPair <string, IList <EnumSNMPOIDIndexType> >(RootEntries[i], SelectedSetting.IndexedOIDSettings[RootEntries[i]]), StrategyDTOobject, MappingHandler[i]);
                }
            }
        }