コード例 #1
0
 private void ShowData(ISNMPRawEntryDTO data)
 {
     if (data != null)
     {
         ViewHelper.RedirectConsoleToFile(true);
         Console.WriteLine($"OID entry of {data.RegardingObject.TargetIP}. Identifier: {data.OID}. DataType: {data.DataType}. Value: {data.ValueData}.\n");
         ViewHelper.RedirectConsoleToFile(false);
     }
 }
コード例 #2
0
ファイル: SNMPModel.cs プロジェクト: mjesusext/ASPB_SNMP
        private bool SNMPDecodeData(SnmpV2Packet Result, Oid indexOid, Oid finalOid, bool InclusiveInterval, ISNMPDeviceDataDTO SNMPDeviceData)
        {
            bool nextEntry = true;

            if (Result != null && Result.Pdu.ErrorStatus == 0)
            {
                // Walk through returned variable bindings
                foreach (Vb ResBinding in Result.Pdu.VbList)
                {
                    // Check that retrieved Oid is higher than the limit or is the last block of leafs
                    if (ResBinding.Oid < finalOid || finalOid.IsRootOf(ResBinding.Oid) && InclusiveInterval)
                    {
                        //Check OID Value Type. If unknown we break loop and storage
                        EnumSNMPOIDType OIDType = (EnumSNMPOIDType)Enum.Parse(typeof(EnumSNMPOIDType), SnmpConstants.GetTypeName(ResBinding.Value.Type));

                        if (OIDType != EnumSNMPOIDType.Unknown)
                        {
                            ISNMPRawEntryDTO SNMPRawData = SNMPDeviceData.BuildSNMPRawEntry(ResBinding.Oid.ToString(), ResBinding.Value.ToString(), OIDType);
                        }
                        else
                        {
                            nextEntry = false;
                            break;
                        }

                        //Check if we have already drilled down all contents
                        if (ResBinding.Value.Type != SnmpConstants.SMI_ENDOFMIBVIEW)
                        {
                            indexOid.Set(ResBinding.Oid); //If we use = operator, we are changing references! In that case, ref keyword is mandatory
                            nextEntry = true;
                        }
                    }
                    else
                    {
                        nextEntry = false;
                        break;
                    }
                }
            }
            else
            {
                //Console.WriteLine("Error in SNMP reply. Error {0} index {1}", Result.Pdu.ErrorStatus, Result.Pdu.ErrorIndex);
            }

            return(nextEntry);
        }
コード例 #3
0
ファイル: StrategyHelper.cs プロジェクト: mjesusext/ASPB_SNMP
        public static void OIDIndexEntryParser(CustomPair <string, IList <EnumSNMPOIDIndexType> > IndexOIDSetting, ISNMPRawEntryDTO RawEntry, IList <string> IndexData)
        {
            List <int> indexValues = RawEntry.OID.Replace(IndexOIDSetting.First + ".", "").Split('.').Select(x => int.Parse(x)).ToList();

            foreach (EnumSNMPOIDIndexType IndexType in IndexOIDSetting.Second)
            {
                switch (IndexType)
                {
                case EnumSNMPOIDIndexType.Number:
                    IndexData.Add(indexValues[0].ToString());
                    indexValues.RemoveAt(0);

                    break;

                case EnumSNMPOIDIndexType.MacAddress:
                    IndexData.Add(string.Join(" ", indexValues.Take(6).Select(x => x.ToString("X").PadLeft(2, '0'))));
                    indexValues.RemoveRange(0, 6);

                    break;

                case EnumSNMPOIDIndexType.IP:
                    break;

                case EnumSNMPOIDIndexType.Date:
                    break;

                case EnumSNMPOIDIndexType.ByteString:
                    break;

                case EnumSNMPOIDIndexType.Oid:
                    break;

                default:
                    break;
                }
            }
        }