Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to GET default parsers #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions cbn_cli.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ def get_get_parser_url(args, config_id):
print(f'Connecting to: {url}')
return url

def get_default_parser_url(args, log_type):
"""Returns get parser endpoint URL for corresponding region and env."""
url = f'{get_connecting_url(args)}/tools/cbnParsers/{log_type}'
print(f'Connecting to: {url}')
return url


def get_archive_parser_url(args, config_id):
"""Returns archive parser endpoint URL for corresponding region and env."""
Expand Down Expand Up @@ -232,6 +238,12 @@ def download_parser(args):

call_download_parser(args, args.config_id, args.log_type)

def default_parser(args):
"""Downloads default Parser to a file, formatted."""
print('\n[cbn_cli]: Downloading default parser... ', flush=True)

call_default_parser(args, args.log_type)


def parser_errors(args):
"""Gets a list of parser errors."""
Expand Down Expand Up @@ -402,6 +414,19 @@ def call_download_parser(args, config_id, log_type):
with open(filename, 'a') as f:
f.write(decoded_config)

def call_default_parser(args, log_type):
"""Calls log_type parsers endpoint and writes default parser config to file."""
parser = make_request(args, get_default_parser_url(args, args.log_type))

decoded_config = base64.b64decode(parser['config'])
decoded_config = decoded_config.decode('utf-8')
timestr = time.strftime('%Y%m%d%H%M%S')
filename = parser['logType'] + '_' + timestr + '.conf'
print(f'Writing parser to: {filename}')
with open(filename, 'a') as f:
f.write(decoded_config)



def call_parser_errors(args, log_type, start_date, end_date):
"""Calls parser errors endpoint and prints the result."""
Expand Down Expand Up @@ -524,6 +549,13 @@ def arg_parser():
dgroup.add_argument('-i', '--config_id', help='unique config ID')
parser_download_command.set_defaults(func=download_parser)

# "default" command
parser_default_command = subparsers.add_parser(
'default', help='download default parser code given log type')
parser_default_command.add_argument(
'-l', '--log_type', required=True, help='Log Type')
parser_default_command.set_defaults(func=default_parser)

# "error" command
error_command = subparsers.add_parser(
'error', aliases=['e', 'err'], help='Get CBN errors')
Expand Down