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

NOPS-488: deprecate pingdom check #135

Merged
merged 1 commit into from
Nov 2, 2020
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
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ A healthcheck config is a Javascript file that exports an object with these prop
* `interval`: time between checks in milliseconds or any string compatible with [ms](https://www.npmjs.com/package/ms) [default: 1minute]
* `officeHoursOnly`: [default: `false`] For queries that will probably fail out of hours (e.g. Internet Explorer usage, B2B stuff), set this to true and the check will pass on weekends and outside office hours (defined as 8am-6pm UTC). Use sparingly.

#### `pingdom`
Will poll the pingdom API to get the status of a specific check

* `checkId`: The id of the check in pingdom

#### `responseCompare`
Fetches from multiple urls and compares the responses. Useful to check that replication is working

Expand Down
2 changes: 0 additions & 2 deletions secrets.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module.exports = {
whitelist: [
'ldbchjvwdc65gbj8grn1xuemlxrq487i', // src/checks/pingdom.check.js
'23077025-960d-11e6-afcc-07964ee4b5be', // test/fixtures/cloudWatchThresholdResponse.json
'f8585BOxnGQDMbnkJoM1e', // test/fixtures/config/graphiteWorkingFixture.js
'sendnotificationwhendown', // test/fixtures/pingdomDownResponse.json + test/fixtures/pingdomUpResponse.json
'736ee205-b510-40bc-b58f-7b97709559a8', // test/fixtures/serviceRegistryFixture.json
'configure/service/3GQMFG1fYBJojRtN2fWQMX', // test/fixtures/serviceRegistryFixture.json
'a8527323-7e3a-4f67-8636-2117426f17ad', // test/fixtures/serviceRegistryFixture.json
Expand Down
31 changes: 4 additions & 27 deletions src/checks/pingdom.check.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,16 @@
'use strict';
const Check = require('./check');
const status = require('./status');
const fetch = require('node-fetch');

class PingdomCheck extends Check{

constructor(options){
constructor(options) {
super(options);
this.checkId = options.checkId;
this.url = `https://api.pingdom.com/api/2.0/checks/${this.checkId}`;
this.headers = {
'Authorization' : 'Basic ' + new Buffer(process.env.PINGDOM_USERNAME + ':' + process.env.PINGDOM_PASSWORD).toString('base64'),
'App-Key' : 'ldbchjvwdc65gbj8grn1xuemlxrq487i',
'Account-Email' : '[email protected]'
};
this.checkOutput = `Pingdom check ${this.checkId} has not yet run`;
}

async tick(){
try {
const response = await fetch(this.url, { headers : this.headers });
const json = await response.json();

if(!response.ok){
throw new Error(`Pingdom API returned ${json.error.statuscode}: ${json.error.errormessage}`);
}

this.status = (json.check.status === 'up') ? status.PASSED : status.FAILED;
this.checkOutput = `Pingdom status: ${json.check.status}`;
} catch(err) {
this.status = status.FAILED;
this.checkOutput = `Failed to get status: ${err.message}`;
}
this.status = status.FAILED;
this.checkOutput = 'Pingdom checks are deprecated and will be removed in a future version of n-health. Remove this check from your healthcheck config, and tag your checks with your system code in Pingdom so they can be monitored. See https://tech.in.ft.com/guides/monitoring/how-to-pingdom-check for more information.';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looove this!

}

tick() {}
}

module.exports = PingdomCheck;
7 changes: 0 additions & 7 deletions test/fixtures/pingdom403Response.json

This file was deleted.

38 changes: 0 additions & 38 deletions test/fixtures/pingdomDownResponse.json

This file was deleted.

38 changes: 0 additions & 38 deletions test/fixtures/pingdomUpResponse.json

This file was deleted.

70 changes: 8 additions & 62 deletions test/pingdom.check.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,18 @@

const expect = require('chai').expect;
const fixture = require('./fixtures/config/pingdomCheckFixture.js').checks[0];
const sinon = require('sinon');
const proxyquire = require('proxyquire').noCallThru().noPreserveCache();
const PingdomCheck = require('../src/checks/pingdom.check');

describe('Pingdom Check', function(){

let check;
let PingdomCheck;
let mockFetch;

function setup(status, body){
mockFetch = sinon.stub().returns(Promise.resolve({
status: status,
ok: status < 300,
json: () => Promise.resolve(body)
}));
PingdomCheck = proxyquire('../src/checks/pingdom.check', {'node-fetch':mockFetch});
check = new PingdomCheck(fixture);
}


it('Should be able to contact pingdom to get the status of a given check', function(done){
setup(200, {});
check.start();
setImmediate(() => {
sinon.assert.called(mockFetch);
let headers = mockFetch.lastCall.args[1].headers;
expect(headers).to.have.property('App-Key');
expect(headers).to.have.property('Account-Email');
done();
});
});

it('Should be ok if the pingdom status is "up', function(done){
setup(200, require('./fixtures/pingdomUpResponse.json'));
check.start();
setImmediate(function(){
expect(check.getStatus().ok).to.be.true;
done();
});
});

it('Should not be ok if the pingdom status is not "up', function(done){
setup(200, require('./fixtures/pingdomDownResponse.json'));
describe('Pingdom Check', function() {
it('should fail and return a deprecation message', function() {
const check = new PingdomCheck(fixture);
check.start();
setImmediate(function(){
expect(check.getStatus().ok).to.be.false;
done();
});
});

it('Should not be ok if the status check failed', function(done){
setup(500, {});
check.start();
setImmediate(function(){
expect(check.getStatus().ok).to.be.false;
done();
});
});

it('should return error message if pingdom returns a 403 status', function(done) {
setup(403, require('./fixtures/pingdom403Response.json'));
check.start();
setImmediate(function(){
expect(check.getStatus().checkOutput).to.eql('Failed to get status: Pingdom API returned 403: Something went wrong! This string describes what happened.');
setImmediate(() => {
const { ok, checkOutput } = check.getStatus();
expect(ok).to.be.false;
expect(checkOutput).to.match(/^Pingdom checks are deprecated/);
done();
});
});

});