Skip to content

nspepi stylebooks integration, logging modified and file path extraction modified #16

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
65 changes: 32 additions & 33 deletions nspepi/nspepi2/check_classic_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def check_pos_expr(commandParseTree, pos, check_removed_expr = True):
rule_expr = rule_node.value
converted_expr = check_classic_expr.check_classic_expr(rule_expr)
if converted_expr is None:
logging.error('Error in checking command : ' +
str(commandParseTree))
logging.error(('Error in checking command : [{}]').format(str(commandParseTree)))

elif converted_expr == "Invalid Expression":
commandParseTree.set_invalid()
else:
Expand Down Expand Up @@ -168,8 +168,7 @@ def check_keyword_expr(commandParseTree, keywordName):
rule_expr = rule_node[0].value
converted_expr = check_classic_expr.check_classic_expr(rule_expr)
if converted_expr is None:
logging.error('Error in checking command : ' +
str(commandParseTree))
logging.error(('Error in checking command : [{}]').format(str(commandParseTree)))
elif converted_expr == "Invalid Expression":
commandParseTree.set_invalid()
else:
Expand Down Expand Up @@ -519,14 +518,14 @@ def check_policy_expr(self, commandParseTree):
" and shouldn't be name of another policy entity"
"; words reserved for policy use may not be used;"
" underscores will be substituted for any invalid"
" characters in corresponding advanced name")
.format(expr_name))
" characters in corresponding advanced name : [{}]")
.format(expr_name, str(commandParseTree)))

if commandParseTree.keyword_exists('clientSecurityMessage'):
NamedExpression.register_classic_entity_name(commandParseTree)
logging.warning(("Client security expressions are deprecated"
" using this command [{}], please use the"
" the advanced authentication policy command")
" using this command, please use the"
" the advanced authentication policy command. : [{}]")
.format(str(commandParseTree).strip()))
return []

Expand All @@ -542,8 +541,8 @@ def check_policy_expr(self, commandParseTree):
"""
NamedExpression.register_policy_entity_name(commandParseTree)
NamedExpression.register_classic_entity_name(original_tree)
logging.warning(("Classic expression has been deprecated in"
" command [{}], please use the advanced expression")
logging.warning(("Classic expression has been deprecated in the"
" following command, please use the advanced expression : [{}]")
.format(str(commandParseTree).strip()))
else:
NamedExpression.register_policy_entity_name(original_tree)
Expand Down Expand Up @@ -911,7 +910,7 @@ def check_deprecated_classic_policy(self, commandParseTree):
commandParseTree = Deprecation.check_pos_expr(commandParseTree, 1, False)
if commandParseTree.invalid:
logging.warning(("Classic expression in the rule field has been deprecated"
" for command [{}], please use the advanced expression")
" for the following command, please use the advanced expression : [{}]")
.format(str(commandParseTree).strip()))
elif is_advanced_removed_expr_present(rule_expr):
commandParseTree.set_invalid()
Expand All @@ -932,8 +931,8 @@ def check_authentication_commands(self, commandParseTree):
"""
Check the Authentication commands which have been deprecated
"""
logging.warning(("[{}] command has been deprecated,"
" please use the advanced authentication policy command")
logging.warning(("Following command has been deprecated,"
" please use the advanced authentication policy command : [{}]")
.format(str(commandParseTree).strip()))
return []

Expand All @@ -942,8 +941,8 @@ def check_ns_traffic_domain(self, commandParseTree):
"""
Check the traffic domain command
"""
logging.warning(("[{}] command has been deprecated,"
" please use the admin partition feature")
logging.warning(("Command has been deprecated,"
" please use the admin partition feature. : [{}]")
.format(str(commandParseTree).strip()))
return []

Expand All @@ -955,8 +954,8 @@ def check_aaa_preauth_params(self, commandParseTree):
"""
if commandParseTree.keyword_exists('rule'):
logging.warning(("Client security expressions are deprecated"
" using this command [{}], please use the"
" the advanced authentication policy command")
" using this command, please use the"
" the advanced authentication policy command : [{}]")
.format(str(commandParseTree).strip()))
return []

