Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: NRK health endpoint #14

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions server/src/expressHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const staticPath = path.join(
'dist'
)
logger.data(staticPath).debug('Express static file path:')

import { setupHealthEndpoint } from './nrk/health'
setupHealthEndpoint(app)

app.use('/', express.static(staticPath))
server.listen(SERVER_PORT)
logger.info(`Server started at http://localhost:${SERVER_PORT}`)
Expand Down
64 changes: 64 additions & 0 deletions server/src/nrk/health.ts
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()
})
}