Clients¶
The messages published by napalm-logs can be used in a variety of applications, as there are no restrictions regarding the channel (see Publisher).
The capabilities are already embedded in well known Frameworks, or the user can consume the structured messages using custom Example Scripts.
Frameworks¶
Example Scripts¶
For simplicity, the examples below assume that napalm-logs is started using –disable-security, and ZeroMQ is used as publisher.
Python¶
Receive the messages from napalm-logs and print on the command line:
import zmq
import napalm_logs.utils
server_address = '127.0.0.1' # --publish-address
server_port = 49017 # --publish-port
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect('tcp://{address}:{port}'.format(address=server_address,
port=server_port))
socket.setsockopt(zmq.SUBSCRIBE, '')
while True:
raw_object = socket.recv()
print(napalm_logs.utils.unserialize(raw_object))
JavaScript (Node.js)¶
Receive the napalm-logs messages into a Node.js app, which only logs on the
console. This assumes zeromq.js and
msgpack-lite bindings are installed
(npm install zeromq
and npm install msgpack-lite
).
var zmq = require('zeromq')
var msgpack = require('msgpack-lite');
var sock = zmq.socket('sub');
sock.connect('tcp://127.0.0.1:49017');
sock.subscribe('');
sock.on('message', function(msg){
var data = msgpack.decode(msg);
console.log('Received message:');
console.log(data);
});