Expand All @@ -968,8 +967,8 @@ def check_vpn_sessionaction(self, commandParseTree):
"""
if commandParseTree.keyword_exists('clientSecurity'):
logging.warning(("Client security expressions are deprecated"
" using this command [{}], please use the"
" the advanced authentication policy command")
" using this command, please use the"
" the advanced authentication policy command : [{}]")
.format(str(commandParseTree).strip()))
return []

Expand All @@ -982,7 +981,7 @@ def check_vpn_url(self, commandParseTree):
sso_type = commandParseTree.keyword_value("ssotype")[0].value.lower()
if sso_type == "selfauth":
logging.warning("Selfauth type has been deprecated"
" in command [{}]".format(str(commandParseTree).strip()))
" in command : [{}]".format(str(commandParseTree).strip()))
return []

@common.register_for_cmd("add", "vpn", "portaltheme")
Expand All @@ -996,8 +995,8 @@ def check_vpn_portaltheme(self, commandParseTree):
if base_theme == "Default" or base_theme == "X1" \
or base_theme == "Greenbubble":
logging.warning(("Default, GreenBubble and X1 themes"
" have been deprecated in command [{}],"
" please use RfWebUI theme or RfWebUI based custom theme")
" have been deprecated in the command,"
" please use RfWebUI theme or RfWebUI based custom theme : [{}]")
.format(str(commandParseTree).strip()))
return []

Expand All @@ -1013,8 +1012,8 @@ def check_vpn_commands(self, commandParseTree):
if base_theme == "Default" or base_theme == "X1" \
or base_theme == "Greenbubble":
logging.warning(("Default, GreenBubble and X1 themes"
" have been deprecated in command [{}],"
" please use RfWebUI theme or RfWebUI based custom theme")
" have been deprecated in the command,"
" please use RfWebUI theme or RfWebUI based custom theme : [{}]")
.format(str(commandParseTree).strip()))
return []

Expand All @@ -1027,13 +1026,13 @@ def check_dns_action(self, commandParseTree):
action_type = commandParseTree.positional_value(1).value.lower()
if action_type == "rewrite_response":
logging.warning(("Rewrite_Response action type is deprecated in"
" command [{}], please use the replace_dns_answer_section"
" action type under Rewrite feature.")
" the command, please use the replace_dns_answer_section"
" action type under Rewrite feature. : [{}]")
.format(str(commandParseTree).strip()))
elif action_type == "drop":
logging.warning(("Drop action type is deprecated in"
" command [{}], please use the Drop"
" action type under Responder feature.")
" the command, please use the Drop"
" action type under Responder feature. : [{}]")
.format(str(commandParseTree).strip()))
return []

Expand All @@ -1049,8 +1048,8 @@ def check_ns_feature(self, commandParseTree):
feature_name = feature_node.value
if feature_name in features_to_remove:
logging.warning("SC, PQ, HDOSP, and CF features"
" have been deprecated in command [{}], please"
" use the APPQOE, REWRITE, and RESPONDER features"
" have been deprecated in the command, please"
" use the APPQOE, REWRITE, and RESPONDER features : [{}]"
.format(str(commandParseTree).strip()))
break
return []
Expand All @@ -1070,7 +1069,7 @@ def check_deprecated_pacingcommands(self, commandParseTree):
commandParseTree.set_invalid()
return [commandParseTree]

logging.warning(("[{}] command has been deprecated")
logging.warning(("Command has been deprecated : [{}]")
.format(str(commandParseTree).strip()))
return []

Expand All @@ -1096,7 +1095,7 @@ def check_lsn_commands(self, commandParseTree):
Check the Authentication commands which have been deprecated
"""
if (int(build_version.split(".")[0]) > 13):
logging.warning(("[{}] command has been deprecated")
logging.warning(("Command has been deprecated : [{}]")
.format(str(commandParseTree).strip()))
return []

Expand All @@ -1120,5 +1119,5 @@ def check_responder_action(self, commandParseTree):
action_type = commandParseTree.positional_value(1).value.lower()
if action_type is "noop":
logging.warning("NOOP action type has been deprecated"
" for command [{}]".format(str(commandParseTree).strip()))
" for the command : [{}]".format(str(commandParseTree).strip()))
return []
6 changes: 2 additions & 4 deletions nspepi/nspepi2/check_classic_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ def check_classic_expr(classic_expr):
of the converted string, so remove that character."""
nspepi_tool_output = nspepi_tool_output.rstrip()
except subprocess.CalledProcessError as exc:
# Log the command which is failing
logging.error(exc)
# Log the error message
logging.error(exc.output)
# Log the command which is failing and also the error message
logging.error(exc.output + " : [" + exc + "]")
return None
nspepi_tool_output = nspepi_tool_output.decode()
if nspepi_tool_output.startswith('ERROR:'):
Expand Down
20 changes: 6 additions & 14 deletions nspepi/nspepi2/cli_lex.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ def token(self):
else:
self.advance_token(self._length)
token_type = "ERROR"
logging.error("Data: {}".format(self._data))
logging.error("Unbalanced closed parenthesis")
logging.error("Unbalanced closed parenthesis : [{}]".format(self._data))
break
elif self._data[self._lex_pos] == "\\":
# backslashes are escapes inside quotes
Expand All @@ -187,9 +186,7 @@ def token(self):
self.advance_and_append_token(
self._data[self._lex_pos])
token_type = "ERROR"
logging.error("Data: {}".format(self._data))
logging.error("Blackslashes inside quotes are "
"followed by end of the command")
logging.error("Blackslashes inside quotes are followed by end of the command : [{}]".format(self._data))
break
if self._data[self._lex_pos + 1] == 't':
self.advance_and_append_token('\t', 2)
Expand All @@ -211,8 +208,7 @@ def token(self):
if state in "\"'" or parenthesis_counter > 0:
# error token for not matching with any rule
token_type = "ERROR"
logging.error("Data: {}".format(self._data))
logging.error("Unbalanced parenthesis or quotes")
logging.error("Unbalanced parenthesis or quotes : [{}]".format(self._data))
next_token = LexToken(token_type, self._token_value, 1,
self._lex_pos - 1)
return next_token
Expand Down Expand Up @@ -333,9 +329,7 @@ def adv_expr_token(self):
self.advance_and_append_token(
self._data[self._lex_pos])
token_type = "ERROR"
logging.error("Data: {}".format(self._data))
logging.error("Blackslashes inside quotes are "
"followed by end of the expression")
logging.error("Blackslashes inside quotes are followed by end of the expression : [{}]".format(self._data))
break
if self._data[self._lex_pos + 1] == 't':
self.advance_and_append_token('\t', 2)
Expand All @@ -357,13 +351,11 @@ def adv_expr_token(self):
if state in "\"'":
# error token for not matching with any rule
token_type = "ERROR"
logging.error("Data: {}".format(self._data))
logging.error("Unbalanced quotes")
logging.error("Unbalanced quotes : [{}]".format(self._data))
elif state == "REGEX":
# error token for not matching with any rule
token_type = "ERROR"
logging.error("Data: {}".format(self._data))
logging.error("Unterminated regex")
logging.error("Unterminated regex : [{}]".format(self._data))
next_token = LexToken(token_type, self._token_value, 1,
self._lex_pos - 1)
return next_token
14 changes: 6 additions & 8 deletions nspepi/nspepi2/convert_classic_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ def convert_classic_expr(classic_expr, ignore_csec_expr = False):
of the converted string, so remove that character."""
nspepi_tool_output = nspepi_tool_output.rstrip()
except subprocess.CalledProcessError as exc:
# Log the command which is failing
logging.error(exc)
# Log the error message
logging.error(exc.output)
# Log the command which is failing and also the reason
logging.error(str(exc) + " : [" + str(exc.output) + "]")
return None
nspepi_tool_output = nspepi_tool_output.decode()
if nspepi_tool_output.startswith('ERROR:'):
Expand Down Expand Up @@ -102,7 +100,7 @@ def convert_adv_expr(advanced_expr):
body_expr_without_arg = is_body_expr_without_arg_present(advanced_expr)
if body_expr_without_arg:
logging.error("Body size needs to process is not present "
"in HTTP.REQ.BODY expression, please privoide the body size.")
"in HTTP.REQ.BODY expression, please provide the body size. : [{}]".format(advanced_expr))
return None
advanced_expr = convert_q_s_expr(advanced_expr)
return convert_sys_eval_classic_expr(advanced_expr)
Expand Down Expand Up @@ -169,7 +167,7 @@ def convert_sys_eval_classic_expr(advanced_expr):
classic_exp_info = PILex.get_pi_string(
advanced_expr[arg_start_index:])
if classic_exp_info is None:
logging.error("Error in converting expression: {}".format(
logging.error("Error in converting expression : [{}]".format(
original_expr))
return None
classic_expr = classic_exp_info[0]
Expand All @@ -184,15 +182,15 @@ def convert_sys_eval_classic_expr(advanced_expr):
sys_end_index += 1
if (sys_end_index >= advanced_expr_length or
advanced_expr[sys_end_index] != ')'):
logging.error("Error in converting expression: {}".format(
logging.error("Error in converting expression : [{}]".format(
original_expr))
return None
converted_expr = convert_classic_expr(classic_expr)
if converted_expr is not None:
# Result from convert_classic_expr will have enclosing quotes.
converted_expr = cli_commands.remove_quotes(converted_expr)
if converted_expr is None or converted_expr == classic_expr:
logging.error("Error in converting expression: {}".format(
logging.error("Error in converting expression: [{}]".format(
original_expr))
return None
# Converted expression should be enclosed in braces because
Expand Down
Loading