Skip to content

Instantly share code, notes, and snippets.

@remie
Created June 21, 2018 20:36
Show Gist options
  • Save remie/4766048652702a6b020163db2d7d5701 to your computer and use it in GitHub Desktop.
Save remie/4766048652702a6b020163db2d7d5701 to your computer and use it in GitHub Desktop.
import { Check, CheckResult, NagiosResult } from '@remie/nagios-cli';
import axios from 'axios';
export class HTTP implements Check {
private host: string;
constructor(host: string) {
this.host = host;
}
async execute(): Promise<CheckResult> {
try {
const result = await axios.get(this.host);
const success = result.status > 200 && result.status < 400;
return {
message: success ? `HTTP OK: ${result.status} Found` : `HTTP NOK: ${result.status} Found`,
code: success ? NagiosResult.OK : NagiosResult.CRITICAL
};
} catch (error) {
return {
message: `HTTP NOK: ${error.toString()}`,
code: NagiosResult.CRITICAL
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment