diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2017-10-16 14:06:19 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2017-10-16 14:06:19 +0200 |
commit | e91ff1f3b5193713f2fef7876db40c4af5cbc01b (patch) | |
tree | 5c91bfbf153b09594b4922feba258ea05370a411 /doc/zmq_remote.py | |
parent | 7a57fb48c25b0dae4e372b8e522f308c589bb35e (diff) | |
download | dabmux-e91ff1f3b5193713f2fef7876db40c4af5cbc01b.tar.gz dabmux-e91ff1f3b5193713f2fef7876db40c4af5cbc01b.tar.bz2 dabmux-e91ff1f3b5193713f2fef7876db40c4af5cbc01b.zip |
Merge state management command into values, adapt munin accordingly
Diffstat (limited to 'doc/zmq_remote.py')
-rwxr-xr-x | doc/zmq_remote.py | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/doc/zmq_remote.py b/doc/zmq_remote.py index 155390b..47da520 100755 --- a/doc/zmq_remote.py +++ b/doc/zmq_remote.py @@ -12,6 +12,9 @@ context = zmq.Context() sock = context.socket(zmq.REQ) +poller = zmq.Poller() +poller.register(sock, zmq.POLLIN) + if len(sys.argv) < 2: print("Usage: program url cmd [args...]") sys.exit(1) @@ -22,34 +25,37 @@ message_parts = sys.argv[2:] # first do a ping test -print("Send ping") -sock.send("ping".encode()) -data = sock.recv_multipart() +print("ping") +sock.send(b"ping") -if len(data) != 1: - print("Received invalid number of parts: {}".format(len(data))) - for i,part in enumerate(data): - print(" {}".format(part)) - sys.exit(1) +socks = dict(poller.poll(1000)) +if socks: + if socks.get(sock) == zmq.POLLIN: -if data[0] != b'ok': - print("Received invalid ping response: {}".format(data.decode())) - sys.exit(1) + data = sock.recv_multipart() + print("Received: {}".format(len(data))) + for i,part in enumerate(data): + print(" {}".format(part)) + + for i, part in enumerate(message_parts): + if i == len(message_parts) - 1: + f = 0 + else: + f = zmq.SNDMORE -print("Ping ok, sending request '{}'...".format(" ".join(message_parts))) + print("Send {}({}): '{}'".format(i, f, part)) -for i, part in enumerate(message_parts): - if i == len(message_parts) - 1: - f = 0 - else: - f = zmq.SNDMORE + sock.send(part.encode(), flags=f) - sock.send(part.encode(), flags=f) + data = sock.recv_multipart() -data = sock.recv_multipart() + print("Received: {}".format(len(data))) + for i,part in enumerate(data): + print(" RX {}: {}".format(i, part)) -print("Received {} entries:".format(len(data))) -print(" " + " ".join([d.decode() for d in data])) +else: + print("ZMQ error: timeout") + context.destroy(linger=5) # This is free and unencumbered software released into the public domain. # |