当前位置: 首页>>代码示例>>Python>>正文


Python Output.warning方法代码示例

本文整理汇总了Python中output.Output.warning方法的典型用法代码示例。如果您正苦于以下问题:Python Output.warning方法的具体用法?Python Output.warning怎么用?Python Output.warning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在output.Output的用法示例。


在下文中一共展示了Output.warning方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_query

# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import warning [as 别名]
  def run_query (self, query, result = False):
    try:
      self.__db_cursor.execute (query)
    except Exception as e:
      Output.warning ('Cannot run query for plugin "%s": %s' % (self.__name, e))
      return []

    if result:
      try:
        rows = self.__db_cursor.fetchall ()
      except Exception as e:
        Output.warning ('Cannot run query for plugin "%s": %s' % (self.__name, e))
        return []

    self.__data += query + '\n' + str(rows) + '\n\n'
    return rows
开发者ID:AntBean,项目名称:alienvault-ossim,代码行数:18,代码来源:plugin.py

示例2: __init_conditions__

# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import warning [as 别名]
  def __init_conditions__ (self, value):
    # Check first if there are @set and other conditions in the same rule.
    # This is not allowed because standalone data type checks rely on order,
    # while @set tries to match with every field of the resulting regex/db query
    # regardless the order.
    if ('@set' in value) and \
        ('@int' in value or '@float' in value or '@string' in value or '@char' in value):
      raise PluginError ('Forbidden "@set" and any other datatype combination in rule "%s" for plugin "%s"' % (self.__name, self.__plugin.get_name()))

    for condition in value.split(';'):
      matches = re.findall('^(@\w+):?(\S+)?$', condition)
      cond_type, cond_str = matches[0]

      if cond_type == '@set':
        matches = re.findall('(@\[email protected])?([^a-zA-Z0-9_\\:\."\'\\/]+)(\S+)', cond_str)
        cond_neg, cond_op, cond_set = matches[0]

        # Permit a @[email protected] in @set comparison.
        self.__not = bool(cond_neg)

        # For sets defined in files.
        if ',' in cond_set:
          items = cond_set.split(',')
        elif path.isfile (cond_set):
          desc = open (cond_set, 'r')
          items = desc.read().splitlines()
        else:
          Output.warning ('Not recognized set type for check "%s" in plugin "%s"' % (self.__name, self.__plugin.get_name()))
          continue

        content = set()
        for item in items:
          splitted_item = item.split('|')
          if len(splitted_item) > 1:
            content.add(tuple(splitted_item))
          else:
            content.add(item)

        self.__conditions['set'].append(cond_op + str(content))
      elif cond_type in ['@string', '@char', '@int', '@float', '@info']:
        self.__conditions['data'].append((cond_type, cond_str.rsplit('@') if cond_str != None and cond_str != '' else None))

      else:
        Output.warning ('Type "%s" not recognized for check "%s" in plugin "%s"' % (cond_type, self.__name, self.__plugin.get_name()))
        continue
开发者ID:AntBean,项目名称:alienvault-ossim,代码行数:47,代码来源:check.py

示例3: __check_set_conditions__

# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import warning [as 别名]
  def __check_set_conditions__ (self, values, set_conditions):
    if set_conditions == []:
      return (True, '')

    ret = True
    values_set = set(values)
    values_set_str = str(values_set)

    for condition in set_conditions:
      try:
        if self.__not:
          if bool(eval(values_set_str + condition)):
            if self.__verbose:
              Output.warning ('Set condition does not met!')
            ret &= False
        else:
          if not bool(eval(values_set_str + condition)):
            if self.__verbose:
              Output.warning ('Set condition does not met!')
            ret &= False

      except SyntaxError, msg:
        Output.warning ('Invalid rule syntax in check "%s"' % self.__name)
        return (False, 'Check "%s" failed because of invalid syntax' % self.__name)
开发者ID:AntBean,项目名称:alienvault-ossim,代码行数:26,代码来源:check.py

示例4: __init__

# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import warning [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
开发者ID:qiwihui,项目名称:alienvault-ossim,代码行数:104,代码来源:check.py

