Listening to events
Out of the two procedures of a Salt event system, one is listening to Salt events. In this chapter, we will learn about the different procedures to listen for Salt events.
How to do it...
On the Salt master, create a file anywhere called
cookbookeventslisten.py
and edit it so it has the following content:#!/usr/bin/python import salt.config import salt.utils.event import time import pprint opts = salt.config.client_config('/etc/salt/master') event = salt.utils.event.get_event( 'master', sock_dir=opts['sock_dir'], transport=opts['transport'], opts=opts) response = event.get_event(wait=30, tag='cookbook/test') print('Event fired at {0}'.format(time.asctime())) print('*' * 25) print('Tag: {0}'.format(response['tag'])) print('Data:') pprint.pprint(response['data'])
Run the script in either of the following ways; however, there will be no output as no events have been sent yet:
[root@salt-master ~]# ./cookbookeventslisten.py [root@salt-master...