Initial commit - basics of checker extensions added
This commit is contained in:
commit
609e4b50d5
4 changed files with 137 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
extensions/__pycache__
|
||||
extensions/checkers/__pycache__
|
||||
extensions/checkers/checker_template/__pycache__
|
15
extensions/checkers/checker_template/checker_template.py
Normal file
15
extensions/checkers/checker_template/checker_template.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
import random
|
||||
|
||||
|
||||
class CheckerTemplate:
|
||||
def __init__(arguments):
|
||||
pass
|
||||
|
||||
def get_status():
|
||||
latency = int(random.random() * 3000)
|
||||
if latency > 2500: # "simulate" a timeout
|
||||
return 0
|
||||
elif latency > 1000: # "simulate" a very slow application - a partial outage
|
||||
return 50
|
||||
else:
|
||||
return 100
|
31
main.py
Normal file
31
main.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
import sys
|
||||
import os
|
||||
import importlib
|
||||
import inspect
|
||||
|
||||
DEBUG = False
|
||||
|
||||
# relative imports suck - https://gideonbrimleaf.github.io/2021/01/26/relative-imports-python.html
|
||||
path = os.path.realpath(__file__)
|
||||
path = path[:path.rfind('/')]
|
||||
sys.path.insert(1, f'{path}/extensions/checkers')
|
||||
|
||||
# importlib used to import stuff programmatically, rather than using the hardcoded import keyword, basically the same but it seems it can't import *just* a class
|
||||
uptime_extension_imports = []
|
||||
for ext_name in os.listdir(f'{path}/extensions/checkers'):
|
||||
if ext_name[0] != '.':
|
||||
uptime_extension_imports.append(f'{ext_name}.{ext_name}')
|
||||
|
||||
# uptime_checkers contains all the classes for the checker extensions
|
||||
# e.g. {'CheckerTemplate': checker_template.checker_template.CheckerTemplate}
|
||||
checkers = dict()
|
||||
for ext in [importlib.import_module(ext) for ext in uptime_extension_imports]:
|
||||
for name, obj in inspect.getmembers(ext):
|
||||
if inspect.isclass(obj):
|
||||
checkers[name] = obj
|
||||
|
||||
if DEBUG:
|
||||
print('uptime_extension_imports:', uptime_extension_imports)
|
||||
print('checkers:', checkers)
|
||||
|
||||
print(checkers['CheckerTemplate'].get_status())
|
88
readme.md
Normal file
88
readme.md
Normal file
|
@ -0,0 +1,88 @@
|
|||
# askiiart/updog
|
||||
|
||||
## What's updog?
|
||||
|
||||
Not much, you?
|
||||
|
||||
<small>(it's a simple, extensible uptime monitor)</small>
|
||||
|
||||
## Warning
|
||||
|
||||
**Extensions will be executed with no safety checks!** Make sure an extension isn't malicious before adding it.
|
||||
|
||||
## Uptime Checker Extensions
|
||||
|
||||
<!-- move to docs folder later -->
|
||||
|
||||
Updog doesn't do any monitoring by itself. Instead, extensions are used to check the status of whatever thing, and are used
|
||||
|
||||
### Metadata
|
||||
|
||||
Extensions need to be put in the `./extensions/checkers` folder and the name of the file must match the name of the folder. In the future, `alerts` and `logging` folders will be added for those extensions. For now, there is only support for checkers, and Updog itself will have very basic logging.
|
||||
|
||||
### Methods
|
||||
|
||||
`*`: indicates a method is required
|
||||
|
||||
#### `__init__()`*
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- a list of strings from `checker-args` in `services.json` - for no arguments an empty list will be used
|
||||
|
||||
**Return**: None
|
||||
|
||||
#### `get_status()`*
|
||||
|
||||
**Arguments**: None
|
||||
|
||||
**Return**: An integer from 0 to 100 indicating status; defaults listed in [`get_return_codes()`](#get_return_codes)
|
||||
|
||||
These values can be overriden by providing [`get_return_codes()`](#get_return_codes)
|
||||
|
||||
#### `get_return_codes()`
|
||||
|
||||
**Arguments**: None
|
||||
|
||||
**Return**: A `dict` containing integers and their associated statuses.
|
||||
|
||||
Default:
|
||||
|
||||
```py
|
||||
{
|
||||
0: "Down",
|
||||
50: "Partial outage",
|
||||
100: "Up"
|
||||
}
|
||||
```
|
||||
|
||||
## To-do
|
||||
|
||||
- Add basic functionality
|
||||
- Read `services.json` file:
|
||||
|
||||
```json
|
||||
{
|
||||
"site" {
|
||||
"name": "A Website",
|
||||
"uptime-checker": "CheckerTemplate",
|
||||
"checker-args": {
|
||||
"url": "https://example.net",
|
||||
"port: "443",
|
||||
},
|
||||
"rate": 60,
|
||||
"alerts": "AlertsTemplate",
|
||||
"alerts-args" {
|
||||
"url": "https://example.com/webhook-url-or-whatever-goes-here"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The args are just passed to the extension as a `dict`, the extension handles it from there.
|
||||
|
||||
- Add support for logging and alert extensions
|
||||
|
||||
---
|
||||
|
||||
***All specs are still a work-in-progress, breaking changes are likely!***
|
Loading…
Reference in a new issue