GithubHelp home page GithubHelp logo

isabella232 / layer-beats-base Goto Github PK

View Code? Open in Web Editor NEW

This project forked from canonical/layer-beats-base

0.0 0.0 0.0 62 KB

Base layer for Elastic Beats. This is a middle layer, and not designed to be self deployable

License: Apache License 2.0

Python 96.08% Makefile 3.92%

layer-beats-base's Introduction

Beats Base

This is a middle layer to include the common functions among the Elastic Beats products. Such as delivery via apt, and common template parsing routines.

States

beat.render - When this state is set, you will need to re-render template data. This state occurs when a unit has received changes from a related application such as elasticsearch or logstash

lib/elasticbeats.py

This python module is an abstraction to aid in deployment of beats following common practices in charming and conventions with the beats stack.

  • render_without_context - This renders a provided jinja template using the charms configuration and relation data as context objects.

  • enable_beat_on_boot - This enables an init.d style job

  • remove_beat_on_boot - This removes symlinks for an init.d style job

  • push_beat_index - Reads from a .json file in /etc/mybeat/mybeat.template.json

  • get_package_candidate - Checks the configured apt repo for an available candidate version.

Writing your own beat

Consuming beats-base as your base-layer when charming a beat makes this an exercise in fill in the blanks. With some project meta, and handling the beat.render state will make this a quick path of integration.

Provide the following as a getting started guide, along with a jinja template of the beats configuration and you're done with the first step to charming up an elastic beat!

layer.yaml

includes:
  - beats-base

metadata.yaml

name: mybeat
summary: Deploys mybeat
maintainer: you <[email protected]>
description: |
  What does your beat do? Specifics count.
series:
  - xenial

reactive/mybeat.py

from charms.reactive import when
from charms.reactive import when_not
from charms.reactive import when_any
from charms.reactive import set_state
from charms.reactive import remove_state

from charmhelpers.core.hookenv import status_set
from charmhelpers.core.host import service_restart

from elasticbeats import render_without_context
from elasticbeats import enable_beat_on_boot
from elasticbeats import push_beat_index


@when_not('mybeat.installed')
def install_mybeat():
    # do something useful here to install your beat

@when('beat.render')
@when_any('elasticsearch.available', 'logstash.available')
def render_mybeat_template():
    render_without_context('packetbeat.yml', '/etc/mybeat/mybeat.yml')
    remove_state('beat.render')
    service_restart('mybeat')
    status_set('active', 'mybeat ready')


@when('mybeat.installed')
@when_not('mybeat.autostarted')
def enlist_beat():
    enable_beat_on_boot('mybeat')
    set_state('mybeat.autostarted')


@when('elasticsearch.available')
@when_not('mybeat.index.pushed')
def push_mybeat_index(elasticsearch):
    hosts = elasticsearch.list_unit_data()
    for host in hosts:
        host_string = "{}:{}".format(host['host'], host['port'])
    push_beat_index(host_string, 'mybeat')
    set_state('mybeat.index.pushed')

layer-beats-base's People

Contributors

kwmonroe avatar agileshaw avatar mbruzek avatar addyess avatar axinojolais avatar tasdomas avatar ktsakalozos avatar johnsca avatar n-pochet avatar nobuto-m avatar wwwtyro avatar jamesbeedy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.