Add default extensions
This commit is contained in:
parent
41379e36df
commit
219bcf8a12
5 changed files with 75 additions and 31 deletions
18
README.md
18
README.md
|
@ -20,21 +20,22 @@ Docs are in the `./docs/` folder, but here's a quick overview on how to use this
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
"global-args": {
|
||||||
|
"default-checker": "CheckerTemplate",
|
||||||
|
"default-alerts": "AlertsTemplate",
|
||||||
|
"default-logging": "LoggingTemplate"
|
||||||
|
},
|
||||||
"site": {
|
"site": {
|
||||||
"name": "A Website",
|
"name": "A Website",
|
||||||
"checker": "CheckerTemplate",
|
"checker": "HttpChecker",
|
||||||
"checker-args": {
|
"checker-args": {
|
||||||
"url": "https://example.net",
|
"url": "https://example.com"
|
||||||
"port": 443,
|
|
||||||
"lol": "CheckerTemplate ignores these options lol"
|
|
||||||
},
|
},
|
||||||
"rate": 60,
|
"rate": 1,
|
||||||
"alerts": "AlertsTemplate",
|
|
||||||
"alerts-args": {
|
"alerts-args": {
|
||||||
"url": "https://example.com/webhook-url-or-whatever-goes-here",
|
"url": "https://example.com/webhook-url-or-whatever-goes-here",
|
||||||
"lol": "irrelevant, AlertsTemplate ignores these options lol"
|
"lol": "irrelevant, AlertsTemplate ignores these options lol"
|
||||||
},
|
},
|
||||||
"logging": "LoggingTemplate",
|
|
||||||
"logging-args": {
|
"logging-args": {
|
||||||
"file": "/home/askiiart/Documents/updog/logs/site-log"
|
"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
|
## To-do
|
||||||
|
|
||||||
- Add maintenance windows (optionally recurring)
|
- Add maintenance windows (optionally recurring)
|
||||||
- Add ability to set default extensions that can be overridden on a per-service basis
|
- Add groups
|
||||||
- Also 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 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)
|
- Add "keywords" to be replaced in the config (for current directory, service name, maybe some others)
|
||||||
|
|
||||||
|
|
|
@ -14,21 +14,22 @@ Then create a `services.json` file for your config, like this:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
"global-args": {
|
||||||
|
"default-checker": "CheckerTemplate",
|
||||||
|
"default-alerts": "AlertsTemplate",
|
||||||
|
"default-logging": "LoggingTemplate"
|
||||||
|
},
|
||||||
"site": {
|
"site": {
|
||||||
"name": "A Website",
|
"name": "A Website",
|
||||||
"checker": "CheckerTemplate",
|
"checker": "HttpChecker",
|
||||||
"checker-args": {
|
"checker-args": {
|
||||||
"url": "https://example.net",
|
"url": "https://example.com"
|
||||||
"port": 443,
|
|
||||||
"lol": "CheckerTemplate ignores these options lol"
|
|
||||||
},
|
},
|
||||||
"rate": 1,
|
"rate": 1,
|
||||||
"alerts": "AlertsTemplate",
|
|
||||||
"alerts-args": {
|
"alerts-args": {
|
||||||
"url": "https://example.com/webhook-url-or-whatever-goes-here",
|
"url": "https://example.com/webhook-url-or-whatever-goes-here",
|
||||||
"lol": "irrelevant, AlertsTemplate ignores these options lol"
|
"lol": "irrelevant, AlertsTemplate ignores these options lol"
|
||||||
},
|
},
|
||||||
"logging": "LoggingTemplate",
|
|
||||||
"logging-args": {
|
"logging-args": {
|
||||||
"file": "/home/askiiart/Documents/updog/logs/site-log"
|
"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:
|
Required arguments:
|
||||||
|
|
||||||
- The key (in this case `site`): A unique string to identify the service in logs, also used internally.
|
- 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.
|
- `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)
|
- `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.
|
- `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.
|
- `logging-args`: Arguments for the logging extension. Check the logger's docs for what to put here.
|
||||||
|
|
||||||
Optional arguments:
|
Optional arguments:
|
||||||
|
|
44
helpers.py
44
helpers.py
|
@ -66,15 +66,45 @@ def create_instances(config, checkers, alerts, logging):
|
||||||
example: {'site': {'checker': instanceOfCheckerTemplate}}
|
example: {'site': {'checker': instanceOfCheckerTemplate}}
|
||||||
'''
|
'''
|
||||||
instances = {}
|
instances = {}
|
||||||
|
|
||||||
|
# global arguments
|
||||||
|
default_checker = ''
|
||||||
|
default_alerter = ''
|
||||||
|
default_logger = ''
|
||||||
for service in config.keys():
|
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] = {}
|
instances[service] = {}
|
||||||
# just creates an instance of the checker with the arguments for it
|
# create an instance of checker with the arguments for them, including the optional `default-checker`
|
||||||
instances[service]['checker'] = checkers[config[service]
|
checker_args = config[service]['checker-args']
|
||||||
['checker']](config[service]['checker-args'])
|
if config[service].get('checker', '') != '':
|
||||||
instances[service]['alerts'] = alerts[config[service]
|
checker = config[service]['checker']
|
||||||
['alerts']](config[service]['alerts-args'])
|
else:
|
||||||
instances[service]['logging'] = logging[config[service]
|
checker = default_checker
|
||||||
['logging']](config[service]['logging-args'])
|
|
||||||
|
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
|
return instances
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
{
|
{
|
||||||
|
"global-args": {
|
||||||
|
"default-checker": "CheckerTemplate",
|
||||||
|
"default-alerts": "AlertsTemplate",
|
||||||
|
"default-logging": "LoggingTemplate"
|
||||||
|
},
|
||||||
"site": {
|
"site": {
|
||||||
"name": "A Website",
|
"name": "A Website",
|
||||||
"checker": "CheckerTemplate",
|
"checker": "HttpChecker",
|
||||||
"checker-args": {
|
"checker-args": {
|
||||||
"url": "https://example.net",
|
"url": "https://askiiart.net"
|
||||||
"port": 443,
|
|
||||||
"lol": "CheckerTemplate ignores these options lol"
|
|
||||||
},
|
},
|
||||||
"rate": 1,
|
"rate": 1,
|
||||||
"alerts": "AlertsTemplate",
|
|
||||||
"alerts-args": {
|
"alerts-args": {
|
||||||
"url": "https://example.com/webhook-url-or-whatever-goes-here",
|
"url": "https://example.com/webhook-url-or-whatever-goes-here",
|
||||||
"lol": "irrelevant, AlertsTemplate ignores these options lol"
|
"lol": "irrelevant, AlertsTemplate ignores these options lol"
|
||||||
},
|
},
|
||||||
"logging": "LoggingTemplate",
|
|
||||||
"logging-args": {
|
"logging-args": {
|
||||||
"file": "/home/askiiart/Documents/updog/logs/site-log"
|
"file": "/home/askiiart/Documents/updog/logs/site-log"
|
||||||
}
|
}
|
||||||
|
|
2
updog.py
2
updog.py
|
@ -78,6 +78,8 @@ timers = {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for service in config.keys():
|
for service in config.keys():
|
||||||
|
if service == 'global-args':
|
||||||
|
continue
|
||||||
timers[service] = RepeatedTimer(config[service]['rate'], run_check,
|
timers[service] = RepeatedTimer(config[service]['rate'], run_check,
|
||||||
service, instances[service]['checker'], instances[service]['alerts'], instances[service]['logging'])
|
service, instances[service]['checker'], instances[service]['alerts'], instances[service]['logging'])
|
||||||
except:
|
except:
|
||||||
|
|
Loading…
Reference in a new issue