Skip to content
Snippets Groups Projects
Commit 914f4174 authored by Pelle Koster's avatar Pelle Koster
Browse files

process feedback

parent be121cd0
No related branches found
No related tags found
No related merge requests found
import json
import logging.config
import os
import socket
from datetime import datetime
from typing import Iterable, List
import click
import jsonschema
from brian_polling_manager.interface_stats import vendors
from brian_polling_manager.interface_stats.click_helpers import (
validate_config,
validate_hostname,
)
from brian_polling_manager.interface_stats.services import (
get_juniper_netconf,
get_netconf_from_source_dir,
write_points_to_influx,
write_points_to_stdout,
)
from brian_polling_manager.interface_stats.vendors import Vendor, juniper
from brian_polling_manager.inventory import load_interfaces
from . import config
logger = logging.getLogger(__file__)
LOGGING_DEFAULT_CONFIG = {
......@@ -222,6 +221,29 @@ def main(
return error_count
def validate_config(_unused_ctx, _unused_param, file):
try:
return config.load(file)
except json.JSONDecodeError:
raise click.BadParameter("config file is not valid json")
except jsonschema.ValidationError as e:
raise click.BadParameter(e)
def validate_hostname(_unused_ctx, _unused_param, hostname_or_names):
hostnames = (
hostname_or_names
if isinstance(hostname_or_names, (list, tuple))
else [hostname_or_names]
)
for _h in hostnames:
try:
socket.gethostbyname(_h)
except socket.error:
raise click.BadParameter(f"{_h} is not resolveable")
return hostname_or_names
@click.command()
@click.option(
"--config",
......
from . import config
import json
import click
import jsonschema
import socket
def validate_config(_unused_ctx, _unused_param, file):
try:
return config.load(file)
except json.JSONDecodeError:
raise click.BadParameter("config file is not valid json")
except jsonschema.ValidationError as e:
raise click.BadParameter(e)
def validate_hostname(_unused_ctx, _unused_param, hostname_or_names):
hostnames = (
hostname_or_names
if isinstance(hostname_or_names, (list, tuple))
else [hostname_or_names]
)
for _h in hostnames:
try:
socket.gethostbyname(_h)
except socket.error:
raise click.BadParameter(f"{_h} is not resolveable")
return hostname_or_names
{
"juniper": {
"key_filename": "~/.ssh/inprov_monitor_dsa",
"username": "Monit0r",
"hostkey_verify": false
"ssh_config": "~/.ssh/config"
},
"nokia": {
"username": "bogus-user",
"password": "bogus-password"
},
"inventory": ["https://test-inprov01.geant.org"],
"inventory": ["blah"],
"influx": {
"brian-counters": {
"hostname": "hostname",
......@@ -24,10 +22,5 @@
"username": "some-username",
"password": "user-password"
}
},
"testing": {
"dry_run": true,
"no-out": false,
"netconf-source-dir": "test/interface_stats/data"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment