From 3ed15409b552e8fe106fdb320853397a3ed3bf61 Mon Sep 17 00:00:00 2001 From: Adam Janis Date: Sun, 22 Nov 2020 15:40:28 +0100 Subject: [PATCH] chore: readme collectResponseTimes example --- .github/workflows/deploy.yml | 1 + README.md | 1 + src/components/monitorHistogram.js | 3 ++- src/functions/cronTrigger.js | 8 +++++--- src/functions/helpers.js | 15 +++++++++++---- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 85a04a6..88e4cfe 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -38,6 +38,7 @@ jobs: SECRET_TELEGRAM_CHAT_ID environment: production env: + NODE_ENV: production CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} SECRET_SLACK_WEBHOOK_URL: ${{secrets.SECRET_SLACK_WEBHOOK_URL}} SECRET_TELEGRAM_API_TOKEN: ${{secrets.SECRET_TELEGRAM_API_TOKEN}} diff --git a/README.md b/README.md index 6db6f28..79afc4e 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ You can either deploy with **Cloudflare Deploy Button** using GitHub Actions or url: 'https://status-page.eidam.dev' # used for Slack messages logo: logo-192x192.png # image in ./public/ folder daysInHistogram: 90 # number of days you want to display in histogram + collectResponseTimes: false # experimental feature, enable only for <5 monitors or on paid plans # configurable texts across the status page allmonitorsOperational: 'All Systems Operational' diff --git a/src/components/monitorHistogram.js b/src/components/monitorHistogram.js index 83ce47c..8675c2c 100644 --- a/src/components/monitorHistogram.js +++ b/src/components/monitorHistogram.js @@ -39,7 +39,8 @@ export default function MonitorHistogram({ monitorId, kvMonitor }) { {dayInHistogramLabel} - {kvMonitor && kvMonitor.checks.hasOwnProperty(dayInHistogram) && + {kvMonitor && + kvMonitor.checks.hasOwnProperty(dayInHistogram) && Object.keys(kvMonitor.checks[dayInHistogram].res).map((key) => { return ( <> diff --git a/src/functions/cronTrigger.js b/src/functions/cronTrigger.js index f12d985..e273de9 100644 --- a/src/functions/cronTrigger.js +++ b/src/functions/cronTrigger.js @@ -79,9 +79,11 @@ export async function processCronTrigger(event) { // Send Telegram message on monitor change if ( - monitorStatusChanged - && typeof SECRET_TELEGRAM_API_TOKEN !== 'undefined' && SECRET_TELEGRAM_API_TOKEN !== 'default-gh-action-secret' - && typeof SECRET_TELEGRAM_CHAT_ID !== 'undefined' && SECRET_TELEGRAM_CHAT_ID !== 'default-gh-action-secret' + monitorStatusChanged && + typeof SECRET_TELEGRAM_API_TOKEN !== 'undefined' && + SECRET_TELEGRAM_API_TOKEN !== 'default-gh-action-secret' && + typeof SECRET_TELEGRAM_CHAT_ID !== 'undefined' && + SECRET_TELEGRAM_CHAT_ID !== 'default-gh-action-secret' ) { event.waitUntil(notifyTelegram(monitor, monitorOperational)) } diff --git a/src/functions/helpers.js b/src/functions/helpers.js index 812c32b..d4e80c4 100644 --- a/src/functions/helpers.js +++ b/src/functions/helpers.js @@ -13,7 +13,7 @@ export async function setKVMonitors(data) { return setKV(kvDataKey, JSON.stringify(data)) } -const getOperationalLabel = operational => { +const getOperationalLabel = (operational) => { return operational ? config.settings.monitorLabelOperational : config.settings.monitorLabelNotOperational @@ -33,7 +33,9 @@ export async function notifySlack(monitor, operational) { type: 'section', text: { type: 'mrkdwn', - text: `Monitor *${monitor.name}* changed status to *${getOperationalLabel(operational)}*`, + text: `Monitor *${ + monitor.name + }* changed status to *${getOperationalLabel(operational)}*`, }, }, { @@ -61,8 +63,13 @@ export async function notifySlack(monitor, operational) { } export async function notifyTelegram(monitor, operational) { - const text = `Monitor *${monitor.name.replace('-', '\\-')}* changed status to *${getOperationalLabel(operational)}* - ${operational ? '✅' : '❌'} \`${monitor.method ? monitor.method : "GET"} ${monitor.url}\` \\- 👀 [Status Page](${config.settings.url})` + const text = `Monitor *${monitor.name.replace( + '-', + '\\-', + )}* changed status to *${getOperationalLabel(operational)}* + ${operational ? '✅' : '❌'} \`${monitor.method ? monitor.method : 'GET'} ${ + monitor.url + }\` \\- 👀 [Status Page](${config.settings.url})` const payload = new FormData() payload.append('chat_id', SECRET_TELEGRAM_CHAT_ID)