Exemplo n.º 1
0
        public async Task <IActionResult> EditMonitor(MonitorJobRequest request)
        {
            string vaild = _monitorService.VaildMonitorJob(request);

            if (!vaild.IsEmpty())
            {
                return(Json(new HttpResultEntity(-1, vaild, null)));
            }

            IMonitorJob model = _monitorService.GetMonitorJob(request);

            if (request.Id.IsEmpty() || request.Id == "0")
            {
                await _storage.AddMonitorJob(model).ConfigureAwait(false);
            }

            else
            {
                await _storage.UpdateMonitorJob(model).ConfigureAwait(false);
            }

            await _scheduleService.UpdateMonitorJobAsync();

            return(Json(new HttpResultEntity(1, "ok", null)));
        }
Exemplo n.º 2
0
        public MonitorJob GetMonitorJob(MonitorJobRequest request)
        {
            MonitorJobPayload payload = new MonitorJobPayload();

            if (request.ResponseTimeOutMonitor != null)
            {
                payload.ResponseTimeOutMonitor = new ResponseTimeOutMonitorJob
                {
                    Status     = request.ResponseTimeOutMonitor.Status,
                    TimeOutMs  = request.ResponseTimeOutMonitor.TimeOutMs.ToInt(),
                    Percentage = request.ResponseTimeOutMonitor.Percentage.Replace("%", "").ToDouble(2)
                };
            }

            if (request.ErrorResponseMonitor != null)
            {
                payload.ErrorResponseMonitor = new ErrorResponseMonitorJob
                {
                    Status         = request.ErrorResponseMonitor.Status,
                    HttpCodeStatus = request.ErrorResponseMonitor.HttpCodeStatus.Replace(",", ","),
                    Percentage     = request.ErrorResponseMonitor.Percentage.Replace("%", "").ToDouble(2)
                };
            }

            if (request.IPMonitor != null)
            {
                payload.IPMonitor = new IPMonitorJob
                {
                    Status     = request.IPMonitor.Status,
                    WhiteList  = (request.IPMonitor.WhiteList ?? string.Empty),
                    Percentage = request.IPMonitor.Percentage.Replace("%", "").ToDouble(2)
                };
            }

            if (request.RequestCountMonitor != null)
            {
                payload.RequestCountMonitor = new RequestCountMonitorJob
                {
                    Status = request.RequestCountMonitor.Status,
                    Max    = request.RequestCountMonitor.Max.ToInt()
                };
            }

            MonitorJob model = new MonitorJob()
            {
                Id          = request.Id,
                Title       = request.Title,
                Description = (request.Description ?? string.Empty),
                CronLike    = ParseJobRate(request.Interval),
                Emails      = request.Emails.Replace(",", ","),
                WebHook     = request.WebHook,
                Mobiles     = (request.Mobiles ?? string.Empty).Replace(",", ","),
                Status      = request.Status,
                Nodes       = request.Nodes,
                Payload     = JsonConvert.SerializeObject(payload),
                CreateTime  = DateTime.Now
            };

            return(model);
        }
Exemplo n.º 3
0
        public MonitorJobRequest GetMonitorJobRequest(IMonitorJob job)
        {
            MonitorJobPayload payload = JsonConvert.DeserializeObject <MonitorJobPayload>(job.Payload);

            MonitorJobRequest request = new MonitorJobRequest()
            {
                Id          = job.Id,
                Title       = job.Title,
                Description = job.Description,
                Emails      = job.Emails,
                Interval    = ParseJobCron(job.CronLike),
                Status      = job.Status,
                Mobiles     = job.Mobiles,
                Service     = job.Service,
                Instance    = job.Instance,
                WebHook     = job.WebHook
            };

            if (payload.ResponseTimeOutMonitor != null)
            {
                request.ResponseTimeOutMonitor = new ResponseTimeOutMonitorViewModel
                {
                    Status     = payload.ResponseTimeOutMonitor.Status,
                    TimeOutMs  = payload.ResponseTimeOutMonitor.TimeOutMs.ToString(),
                    Percentage = payload.ResponseTimeOutMonitor.Percentage + "%"
                };
            }

            if (payload.ErrorResponseMonitor != null)
            {
                request.ErrorResponseMonitor = new ErrorResponseMonitorViewModel
                {
                    Status         = payload.ErrorResponseMonitor.Status,
                    HttpCodeStatus = payload.ErrorResponseMonitor.HttpCodeStatus,
                    Percentage     = payload.ErrorResponseMonitor.Percentage + "%"
                };
            }

            if (payload.IPMonitor != null)
            {
                request.IPMonitor = new IPMonitorViewModel
                {
                    Status     = payload.IPMonitor.Status,
                    WhiteList  = payload.IPMonitor.WhiteList,
                    Percentage = payload.IPMonitor.Percentage + "%"
                };
            }

            if (payload.RequestCountMonitor != null)
            {
                request.RequestCountMonitor = new RequestCountMonitorViewModel
                {
                    Status = payload.RequestCountMonitor.Status,
                    Max    = payload.RequestCountMonitor.Max.ToString()
                };
            }

            return(request);
        }
