def __init__(self,
                 audit_type,
                 confdir=None,
                 show_content=False,
                 dirsizes=False,
                 depth=2,
                 to_check=None,
                 ignore_also=None,
                 maxfiles=None):
        '''
        audit_type:   type of audit e.g. 'logs', 'homes'
        confdir:      dir path where yaml config files are kept
        show_content: show the first line or so from problematic files
        dirsizes:     show only directories which have too many files to
                      audit properly, don't report on files at all
        depth:        the auditor will give up if a directory has too any files
                      it (saves it form dying on someone's 25gb homedir).
                      this option tells it how far down the tree to go from
                      the top dir of the audit, before starting to count.
                      e.g. do we count in /home/ariel or separately in
                      /home/ariel/* or in /home/ariel/*/*, etc.
        to_check:     comma-separated list of dirs (must end in '/') and/or
                      files that will be checked; if this is None then
                      all dirs/files will be checked
        ignore_also:  comma-separated list of dirs (must end in '/') and/or
                      files that will be skipped in addition to the ones
                      in the config, rules, etc.
        maxfiles:     how many files in a directory tree is too many to audit
                      (at which point we warn about that and move on)
        '''

        self.audit_type = audit_type
        self.confdir = confdir
        self.locations = audit_type + "_locations"
        self.show_sample_content = show_content
        self.dirsizes = dirsizes
        self.depth = depth + 1  # actually count of path separators in dirname
        self.filenames_to_check = None
        self.dirs_to_check = None
        self.set_up_to_check(to_check)

        clouseau.retention.utils.config.set_up_conf(self.confdir)

        if ignore_also is not None:
            ignore_also = ignore_also.split(',')
        ignore_also_ignoreds = convert_ignore_also_to_ignores(ignore_also)
        self.ignores = Ignores(self.confdir)
        ignored_from_export = get_ignored_from_exported_rules(self.confdir)
        hostname = socket.getfqdn()

        self.ignored = self.ignores.merge(
            [ignore_also_ignoreds, ignored_from_export], hostname)

        self.max_files = maxfiles
        self.set_up_max_files()
        self.warnings = []
Пример #2
0
    def __init__(self,
                 confdir,
                 store_filepath,
                 timeout,
                 audit_type,
                 ignore_also=None,
                 hosts_expr=None):
        self.confdir = confdir

        self.cdb = RuleStore(store_filepath)
        self.cdb.store_db_init(None)

        self.timeout = timeout
        self.audit_type = audit_type
        self.locations = audit_type + "_locations"
        self.hosts_expr = hosts_expr

        self.basedir = None

        clouseau.retention.utils.cliutils.init_readline_hist()
        # this is arbitrary, can tweak it later
        # how many levels down we keep in our list of
        # top-level dirs from which the user can start
        # their interactive session
        self.max_depth_top_level = 3

        self.filtertype = 'all'

        # fixme completely wrong
        self.batchno = 1

        clouseau.retention.utils.config.set_up_conf(self.confdir)

        # duplicate all the ignores except for the uh
        # ones specific to a host. those will be done
        # at host choice time
        # this includes rules, we will do those at host choice time too
        # we want: global, perhost, ignore_also (if there were any)

        self.local_ignored = None
        self.ignores = Ignores(self.confdir)
        self.ignored_from_rulestore = {}
        self.ignored_also = clouseau.retention.utils.ignores.convert_ignore_also_to_ignores(
            ignore_also)

        self.dircontents = CurrentDirContents(self.timeout)
        self.cenv = CurrentEnv()
        self.cmpl = Completion(self.dircontents, self.cenv,
                               self.max_depth_top_level)