本文整理汇总了Python中output.Output.emphasized方法的典型用法代码示例。如果您正苦于以下问题:Python Output.emphasized方法的具体用法?Python Output.emphasized怎么用?Python Output.emphasized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类output.Output
的用法示例。
在下文中一共展示了Output.emphasized方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import emphasized [as 别名]
def run (self):
total = 0
passed = 0
json_msg = {'plugin': self.__name, 'checks': {}}
if self.__raw:
json_msg['source'] = self.__data[-(self.__raw_limit * 1024):]
if self.__verbose > 0:
Output.emphasized ('\nRunning checks for plugin "%s"...' % self.__name, [self.__name])
for check in self.__checks:
total += 1
result, msg = check.run()
if not result:
if self.__verbose == 2:
Output.error ('Check "%s" failed: %s!' % (check.get_name(), msg))
elif self.__verbose == 1:
Output.error ('Check "%s" failed!' % check.get_name())
json_msg['checks'][check.get_name()] = {'result': False, 'severity': check.get_severity(), 'warning': check.get_warning(), 'advice': check.get_advice()}
# Exit the loop if one check has failed.
if self.__cutoff:
break
else:
if self.__verbose > 0:
Output.info ('Check "%s" passed!' % check.get_name())
json_msg['checks'][check.get_name()] = {'result': True}
passed += 1
if self.__verbose > 0:
if passed == total:
Output.info ('All tests passed')
else:
Output.info ('%d out of %d tests passed' % (passed, total))
return (json_msg)
示例2: run
# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import emphasized [as 别名]
#.........这里部分代码省略.........
aux_command = "cat %s" % self.__filename
elif self.__type == "command":
aux_command = self.__command
elif self.__type == "db":
aux_command = "echo '%s' | ossim-db" % check.get_query()
if not result:
if self.__verbose >= 2:
Output.error("Check '%s' failed: %s" % (check.get_name(), msg))
elif self.__verbose == 1:
Output.error("Check '%s' failed" % check.get_name())
if self.__alienvault_config['has_ha'] and check.get_ha_dependant():
json_msg['checks'][check.get_name()] = {'result': 'passed',
'severity': check.get_severity(),
'description': check.get_description(),
'summary': 'HA configuration detected. Invalid issue: %s. Disregard this check' % check.get_summary_failed(),
'remediation': check.get_remediation(),
'detail': fo.lstrip().replace('\n\t', ';'),
'debug_detail': msg.lstrip().replace('\n\t', ';'),
'pattern': str(check.get_pattern()),
'command': aux_command,
'output': check.get_output(),
'strike_zone': True}
elif check.get_severity() != 'Info':
json_msg['checks'][check.get_name()] = {'result': 'failed',
'severity': check.get_severity(),
'description': check.get_description(),
'summary': check.get_summary_failed(),
'remediation': check.get_remediation(),
'detail': fo.lstrip().replace('\n\t', ';'),
'debug_detail': msg.lstrip().replace('\n\t', ';'),
'pattern': check.get_pattern(),
'command': aux_command,
'output': check.get_output()}
# If current check affects to strike_zone, set 'strike_zone' param to 'False'
json_msg['checks'][check.get_name()]['strike_zone'] = False if check.get_strike_zone() else True
else:
json_msg['checks'][check.get_name()] = {'result': 'passed',
'severity': check.get_severity(),
'description': check.get_description(),
'summary': check.get_summary_failed(),
'remediation': check.get_remediation(),
'detail': fo.lstrip().replace('\n\t', ';'),
'debug_detail': msg.lstrip().replace('\n\t', ';'),
'pattern': check.get_pattern(),
'command': aux_command,
'output': check.get_output(),
'strike_zone': True}
if json_msg['checks'][check.get_name()]['result'] == 'failed':
self.__result &= False
# Evaluate strike zone. We have to take in mind:
# 1. If the current plugin affects to the strike zone
# 2. If the check analysed affects to the strike zone
# 3. If this is an info check
if self.__strike_zone:
if check.get_strike_zone():
if check.get_severity() != 'Info':
json_msg['strike_zone'] = False
# Exit the loop if one check has failed.
if self.__cutoff:
break
else:
if self.__verbose > 0:
Output.info('Check "%s" passed' % check.get_name())
if check.get_severity() != 'Debug':
json_msg['checks'][check.get_name()] = {'result': 'passed',
'severity': check.get_severity(),
'description': check.get_description(),
'summary': check.get_summary_passed(),
'pattern': str(check.get_pattern()),
'command': aux_command,
'output': check.get_output(),
'strike_zone': True}
else:
json_msg['checks'][check.get_name()] = {'result': 'passed',
'severity': check.get_severity(),
'description': check.get_description(),
'summary': fo.lstrip().replace('\n\t', ';'),
'pattern': str(check.get_pattern()),
'command': aux_command,
'output': check.get_output(),
'strike_zone': True}
passed += 1
json_msg['result'] = self.get_result()
if self.__verbose > 0:
if passed == total:
Output.emphasized('\nAll checks passed for plugin "%s".' % self.__name, [self.__name])
else:
Output.emphasized('\n%d out of %d checks passed for plugin "%s".' % (passed, total, self.__name), [self.__name])
return (json_msg)
示例3: __init__
# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import emphasized [as 别名]
def __init__(self, filename, config_file, alienvault_config, severity_list, appliance_type_list, ignore_dummy_platform, verbose, raw):
# Common properties.
self.__config_file = None
self.__sections = []
self.__alienvault_config = {}
self.__severity_list = []
self.__appliance_type_list = []
self.__ignore_dummy_platform = False
self.__verbose = 0
self.__raw = False
self.__name = ''
self.__id = ''
self.__description = ''
self.__type = ''
self.__exclude = ''
self.__category = []
self.__requires = []
self.__profiles = []
self.__cutoff = False
self.__strike_zone = False
self.__raw_limit = 0
self.__result = True
# 'file' type properties.
self.__filename = ''
self.__file_must_exist = False
self.__check_force_true = False
# 'command' type properties.
self.__command = ''
# Shared properties for 'file' and 'command' types.
self.__data = ''
self.__data_len = ''
# 'db' type properties.
self.__host = ''
self.__user = ''
self.__password = ''
self.__database = ''
self.__db_conn = None
self.__db_cursor = None
# Plugin defined checks.
self.__checks = []
self.__config_file = config_file
self.__alienvault_config = alienvault_config
self.__severity_list = severity_list
self.__appliance_type_list = appliance_type_list
self.__ignore_dummy_platform = ignore_dummy_platform
self.__verbose = verbose
self.__raw = raw
# try:
# # Parse the plugin configuration file.
# self.__config_file = PluginConfigParser()
# self.__config_file.read(filename)
# except PluginConfigParserError:
# raise
# except Exception as e:
# raise PluginError('Cannot parse plugin file "%s": %s' % (filename, str(e)), filename)
try:
# Parse 'check' sections.
self.__sections = self.__config_file.sections()
self.__name = self.__config_file.get('properties', 'name')
self.__id = self.__config_file.get('properties', 'id')
self.__description = self.__config_file.get('properties', 'description')
self.__type = self.__config_file.get('properties', 'type')
self.__category = self.__config_file.get('properties', 'category').split(',')
plugin_data = {'id': self.__id if self.__id else '',
'type': self.__type if self.__type else '',
'description': self.__description if self.__description else ''}
if self.__verbose > 0:
Output.emphasized('\nRunning plugin "%s"...\n' % self.__name, [self.__name])
if self.__config_file.has_option('properties', 'requires'):
self.__requires = self.__config_file.get('properties', 'requires').split(';')
self.__check_requirements__()
# Check for the 'cutoff' option
if self.__config_file.has_option('properties', 'cutoff'):
self.__cutoff = self.__config_file.getboolean('properties', 'cutoff')
# Check for the 'strike_zone' option
if self.__config_file.has_option('properties', 'affects_strike_zone'):
self.__strike_zone = self.__config_file.getboolean('properties', 'affects_strike_zone')
# Check for the 'file_must_exist' option
if self.__config_file.has_option('properties', 'file_must_exist'):
self.__file_must_exist = self.__config_file.getboolean('properties', 'file_must_exist')
# Check for the 'exclude' option
if self.__config_file.has_option('properties', 'exclude'):
self.__exclude = self.__config_file.get('properties', 'exclude').split(',')
for excluding_profile in self.__exclude:
excluding_profile = excluding_profile.strip()
if excluding_profile in self.__alienvault_config['hw_profile']:
#.........这里部分代码省略.........