Created
June 21, 2018 20:36
-
-
Save remie/4766048652702a6b020163db2d7d5701 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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