Flesh out basic structure of the program, finish initial extension docs

This commit is contained in:
askiiart 2024-01-31 17:58:26 -06:00
parent ed220154d8
commit ed8593e41d
Signed by untrusted user who does not match committer: askiiart
GPG key ID: BC3800E55FB54D67
6 changed files with 113 additions and 28 deletions

2
.gitignore vendored
View file

@ -1,3 +1,3 @@
extensions/
extensions/*
__pycache__/
logs/

39
docs/extensions/alerts.md Normal file
View file

@ -0,0 +1,39 @@
# Alerts Extensions
Updog doesn't do any monitoring by itself. Instead, extensions are used to check the status of whatever thing, send alerts, and log stuff. Updog just chains them together.
Example extension: [askiiart/updog-alerts_template](https://git.askiiart.net/askiiart/updog-alerts_template)
## Folder layout
Extensions need to be put in the `./extensions/alerts` folder, and the name of the file must match the name of the folder.
```txt
.
├── extensions
│ ├── alerts
│ └── alerts_template
│ └── alerts_template.py
```
## Methods
`*`: indicates a method is required
### `__init__()`*
**Arguments**:
- (dict) Arguments from `alerts-args` in `services.json` - For no arguments, an empty dict will be used
**Return**: None
### `alert()`*
**Arguments**:
- (str) The name of the service the alert is for
- (int) The status code returned by the checker
- (str) The status message for that status code
**Return**: Nothing

View file

@ -11,9 +11,9 @@ Extensions need to be put in the `./extensions/checkers` folder, and the name of
```txt
.
├── extensions
│ ├── alerts
│ └── alerts_template
│ └── alerts_template.py
│ ├── checkers
│ └── checker_template
│ └── checker_template.py
```
## Methods
@ -24,7 +24,7 @@ Extensions need to be put in the `./extensions/checkers` folder, and the name of
**Arguments**:
- A dict of arguments from `checker-args` in `services.json` - For no arguments, an empty dict will be used
- (dict) Arguments from `checker-args` in `services.json` - For no arguments, an empty dict will be used
Example:

View file

@ -0,0 +1,39 @@
# Alerts Extensions
Updog doesn't do any monitoring by itself. Instead, extensions are used to check the status of whatever thing, send alerts, and log stuff. Updog just chains them together.
Example extension: [askiiart/updog-logging_template](https://git.askiiart.net/askiiart/updog-logging_template)
## Folder layout
Extensions need to be put in the `./extensions/logging` folder, and the name of the file must match the name of the folder.
```txt
.
├── extensions
│ ├── logging
│ └── logging_template
│ └── logging_template.py
```
## Methods
`*`: indicates a method is required
### `__init__()`*
**Arguments**:
- A dict of arguments from `logging-args` in `services.json` - For no arguments, an empty dict will be used
**Return**: None
### `log()`*
**Arguments**: `service_name`, `code`, `status`
- `service_name`: The name of the service the logger is logging - currently it's always the same value for a single instance, but this is required for compatibility when support for logging multiple things with one instance of the logger is supported.
- `code`: The status code returned by the checker
- `status`: The status message for that status code
**Return**: Nothing

View file

@ -52,3 +52,31 @@ class RepeatedTimer(object):
def stop(self):
self._timer.cancel()
self.is_running = False
def create_instances(config, checkers, alerts, logging):
'''
Creates instances of all the extensions according to config
Parameters:
config: the dictionary containing the config
Returns:
instances (dict): A dictionary containing instances of the extensions
example: {'site': {'checker': instanceOfCheckerTemplate}}
'''
instances = {}
for service in config.keys():
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'])
return instances
def run_check(checker, alerts, logging):
'''
Does the logic and stuff for running the checker, calling alerts/logging, and so on
'''
pass

View file

@ -1,4 +1,4 @@
from timer import RepeatedTimer
from helpers import RepeatedTimer, create_instances, run_check
import sys
import os
import importlib
@ -73,25 +73,4 @@ elif 'services-example.json' in os.listdir():
with open(config_filename, 'rt') as config_file:
config = json.loads(''.join(config_file.readlines()))
def create_instances(config):
'''
Creates instances of all the extensions according to config
Parameters:
config: the dictionary containing the config
Returns:
instances (dict): A dictionary containing instances of the extensions
example: {'site': {'checker': instanceOfCheckerTemplate}}
'''
instances = {}
for service in config.keys():
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'])
return instances
print(create_instances(config, checkers, alerts, logging))