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


Python Output.info方法代码示例

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


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

示例1: run

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

示例2: __check_data_conditions__

# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import info [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

示例3: run

# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import info [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())
#.........这里部分代码省略.........
开发者ID:qiwihui,项目名称:alienvault-ossim,代码行数:103,代码来源:plugin.py

示例4: __init__

# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import info [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.info("\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.info("\nCheck %s cannot be run in version %s" % (section,
                                                                                self.__alienvault_config['version']))
                        needs_deletion = True

                    elif not check.check_version_type():
                        Output.info("\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:jpalanco,项目名称:alienvault-ossim,代码行数:104,代码来源:plugin.py


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