Пример #1
0
        private void CalcPing()
        {
            double lostRate = _cache.Count(n => n.Status != IPStatus.Success) / _cache.Count;
            double delay    = _cache.Average(n => n.RoundtripTime);
            //bool state = lostRate > 0;
            bool state = lostRate == 0;
            var  time  = DateTime.Now;

            _lastTime = time;
            _state    = new PingState()
            {
                Ip          = _param.Ip,
                CollectTime = time,
                Delay       = delay,
                LostRate    = lostRate,
                State       = state
            };
            _cache.Clear();
            //报警
            Collected?.Invoke(_param.Id, _state);
            _inWork = false;
        }
Пример #2
0
        /// <summary>
        /// 修改线路状态、Alarm的恢复时间
        /// </summary>
        /// <param name="id">线路Id</param>
        /// <param name="pingState"></param>
        public void UpdateStateToDB(int id, PingState pingState)
        {
            try
            {
                //string condition = "AND Id = @Id";
                //var item = MonitorADOProvider.GetInstance().GetLineModel(condition, new { Id = id });
                ////if (item == null)
                ////{
                ////    throw new Exception("所要修改的信息不存在,请重试");
                ////}
                ////string field = "ConnectState=@ConnectState,Log=@Log,CheckDate=@CheckDate";
                ////item.ConnectState = pingState.State;
                ////item.CheckDate = pingState.CollectTime;
                ////item.Log = pingState.GetInfo();
                //////new LineDataProvider().Update(field, condition, item);
                ////_provider.Update(field, condition, item);
                //////_provider.Update(field, condition, new { Id = id, ConnectState = pingState.State, Log = pingState.Info });



                ////MonitorADOProvider.GetInstance().ExistLineModel(id)
                //if (item != null)
                //{
                MonitorADOProvider.GetInstance().UpdateLineState(new LineModel()
                {
                    Id = id, CheckDate = pingState.CollectTime, ConnectState = pingState.State
                });
                //}
                //else
                //{
                //    throw new Exception("所要修改的信息不存在,请重试");
                //}
            }
            catch (Exception ex)
            {
                //LogBusiness.GetInstance().Add(new LogModel() { Content = ex.Message + ex.StackTrace, Time = DateTime.Now, Type = LogType.AlarmManage, Username = "******" });
            }
        }
Пример #3
0
        private void CalcPing()
        {
            //double lostRate = _cache.Count(n => n.Status == IPStatus.Success) / _cache.Count;
            double lostRate = _cache.Count(n => n.Status != IPStatus.Success) / _cache.Count;
            double delay    = _cache.Average(n => n.RoundtripTime);
            //bool state = lostRate > 0;
            bool state = lostRate == 0;
            var  time  = DateTime.Now;

            _lastTime = time;
            _state    = new PingState()
            {
                Ip          = _param.Ip,
                CollectTime = time,
                Delay       = delay,
                //深拷贝
                //Info = new List<PingReply>(_cache),
                LostRate = lostRate,
                State    = state
            };
            //报警
            Collected?.Invoke(_param.Id, _state);
        }
Пример #4
0
 private void OnCollected(int id, PingState state)
 {
     Report?.Invoke(id, state);
 }
