mirror of
https://github.com/KevinMidboe/mktxp-no-cli.git
synced 2025-10-29 17:50:23 +00:00
custom config files directory
This commit is contained in:
@@ -186,12 +186,27 @@ class LinuxConfig(OSConfig):
|
|||||||
@property
|
@property
|
||||||
def mktxp_user_dir_path(self):
|
def mktxp_user_dir_path(self):
|
||||||
return FSHelper.full_path('~/mktxp')
|
return FSHelper.full_path('~/mktxp')
|
||||||
# return FSHelper.full_path('/etc/mktxp')
|
|
||||||
|
|
||||||
|
class CustomConfig(OSConfig):
|
||||||
|
''' Custom config
|
||||||
|
'''
|
||||||
|
def __init__(self, path):
|
||||||
|
self._user_dir_path = path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def mktxp_user_dir_path(self):
|
||||||
|
return FSHelper.full_path(self._user_dir_path)
|
||||||
|
|
||||||
|
|
||||||
class MKTXPConfigHandler:
|
class MKTXPConfigHandler:
|
||||||
|
# two-phase init
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.os_config = OSConfig.os_config()
|
pass
|
||||||
|
|
||||||
|
# two-phase init, to enable custom config
|
||||||
|
def __call__(self, os_config = None):
|
||||||
|
self.os_config = os_config if os_config else OSConfig.os_config()
|
||||||
if not self.os_config:
|
if not self.os_config:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,9 @@
|
|||||||
ipv6_firewall = False # IPv6 Firewall rules traffic metrics
|
ipv6_firewall = False # IPv6 Firewall rules traffic metrics
|
||||||
ipv6_neighbor = False # Reachable IPv6 Neighbors
|
ipv6_neighbor = False # Reachable IPv6 Neighbors
|
||||||
|
|
||||||
monitor = True # Interface monitor metrics
|
|
||||||
poe = True # POE metrics
|
poe = True # POE metrics
|
||||||
|
monitor = True # Interface monitor metrics
|
||||||
|
netwatch = True # Netwatch metrics
|
||||||
public_ip = True # Public IP metrics
|
public_ip = True # Public IP metrics
|
||||||
route = True # Routes metrics
|
route = True # Routes metrics
|
||||||
wireless = True # WLAN general metrics
|
wireless = True # WLAN general metrics
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
import os
|
import os
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
from argparse import ArgumentParser, HelpFormatter
|
from argparse import ArgumentParser, HelpFormatter
|
||||||
from mktxp.cli.config.config import config_handler, MKTXPConfigKeys
|
from mktxp.cli.config.config import config_handler, MKTXPConfigKeys, CustomConfig
|
||||||
from mktxp.utils.utils import FSHelper, UniquePartialMatchList, run_cmd
|
from mktxp.utils.utils import FSHelper, UniquePartialMatchList, run_cmd
|
||||||
|
|
||||||
|
|
||||||
@@ -62,22 +62,31 @@ Selected metrics info can be printed on the command line. For more information,
|
|||||||
def parse_options(self):
|
def parse_options(self):
|
||||||
''' General Options parsing workflow
|
''' General Options parsing workflow
|
||||||
'''
|
'''
|
||||||
parser = ArgumentParser(prog = self._script_name,
|
|
||||||
|
global_options_parser = ArgumentParser(add_help=False)
|
||||||
|
self.parse_global_options(global_options_parser)
|
||||||
|
namespace, _ = global_options_parser.parse_known_args()
|
||||||
|
if namespace.dir:
|
||||||
|
config_handler(CustomConfig(namespace.dir))
|
||||||
|
else:
|
||||||
|
config_handler()
|
||||||
|
|
||||||
|
commands_parser = ArgumentParser(prog = self._script_name,
|
||||||
description = 'Prometheus Exporter for Mikrotik RouterOS',
|
description = 'Prometheus Exporter for Mikrotik RouterOS',
|
||||||
formatter_class=MKTXPHelpFormatter)
|
formatter_class=MKTXPHelpFormatter, parents=[global_options_parser])
|
||||||
|
self.parse_commands(commands_parser)
|
||||||
|
args = vars(commands_parser.parse_args())
|
||||||
|
|
||||||
self.parse_global_options(parser)
|
self._check_args(args, commands_parser)
|
||||||
self.parse_commands(parser)
|
|
||||||
args = vars(parser.parse_args())
|
|
||||||
|
|
||||||
self._check_args(args, parser)
|
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
def parse_global_options(self, parser):
|
def parse_global_options(self, parser):
|
||||||
''' Parses global options
|
''' Parses global options
|
||||||
'''
|
'''
|
||||||
pass
|
parser.add_argument('--dir', dest = 'dir',
|
||||||
|
type = lambda d: self._is_valid_dir_path(parser, d),
|
||||||
|
help = 'MKTXP config files directory (optional)')
|
||||||
|
|
||||||
def parse_commands(self, parser):
|
def parse_commands(self, parser):
|
||||||
''' Commands parsing
|
''' Commands parsing
|
||||||
|
|||||||
Reference in New Issue
Block a user