Exemplo n.º 4
0
        public string VaildMonitorJob(MonitorJobRequest request)
        {
            if (request.Title.IsEmpty())
            {
                return(_lang.Monitor_TitleNotNull);
            }

            if (request.Title.Length > 30)
            {
                return(_lang.Monitor_TitleTooLong);
            }

            if (!request.Description.IsEmpty() && request.Description.Length > 100)
            {
                return(_lang.Monitor_DescTooLong);
            }

            if (request.Nodes.IsEmpty())
            {
                return(_lang.Monitor_MustSelectNode);
            }

            if (request.Emails.IsEmpty() && request.WebHook.IsEmpty())
            {
                return(_lang.Monitor_EmailOrWebHookNotNull);
            }

            if (!request.Emails.IsEmpty() && request.Emails.Length > 100)
            {
                return(_lang.Monitor_EmailTooLong);
            }

            if (!request.WebHook.IsEmpty() && request.WebHook.Length > 100)
            {
                return(_lang.Monitor_WebHookTooLong);
            }

            if (request.ResponseTimeOutMonitor != null)
            {
                if (!request.ResponseTimeOutMonitor.TimeOutMs.IsInt() || request.ResponseTimeOutMonitor.TimeOutMs.ToInt() <= 0 || request.ResponseTimeOutMonitor.TimeOutMs.ToInt() > 1000000)
                {
                    return(_lang.Monitor_TimeOut_TimeFormatError);
                }

                if (!VaildPercentage(request.ResponseTimeOutMonitor.Percentage))
                {
                    return(_lang.Monitor_TimeOut_PercnetError);
                }
            }

            if (request.ErrorResponseMonitor != null)
            {
                if (request.ErrorResponseMonitor.HttpCodeStatus.IsEmpty())
                {
                    return(_lang.Monitor_Error_StatusCodeNotNull);
                }

                if (request.ErrorResponseMonitor.HttpCodeStatus.Length > 100)
                {
                    return(_lang.Monitor_Error_StatusCodeTooLong);
                }

                if (!VaildPercentage(request.ErrorResponseMonitor.Percentage))
                {
                    return(_lang.Monitor_Error_PercnetError);
                }
            }

            if (request.IPMonitor != null)
            {
                if (!request.IPMonitor.WhiteList.IsEmpty() && request.IPMonitor.WhiteList.Length > 100)
                {
                    return(_lang.Monitor_IP_WhiteListTooLong);
                }

                if (!VaildPercentage(request.IPMonitor.Percentage))
                {
                    return(_lang.Monitor_IP_PercentError);
                }
            }

            if (request.RequestCountMonitor != null)
            {
                if (request.RequestCountMonitor.Max.ToInt() <= 0)
                {
                    return(_lang.Monitor_Request_FormatError);
                }
            }

            if (request.ResponseTimeOutMonitor == null && request.ErrorResponseMonitor == null && request.IPMonitor == null && request.RequestCountMonitor == null)
            {
                return(_lang.Monitor_MustSelectType);
            }

            return(null);
        }
Exemplo n.º 5
0
        public string VaildMonitorJob(MonitorJobRequest request)
        {
            if (request.Title.IsEmpty())
            {
                return("标题不能为空");
            }

            if (request.Title.Length > 30)
            {
                return("标题过长");
            }

            if (!request.Description.IsEmpty() && request.Description.Length > 100)
            {
                return("描述过长");
            }

            if (request.Nodes.IsEmpty())
            {
                return("至少要选择一个服务节点");
            }

            if (request.Emails.IsEmpty() && request.WebHook.IsEmpty())
            {
                return("通知邮箱,推送地址不能都为空");
            }

            if (request.Emails.Length > 100)
            {
                return("邮箱过长");
            }

            if (request.WebHook.Length > 100)
            {
                return("推送地址过长");
            }

            if (request.ResponseTimeOutMonitor != null)
            {
                if (!request.ResponseTimeOutMonitor.TimeOutMs.IsInt() || request.ResponseTimeOutMonitor.TimeOutMs.ToInt() <= 0 || request.ResponseTimeOutMonitor.TimeOutMs.ToInt() > 1000000)
                {
                    return("响应超时监控-超时时间格式错误");
                }

                if (!VaildPercentage(request.ResponseTimeOutMonitor.Percentage))
                {
                    return("响应超时监控-百分比格式错误");
                }
            }

            if (request.ErrorResponseMonitor != null)
            {
                if (request.ErrorResponseMonitor.HttpCodeStatus.IsEmpty())
                {
                    return("请求错误监控-HTTP状态码不能为空");
                }

                if (request.ErrorResponseMonitor.HttpCodeStatus.Length > 100)
                {
                    return("请求错误监控-HTTP状态码过长");
                }

                if (!VaildPercentage(request.ErrorResponseMonitor.Percentage))
                {
                    return("请求错误监控-百分比格式错误");
                }
            }

            if (request.IPMonitor != null)
            {
                if (!request.IPMonitor.WhileList.IsEmpty() && request.IPMonitor.WhileList.Length > 100)
                {
                    return("IP监控-白名单过长");
                }

                if (!VaildPercentage(request.IPMonitor.Percentage))
                {
                    return("IP监控-百分比格式错误");
                }
            }

            if (request.RequestCountMonitor != null)
            {
                if (request.RequestCountMonitor.Max.ToInt() <= 0)
                {
                    return("请求量监控-最大请求数格式错误");
                }
            }

            if (request.ResponseTimeOutMonitor == null && request.ErrorResponseMonitor == null && request.IPMonitor == null && request.RequestCountMonitor == null)
            {
                return("至少要开启一项监控类型");
            }

            return(null);
        }