Initial commit
This commit is contained in:
commit
9c8299055a
3 changed files with 78 additions and 0 deletions
4
.markdownlint.json
Normal file
4
.markdownlint.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"MD013": false,
|
||||
"MD024": false
|
||||
}
|
51
README.md
Normal file
51
README.md
Normal file
|
@ -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"
|
||||
}
|
||||
```
|
23
http_checker.py
Normal file
23
http_checker.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue