Commit a69e019f authored by kaiyou's avatar kaiyou

Remove the wrapping decorator, will now rely on hooks

parent 0a3be672
from amonit import util
import requests import requests
import requests_html import requests_html
@util.wrap
def get(context, url, expected_code=200, expected_string=None): def get(context, url, expected_code=200, expected_string=None):
""" Run a GET http request and test the HTTP response code """ Run a GET http request and test the HTTP response code
""" """
...@@ -26,7 +23,6 @@ def get(context, url, expected_code=200, expected_string=None): ...@@ -26,7 +23,6 @@ def get(context, url, expected_code=200, expected_string=None):
} }
@util.wrap
def get_xpath(context, url, query, result_type="str", destination="message"): def get_xpath(context, url, query, result_type="str", destination="message"):
""" Run a GET http requests and use xpath to extract a result """ Run a GET http requests and use xpath to extract a result
""" """
......
...@@ -3,7 +3,6 @@ import smtplib ...@@ -3,7 +3,6 @@ import smtplib
import os import os
from email.mime import text, multipart from email.mime import text, multipart
from amonit import util
def get_imap_client(host, port, encrypt): def get_imap_client(host, port, encrypt):
...@@ -28,7 +27,6 @@ def get_smtp_client(host, port, encrypt): ...@@ -28,7 +27,6 @@ def get_smtp_client(host, port, encrypt):
return client return client
@util.wrap
def imap_login(context, host, username, password, port=143, encrypt=None): def imap_login(context, host, username, password, port=143, encrypt=None):
""" Check that IMAP login works properly and accesses the INBOX """ Check that IMAP login works properly and accesses the INBOX
""" """
...@@ -37,7 +35,6 @@ def imap_login(context, host, username, password, port=143, encrypt=None): ...@@ -37,7 +35,6 @@ def imap_login(context, host, username, password, port=143, encrypt=None):
client.logout() client.logout()
@util.wrap
def send_then_receive(context, account_from, account_to): def send_then_receive(context, account_from, account_to):
""" Send a mail using SMTP, then check that it is received using IMAP """ Send a mail using SMTP, then check that it is received using IMAP
This is useful either on a single server or across servers to ensure This is useful either on a single server or across servers to ensure
......
import os import os
import json import json
from amonit import util
from matrix_client import client as matrix_client from matrix_client import client as matrix_client
from matrix_client import room as matrix_room from matrix_client import room as matrix_room
......
import ssl import ssl
import OpenSSL import OpenSSL
from amonit import util
@util.wrap
def check_certificate(context, host, port): def check_certificate(context, host, port):
""" Retrieve and check a TLS certificate """ Retrieve and check a TLS certificate
""" """
......
...@@ -57,7 +57,10 @@ def check_run(checkid, function, context, args): ...@@ -57,7 +57,10 @@ def check_run(checkid, function, context, args):
context, args = scheduler.hook("precheck", context, args) context, args = scheduler.hook("precheck", context, args)
context = dict(scheduler.state[checkid], **context) context = dict(scheduler.state[checkid], **context)
context.update(checkid=checkid, function=function) context.update(checkid=checkid, function=function)
result = util.resolve(function)(context, **args) try:
result = util.resolve(function)(context, **args)
except Exception as error:
result = error
context, result = scheduler.hook("postcheck", context, result) context, result = scheduler.hook("postcheck", context, result)
scheduler.state[checkid] = context scheduler.state[checkid] = context
scheduler.notify(checkid, context) scheduler.notify(checkid, context)
......
...@@ -52,25 +52,6 @@ def merge(*objects): ...@@ -52,25 +52,6 @@ def merge(*objects):
elif mode is list: elif mode is list:
return sum(objects) return sum(objects)
else: else:
raise ValueError("Cannot merge objects of type {}".format(mode)) raise ValueError("Cannot merge objects of type {}: {}".format(
mode, objects))
def wrap(function):
""" Wrap a check function to handle simple results and exceptions
"""
def replacement(*args, **kwargs):
try:
result = function(*args, **kwargs)
if type(result) is not dict or "up" not in result:
result = {
"up": True,
"message": str(result)
}
except Exception as error:
result = {
"up": False,
"error": type(error).__name__,
"message": str(error)
}
return result
return replacement
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment