From ea21414634719e568fbd47e58c94ace3779db7cb Mon Sep 17 00:00:00 2001 From: checktheroads Date: Thu, 16 Apr 2020 00:27:00 -0700 Subject: [PATCH] general cleanup --- docs/docs/logging.mdx | 27 ++++++++++++++++++++++++++ hyperglass/api/events.py | 29 ++++++++++++++++++++++++++-- hyperglass/ui/components/Debugger.js | 2 +- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/docs/docs/logging.mdx b/docs/docs/logging.mdx index f519fe4..63eb4fc 100644 --- a/docs/docs/logging.mdx +++ b/docs/docs/logging.mdx @@ -66,6 +66,33 @@ Basic and API key authentication are supported. If `api_key` is used, the header `X-API-Key: {key}` is added to the request, where `{key}` is the password. ::: +### Webhook Data Structure + +The webhook will POST JSON data in the following format: + +```json +{ + "query_location": "router01", + "query_type": "bgp_route", + "query_vrf": "default", + "query_target": "1.1.1.0/24", + "headers": { + "content-length": "103", + "accept": "application/json, text/plain, */*", + "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36", + "content-type": "application/json;charset=UTF-8", + "referer": "http://lg.example.com/", + "accept-encoding": "gzip, deflate, br", + "accept-language": "en-US,en;q=0.9,fr;q=0.8,lb;q=0.7,la;q=0.6" + }, + "source": "192.0.2.1", + "network": { + "prefix": "192.0.2.0/24", + "asns": ["64496"] + } +} +``` + ## Full example ```yaml diff --git a/hyperglass/api/events.py b/hyperglass/api/events.py index 5572f75..6b09c22 100644 --- a/hyperglass/api/events.py +++ b/hyperglass/api/events.py @@ -1,4 +1,29 @@ """API Events.""" -on_startup = [] -on_shutdown = [] +# Project +from hyperglass.log import log +from hyperglass.util import check_redis +from hyperglass.exceptions import HyperglassError +from hyperglass.configuration import REDIS_CONFIG, params + + +async def _check_redis(): + """Ensure Redis is running before starting server. + + Raises: + HyperglassError: Raised if Redis is not running. + + Returns: + {bool} -- True if Redis is running. + """ + try: + await check_redis(db=params.cache.database, config=REDIS_CONFIG) + except RuntimeError as e: + raise HyperglassError(str(e), level="danger") from None + + log.debug(f"Redis is running at: {REDIS_CONFIG['host']}:{REDIS_CONFIG['port']}") + return True + + +on_startup = (_check_redis,) +on_shutdown = () diff --git a/hyperglass/ui/components/Debugger.js b/hyperglass/ui/components/Debugger.js index 02a7fe1..a407c56 100644 --- a/hyperglass/ui/components/Debugger.js +++ b/hyperglass/ui/components/Debugger.js @@ -11,7 +11,7 @@ import { Tag, useDisclosure, useColorMode, - useTheme + useTheme, } from "@chakra-ui/core"; import useConfig from "~/components/HyperglassProvider"; import useMedia from "~/components/MediaProvider";