Ejemplo n.º 1
0
def main():
    '''Main function for pmort.  Does all the things…sort of.

    Performs the basic loop of pmort but none of the normal daemon setup items.
    The basic logic in pmort is log all the things, sleep until the next time,
    and do it again.

    Returns
    -------

    1 if an error occurred; otherwise, it keeps running.

    '''

    error = 0

    global PARAMETERS
    PARAMETERS = PARAMETERS.parse()

    if os.access(PARAMETERS['logging.configuration_file_path'], os.R_OK):
        logging.config.fileConfig(PARAMETERS['logging.configuration_file_path'])

    # TODO Add last crash symlink.

    while True:
        for collector in COLLECTORS:
            thread = threading.Thread(
                    target = output.write_output,
                    group = 'pmort.collectors',
                    name = collector.__name__,
                    args = (collector.__name__.replace('_collector', ''), collector())
                    )
            thread.start()

        logging.info('started %s threads', len(COLLECTORS))
        logging.info('active threads: %s', threading.active_count())

        signal.alarm(LEARNERS[PARAMETERS['learner.active']].time())
        signal.pause()

    return error
Ejemplo n.º 2
0
    scripts.extend(find_scripts(PARAMETERS['collector_execute.directory']))

    errors = 0

    for script in scripts:
        logger.info('executing %s', script)

        try:
            output = subprocess.check_output(script)
        except subprocess.CalledProcessError as e:
            logger.warning('error in %s', script)
            logger.exception(e)

            errors += 1

            continue

        _ = ' '.join([ _.rsplit('/', 1)[-1] for _ in script ])
        write_output(_, output.decode('utf-8'))

    return '\n'.join([
        'ran {0} execute plugins'.format(len(scripts)),
        '  {0} errors'.format(errors),
        ])

COLLECTORS['execute'] = execute_collector

if __name__ == '__main__':
    PARAMETERS.parse()
    print(execute_collector())