Add default extensions

This commit is contained in:
askiiart 2024-02-06 12:37:19 -06:00
parent 41379e36df
commit 219bcf8a12
Signed by untrusted user who does not match committer: askiiart
GPG key ID: BC3800E55FB54D67
5 changed files with 75 additions and 31 deletions

View file

@ -20,21 +20,22 @@ Docs are in the `./docs/` folder, but here's a quick overview on how to use this
```json
{
"global-args": {
"default-checker": "CheckerTemplate",
"default-alerts": "AlertsTemplate",
"default-logging": "LoggingTemplate"
},
"site": {
"name": "A Website",
"checker": "CheckerTemplate",
"checker": "HttpChecker",
"checker-args": {
"url": "https://example.net",
"port": 443,
"lol": "CheckerTemplate ignores these options lol"
"url": "https://example.com"
},
"rate": 60,
"alerts": "AlertsTemplate",
"rate": 1,
"alerts-args": {
"url": "https://example.com/webhook-url-or-whatever-goes-here",
"lol": "irrelevant, AlertsTemplate ignores these options lol"
},
"logging": "LoggingTemplate",
"logging-args": {
"file": "/home/askiiart/Documents/updog/logs/site-log"
}
@ -45,8 +46,7 @@ Docs are in the `./docs/` folder, but here's a quick overview on how to use this
## To-do
- Add maintenance windows (optionally recurring)
- Add ability to set default extensions that can be overridden on a per-service basis
- Also add groups
- Add groups
- Add ability for checkers to have preferred alerts and logging extensions - will print a warning if the preferred extension(s) are not used
- Add "keywords" to be replaced in the config (for current directory, service name, maybe some others)

View file

@ -14,21 +14,22 @@ Then create a `services.json` file for your config, like this:
```json
{
"global-args": {
"default-checker": "CheckerTemplate",
"default-alerts": "AlertsTemplate",
"default-logging": "LoggingTemplate"
},
"site": {
"name": "A Website",
"checker": "CheckerTemplate",
"checker": "HttpChecker",
"checker-args": {
"url": "https://example.net",
"port": 443,
"lol": "CheckerTemplate ignores these options lol"
"url": "https://example.com"
},
"rate": 1,
"alerts": "AlertsTemplate",
"alerts-args": {
"url": "https://example.com/webhook-url-or-whatever-goes-here",
"lol": "irrelevant, AlertsTemplate ignores these options lol"
},
"logging": "LoggingTemplate",
"logging-args": {
"file": "/home/askiiart/Documents/updog/logs/site-log"
}
@ -36,15 +37,25 @@ Then create a `services.json` file for your config, like this:
}
```
#### Global config
Optional arguments:
- `default-checker`: The default checker for all services, can be overriden per-service using `checker`
- `default-alerts`: The default alerter extension for all services, can be overriden per-service using `alerts`
- `default-logging`: The default logging extension for all services, can be overriden per-service using `logging`
#### Service config
Required arguments:
- The key (in this case `site`): A unique string to identify the service in logs, also used internally.
- `checker`: The name of the checker extension's *class*.
- `checker`: The name of the checker extension's *class* - optional if `default-checker` is specified in the global arguments.
- `checker-args`: Arguments for the checker. Check the checker's docs for what to put here.
- `rate`: How often to check if the service is up (every *x* seconds)
- `alerts`: The name of the alerting extension's *class*.
- `alerts`: The name of the alerting extension's *class* - optional if `default-alerts` is specified in the global arguments.
- `alerts-args`: Arguments for the alerting extension. Check the alerter's docs for what to put here.
- `logging`: The name of the logging extension's *class*.
- `logging`: The name of the logging extension's *class* - optional if `default-logging` is specified in the global arguments.
- `logging-args`: Arguments for the logging extension. Check the logger's docs for what to put here.
Optional arguments:

View file

@ -66,15 +66,45 @@ def create_instances(config, checkers, alerts, logging):
example: {'site': {'checker': instanceOfCheckerTemplate}}
'''
instances = {}
# global arguments
default_checker = ''
default_alerter = ''
default_logger = ''
for service in config.keys():
if service == 'global-args':
default_checker = config['global-args'].get('default-checker', '')
default_alerter = config['global-args'].get('default-alerts', '')
default_logger = config['global-args'].get('default-logging', '')
continue
instances[service] = {}
# just creates an instance of the checker with the arguments for it
instances[service]['checker'] = checkers[config[service]
['checker']](config[service]['checker-args'])
instances[service]['alerts'] = alerts[config[service]
['alerts']](config[service]['alerts-args'])
instances[service]['logging'] = logging[config[service]
['logging']](config[service]['logging-args'])
# create an instance of checker with the arguments for them, including the optional `default-checker`
checker_args = config[service]['checker-args']
if config[service].get('checker', '') != '':
checker = config[service]['checker']
else:
checker = default_checker
instances[service]['checker'] = checkers[checker](checker_args)
# and for alerts
alerter_args = config[service]['alerts-args']
if config[service].get('alerts', '') != '':
alerter = config[service]['alerts']
else:
alerter = default_alerter
instances[service]['alerts'] = alerts[alerter](alerter_args)
# and for logging
logger_args = config[service]['logging-args']
if config[service].get('logging', '') != '':
logger = config[service]['logging']
else:
logger = default_logger
instances[service]['logging'] = logging[logger](logger_args)
return instances

View file

@ -1,19 +1,20 @@
{
"global-args": {
"default-checker": "CheckerTemplate",
"default-alerts": "AlertsTemplate",
"default-logging": "LoggingTemplate"
},
"site": {
"name": "A Website",
"checker": "CheckerTemplate",
"checker": "HttpChecker",
"checker-args": {
"url": "https://example.net",
"port": 443,
"lol": "CheckerTemplate ignores these options lol"
"url": "https://askiiart.net"
},
"rate": 1,
"alerts": "AlertsTemplate",
"alerts-args": {
"url": "https://example.com/webhook-url-or-whatever-goes-here",
"lol": "irrelevant, AlertsTemplate ignores these options lol"
},
"logging": "LoggingTemplate",
"logging-args": {
"file": "/home/askiiart/Documents/updog/logs/site-log"
}

View file

@ -78,6 +78,8 @@ timers = {}
try:
for service in config.keys():
if service == 'global-args':
continue
timers[service] = RepeatedTimer(config[service]['rate'], run_check,
service, instances[service]['checker'], instances[service]['alerts'], instances[service]['logging'])
except: