commit 9c8299055a3350500b93c3319791e93ca75bd91f Author: askiiart Date: Mon Feb 5 18:01:49 2024 -0600 Initial commit diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 0000000..0350782 --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,4 @@ +{ + "MD013": false, + "MD024": false +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..cba932f --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# Updog HTTP checker + +An HTTP checker for updog. + +## Arguments + +Arguments marked with * are required. + +### `url`* + +The URL for the thing being checked. + +Default: None, this is a required value. + +#### Example + +```json +"url": "https://example.com:443" +``` + +### `append-messages` + +Text to be appended after the status message for each status code. + +TODO: Add ranges and lists for these - will not be stored like that, just processed into a normal dict like this. + +Default: None + +#### Example + +```json +"append-messages": { + 200: " - Up", + 404: " - Partial outage", + 502: " - Down" +} +``` + +### `headers` + +Headers to be sent for the HTTP request. + +Default: None + +#### Example + +```json +"headers": { + "Content-Type": "text" +} +``` diff --git a/http_checker.py b/http_checker.py new file mode 100644 index 0000000..4ac95e3 --- /dev/null +++ b/http_checker.py @@ -0,0 +1,23 @@ +import requests +from http.client import responses + + +class HttpChecker: + def __init__(self, arguments): + self.url = arguments['url'] + # return an empty dict for optional things + append_messages = arguments.get( + 'append-messages', dict()) + self.headers = arguments.get('headers', dict()) + + # Append the custom stuff to the response status code messages + self.status_messages = responses + for status_code in self.status_messages: + self.status_messages[status_code] = str( + self.status_messages[status_code]) + append_messages.get(str(status_code), '') + + def get_status(self): + return requests.get(self.url, headers=self.headers).status_code() + + def get_return_codes(self): + return (self.status_messages)