Пример #1
0
        private async Task CheckHost(HostToCheck host)
        {
            try
            {
                var result = await HttpRequestClient.GetRequestAsync(host.Url);

                string version = null;
                try
                {
                    var model = result.DeserializeJson <AmIAliveModel>();
                    version = model?.Version;

                    if (!string.IsNullOrEmpty(model?.Error))
                    {
                        await SendNotification(
                            SlackMonitorChannel, $":exclamation: {_appName} {_appVersion}: {host.ServiceName}: {model.Error}");
                    }
                }
                catch
                {
                    // ignored
                    //not all system support version yet
                }

                await _serviceMonitoringRepository.UpdateOrCreate(
                    MonitoringRecord.Create(host.ServiceName, DateTime.UtcNow, version));
            }
            catch (WebException ex)
            {
                using (var receiveStream = ex.Response.GetResponseStream())
                {
                    using (var sr = new StreamReader(receiveStream))
                    {
                        var content = await sr.ReadToEndAsync();

                        await _log.WriteErrorAsync("CheckAllServices", "CheckHost", content, ex);
                    }
                }
            }
        }