本文整理汇总了Python中output.Output.error方法的典型用法代码示例。如果您正苦于以下问题:Python Output.error方法的具体用法?Python Output.error怎么用?Python Output.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类output.Output
的用法示例。
在下文中一共展示了Output.error方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import error [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: int
# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import error [as 别名]
for o, a in opts:
if o == '-l':
LISTEN = a
elif o == '-p':
PORT = int(a)
elif o == '-i':
INTERACTIVE=True
elif o == '-v':
if OUTPUT_LEVEL == logging.INFO:
OUTPUT_LEVEL = logging.DEBUG
elif OUTPUT_LEVEL > 0:
OUTPUT_LEVEL -= 10
elif o == "-h":
Usage()
else:
Output.error('Invalid option "%s"' % o)
Usage(-1)
Output.setLevel(OUTPUT_LEVEL)
Output.debug("Starting server on %s:%s" % (LISTEN, PORT))
Server = ThreadedTCPServer((LISTEN, PORT), ThreadedTCPRequestHandler)
ServerThread = threading.Thread(target=Server.serve_forever)
ServerThread.daemon = True
ServerThread.start()
Output.debug("Server successfully started")
if INTERACTIVE == True:
while True:
sys.stdout.write("> ")
szCmd = sys.stdin.readline().rstrip('\n')
if len(szCmd) == 0:
示例3: __init__
# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import error [as 别名]
#.........这里部分代码省略.........
self.__formatted_output = ''
self.__appliance_type = []
self.__fail_if_empty = True
self.__fail_if_empty_output = ''
self.__fail_only_if_all_failed = False
self.__split_by_comma = False
self.__ha_dependant = False
self.__severity = 'Warning'
self.__conditions = {'basic': [], 'set': []}
self.__actions = []
self.__aux_data = {}
self.__strike_zone = False
self.__version_type = ''
config_file = plugin.get_config_file()
self.__name = section
self.__plugin = plugin
# Parse section options.
# Different sections or check 'types' are mutually exclusive.
items = config_file.items(section)
try:
# Retrieve first the formatted_output field
for (name, value) in items:
if name == 'formatted_output':
self.__formatted_output = value.replace("{nl}", "\n")
items.remove((name, value))
break
# Now the rest
for (name, value) in items:
if name == 'checksum':
self.__type = name
self.__checksums = [tuple(x.split(':')) for x in value.split(';')]
elif name == 'pattern':
self.__type = name
self.__pattern = str(value)
value = Wildcard.av_config(value, escape=True)
self.__regex = re.compile(value, re.MULTILINE)
elif name == 'query':
self.__type = name
if value.startswith("@[email protected]:"):
self.__query = value[8:]
self.__pivot = True
else:
self.__query = value
self.__query = Wildcard.av_config(self.__query, escape=True)
elif name == 'hardware':
self.__type = name
self.__hw_list = value
elif name == 'category':
self.__category = value
elif name == 'fail_if_empty':
if value in ['True', 'False']:
self.__fail_if_empty = eval(value)
elif name == 'fail_if_empty_output':
self.__fail_if_empty_output = value
elif name == 'fail_only_if_all_failed':
if value in ['True', 'False']:
self.__fail_only_if_all_failed = eval(value)
elif name == 'split_by_comma':
if value in ['True', 'False']:
self.__split_by_comma = eval(value)
elif name == 'ha_dependant':
if value in ['True', 'False']:
self.__ha_dependant = eval(value)
elif name == 'version_type':
self.__version_type = value
elif name == 'severity':
if value in default.severity:
self.__severity = value
elif name == 'min_doctor_version':
self.__min_doctor_version = value
elif name == 'appliance_type':
for x in value.split(','):
self.__appliance_type += Wildcard.appliance_exec(x.strip())
elif name == 'conditions':
self.__init_conditions__(value)
elif name == 'actions':
self.__init_actions__(value)
elif name == 'description':
self.__description = value
elif name == 'summary_passed':
self.__summary_passed = value
elif name == 'summary_failed':
self.__summary_failed = value
elif name == 'remediation':
self.__remediation = value
elif name == 'affects_strike_zone':
if value in ['True', 'False']:
self.__strike_zone = eval(value)
else:
Output.warning('Unknown field in check "%s": %s' % (self.__name, name))
except CheckError:
raise
except Exception, msg:
Output.error('Cannot parse check "%s" in plugin "%s": %s' % (self.__name, self.__plugin.get_name(), msg))
raise
示例4: __init__
# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import error [as 别名]
def __init__ (self, plugin, section, verbose):
# 'check' properties.
self.__name = ''
self.__type = ''
self.__category = ''
self.__warning = ''
self.__advice = ''
self.__plugin = None
# 'file' type checks only.
self.__checksums = []
# 'file' and 'command' checks.
self.__regex = None
# 'db' type checks.
self.__query = ''
self.__pivot = False
self.__fail_if_empty = True
self.__severity = 'Medium'
self.__not = False
self.__conditions = {'set':[], 'data':[]}
self.__actions = []
config_file = plugin.get_config_file ()
self.__name = section
self.__plugin = plugin
self.__verbose = verbose > 1
# Parse section options.
# Different sections or check 'types' are mutually exclusive.
items = config_file.items (section)
try:
for (name, value) in items:
if name == 'checksum':
self.__type = name
self.__checksums = [tuple (x.split(':')) for x in value.split(';')]
elif name == 'pattern':
self.__type = name
self.__regex = re.compile (value, re.MULTILINE)
elif name == 'query':
self.__type = name
if value.startswith("pivot:"):
self.__query = value[6:]
self.__pivot = True
else:
self.__query = value
elif name == 'category':
self.__category = value
elif name == 'fail_if_empty':
if value in ['True', 'False']:
self.__fail_if_empty = eval(value)
elif name == 'severity':
if value in SEVERITY:
self.__severity = value
elif name == 'conditions':
self.__init_conditions__ (value)
elif name == 'actions':
self.__init_actions__ (value)
elif name == 'warning':
self.__warning = value
elif name == 'advice':
self.__advice = value
else:
Output.warning ('Unknown field in check "%s": %s' % (self.__name, name))
except PluginError:
raise
except Exception, msg:
Output.error ('Cannot parse check "%s" in plugin "%s": %s' % (self.__name, self.__plugin.get_name(), msg))
raise
示例5: run
# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import error [as 别名]
def run(self):
total = 0
passed = 0
json_msg = {'id': self.__id,
'name': self.__name,
'description': self.__description,
'checks': {},
}
if self.__strike_zone:
json_msg['strike_zone'] = True
if self.__raw:
json_msg['source'] = unicode(self.__data[-(self.__raw_limit * 1024):], errors='replace')
for check in self.__checks:
total += 1
result = False
msg = ''
if self.__check_force_true:
result = True
else:
result, msg, fo = check.run()
fo = fo.lstrip().split('\n\t')[-1]
# Prepare 'command' field
aux_command = ''
if self.__type == "file":
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())
#.........这里部分代码省略.........