salt/doc/topics/event/index.rst

60 lines
2.0 KiB
ReStructuredText
Raw Normal View History

2012-06-08 01:37:55 +00:00
=================
Salt Event System
=================
Salt 0.9.10 introduced the Salt Event System. This system is used to fire
2012-06-08 01:51:40 +00:00
off events enabling third party applications or external processes to react
2012-06-08 01:37:55 +00:00
to behavior within Salt.
2012-06-08 01:51:40 +00:00
The event system is comprised of a few components, the event sockets which
publish events, and the event library which can listen to events and send
2012-06-08 01:37:55 +00:00
events into the salt system.
Listening for Events
====================
2012-06-08 01:51:40 +00:00
The event system is accessed via the event library and can only be accessed
2012-06-08 01:37:55 +00:00
by the same system user that Salt is running as. To listen to events a
SaltEvent object needs to be created and then the get_event function needs to
be run. The SaltEvent object needs to know the location that the Salt unix
sockets are kept. In the configuration this is the ``sock_dir`` option. The
``sock_dir`` option defaults to "/var/run/salt" on most systems.
2012-06-08 01:37:55 +00:00
The following code will check for a single event:
.. code-block:: python
import salt.utils.event
event = salt.utils.event.MasterEvent('/var/run/salt')
2012-06-08 01:37:55 +00:00
data = event.get_event()
2012-06-08 01:51:40 +00:00
Events will also use a "tag". A "tag" allows for events to be filtered. By
default all events will be returned, but if only authentication events are
desired, then pass the tag "auth". Also, the get_event method has a default
poll time assigned of 5 seconds, to change this time set the "wait" option.
This example will only listen for auth events and will wait for 10 seconds
instead of the default 5.
.. code-block:: python
import salt.utils.event
event = salt.utils.event.MasterEvent('/var/run/salt')
2012-06-08 01:51:40 +00:00
data = event.get_event(wait=10, tag='auth')
Instead of looking for a single event, the iter_events method can be used to
make a generator which will continually yield salt events. The iter_events
2012-06-08 01:51:40 +00:00
method also accepts a tag, but not a wait time:
.. code-block:: python
import salt.utils.event
event = salt.utils.event.MasterEvent('/var/run/salt')
2012-06-08 01:51:40 +00:00
for data in event.iter_events(tag='auth'):
2012-06-08 01:51:40 +00:00
print(data)