示例5: __init__

# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import warning [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
开发者ID:AntBean,项目名称:alienvault-ossim,代码行数:76,代码来源:check.py

示例6: __check_data_conditions__

# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import warning [as 别名]
  def __check_data_conditions__ (self, values, data_conditions):
    if data_conditions == []:
      return (True, '')

    ret = True
    info = []

    for value in values:
      if type(value) == tuple:
        value = enumerate(value)
      else:
        value = [(0, value)]

      for j, data in value:
        try:
          datatype, condition = data_conditions[j]
        except IndexError:
          return (False, 'A pattern for check "%s" does not have the same size as the values set' % (self.__name))
        except ValueError:
          datatype, = data_conditions[j]
          condition = None

        # Check type.
        if datatype == '@info':
          info = data
          continue
        elif datatype == '@set':
          continue
        elif datatype == '@int':
          try:
            if data != '':
              data = int(data)
            else:
              data = 0
          except:
            return (False, 'Condition datatype is marked as "int" but is not an integer')
        elif datatype == '@float':
          try:
            if data != '':
              data = float(data)
            else:
              data = 0.0
          except:
            return (False, 'Condition datatype is marked as "float" but is not an floating point integer')
        elif datatype == '@char' and not data.isalpha():
          return (False, 'Condition datatype is marked as "char" but is not a character')

        # Sometimes, conditions are only for checking the match type, so they have
        # only a type, e.g. '@string;@int:==1'
        if condition == None:
          continue

        # Two methods here: pattern matching or simple operator ('>=<') match.
        # Pattern matching does not allow logical operations such as 'and' or 'or'.
        if condition[0].startswith('~'):
          regex = re.compile (condition[0][1:])
          partial = bool(regex.match (data))
          ret &= partial

          # Notify the user if a condition doesn't match
          if not partial and self.__verbose:
            Output.warning ('Pattern "%s" does not match' % condition[0][1:])
        else:
          eval_str = ''

          for item in condition:
            # This condition may have a logical connector ('something'=='anything' or 'whatever')
            if item in ['and', 'or', 'not']:
              eval_str = eval_str + ' ' + item
            else:
              # There are other conditions or 'wildcards' that may be used here.
              # 'position' accepts an integer that represents the position variable in the match tuple.
              # 'count' accepts an integer to compare with the match count in this position.
              position_pattern = '(?P<position>(?P<pos_operator>(?:==|<|>))position\[(?P<pos_value>\d+)\])'
              count_pattern = '(?P<count>(?P<count_operator>(?:==|<|>))count\[(?P<count_value>\d+|position\[(?P<pos_count>\d+)\]|even|odd)\])'
              pattern = position_pattern + '|' + count_pattern

              wildcards = re.search (pattern, item)
              single_cond = item

              if wildcards != None:
                # 'position' wildcard.
                if wildcards.group('position') != None:
                  if datatype == '@int' or datatype == '@float':
                    pos_value = values[j][int(wildcards.group('pos_value'))]
                  elif datatype == '@char' or datatype == '@string':
                    pos_value = '"' + values[j][int(wildcards.group('pos_value'))] + '"'
                  else:
                    pos_value = ''
                  single_cond = single_cond.replace(wildcards.group('position'), wildcards.group('pos_operator') + pos_value)

                # 'count' wildcard.
                # This uses a pityful trick, because it doesn't check the actual 'data' value but the occurrence count.
                # TODO: this is poorly implemented. It should not check the value every time, only once is enough.
                if wildcards.group('count') != None:
                  matched_value_count = len([x for x in values if x[j] != ''])
                  subs_cond = '== "%s" and ' % str(data)

                  if wildcards.group('count_value').isdigit():
                    subs_cond += str(matched_value_count) + wildcards.group('count_operator') + str(wildcards.group('count_value'))
#.........这里部分代码省略.........
开发者ID:AntBean,项目名称:alienvault-ossim,代码行数:103,代码来源:check.py

示例7: __init__

# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import warning [as 别名]

