public static CheckReesultInfo ExtractionPingResult(string ipV4, string port, string remarks, DateTime receiveTime, string resultMessage)
        {
            //空串证明地址ping出了异常
            if (string.IsNullOrWhiteSpace(resultMessage))
            {
                //既然已经异常了,就退出当前任务执行,可以考虑统计同一个地址出错次数,一定时间内冻结任务,避免过多的访问不正常的地址
                return(new CheckReesultInfo(ipV4, port, remarks, PingResultStatus.Exception, receiveTime));
            }

            try
            {
                return(CheckReesultInfo.CreateFromExtractInfo(ipV4, port, remarks, receiveTime, ExtractChainFactory.GetExtractChain().Extract(resultMessage)));
            }
            catch (System.Exception ex)
            {
                //todo:日志记录
                System.Console.WriteLine(ex.Message);

                return(new CheckReesultInfo(ipV4, port, remarks, PingResultStatus.Exception, receiveTime));
            }
        }
Exemple #2
0
        /// <summary>
        /// 尝试异步ping目标地址
        /// </summary>
        /// <param name="timeout">超时时间</param>
        /// <param name="tryCount">ping的次数</param>
        /// <returns></returns>
        public Task TryPingAsync(int timeout, int tryCount)
        {
            return(Task.Run(async() =>
            {
                string pingResult = await CheckTargetService.PingRemoteTargetAsync(this, timeout, tryCount);

                Console.WriteLine(pingResult);

                //NLogMgr.DebugLog(_programLog, $"TryPingAsync=>{this.Remarks}调用结束{Environment.NewLine}");
                Console.WriteLine($"TryPingAsync=>{this.Remarks}调用结束{Environment.NewLine}");

                ////返回空串证明地址ping出了异常
                //if (string.IsNullOrWhiteSpace(pingResult))
                //{
                //    //既然已经异常了,就退出当前任务执行,可以考虑统计同一个地址出错次数,一定时间内冻结任务,避免过多的访问不正常的地址
                //    return;
                //}

                CheckReesultInfo checkReesultInfo = await CheckResultService.UnscramblePingResultAsync(IpAddresV4, TargetPort, Remarks, TimeMgr.GetLoaclDateTime(), pingResult);



                NLogMgr.DebugLog(_programLog, checkReesultInfo.GetResultInfoString());
                if (PingResultStatus.Pass == checkReesultInfo.Status)
                {
                    //NLogMgr.CheckMsgLog(_checkLog, LogLevel.Debug, checkReesultInfo.GetResultInfoString(), pingResult, $"[{this.IpAddresV4}]{this.Remarks}", checkReesultInfo.ResultReceiveTime);
                    return;
                }

                //todo:将非正常结果推送到消息队列(考虑开发时间问题,目前先直接写入日志)

                NLogMgr.CheckMsgLog(_checkLog, LogLevel.Error, checkReesultInfo.GetResultInfoString(), pingResult, $"[{this.IpAddresV4}]{this.Remarks}", checkReesultInfo.ResultReceiveTime);


                //Console.Clear();
            }));
        }