コード例 #1
0
def mocked_start_child_fprobe_fail(params, pass_fds, null_fds, ign_sigs,
                                   setsid=False, **kwargs):
    if params[0] == 'softflowd':
        return start_child(['___no_such_file'], pass_fds, null_fds, ign_sigs,
                           setsid, **kwargs)
    return start_child(['sleep', '1'], pass_fds, null_fds, ign_sigs, setsid,
                       **kwargs)
コード例 #2
0
def mocked_start_child_collector_fail(params, pass_fds, null_fds, ign_sigs,
                                      setsid=False, **kwargs):
    if params[0] == 'socket-datacollector':
        return start_child(['___no_such_file'], pass_fds, null_fds, ign_sigs,
                           setsid, **kwargs)
    return start_child(['sleep', '1'], pass_fds, null_fds, ign_sigs,
                       setsid, **kwargs)
コード例 #3
0
    def start_collector(self, user, socket, output_dir, watch_pid, metadata,
                        **kwargs):
        """
          Start the collector process; have it drop privileges by
          switching to the given user; have it write the data to the
          output_dir and use a filename pattern given by
          filenamepattern; have it watch the process with the given
          watch_pid
        """
        filepattern = kwargs.get('output_filepattern',
                                 'fprobe-{ifname}-{timestamp}')

        params = ['socket-datacollector',
                  '--user', user,
                  '--sockfd', str(socket.fileno()),
                  '--dir', output_dir,
                  '--filepattern', filepattern,
                  '--watch-pid', str(watch_pid),
                  '--metadata', json.dumps(metadata),
                  '--md-filter', 'ip-addresses']
        try:
            pid, errcode = start_child(params, [socket.fileno()], [],
                                       [signal.SIGCHLD],
                                       setsid=True,
                                       max_close_fd=128)
            logger.info('Started collector as pid %d' % pid)
        except:
            pid = -1
            errcode = errno.EINVAL

        return pid, errcode
コード例 #4
0
    def start_collector(self, user, socket, output_dir, watch_pid, metadata,
                        **kwargs):
        """
          Start the collector process; have it drop privileges by
          switching to the given user; have it write the data to the
          output_dir and use a filename pattern given by
          filenamepattern; have it watch the process with the given
          watch_pid
        """
        filepattern = kwargs.get('output_filepattern',
                                 'fprobe-{ifname}-{timestamp}')

        params = [
            'socket-datacollector', '--user', user, '--sockfd',
            str(socket.fileno()), '--dir', output_dir, '--filepattern',
            filepattern, '--watch-pid',
            str(watch_pid), '--metadata',
            json.dumps(metadata), '--md-filter', 'ip-addresses'
        ]
        try:
            pid, errcode = start_child(params, [socket.fileno()], [],
                                       [signal.SIGCHLD],
                                       setsid=True,
                                       max_close_fd=128)
            logger.info('Started collector as pid %d' % pid)
        except:
            pid = -1
            errcode = errno.EINVAL

        return pid, errcode
コード例 #5
0
    def start_ctprobe(self, sockpath=DEFAULT_UNIX_PATH, **kwargs):
        """
          Start the conntrackprobe process;
          use the bindaddr and port as the collector.
          This function returns the process ID of the started process
          and an errcode (errno) in case an error was encountered in
          the start_child function.
        """
        ctprobe_user, passwd = self._get_user(**kwargs)
        if not passwd:
            return -1, errno.ENOENT

        params = ['conntrackprobe',
                  '--unix', sockpath,
                  '--user', ctprobe_user,
                  '--logfile', '/var/log/conntrackprobe.log']

        try:
            pid, errcode = start_child(params, [], [0, 1, 2],
                                       [],
                                       setsid=False,
                                       max_close_fd=128)
            logger.info('Started conntrackprobe as pid %d' % pid)
        except Exception:
            pid = -1
            errcode = errno.EINVAL

        return pid, errcode
コード例 #6
0
def mocked_start_child(params,
                       pass_fds,
                       null_fds,
                       ign_sigs,
                       setsid=False,
                       **kwargs):
    return start_child(['sleep', '1'], pass_fds, null_fds, ign_sigs, setsid)
コード例 #7
0
def mocked_start_child(params, pass_fds, null_fds, ign_sigs, setsid=False,
                       **kwargs):
    if params[0] == 'socket-datacollector':
        # in case the socket-datacollector is started, we just write
        # the frame without actually starting that program.
        simulate_socket_datacollector(params)

    # return appropriate values
    return start_child(['sleep', '1'], pass_fds, null_fds, ign_sigs, setsid)
