updog-http_checker/http_checker.py
2024-02-06 12:25:08 -06:00

24 lines
809 B
Python

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)