Пример #5
0
        /// <summary>
        /// 返回结果,直接写入数据库(alarm,alarm_log,line)
        /// </summary>
        /// <param name="id">线路Id</param>
        /// <param name="pingState"></param>
        public void WriteAlarmToDB(int id, PingState pingState)
        {
            lock (_lock)
            {
                try
                {
                    if (!_catch.ContainsKey(id))
                    {
                        _catch.Add(id, new LineAlarmCache()
                        {
                            Alarm = null, Count = 0
                        });
                    }

                    if (!pingState.State)
                    {
                        _catch[id].Count++;
                        if (_catch[id].Alarm == null)
                        {
                            LineModel line = new LineBusiness().GetItem(id);
                            if (_catch[id].Count >= line.AlarmMax)
                            {
                                _catch[id].Alarm = new AlarmModel()
                                {
                                    AlarmCount = 1,
                                    Confirm    = false,
                                    FirstTime  = pingState.CollectTime,
                                    IP         = line.LineIP,
                                    LineId     = line.Id,
                                    LineName   = line.Name,
                                    OrganId    = line.OrganizationId,
                                    OrganName  = line.OrganizationName,
                                    State      = AlarmStateType.OnAlarm,
                                    LastTime   = pingState.CollectTime,
                                    Type       = AlarmType.LineNotConnected
                                };
                                //状态改为 正在告警
                                MonitorADOProvider.GetInstance().InsertAlarm(_catch[id].Alarm);
                                SendMessage?.Invoke(_catch[id].Alarm, line.SMSTelphone);
                            }
                        }
                        else
                        {
                            if (_catch[id].Alarm.Id == 0)
                            {
                                _catch[id].Alarm = MonitorADOProvider.GetInstance().GetLastestAlarm(id, AlarmType.LineNotConnected);
                            }
                            //更新次数和最后时间
                            MonitorADOProvider.GetInstance().UpdateAlarm(_catch[id].Alarm.Id, pingState.CollectTime);
                        }
                    }
                    else
                    {
                        if (_catch[id].Alarm != null)
                        {
                            if (_catch[id].Alarm.Id == 0)
                            {
                                _catch[id].Alarm = MonitorADOProvider.GetInstance().GetLastestAlarm(id, AlarmType.LineNotConnected);
                            }
                            LineModel line = MonitorADOProvider.GetInstance().GetLineModel(id);
                            MonitorADOProvider.GetInstance().RecoverAlarm(_catch[id].Alarm.Id, DateTime.Now, AlarmStateType.Recover);
                            SendMessage?.Invoke(_catch[id].Alarm, line.SMSTelphone);
                        }
                    }



                    //var alarm = _catch[id].Provider.GetLastestAlarm(id, AlarmType.LineNotConnected);
                    //if (!pingState.State)
                    //{
                    //    _catch[id].Count++;

                    //    //根据告警策略 更新 告警状态
                    //    if (alarm == null)
                    //    {
                    //        LineModel line = new LineBusiness().GetItem(id);
                    //        //肯定是有alarm的
                    //        if (_catch[id].Count >= line.AlarmMax)
                    //        {
                    //            alarm = new AlarmModel()
                    //            {
                    //                AlarmCount = 1,
                    //                Confirm = false,
                    //                FirstTime = pingState.CollectTime,
                    //                IP = line.LineIP,
                    //                LineId = line.Id,
                    //                LineName = line.Name,
                    //                OrganId = line.OrganizationId,
                    //                OrganName = line.OrganizationName,
                    //                State = AlarmStateType.OnAlarm,
                    //                LastTime = pingState.CollectTime,
                    //                Type = AlarmType.LineNotConnected
                    //            };
                    //            //状态改为 正在告警
                    //            _catch[id].Provider.InsertSync(alarm);
                    //            SendMessage?.Invoke(alarm, line.SMSTelphone);
                    //        }
                    //    }
                    //    else
                    //    {
                    //        //更新次数和最后时间
                    //        string condition = "AND Id = @Id";
                    //        string field = "AlarmCount=@AlarmCount,LastTime=@LastTime";
                    //        _catch[id].Provider.UpdateSync(condition, field, new { Id = alarm.Id, AlarmCount = alarm.AlarmCount + 1, LastTime = pingState.CollectTime });
                    //    }
                    //}
                    //else
                    //{
                    //    if (alarm != null)
                    //    {
                    //        LineModel line = new LineBusiness().GetItem(id);
                    //        alarm.RecoverDate = pingState.CollectTime;
                    //        alarm.State = AlarmStateType.Recover;
                    //        //alarm.AlarmCount = _catch[id].Count;
                    //        _catch[id].Provider.AddRecoverDate(alarm);
                    //        SendMessage?.Invoke(alarm, line.SMSTelphone);
                    //    }
                    //}
                }
                catch (Exception ex)
                {
                }
            }
        }