From 9eacab4869a846bda028592aec3c7c42dc019b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=ABl=20Mugnier?= Date: Wed, 25 Nov 2020 18:40:00 +0100 Subject: [PATCH] New - Ajout de monitoring sur les endpoints --- Docker/cachet-monitor/DockerFile | 15 +++ Docker/cachet-monitor/config.yml | 91 +++++++++++++++++++ Docker/cachet-monitor/docker-entrypoint.sh | 13 +++ Docker/sheaft-status/docker-compose.yml | 43 +++++++++ .../Controllers/HealthController.cs | 17 ++++ Sheaft.Web.Api/Controllers/HomeController.cs | 2 +- .../Controllers/UploadController.cs | 2 +- Sheaft.Web.Api/Startup.cs | 7 +- .../Controllers/HealthController.cs | 17 ++++ .../Controllers/HealthController.cs | 17 ++++ .../Controllers/HealthController.cs | 17 ++++ .../Controllers/HealthController.cs | 17 ++++ 12 files changed, 255 insertions(+), 3 deletions(-) create mode 100644 Docker/cachet-monitor/DockerFile create mode 100644 Docker/cachet-monitor/config.yml create mode 100644 Docker/cachet-monitor/docker-entrypoint.sh create mode 100644 Docker/sheaft-status/docker-compose.yml create mode 100644 Sheaft.Web.Api/Controllers/HealthController.cs create mode 100644 Sheaft.Web.Jobs/Controllers/HealthController.cs create mode 100644 Sheaft.Web.Manage/Controllers/HealthController.cs create mode 100644 Sheaft.Web.Payment/Controllers/HealthController.cs create mode 100644 Sheaft.Web.Signalr/Controllers/HealthController.cs diff --git a/Docker/cachet-monitor/DockerFile b/Docker/cachet-monitor/DockerFile new file mode 100644 index 000000000..55dd5f5c3 --- /dev/null +++ b/Docker/cachet-monitor/DockerFile @@ -0,0 +1,15 @@ +FROM alpine + +ENV VERSION=v3.0 + +ADD https://github.com/CastawayLabs/cachet-monitor/releases/download/${VERSION}/cachet_monitor_linux_amd64 /usr/bin/cachet-monitor + +RUN apk add --no-cache --virtual ca-certificates \ + && apk add --no-cache --virtual tzdata \ + && chmod 755 /usr/bin/cachet-monitor + +COPY docker-entrypoint.sh / + +ENTRYPOINT [ "/docker-entrypoint.sh" ] + +CMD [ "cachet-monitor","-c", "/etc/cachet-monitor.yaml"] \ No newline at end of file diff --git a/Docker/cachet-monitor/config.yml b/Docker/cachet-monitor/config.yml new file mode 100644 index 000000000..bc44fc457 --- /dev/null +++ b/Docker/cachet-monitor/config.yml @@ -0,0 +1,91 @@ +api: + url: https://status.sheaft.com/api/v1 + token: ###### + insecure: false +date_format: 02/01/2006 15:04:05 MST +monitors: + - name: graphql + target: https://api.sheaft.com/health/livez + strict: true + method: GET + component_id: 3 + metric_id: 1 + template: + investigating: + subject: "{{ .Monitor.Name }} - {{ .SystemName }}" + message: "{{ .Monitor.Name }} check **failed** (server time: {{ .now }})\n\n{{ .FailReason }}" + fixed: + subject: "GraphQL Fixed" + interval: 60 + timeout: 10 + threshold: 80 + expected_status_code: 200 + expected_body: "OK" + - name: jobs + target: https://jobs.sheaft.com/health/livez + strict: true + method: GET + component_id: 4 + metric_id: 2 + template: + investigating: + subject: "{{ .Monitor.Name }} - {{ .SystemName }}" + message: "{{ .Monitor.Name }} check **failed** (server time: {{ .now }})\n\n{{ .FailReason }}" + fixed: + subject: "Jobs Fixed" + interval: 60 + timeout: 10 + threshold: 80 + expected_status_code: 200 + expected_body: "OK" + - name: payment + target: https://payment.sheaft.com/health/livez + strict: true + method: GET + component_id: 5 + metric_id: 3 + template: + investigating: + subject: "{{ .Monitor.Name }} - {{ .SystemName }}" + message: "{{ .Monitor.Name }} check **failed** (server time: {{ .now }})\n\n{{ .FailReason }}" + fixed: + subject: "Payment Fixed" + interval: 60 + timeout: 10 + threshold: 80 + expected_status_code: 200 + expected_body: "OK" + - name: signalr + target: https://signalr.sheaft.com/health/livez + strict: true + method: GET + component_id: 6 + metric_id: 4 + template: + investigating: + subject: "{{ .Monitor.Name }} - {{ .SystemName }}" + message: "{{ .Monitor.Name }} check **failed** (server time: {{ .now }})\n\n{{ .FailReason }}" + fixed: + subject: "Signalr Fixed" + interval: 60 + timeout: 10 + threshold: 80 + expected_status_code: 200 + expected_body: "OK" + - name: identity + target: https://auth.sheaft.com/health/livez + strict: true + method: GET + component_id: 13 + metric_id: 5 + template: + investigating: + subject: "{{ .Monitor.Name }} - {{ .SystemName }}" + message: "{{ .Monitor.Name }} check **failed** (server time: {{ .now }})\n\n{{ .FailReason }}" + fixed: + subject: "Identity Fixed" + interval: 60 + timeout: 10 + threshold: 80 + expected_status_code: 200 + expected_body: "OK" \ No newline at end of file diff --git a/Docker/cachet-monitor/docker-entrypoint.sh b/Docker/cachet-monitor/docker-entrypoint.sh new file mode 100644 index 000000000..d2c5e5d57 --- /dev/null +++ b/Docker/cachet-monitor/docker-entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/sh +set -e + + +if [ -n "$CONFIG" ]; then + echo "Found configuration variable, will write it to /etc/cachet-monitor.yaml" + echo "$CONFIG" > /etc/cachet-monitor.yaml +elif [ ! -f /etc/cachet-monitor.yaml ]; then + echo "Please provide configuration in CONFIG variable or write it in /etc/cachet-monitor.yaml" + exit 1 +fi + +exec "$@" \ No newline at end of file diff --git a/Docker/sheaft-status/docker-compose.yml b/Docker/sheaft-status/docker-compose.yml new file mode 100644 index 000000000..45994a18c --- /dev/null +++ b/Docker/sheaft-status/docker-compose.yml @@ -0,0 +1,43 @@ +version: '3' +services: + sql: + image: mysql:5.7 + restart: always + environment: + - MYSQL_ROOT_PASSWORD=######### + - MYSQL_USER=user_sa + - MYSQL_PASSWORD=######### + - MYSQL_DATABASE=cachethq + volumes: + - sheaftstatus:/var/lib/mysql + cachet: + image: sheaft/sheaft.cachethq:latest + ports: + - 8000:8080 + environment: + - DB_DRIVER=mysql + - DB_HOST=sql + - DB_DATABASE=cachethq + - DB_USERNAME=user_sa + - DB_PASSWORD==######### + - DB_PREFIX=chq_ + - APP_KEY=base64:D9XPB/5oa1fi7RfcWdkZGtqx90JHdJXCfS/J7g0ZnZ4= + - APP_LOG=errorlog + - APP_ENV=production + - APP_DEBUG=true + - APP_URL=https://status.sheaft.com + - QUEUE_DRIVER=sync + - MAIL_DRIVER=SMTP + - MAIL_HOST==######### + - MAIL_PORT=25 + - MAIL_USERNAME=######### + - MAIL_PASSWORD==######### + - MAIL_ADDRESS=status@sheaft.com + - MAIL_NAME="Monitoring Sheaft" + - MAIL_ENCRYPTION=tls + restart: always + monitoring: + image: sheaft/sheaft.cachetmonitor:latest + restart: always + volumes: + - ${WEBAPP_STORAGE_HOME}/site/wwwroot/config.yml:/etc/cachet-monitor.yaml \ No newline at end of file diff --git a/Sheaft.Web.Api/Controllers/HealthController.cs b/Sheaft.Web.Api/Controllers/HealthController.cs new file mode 100644 index 000000000..90f7c1437 --- /dev/null +++ b/Sheaft.Web.Api/Controllers/HealthController.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Sheaft.Web.Api.Controllers +{ + public class HealthController : Controller + { + public IActionResult Livez() + { + return Ok("OK"); + } + + public IActionResult Readyz() + { + return Ok("OK"); + } + } +} \ No newline at end of file diff --git a/Sheaft.Web.Api/Controllers/HomeController.cs b/Sheaft.Web.Api/Controllers/HomeController.cs index 1eb74f977..e3074df92 100644 --- a/Sheaft.Web.Api/Controllers/HomeController.cs +++ b/Sheaft.Web.Api/Controllers/HomeController.cs @@ -2,7 +2,7 @@ namespace Sheaft.Web.Api.Controllers { - public class HomeController : ControllerBase + public class HomeController : Controller { public IActionResult Index() { diff --git a/Sheaft.Web.Api/Controllers/UploadController.cs b/Sheaft.Web.Api/Controllers/UploadController.cs index fcc35aaf0..fe596cb92 100644 --- a/Sheaft.Web.Api/Controllers/UploadController.cs +++ b/Sheaft.Web.Api/Controllers/UploadController.cs @@ -19,7 +19,7 @@ namespace Sheaft.Web.Api.Controllers [Authorize] [ApiController] [Route("upload")] - public class UploadController : ControllerBase + public class UploadController : Controller { private readonly ISheaftMediatr _mediatr; private readonly IHttpContextAccessor _httpContextAccessor; diff --git a/Sheaft.Web.Api/Startup.cs b/Sheaft.Web.Api/Startup.cs index d68705214..a31974a32 100644 --- a/Sheaft.Web.Api/Startup.cs +++ b/Sheaft.Web.Api/Startup.cs @@ -433,7 +433,12 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IConfigu app.UseIpRateLimiting(); - app.UseMvc(); + app.UseMvc(endpoints => + { + endpoints.MapRoute( + name: "default", + template: "{controller=Home}/{action=Index}/{id?}"); + }); app.UseWebSockets(); app.UseGraphQL("/graphql"); diff --git a/Sheaft.Web.Jobs/Controllers/HealthController.cs b/Sheaft.Web.Jobs/Controllers/HealthController.cs new file mode 100644 index 000000000..5a47124ea --- /dev/null +++ b/Sheaft.Web.Jobs/Controllers/HealthController.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Sheaft.Web.Jobs.Controllers +{ + public class HealthController : Controller + { + public IActionResult Livez() + { + return Ok("OK"); + } + + public IActionResult Readyz() + { + return Ok("OK"); + } + } +} \ No newline at end of file diff --git a/Sheaft.Web.Manage/Controllers/HealthController.cs b/Sheaft.Web.Manage/Controllers/HealthController.cs new file mode 100644 index 000000000..8210a9d7b --- /dev/null +++ b/Sheaft.Web.Manage/Controllers/HealthController.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Sheaft.Web.Manage.Controllers +{ + public class HealthController : Controller + { + public IActionResult Livez() + { + return Ok("OK"); + } + + public IActionResult Readyz() + { + return Ok("OK"); + } + } +} \ No newline at end of file diff --git a/Sheaft.Web.Payment/Controllers/HealthController.cs b/Sheaft.Web.Payment/Controllers/HealthController.cs new file mode 100644 index 000000000..58da08574 --- /dev/null +++ b/Sheaft.Web.Payment/Controllers/HealthController.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Sheaft.Web.Payment.Controllers +{ + public class HealthController : Controller + { + public IActionResult Livez() + { + return Ok("OK"); + } + + public IActionResult Readyz() + { + return Ok("OK"); + } + } +} \ No newline at end of file diff --git a/Sheaft.Web.Signalr/Controllers/HealthController.cs b/Sheaft.Web.Signalr/Controllers/HealthController.cs new file mode 100644 index 000000000..b90333550 --- /dev/null +++ b/Sheaft.Web.Signalr/Controllers/HealthController.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Sheaft.Web.Signalr.Controllers +{ + public class HealthController : Controller + { + public IActionResult Livez() + { + return Ok("OK"); + } + + public IActionResult Readyz() + { + return Ok("OK"); + } + } +} \ No newline at end of file