-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fire_event() code call does not seem to work for me #8849
Comments
What version of salt are you using? |
Thanks. It definitely seems like it should be working. Any chance you'd be willing to test on the current |
@basepi I still get the same results with version 0.17.0-5250-g86c8a5c, that is, the command line works, but doing it via code, nothing happens. Code on master: import salt.utils.event
event = salt.utils.event.MasterEvent('/var/run/salt/master')
for data in event.iter_events(full=True):
print(data) code on minion (remote and local to master): # Import the proper library
# pasted from the docs
import salt.utils.event
# Fire deploy action
sock_dir = '/var/run/salt/minion'
payload = {'sample-msg': 'this is a test',
'example': 'this is the same test'}
event = salt.utils.event.SaltEvent('master', sock_dir)
event.fire_event(payload, 'tag') Both code runs as |
Right, the auths are expected, I think -- part of |
Currently fire_event is not being passed via a 0MQ to the master but is calling directly to the master this means |
@SmithSamuelM when you said:
and
It does not work at all, I ran both code as the If this is supposed to be done a different way, I don't mind it much but the documentation, as it stands now, is not correct. |
There may be a bug somewhere that has broken it. We will look into it. Thanks for trying this out. |
@wari I believe you'll also need to use the same sock_dir for the event sender and listener |
@olliewalsh how do I send an event to the master from a minion that's on another host via the API? Definitely they don't share the same sock_dir. |
@wari I think what @SmithSamuelM was saying is that it's using an IPC socket on the filesystem, not a TCP socket. So you can use the API to send minion events on the minion or to send master events on the master. To send a master event from a minion you would need to replicate what the minion does: Line 13 in 889eb74
IIRC this sends an event to the event publisher on the master which relays this to the master IPC socket. Running salt-api on the master might be the way to go. It gives a REST interface to the master event system but it appears to be read only at the moment. Adding support for sending should be straightforward I think. |
Hi, sorry for the late reply. Ok, I'm trying to do my own event sender from a minion. Based on import salt.crypt
import salt.utils
import salt.payload.event
import salt.config
__opts__ = salt.config.minion_config('/etc/salt/minion')
auth = salt.crypt.SAuth(__opts__) So this is where it borks: KeyError Traceback (most recent call last)
/root/<ipython-input-10-4d66448eaeb7> in <module>()
----> 1 auth = salt.crypt.SAuth(__opts__)
/usr/lib/python2.7/dist-packages/salt/crypt.pyc in __init__(self, opts)
444 def __init__(self, opts):
445 super(SAuth, self).__init__(opts)
--> 446 self.crypticle = self.__authenticate()
447
448 def __authenticate(self):
/usr/lib/python2.7/dist-packages/salt/crypt.pyc in __authenticate(self)
456 creds = self.sign_in(
457 self.opts.get('_auth_timeout', 60),
--> 458 self.opts.get('_safe_auth', True)
459 )
460
/usr/lib/python2.7/dist-packages/salt/crypt.pyc in sign_in(self, timeout, safe)
294
295 sreq = salt.payload.SREQ(
--> 296 self.opts['master_uri'],
297 )
298 try:
KeyError: 'master_uri' So how do I get |
Hi @cachedout, pulled the changes, and tested. Master URI is there, but I think it points to the wrong IP: In [46]: cfg = salt.config.client_config('/etc/salt/minion')
In [47]: cfg['master_uri']
Out[47]: 'tcp://127.0.0.1:4506' Anyway, further on, I've even changed it to First, Again, there must be an easier way to send out events programmatically in python. And I don't mean |
Hi again @wari Apologies for the delay in responding to this. To get right to the point, here is some code that works for me when run on the minion as root. Note that if the key is unaccepted for the given ID, you may need to accept it using Obviously, you can just go ahead and replicate the very basic steps present in
On the master, using
Note that if the 'act' argument in the key event is |
Hi there @cachedout sorry for the late reply, on >>> sf = salt.utils.event.StateFire(opts)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/pymodules/python2.7/salt/utils/event.py", line 602, in __init__
self.auth = salt.crypt.SAuth(self.opts)
File "/usr/lib/pymodules/python2.7/salt/crypt.py", line 502, in __init__
self.crypticle = self.__authenticate()
File "/usr/lib/pymodules/python2.7/salt/crypt.py", line 514, in __authenticate
self.opts.get('_safe_auth', True)
File "/usr/lib/pymodules/python2.7/salt/crypt.py", line 335, in sign_in
self.opts['master'],
KeyError: 'master' Also, does |
@wari you might have an easier time going through the Python class for salt-call instead: import salt.client
caller = salt.client.Caller('/etc/salt/minion')
caller.sminion.functions['event.fire_master']({'foo': 'Foo!'}, 'my/custom/tag') |
@whiteinge thanks a lot! This works nicely (and easier too!). Does this work with auth tokens? I guess not, as only the master has external-auth items. What I mean is that if I can do it in this way programmatically, I would need to have something that runs as root to do the calls, or program a kind of communication bridge, either via http, or a setuid type of program. |
@wari You're right this doesn't work with auth for the reasons you specified. If you need auth and can/want to do this via HTTP you may be interested in this webhook addition to salt-api. I'll be cutting a release with that addition soon. |
Hi @wari. Does @whiteinge 's suggestion allow us to close this issue? If there are remaining bugs to be worked out, we can certainly handle them but we'd like to get this closed if there's no additional bugs to be worked on. Thanks! |
@whiteinge and @cachedout, thanks for your help, I would actually consider this closed if the documentation points out the way to fire events from the minions -> http://docs.saltstack.com/topics/event/index.html <- this one still won't work. Using I can only see myself using a simple flask based app running on localhost (or file socket) as root to talk fire events using the
Anyway, I'll close the issue.. Thanks guys, |
I've been following the documentation @ http://docs.saltstack.com/topics/event/index.html
So, I have the event listener code running on the master side, and it's happily returning events as I got them via
iter_events(full=True)
call.Now to fire events from any minions!
Yup, that works.
This however, does not work, nothing seems to happen. I tried changing
'master'
to the actual master id, or event the minion id, but still, I see nothing coming through the event bus. I'm running the code on other minions as well as minion that is running on the master server. Anything else I might forget?The text was updated successfully, but these errors were encountered: