Skip to content

Commit

Permalink
feat: added up_message and down_message to [uptimerobotstatus] (#9662)
Browse files Browse the repository at this point in the history
* feat: added up_message and down_message into uptimerobot-status [8816-issue]

* implement up/down color params, add query params to docs

---------

Co-authored-by: chris48s <[email protected]>
  • Loading branch information
filipgrudzien and chris48s authored Jan 23, 2024
1 parent 560f79d commit e032f3d
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions services/uptimerobot/uptimerobot-status.service.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import { pathParams } from '../index.js'
import { pathParam } from '../index.js'
import { queryParamSchema, queryParams } from '../website-status.js'
import UptimeRobotBase from './uptimerobot-base.js'

export default class UptimeRobotStatus extends UptimeRobotBase {
static route = {
base: 'uptimerobot/status',
pattern: ':monitorSpecificKey',
queryParamSchema,
}

static openApi = {
'/uptimerobot/status/{monitorSpecificKey}': {
get: {
summary: 'Uptime Robot status',
parameters: pathParams({
name: 'monitorSpecificKey',
example: 'm778918918-3e92c097147760ee39d02d36',
}),
parameters: [
pathParam({
name: 'monitorSpecificKey',
example: 'm778918918-3e92c097147760ee39d02d36',
}),
...queryParams,
],
},
},
}
Expand All @@ -23,26 +28,46 @@ export default class UptimeRobotStatus extends UptimeRobotBase {
label: 'status',
}

static render({ status }) {
static render({
status,
upMessage = 'up',
downMessage = 'down',
upColor = 'brightgreen',
downColor = 'red',
}) {
switch (status) {
case 0:
return { message: 'paused', color: 'yellow' }
case 1:
return { message: 'not checked yet', color: 'yellowgreen' }
case 2:
return { message: 'up', color: 'brightgreen' }
return { message: upMessage, color: upColor }
case 8:
return { message: 'seems down', color: 'orange' }
case 9:
return { message: 'down', color: 'red' }
return { message: downMessage, color: downColor }
default:
throw Error('Should not get here due to validation')
}
}

async handle({ monitorSpecificKey }) {
async handle(
{ monitorSpecificKey },
{
up_message: upMessage,
down_message: downMessage,
up_color: upColor,
down_color: downColor,
},
) {
const { monitors } = await this.fetch({ monitorSpecificKey })
const { status } = monitors[0]
return this.constructor.render({ status })
return this.constructor.render({
status,
upMessage,
downMessage,
upColor,
downColor,
})
}
}

0 comments on commit e032f3d

Please sign in to comment.