forked from tv2/sisyfos-audio-controller
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from nrkno/feat/health-endpoint
feat: NRK health endpoint
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Express } from 'express' | ||
import { state } from '../reducers/store' | ||
|
||
/** | ||
* Health report as described in internal NRK blaabok spec | ||
*/ | ||
interface HealthReport { | ||
/** Overordnet status på det kjørende systemet. Se Registrerte Definerte Verdier STATUS. */ | ||
status: Status | ||
/** Navn på det kjørende systemet (Må være statisk! dvs ikke inneholde data om feks timings el.). */ | ||
name: string | ||
/** Tidspunkt for når innholdet i rapporten ble oppdatert eller rapporten ble generert. Format: Timestamps. */ | ||
updated: string | ||
/** Hvor finner du dokumentasjonen til systemet. */ | ||
documentation: string | ||
/** Hvilken version av helsesjekk standard er implementert. */ | ||
version: '5' | ||
|
||
// internal fields (not according to spec, but sofie uses these): | ||
_internal: { | ||
// statusCode: StatusCode, | ||
statusCodeString: string | ||
messages: Array<string> | ||
versions: { [component: string]: string } | ||
} | ||
} | ||
enum Status { | ||
OK = 'OK', | ||
Warning = 'WARNING', | ||
Fail = 'FAIL', | ||
Undefined = 'UNDEFINED', | ||
} | ||
|
||
export function setupHealthEndpoint(app: Express) { | ||
app.get('/health', (req, res) => { | ||
const health: HealthReport = { | ||
status: Status.OK, | ||
name: 'Sisyfos', | ||
updated: new Date().toISOString(), | ||
documentation: | ||
'https://github.com/nrkno/sofie-sisyfos-audio-controller', | ||
version: '5', | ||
_internal: { | ||
statusCodeString: 'OK', | ||
messages: [], | ||
versions: { | ||
sisyfos: process.env.npm_package_version, | ||
}, | ||
}, | ||
} | ||
|
||
const isOnline = state.settings[0].serverOnline | ||
if (!isOnline) { | ||
health.status = Status.Warning | ||
health._internal.statusCodeString = 'WARNING' | ||
health._internal.messages.push('Mixer disconnected') | ||
} | ||
|
||
res.json(health) | ||
res.status(200) | ||
res.end() | ||
}) | ||
} | ||
|