Last active
August 29, 2015 14:06
-
-
Save syphernl/25b901d343588ada6e7b to your computer and use it in GitHub Desktop.
Saltstack "eventbus" returner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
''' | |
Return data to a the Salt Eventbus. | |
Huh, that's default behavior isn't it? Technically yes. | |
But.. Not when you: | |
- use 'salt-call' on a minion | |
- use the Salt scheduler to execute periodically | |
Which means, the master doesn't get executed tasks in its job cache. | |
Very annoying if you want to create nice graphs of state executions. | |
Sure, you can use a returner to dump stuff in the DB but the downside of that | |
is that the minion has to (be able to) connect to that particular service. | |
Also, there is no way of verifying whether the return is legit. | |
The bug has been reported upstream (saltstack/salt/issues/12935) but still | |
needs to be resolved. | |
This is where this returner comes in. It will emulate the normal salt return | |
by raising the event and all data attached to it. | |
Please note: you still have to post-process the output as everything is nested | |
in the 'data' section unlike normal highstate returns. | |
To use this, append '--return eventbus' to the salt command. ex: | |
salt-call state.highstate --return eventbus | |
''' | |
# Import python libs | |
import logging | |
# Import third party libs | |
try: | |
import salt.client | |
HAS_SALTCLIENT = True | |
except ImportError: | |
HAS_SALTCLIENT = False | |
log = logging.getLogger(__name__) | |
# Define the module's virtual name | |
__virtualname__ = 'eventbus' | |
def __virtual__(): | |
if not HAS_SALTCLIENT: | |
return False | |
return __virtualname__ | |
def returner(ret): | |
''' | |
Return data to the eventbus | |
''' | |
caller = salt.client.Caller('/etc/salt/minion') | |
tag = 'salt/job/%s/ret/%s' % (ret['jid'], ret['id'], ) | |
caller.sminion.functions['event.fire_master'](ret, tag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment