Flesh out basic structure of the program, finish initial extension docs
This commit is contained in:
parent
ed220154d8
commit
ed8593e41d
6 changed files with 113 additions and 28 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,3 @@
|
||||||
extensions/
|
extensions/*
|
||||||
__pycache__/
|
__pycache__/
|
||||||
logs/
|
logs/
|
39
docs/extensions/alerts.md
Normal file
39
docs/extensions/alerts.md
Normal 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
|
|
@ -11,9 +11,9 @@ Extensions need to be put in the `./extensions/checkers` folder, and the name of
|
||||||
```txt
|
```txt
|
||||||
.
|
.
|
||||||
├── extensions
|
├── extensions
|
||||||
│ ├── alerts
|
│ ├── checkers
|
||||||
│ └── alerts_template
|
│ └── checker_template
|
||||||
│ └── alerts_template.py
|
│ └── checker_template.py
|
||||||
```
|
```
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
@ -24,7 +24,7 @@ Extensions need to be put in the `./extensions/checkers` folder, and the name of
|
||||||
|
|
||||||
**Arguments**:
|
**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:
|
Example:
|
||||||
|
|
||||||
|
|
39
docs/extensions/logging.md
Normal file
39
docs/extensions/logging.md
Normal 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
|
|
@ -52,3 +52,31 @@ class RepeatedTimer(object):
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self._timer.cancel()
|
self._timer.cancel()
|
||||||
self.is_running = False
|
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
|
25
updog.py
25
updog.py
|
@ -1,4 +1,4 @@
|
||||||
from timer import RepeatedTimer
|
from helpers import RepeatedTimer, create_instances, run_check
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import importlib
|
import importlib
|
||||||
|
@ -73,25 +73,4 @@ elif 'services-example.json' in os.listdir():
|
||||||
with open(config_filename, 'rt') as config_file:
|
with open(config_filename, 'rt') as config_file:
|
||||||
config = json.loads(''.join(config_file.readlines()))
|
config = json.loads(''.join(config_file.readlines()))
|
||||||
|
|
||||||
|
print(create_instances(config, checkers, alerts, logging))
|
||||||
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
|
|
Loading…
Reference in a new issue