Beispiel #1
0
def render_filebeat_template():
    """Create the filebeat.yaml config file.

    Renders the appropriate template for the major version of filebeat that
    is installed.
    """
    # kube_logs requires access to k8s-related filesystem data. If configured,
    # don't try to start filebeat until that data is present.
    if config().get('kube_logs') and not os.path.exists(KUBE_CONFIG):
        status.maint('Waiting for: {}'.format(KUBE_CONFIG))
        return

    version = charms.apt.get_package_version('filebeat')[0]
    cfg_original_hash = file_hash(FILEBEAT_CONFIG)
    connections = render_without_context('filebeat-{}.yml'.format(version),
                                         FILEBEAT_CONFIG)
    cfg_new_hash = file_hash(FILEBEAT_CONFIG)

    # Ensure ssl files match config each time we render a new template
    manage_filebeat_logstash_ssl()
    remove_state('beat.render')

    if connections:
        if cfg_original_hash != cfg_new_hash:
            service('restart', 'filebeat')
        status.active('Filebeat ready.')
    else:
        # Stop the service when not connected to any log handlers.
        # NB: beat base layer will handle setting a waiting status
        service('stop', 'filebeat')
Beispiel #2
0
def remove_filebeat():
    """Stop, purge, and remove all traces of filebeat."""
    status.maint('Removing filebeat.')
    service_stop('filebeat')
    try:
        os.remove(FILEBEAT_CONFIG)
    except OSError:
        pass
    charms.apt.purge('filebeat')
    remove_beat_on_boot('filebeat')
    remove_state('filebeat.autostarted')
def update_status():
    if service_running('update-conda-mirror.service'):
        pkgs = [
            pkg for d in os.walk(str(temp_dir)) for pkg in d[2]
            if pkg.endswith('.tar.bz2')
        ]
        status.maint(f'Updating mirror - {len(pkgs)} packages downloaded')
    else:
        pkgs = [
            pkg for d in os.walk(str(target_dir)) for pkg in d[2]
            if pkg.endswith('.tar.bz2')
        ]
        status.active(f'Conda mirror ready - {len(pkgs)} packages available')
def install_elastic_pkgs():
    for pkg in ELASTIC_PKGS:
        status.maint(f'Installing {pkg} from elastic.co apt repos')
        charms.apt.queue_install([pkg])
    set_flag('elastic.pkgs.installed')
Beispiel #5
0
def install_filebeat():
    # Our layer options will initially install filebeat, so just set a
    # message while we wait for the apt layer to do its thing.
    status.maint('Preparing to install filebeat.')
Beispiel #6
0
def change_filebeat_repo():
    """Set a flag when the apt repo changes."""
    # NB: we can't check for new versions yet because we cannot be sure that
    # the apt update has completed. Set status and a flag to check later.
    status.maint('Pending scan for apt repo changes.')
    set_state('filebeat.repo.changed')