コード例 #8
0
    def start_fprobe(self, ifname, user, bindaddr, port, **kwargs):
        """
          Start the flow probe process on the given interface;
          use the bindaddr and port as the collector.
          This function returns the process ID of the started process
          and an errcode (errno) in case an error was encountered in
          the start_child function.
        """
        maxlife_timeout = get_uint_arg('maxlife_timeout', 30, **kwargs)
        netflow_version = get_uint_arg('netflow_version', 5, **kwargs)
        if netflow_version not in [1, 5, 9, 10]:
            logger.info('Unsupported netflow version was chosen: %d' %
                        netflow_version)
            netflow_version = 5

        terminate_process = kwargs.get('terminate_fprobe', 'FALSE').upper()
        setsid = terminate_process in ['0', 'FALSE']
        fprobe_bpf = kwargs.get('fprobe_bpf', '')

        params = ['softflowd',
                  '-i', ifname,
                  '-v', '%d' % netflow_version,
                  '-d',
                  '-t', 'maxlife=%d' % maxlife_timeout,
                  '-n', '%s:%d' % (bindaddr, port)]
        if len(fprobe_bpf.strip()):
            params.insert(1, fprobe_bpf)
        if netflow_version == 10:
            params.insert(1, '-b')
        try:
            pid, errcode = start_child(params, [], [0, 1, 2],
                                       [signal.SIGCHLD],
                                       setsid=setsid,
                                       max_close_fd=128)
            logger.info('Started softflowd as pid %d' % pid)
        except:
            pid = -1
            errcode = errno.EINVAL

        return pid, errcode
コード例 #9
0
    def start_fprobe(self, ifname, user, bindaddr, port, **kwargs):
        """
          Start the flow probe process on the given interface;
          use the bindaddr and port as the collector.
          This function returns the process ID of the started process
          and an errcode (errno) in case an error was encountered in
          the start_child function.
        """
        maxlife_timeout = get_uint_arg('maxlife_timeout', 30, **kwargs)
        netflow_version = get_uint_arg('netflow_version', 5, **kwargs)
        if netflow_version not in [1, 5, 9, 10]:
            logger.info('Unsupported netflow version was chosen: %d' %
                        netflow_version)
            netflow_version = 5

        terminate_process = kwargs.get('terminate_fprobe', 'FALSE').upper()
        setsid = terminate_process in ['0', 'FALSE']
        fprobe_bpf = kwargs.get('fprobe_bpf', '')

        params = [
            'softflowd', '-i', ifname, '-v',
            '%d' % netflow_version, '-d', '-t',
            'maxlife=%d' % maxlife_timeout, '-n',
            '%s:%d' % (bindaddr, port)
        ]
        if len(fprobe_bpf.strip()):
            params.insert(1, fprobe_bpf)
        if netflow_version == 10:
            params.insert(1, '-b')
        try:
            pid, errcode = start_child(params, [], [0, 1, 2], [signal.SIGCHLD],
                                       setsid=setsid,
                                       max_close_fd=128)
            logger.info('Started softflowd as pid %d' % pid)
        except:
            pid = -1
            errcode = errno.EINVAL

        return pid, errcode
コード例 #10
0
    def start_fprobe(self, ifname, user, bindaddr, port, **kwargs):
        """
          Start the fprobe process on the given interface, using the
          given user, and use the bindaddr and port as the collector.
          This function returns the process ID of the started process
          and an errcode (errno) in case an error was encountered in
          the start_child function.
        """
        lifetime_timeout = get_uint_arg('lifetime_timeout', 30, **kwargs)
        idle_timeout = get_uint_arg('idle_timeout', 30, **kwargs)
        netflow_version = get_uint_arg('netflow_version', 5, **kwargs)
        if netflow_version not in [1, 5, 7]:
            logger.info('Unsupported netflow version was chosen: %d' %
                        netflow_version)
            netflow_version = 5

        terminate_process = kwargs.get('terminate_fprobe', 'FALSE').upper()
        setsid = terminate_process in ['0', 'FALSE']

        params = ['fprobe',
                  '-i', ifname,
                  '-u', user,
                  '-n', '%d' % netflow_version,
                  '-fip',
                  '-l', '2',
                  '-e', '%d' % lifetime_timeout,
                  '-d', '%d' % idle_timeout,
                  '%s:%d' % (bindaddr, port)]
        try:
            pid, errcode = start_child(params, [], [0, 1, 2],
                                       [signal.SIGCHLD],
                                       setsid=setsid)
            logger.info('Started fprobe as pid %d' % pid)
        except:
            pid = -1
            errcode = errno.EINVAL

        return pid, errcode
コード例 #11
0
def mocked_start_child(params, pass_fds, null_fds, ign_sigs, setsid=False,
                       **kwargs):
    return start_child(['sleep', '1'], pass_fds, null_fds, ign_sigs, setsid)