mirror of
https://github.com/badges/shields.git
synced 2025-04-18 19:44:04 +03:00
feat: added up_message and down_message to [uptimerobotstatus] (#9662)
* 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 <git@chris-shaw.dev>
This commit is contained in:
parent
560f79df59
commit
e032f3d4b7
@ -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,
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user