...

Open source softwares - SaltStack

Back to Course

Lesson Description


Lession - #1533 SaltStack Event System


The Salt Event System is used to fire off events enabling third party applications or external processes to react to behavior within Salt. The event system uses a publish- subscribe pattern, else know as pub/ sub.

EVENT BUS

The event system is comprised of a two primary components, which make up the concept of an Event Bus

The event sockets, which publish events

The event library, which can listen to events and send events into the salt system

Events are published onto the event bus and event bus subscribers listen for the published events.

The event machine is used for bothinter-process communication as well as network transport in Salt. Inter-process communication is provided through UNIX domain sockets( UDX>
.

The Salt Master and each Salt Minion has their own event bus.

EVENT TYPES

  • Salt Master Events
  • Authentication events
  • Start events
  • Key events
  • Job events
  • Runner Events
  • Presence Events
  • Cloud Events

    LISTENING FOR EVENTS

    Salt's event system is used heavily within Salt and it's also written to integrate heavily with existing tooling and scripts. There's a variety of ways to consume it.

    FROM THE CLI

    The quickest way to watch the event bus is by calling thestate.event runner

    
     salt- runstate.event pretty = True 
     


    That runner is designed to interact with the event bus from external tools and shell scripts. See the documentation for further examples.

    REMOTELY VIA THE REST API

    
     Salt's event bus can be consumedsalt.netapi.rest_cherrypy.app.Events as an HTTP stream from external tools or services. 
     curl- SsNk https//salt-api.example.com 8000/events?token = 05A3 
     


    FIRING EVENTS

    It's possible to fire events on either the minion's local bus or to fire events intended for the master.

    To fire a local event from the minion on the command line call theevent.fire execution function

    
     salt- callevent.fire'{" data"" message to be sent in the event"}'' tag' 
     


    To fire an event to be sent up to the master from the minion call theevent.send execution function. Remember YAML can be used at the CLI in function arguments

    
     salt- callevent.send' myco/ mytag/ success''{ success True, message" It works!"}' 
     


    However, it may be useful for a user on the master to fire an event to it, If a process is listening on the minion. An illustration of listening local events on a minion on anon-Windows system

    Job on minion

    
     importsalt.utils.event 
     
     opts = salt.config.minion_config(" etc/ salt/ minion">
    event = salt.utils.event.MinionEvent( opts>
    for evdata inevent.iter_events(match_type = " regex", tag = " custom/. *">
    do your processing here. ....