-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into logo-test-page
- Loading branch information
Showing
15 changed files
with
514 additions
and
373 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,105 @@ | ||
'use strict' | ||
|
||
const { BaseJsonService } = require('..') | ||
const Joi = require('joi') | ||
|
||
const rowSchema = Joi.object().keys({ su: Joi.boolean() }) | ||
|
||
const schema = Joi.array() | ||
.items(rowSchema) | ||
.min(1) | ||
|
||
/* | ||
* this is the checkUuid for the NodePing.com (as used on the [example page](https://nodeping.com/reporting.html#results)) | ||
*/ | ||
const sampleCheckUuid = 'jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei' | ||
|
||
class NodePingStatus extends BaseJsonService { | ||
static get category() { | ||
return 'monitoring' | ||
} | ||
|
||
static get defaultBadgeData() { | ||
return { | ||
label: 'Status', | ||
} | ||
} | ||
|
||
static get route() { | ||
return { | ||
base: 'nodeping/status', | ||
pattern: ':checkUuid', | ||
queryParams: ['up_message', 'down_message', 'up_color', 'down_color'], | ||
} | ||
} | ||
|
||
static get examples() { | ||
return [ | ||
{ | ||
title: 'NodePing status', | ||
namedParams: { | ||
checkUuid: sampleCheckUuid, | ||
}, | ||
staticPreview: this.render({ status: true }), | ||
}, | ||
{ | ||
title: 'NodePing status (customized)', | ||
namedParams: { | ||
checkUuid: sampleCheckUuid, | ||
}, | ||
queryParams: { | ||
up_message: 'Online', | ||
up_color: 'blue', | ||
down_message: 'Offline', | ||
down_color: 'lightgrey', | ||
}, | ||
staticPreview: this.render({ | ||
status: true, | ||
upMessage: 'Online', | ||
upColor: 'blue', | ||
}), | ||
}, | ||
] | ||
} | ||
|
||
async fetch({ checkUuid }) { | ||
const rows = await this._requestJson({ | ||
schema, | ||
url: `https://nodeping.com/reports/results/${checkUuid}/1`, | ||
options: { | ||
qs: { format: 'json' }, | ||
headers: { | ||
'cache-control': 'no-cache', | ||
}, | ||
}, | ||
}) | ||
return { status: rows[0].su } | ||
} | ||
|
||
async handle( | ||
{ checkUuid }, | ||
{ | ||
up_message: upMessage, | ||
down_message: downMessage, | ||
up_color: upColor, | ||
down_color: downColor, | ||
} | ||
) { | ||
const { status } = await this.fetch({ checkUuid }) | ||
return this.constructor.render({ | ||
status, | ||
upMessage, | ||
downMessage, | ||
upColor, | ||
downColor, | ||
}) | ||
} | ||
|
||
static render({ status, upMessage, downMessage, upColor, downColor }) { | ||
return status | ||
? { message: upMessage || 'up', color: upColor || 'brightgreen' } | ||
: { message: downMessage || 'down', color: downColor || 'red' } | ||
} | ||
} | ||
|
||
module.exports = NodePingStatus |
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,75 @@ | ||
'use strict' | ||
|
||
const Joi = require('joi') | ||
|
||
const t = (module.exports = require('../tester').createServiceTester()) | ||
|
||
t.create('NodePing status - live').get( | ||
'/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei.json' | ||
) | ||
Joi.object().keys({ | ||
name: 'Status', | ||
value: Joi.equal('up', 'down').required(), | ||
}) | ||
|
||
t.create('NodePing status - up (mock)') | ||
.get('/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei.json') | ||
.intercept(nock => | ||
nock('https://nodeping.com') | ||
.get( | ||
'/reports/results/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei/1?format=json' | ||
) | ||
.reply(200, [{ su: true }]) | ||
) | ||
.expectJSON({ | ||
name: 'Status', | ||
value: 'up', | ||
}) | ||
|
||
t.create('NodePing status - down (mock)') | ||
.get('/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei.json') | ||
.intercept(nock => | ||
nock('https://nodeping.com') | ||
.get( | ||
'/reports/results/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei/1?format=json' | ||
) | ||
.reply(200, [{ su: false }]) | ||
) | ||
.expectJSON({ | ||
name: 'Status', | ||
value: 'down', | ||
}) | ||
|
||
t.create('NodePing status - custom up color/message') | ||
.get( | ||
'/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei.json?style=_shields_test&up_color=blue&up_message=happy' | ||
) | ||
.intercept(nock => | ||
nock('https://nodeping.com') | ||
.get( | ||
'/reports/results/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei/1?format=json' | ||
) | ||
.reply(200, [{ su: true }]) | ||
) | ||
.expectJSON({ | ||
name: 'Status', | ||
value: 'happy', | ||
color: 'blue', | ||
}) | ||
|
||
t.create('NodePing status - custom down color/message') | ||
.get( | ||
'/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei.json?style=_shields_test&down_color=yellow&down_message=sad' | ||
) | ||
.intercept(nock => | ||
nock('https://nodeping.com') | ||
.get( | ||
'/reports/results/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei/1?format=json' | ||
) | ||
.reply(200, [{ su: false }]) | ||
) | ||
.expectJSON({ | ||
name: 'Status', | ||
value: 'sad', | ||
color: 'yellow', | ||
}) |
Oops, something went wrong.