-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
venv/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,32 @@ | ||
# check_ripe_db | ||
Monitoring check plugin that queries the RIPE database and checks whether its results match the expectations | ||
Monitoring check plugin that queries the RIPE database and checks whether its results match the expectations. | ||
|
||
### Usage | ||
Possible options: | ||
|
||
| Option | Description | required? | | ||
|-----------------------------------------------------------------|----------------------------|---------------------| | ||
| -h | Help | no | | ||
| -s/--source <DB source>: | The DB source to query | no (default: ripe) | | ||
| -o/--objecttype <DB objecttype> | The DB objecttype to query | yes | | ||
| -k/--key <DB search key> | The DB key to query | yes | | ||
| -e/--expected "<(attribute, [value, value2], match_mode), ...>" | The expected attributes | yes | | ||
|
||
There are three different match modes for the expected values: | ||
|
||
1. SINGLEVALUE: The expected value has to match the resulting value | ||
2. EXACTLIST: The expacted values must exactly match the resulting values list | ||
|
||
A possible usage could look like this: | ||
|
||
```shell | ||
python check_ripe_db.py -s "ripe" -o "aut-num" -k "as44163" -e "(status, Assigned, SINGLEVALUE), (source, [Filtered, Assigned], EXACTLIST)" | ||
``` | ||
|
||
### Dependencies | ||
|
||
The plugin only needs the requests library to run. The library can be installed by running: | ||
|
||
```shell | ||
python -m pip install requests | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import argparse | ||
import json | ||
|
||
import requests | ||
|
||
|
||
def parse_cli(): | ||
parser = argparse.ArgumentParser( | ||
description="Monitoring check plugin to query the RIPE database and check if the values match the expectations") | ||
parser.add_argument("-s", "--source", type=str, help="RIPE database source", default="ripe") | ||
parser.add_argument("-o", "--objecttype", type=str, help="RIPE database objecttype") | ||
parser.add_argument("-k", "--key", type=str, help="RIPE database objecttype") | ||
parser.add_argument("-e", "--expected", type=str, help="Expected values to check") | ||
args = parser.parse_args() | ||
args = args.__dict__ | ||
if "objecttype" not in args.keys(): | ||
print("UNKNOWN - The DB objecttype (-o/--objecttype) is required, but was not given") | ||
exit(3) | ||
if "key" not in args.keys(): | ||
print("UNKNOWN - The DB key (-k/--key) is required, but was not given") | ||
exit(3) | ||
if "expected" not in args.keys(): | ||
print("UNKNOWN - The expected values (-e/--expected) are required, but were not given") | ||
exit(3) | ||
source, objecttype, key = args["source"], args["objecttype"], args["key"] | ||
expected_string = args["expected"] | ||
expected = [] | ||
for value in expected_string.split("),"): | ||
elements = value.split(",") | ||
if len(elements) < 3: | ||
print("UNKNOWN - The expected results format is wrong, please use the following format:" | ||
"<(attribute, [value, ...], match_mode), ...>") | ||
exit(3) | ||
else: | ||
values = [] | ||
for val in elements[1:len(elements)-1]: | ||
values.append(val.replace("[", "").replace("]", "").lstrip(" ")) | ||
expected.append((elements[0].replace("(", ""), values, elements[len(elements)-1].replace(")", ""))) | ||
return source, objecttype, key, expected | ||
|
||
|
||
def check_values(res): | ||
pass | ||
|
||
|
||
def main(): | ||
src, objtype, key, exp = parse_cli() | ||
url = f"https://rest.db.ripe.net/{src}/{objtype}/{key}" | ||
resp = requests.get(url, headers={"Accept": "application/json"}) | ||
resp_dict = json.loads(resp.text) | ||
check_values(resp_dict) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |