Exemple #1
0
 // GET: Diagram
 public ActionResult Index()
 {
     using (IDbConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DeviceConnection"].ConnectionString))
     {
         device_tower_IP = "192.168.24.12";
         device          = connection.Query <MibGet>($"select * from MibGet where IP='{device_tower_IP}'").FirstOrDefault();
     }
     //
     //device = db.MibGets.Where(d => d.IP =='192.168.24.12').FirstOrDefault().ID;
     //page = 1;
     return(View());
 }
Exemple #2
0
        public void ThreadPreset(int WalkID, int StringParserInd, string DivideMultiply, int ID, int TowerID, string IP, int time, int Deviceid, string getOid, string Version, string StartCorrect, string EndCorrect, string OneStartError, string OneEndError, string OneStartCrash, string OneEndCrash, string TwoStartError, string TwoEndError, string TwoStartCrash, string TwoEndCrash)
        {
            var context = GlobalHost.ConnectionManager.GetHubContext <HubMessage>();
            // string Version = "V2";
            var    values        = "";
            string communityRead = "public";
            int    Port          = 161;

            while (true)
            {
                OctetString community = new OctetString(communityRead);

                AgentParameters param = new AgentParameters(community);
                if (Version == "V1")
                {
                    param.Version = SnmpVersion.Ver1;
                }
                if (Version == "V2")
                {
                    param.Version = SnmpVersion.Ver2;
                }
                IpAddress agent = new IpAddress(IP);

                UdpTarget target = new UdpTarget((IPAddress)agent, Port, 2000, 1);

                Pdu pdu = new Pdu(PduType.Get);
                try
                {
                    if (pdu.RequestId != 0)
                    {
                        pdu.RequestId += 1;
                    }
                    pdu.VbList.Clear();
                    pdu.VbList.Add(getOid);

                    if (Version == "V1")
                    {
                        result = (SnmpV1Packet)target.Request(pdu, param);
                    }
                    if (Version == "V2")
                    {
                        result = (SnmpV2Packet)target.Request(pdu, param);
                    }

                    foreach (Vb v in result.Pdu.VbList)
                    {
                        MibGet get = new MibGet();
                        get.Value    = v.Value.ToString();
                        get.DeviceID = Deviceid;
                        get.dateTime = DateTime.Now;
                        get.WalkOID  = v.Oid.ToString();
                        get.IP       = IP;
                        get.WalkID   = WalkID;
                        if (StringParserInd == 1)
                        {
                            char[] arr = get.Value.ToCharArray();
                            get.Value = new string(Array.FindAll <char>(arr, (c => (char.IsDigit(c) || c == '.'))));
                            values    = new string(Array.FindAll <char>(arr, (c => (char.IsLetterOrDigit(c) || char.IsWhiteSpace(c) || c == '.'))));
                        }
                        get.ResultCorrectError = correctError.CompareCorrectError(WalkID, values, DivideMultiply, Deviceid, ID, TowerID, get.Value, StartCorrect, EndCorrect, OneStartError, OneEndError, OneStartCrash, OneEndCrash, TwoStartError, TwoEndError, TwoStartCrash, TwoEndCrash);

                        db.MibGets.Add(get);
                        db.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    var ks = 1;
                }

                target.Close();
                Thread.Sleep((time * 1000));
            }
        }