Exemple #1
0
        public string RefreshTestResults(TestModel testModel)
        {
            if (!SNMPHelper.ValidIpHost(testModel.MasterAgentIp))
            {
                return String.Format("Błąd! IP Master Agnet jest nie osiągalne. {0}", testModel);
            }

            IPAddress masterAgentIP = IPAddress.Parse(testModel.MasterAgentIp);
            var receiver = new IPEndPoint(masterAgentIP, 163);

            var vList = new List<Variable>
                {
                    new Variable(
                        new ObjectIdentifier(String.Format(SNMPHelper.TestTreePathFormat, testModel.TestId*4 + 2)))
                };
            IList<Variable> resultList = SNMPHelper.SNMPGet(vList, receiver);
            if (resultList.Count > 0)
            {
                ISnmpData result = resultList[0].Data;

                if (result.ToString() == bool.FalseString)
                {
                    return "Stan NIEpoprawny";
                }

                if (result.ToString() == bool.TrueString)
                {
                    return "Stan poprawny";
                }
            }
            return "Stan NIEpoprawny";
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var ipDestVal = IpDestControl.Text.Replace(',', '.').Replace("_", "");
            var ipSrcVal = IpSrcControl.Text.Replace(',', '.').Replace("_", "");
            var masterAgentIpVal = MasterAgentIpControl.Text.Replace(',', '.').Replace("_", "");

            if (!valiIP(ipSrcVal) || !valiIP(ipDestVal) || !valiIP(masterAgentIpVal))
            {
                MessageBox.Show("Błędnie wpisany adres IP.", "Błąd IP.", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }

            var testCount = (from t in SectionList
                             where t.IpDest == ipDestVal && t.IpSrc == ipSrcVal
                             select t).Count();
            if (testCount != 0) return;

            var testModel = new TestModel
                {
                    ControlUnitIp = IpList.SelectedValue.ToString(),
                    TestId = SectionList.Count,
                    IpSrc = ipSrcVal,
                    IpDest = ipDestVal,
                    MasterAgentIp = masterAgentIpVal
                };

            SectionList.Add(testModel);

            IpSrcControl.Text = "";
            IpDestControl.Text = "";
            MasterAgentIpControl.IsEnabled = false;
            AddGlobalOpinionBtn.IsEnabled = true;
        }
 private void SnmpProviderTrapRecived(object sender, TestModel e)
 {
     Dispatcher.Invoke(DispatcherPriority.Normal, new Action(RefreshResults));
 }
Exemple #4
0
        private void WatcherTrapV1Received(object sender, TrapV1MessageReceivedEventArgs e)
        {
            logger.Info("Trap recived");

            logger.Debug(e);
            foreach (Variable variable in e.TrapV1Message.Scope.Pdu.Variables)
            {
                logger.DebugFormat("Trap var: {0}", variable);
            }

            var testModel = new TestModel();

            //testModel.TestId = Convert.ToInt32(e.TrapV1Message.Scope.Pdu.Variables[0].Data.ToString());
            //testModel.IpDest = e.TrapV1Message.Scope.Pdu.Variables[1].Data.ToString();
            //testModel.Status = e.TrapV1Message.Scope.Pdu.Variables[2].Data.ToString();
            //testModel.IpSrc = e.TrapV1Message.Scope.Pdu.Variables[3].Data.ToString();

            if (TrapRecived != null)
            {
                TrapRecived.Invoke(this, testModel);
            }
        }
Exemple #5
0
        public string UpdateMasterAgentDB(TestModel testModel)
        {
            if (!SNMPHelper.ValidIpHost(testModel.MasterAgentIp))
            {
                return String.Format("Błąd! IP Master Agnet jest nie osiągalne. {0}", testModel);
            }

            IPAddress masterAgentIP = IPAddress.Parse(testModel.MasterAgentIp);
            var receiver = new IPEndPoint(masterAgentIP, 163);

            try
            {
                var vList = new List<Variable>();

                vList.AddRange(testModel.SerializeToMasterAgent());

                SNMPHelper.SNMPSet(vList, receiver);
                return "Master Agent zaktualizowany...";
            }
            catch (Exception e)
            {
                logger.Error(e);
            }
            return String.Format("Błąd! Podczas aktualizacji Master Agent. {0}", testModel);
        }
Exemple #6
0
        public void InsertTestModel(TestModel testModel)
        {
            var sectionDB = new SectionsEntities();

            var test = new Test
                {
                    ID = sectionDB.Test.NextId(v => v.ID),
                    TestID = testModel.TestId,
                    IPDest = testModel.IpDest,
                    IPSrc = testModel.IpSrc,
                    MasterAgentIP = testModel.MasterAgentIp,
                    Number = testModel.Number,
                    ControlUnitIP = testModel.ControlUnitIp
                };

            sectionDB.AddToTest(test);
            sectionDB.SaveChanges();
        }