#.........这里部分代码省略.........
                for excluding_profile in self.__exclude:
                    excluding_profile = excluding_profile.strip()
                    if excluding_profile in self.__alienvault_config['hw_profile']:
                        raise PluginError(msg='Plugin cannot be executed in %s' % self.__alienvault_config['hw_profile'],
                                          plugin=self.__name,
                                          plugin_data=plugin_data)

            # Check for the 'limit' option (in kbytes), used in combination with the raw data output. '0' means no limit.
            if self.__raw and self.__config_file.has_option('properties', 'raw_limit'):
                self.__raw_limit = self.__config_file.getint('properties', 'raw_limit')

            # Check for profile & version where this plugin is relevant.
            if self.__config_file.has_option('properties', 'profiles'):
                profiles_versions = self.__config_file.get('properties', 'profiles')
                self.__profiles = [(x.partition(':')[0], x.partition(':')[2]) for x in profiles_versions.split(';')]

                for (profile, version) in self.__profiles:
                    if profile == '' or version == '':
                        raise PluginError(msg='Empty profile or version in "profiles" field',
                                          plugin=self.__name,
                                          plugin_data=plugin_data)

                    if profile not in self.__alienvault_config['sw_profile'] and \
                       profile != self.__alienvault_config['hw_profile']:
                        raise PluginError(msg='Profile "%s" does not match installed profiles' % profile,
                                          plugin=self.__name,
                                          plugin_data=plugin_data)

                    if version.startswith('>'):
                        ret = LooseVersion(self.__alienvault_config['version']) > LooseVersion(version[1:])
                    elif version.startswith('<'):
                        ret = LooseVersion(self.__alienvault_config['version']) < LooseVersion(version[1:])
                    elif version.startswith('=='):
                        ret = LooseVersion(self.__alienvault_config['version']) == LooseVersion(version[2:])
                    elif version.startswith('!='):
                        ret = LooseVersion(self.__alienvault_config['version']) != LooseVersion(version[2:])
                    else:
                        raise PluginError(msg='Profile "%s" version does not match installed profiles' % profile,
                                          plugin=self.__name,
                                          plugin_data=plugin_data)

            # Ugly...
            if self.__type == 'file':
                self.__init_file__()
            elif self.__type == 'command':
                self.__init_command__()
            elif self.__type == 'db':
                self.__init_db__()
            elif self.__type == 'hardware':
                pass
            else:
                raise PluginError(msg='Unknown type',
                                  plugin=self.__name,
                                  plugin_data=plugin_data)

            # Parse 'check' sections.
            sections = self.__config_file.sections()
            for section in sections:
                if section != 'properties':
                    check = Check(self, section)
                    needs_deletion = False
                    if not check.check_appliance_type(self.__alienvault_config['hw_profile'],
                                                      self.__appliance_type_list,
                                                      self.__ignore_dummy_platform):
                        Output.warning("\nCheck %s is not meant to be run in %s" % (section,
                                                                                    self.__alienvault_config['hw_profile']))
                        needs_deletion = True

                    elif not check.check_version(self.__alienvault_config['version']):
                        Output.warning("\nCheck %s cannot be run in version %s" % (section,
                                                                                   self.__alienvault_config['version']))
                        needs_deletion = True

                    elif not check.check_version_type():
                        Output.warning("\nCheck %s is not meant to be run in a %s license" % (section,
                                                                                              self.__alienvault_config['versiontype']))
                        needs_deletion = True
                    if not needs_deletion:
                        self.__checks.append(check)
                    else:
                        del check

        except PluginError:
            raise

        except PluginConfigParserError:
            raise

        except CheckError as e:
            plugin_data = {'id': self.__id if self.__id else '',
                           'type': self.__type if self.__type else '',
                           'description': self.__description if self.__description else ''}
            raise PluginError(msg=e.msg,
                              plugin=e.plugin,
                              plugin_data=plugin_data)

        except Exception as e:
            raise PluginError(msg='%s' % str(e),
                              plugin=filename,
                              plugin_data={})
开发者ID:qiwihui,项目名称:alienvault-ossim,代码行数:104,代码来源:plugin.py


注:本文中的output.Output.warning方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。