コード例 #1
0
ファイル: Overmind.cs プロジェクト: gyantal/SqCore
        async void CheckHealthMonitorAlive()
        {
            bool           isHealthMonitorAlive = false;
            Task <string?> tcpMsgTask           = TcpMessage.Send(string.Empty, (int)HealthMonitorMessageID.Ping, ServerIp.HealthMonitorPublicIp, ServerIp.DefaultHealthMonitorServerPort);
            string?        tcpMsgResponse       = await tcpMsgTask;

            Utils.Logger.Debug("CheckHealthMonitorAlive() returned answer: " + tcpMsgResponse ?? string.Empty);
            Console.WriteLine($"HealthMonitor Ping return: '{tcpMsgResponse ?? string.Empty}'");
            if (tcpMsgTask.Exception != null || String.IsNullOrEmpty(tcpMsgResponse))
            {
                string errorMsg = $"Error. CheckHealthMonitorAlive() to {ServerIp.HealthMonitorPublicIp}:{ServerIp.DefaultHealthMonitorServerPort}";
                Utils.Logger.Error(errorMsg);
            }
            else
            {
                isHealthMonitorAlive = tcpMsgResponse.StartsWith("Ping. Healthmonitor UtcNow: ");
            }

            if (!isHealthMonitorAlive)
            {
                new Email
                {
                    ToAddresses = Utils.Configuration["Emails:Gyant"],
                    Subject     = "SqCore Warning! : HealthMonitor is NOT Alive.",
                    Body        = $"SqCore Warning! : HealthMonitor is NOT Alive.",
                    IsBodyHtml  = false
                }
            }
コード例 #2
0
ファイル: WebServerController.cs プロジェクト: gyantal/SqCore
        [HttpPost, HttpGet]     // message from HealthMonitor webApp arrives as a Post, not a Get
        public async Task <ActionResult> ReportHealthMonitorCurrentStateToDashboardInJSON()
        {
            Utils.Logger.Info("ReportHealthMonitorCurrentStateToDashboardInJSON() BEGIN");
            // TODO: we should check here if it is a HttpGet (or a message without data package) and return gracefully

            string response = string.Empty;

            try
            {
                if (Request.Body.CanSeek)
                {
                    Request.Body.Position = 0;                 // Reset the position to zero to read from the beginning.
                }
                string jsonToBackEnd = await new StreamReader(Request.Body).ReadToEndAsync();

                Task <string?> tcpMsgTask     = TcpMessage.Send(jsonToBackEnd, (int)HealthMonitorMessageID.GetHealthMonitorCurrentStateToHealthMonitorWebsite, ServerIp.HealthMonitorPublicIp, ServerIp.DefaultHealthMonitorServerPort, TcpMessageResponseFormat.JSON);
                string?        tcpMsgResponse = await tcpMsgTask;
                if (tcpMsgTask.Exception != null || String.IsNullOrEmpty(tcpMsgResponse))
                {
                    Utils.Logger.Error("Error:HealthMonitor SendMessage exception.");
                    response = @"{""ResponseToFrontEnd"" : ""Error:HealthMonitor SendMessage exception. Check log file of the WepApp: ";
                }
                else
                {
                    response = tcpMsgResponse;
                }
            }
            catch (Exception ex)
            {
                Utils.Logger.Error(ex, "Error:HealthMonitor GetMessage exception.");
                response = @"{""ResponseToFrontEnd"" : ""Error: " + ex.Message + @"""}";
            }

            Utils.Logger.Info("ReportHealthMonitorCurrentStateToDashboardInJSON() END");
            return(Content(response, "application/json"));
        }