How to continuously feed sniffed packets to kafka?

前端 未结 4 1438
清酒与你
清酒与你 2021-01-21 04:56

Currently I am sniffing packets from my local wlan interface like :

sudo tshark > sampleData.pcap

However, I need to feed this data to kafka.

4条回答
  •  失恋的感觉
    2021-01-21 05:16

    If you use Node, you can use child_process and kafka_node to do it. Something like this:

    var kafka = require('kafka-node');
    var client = new kafka.Client('localhost:2181');
    var producer = new kafka.Producer(client);
    
    var spawn = require('child_process').spawn;
    var tshark = spawn('sudo', ['/usr/sbin/tshark']);
    
    tshark.stdout.on('data', (data) => {
      producer.send([
        {topic: 'spark-kafka', messages: [data.split("\n")]}
      ], (err,result) => { console.log("sent to kafka")});
    });
    

提交回复
热议问题