From 8ccb2fd7b2eaa83ef25ff818019665e4e5a14aac Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 6 Jul 2020 02:04:21 +0000 Subject: [PATCH 1/5] Update dependency express to ^4.17.1 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 90a6c9d..8fe66c5 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "@fortawesome/fontawesome-free": "^5.13.1", "@nguniversal/express-engine": "^10.0.1", "bootstrap": "^4.5.0", - "express": "^4.15.2", + "express": "^4.17.1", "jsonpath-plus": "^4.0.0", "roboto-fontface": "^0.10.0", "rxjs": "~6.6.0", @@ -42,7 +42,7 @@ "@angular/compiler-cli": "~10.0.2", "@angular/language-service": "~10.0.2", "@nguniversal/builders": "^10.0.1", - "@types/express": "^4.17.0", + "@types/express": "^4.17.6", "@types/node": "^14.0.14", "@types/jasmine": "~3.5.11", "@types/jasminewd2": "~2.0.3", From b6218575bf120cbe092a459376427de62f56d490 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 7 Jul 2020 02:04:22 +0000 Subject: [PATCH 2/5] Update dependency @types/express to ^4.17.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8fe66c5..4ae57e9 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@angular/compiler-cli": "~10.0.2", "@angular/language-service": "~10.0.2", "@nguniversal/builders": "^10.0.1", - "@types/express": "^4.17.6", + "@types/express": "^4.17.7", "@types/node": "^14.0.14", "@types/jasmine": "~3.5.11", "@types/jasminewd2": "~2.0.3", From 2e763964dd3dd89b9d053b100bdbdfda215506a9 Mon Sep 17 00:00:00 2001 From: Samuel Philipp Date: Thu, 9 Jul 2020 07:02:40 +0000 Subject: [PATCH 3/5] Update 'renovate.json' --- renovate.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/renovate.json b/renovate.json index b10109a..750c5c1 100644 --- a/renovate.json +++ b/renovate.json @@ -25,7 +25,7 @@ "zone.js" ], "packagePatterns": [ - "^angular", + "^@angular", "^karma", "^jasmine" ], From f6b1f2b13d7c3ef0096336a3946df1c7829ee8a4 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Thu, 16 Jul 2020 02:07:56 +0000 Subject: [PATCH 4/5] Update dependency @fortawesome/fontawesome-free to ^5.14.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ae57e9..cff548c 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "@angular/platform-browser-dynamic": "~10.0.2", "@angular/platform-server": "~10.0.2", "@angular/router": "~10.0.2", - "@fortawesome/fontawesome-free": "^5.13.1", + "@fortawesome/fontawesome-free": "^5.14.0", "@nguniversal/express-engine": "^10.0.1", "bootstrap": "^4.5.0", "express": "^4.17.1", From 6799b64f2adad7daa6ef957fccbef8c34b37f294 Mon Sep 17 00:00:00 2001 From: samuel-p Date: Thu, 16 Jul 2020 22:08:02 +0200 Subject: [PATCH 5/5] added option to update multiple service states at once minor frontend improvements --- Dockerfile | 2 +- config.json | 14 +++---- src/app/_data/data.ts | 3 +- src/app/status/status.component.html | 11 +++--- src/app/status/status.component.scss | 5 +++ src/main.status.ts | 59 +++++++++++++--------------- 6 files changed, 48 insertions(+), 46 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2d4262b..93f7d8f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:alpine +FROM node:14.5.0-alpine COPY dist/universal-statuspage /universal-statuspage diff --git a/config.json b/config.json index a01e3b9..d988f5c 100644 --- a/config.json +++ b/config.json @@ -2,25 +2,23 @@ "authToken": "test", "title": "sp-status", "description": "Services hosted by sp-codes", + "servicesPath": "$.alerts.*", + "idPath": "$.labels.status_service", "statePath": "$.status", "stateValues": { - "operational": ["OK"], - "maintenance": ["PAUSED"] + "operational": ["ok", "resolved"], + "maintenance": ["paused"] }, "groups": [ { "id": "test", "name": "Test", + "url": "http://sp-codes.de", "services": [ { "id": "test", "name": "test", - "url": "http://sp-codes.de", - "statePath": "$.state", - "stateValues": { - "operational": ["ok"], - "maintenance": ["paused"] - } + "statePath": "$.state" } ] } diff --git a/src/app/_data/data.ts b/src/app/_data/data.ts index 355e0dc..478dd1a 100644 --- a/src/app/_data/data.ts +++ b/src/app/_data/data.ts @@ -8,6 +8,7 @@ export interface CurrentStatus { export interface Group { id: string; name: string; + url?: string; state: State; services: Service[]; } @@ -15,7 +16,7 @@ export interface Group { export interface Service { id: string; name: string; - url: string; + url?: string; state: State; } diff --git a/src/app/status/status.component.html b/src/app/status/status.component.html index 6ef500a..f0b5aa2 100644 --- a/src/app/status/status.component.html +++ b/src/app/status/status.component.html @@ -1,14 +1,15 @@ - {{group.name}} - - - + + + {{group.name}} + {{group.name}} + - +
{{service.name}} diff --git a/src/app/status/status.component.scss b/src/app/status/status.component.scss index 558a8af..310e4f4 100644 --- a/src/app/status/status.component.scss +++ b/src/app/status/status.component.scss @@ -13,6 +13,11 @@ a { text-decoration: none; outline: none; + color: #ffffff; + + &:hover.name, &:hover .name { + text-decoration: underline; + } } mat-panel-title { diff --git a/src/main.status.ts b/src/main.status.ts index 54e7f4d..8b466bd 100644 --- a/src/main.status.ts +++ b/src/main.status.ts @@ -12,7 +12,9 @@ interface Config { authToken: string; title: string; description: string; - statePath: string; + servicesPath?: string; + idPath?: string; + statePath?: string; stateValues: { operational: string[]; maintenance: string[]; @@ -20,42 +22,26 @@ interface Config { groups: { id: string; name: string; + url?: string; services: { id: string; name: string; - url: string; + url?: string; statePath?: string; - stateValues?: { - operational?: string[]; - maintenance?: string[]; - }; }[]; }[]; } -interface StateKey { - statePath: string; - stateValues: { - operational: string[]; - maintenance: string[]; - }; -} - const api = Router(); api.use(json()); const serviceStates = existsSync(join(process.cwd(), 'cache.json')) ? JSON.parse(readFileSync(join(process.cwd(), 'cache.json'), {encoding: 'utf-8'})) : {} as Cache; const config = JSON.parse(readFileSync(join(process.cwd(), 'config.json'), {encoding: 'utf-8'})) as Config; -const stateKeys: { [service: string]: StateKey } = config.groups +const serviceStatePaths: { [service: string]: string } = config.groups .map(g => g.services).reduce((x, y) => x.concat(y), []) + .filter(s => s.statePath) .reduce((services, service) => { - services[service.id] = { - statePath: service.statePath || config.statePath, - stateValues: { - operational: service.stateValues ? service.stateValues.operational || config.stateValues.operational : config.stateValues.operational, - maintenance: service.stateValues ? service.stateValues.maintenance || config.stateValues.maintenance : config.stateValues.maintenance, - } - }; + services[service.id] = service.statePath; return services; }, {}); @@ -68,17 +54,27 @@ api.post('/update/health', (req, res) => { return res.status(401).send('invalid token'); } const serviceId = req.query.service as string; - const keys = stateKeys[serviceId]; - const state = JSONPath({path: keys.statePath, json: req.body, wrap: false}); - - if (keys.stateValues.operational.includes(state)) { - serviceStates[serviceId] = 'operational'; - } else if (keys.stateValues.maintenance.includes(state)) { - serviceStates[serviceId] = 'maintenance'; - } else { - serviceStates[serviceId] = 'outage'; + let services: { id: string, state: string }[] = []; + if (serviceId) { + services = [{id: serviceId, state: JSONPath({path: serviceStatePaths[serviceId], json: req.body, wrap: false})}]; + } else if (config.servicesPath && config.idPath && config.statePath) { + services = JSONPath({path: config.servicesPath, json: req.body}) + .map(s => ({ + id: JSONPath({path: config.idPath, json: s, wrap: false}), + state: JSONPath({path: config.statePath, json: s, wrap: false}) + })); } + services.forEach(s => { + if (config.stateValues.operational.includes(s.state)) { + serviceStates[s.id] = 'operational'; + } else if (config.stateValues.maintenance.includes(s.state)) { + serviceStates[s.id] = 'maintenance'; + } else { + serviceStates[s.id] = 'outage'; + } + }); + updateCache(); writeFileSync('cache.json', JSON.stringify(serviceStates), {encoding: 'utf-8'}); @@ -110,6 +106,7 @@ function updateCache(): void { return { id: group.id, name: group.name, + url: group.url, state: calculateOverallState(services.map(s => s.state)), services: services };