pcap2json is a high speed utility that converts PCAP data into JSON flow snapshots. This allows highspeed 10Gbps-100Gbps of capture data size be reduced by x10 into JSON records which can be ingested by an Elastic Stack cluster.
pcap2json pushes data directly to the Elastics Stack cluster, typically over HTTP and port 9200. There is no load balancer, LogStash, Reddis or other system between FMADIO pcap2json and the ES Cluster. as shown below.
Elastic Stack version:
7.17.12
PCAP2JSON Plugin
pcap2json is created using FMADIO Packet Capture plugin architecture. It requires the plugin file to load the plugin as follows using the command
Instead of turning everything on at one time and trying to debug the system, a good way is to start with running pcap2json in "offline" mode using stdout with a small PCAP.
What this does is run pcap2json and instead of pushing to the ES Cluster, it writes the JSON to a local file. This is good as we can confirm pcap2json is functioning correctly first, then look at confirming pcap2json + ES is working correctly.
First ensure the option, per the pcap2json.lua config file above is set
"--output-stdout",
Next find a small ish sized capture file, using the command
sudostream_dump
Output of this command will look similar to this
madio@fmadio100v2-228U:$sudostream_dumpStreams: [0000] [this should be empty] 0GBChunk(Cnt:0Start:1End:0Comp:0.00) Inv:-nanCap:-nanCacheI:-nanCache:-nanDisk:-nanDrop:-nanPkt:0 [0423] test_20210712_154359GBChunk(Cnt:244288Start:634032End:878319Comp:0.00) Inv:-nanCap:-nanCacheI:-nanCache:-nanDisk:-nanDrop:-nanPkt:0 [0424] blah_20210712_160259GBChunk(Cnt:244632Start:878320End:1122951Comp:0.00) Inv:-nanCap:-nanCacheI:-nanCache:-nanDisk:-nanDrop:-nanPkt:0 [0433] interop17_20210716_071615GBChunk(Cnt:63848Start:8475424End:8539271Comp:0.00) Inv:-nanCap:-nanCacheI:-nanCache:-nanDisk:-nanDrop:-nanPkt:0fmadio@fmadio100v2-228U:$sudostream_dump
In the above example we will use the file named "interop17_20210716_0716"
Next move to a temporary directory
cd/mnt/store0/tmp2/
Then start pcap2json in offline mode with the above capture
If your stdout file looks similar, ready to connect the system to Elastic Stack. If not please check the above steps again until stdout file looks correct.
Elastic Stack Push
After the Test Run writing to file "stdout" is functioning correctly, next step is to connect and push that JSON data to Elastic Stack.
First is checking the ES version, via CLI as below. We are using Elastic Stack 7.10+ (7.10.1)
fmadio@fmadio100v2-228U:/mnt/store0/tmp2$ /usr/local/bin/curl -H"Content-Type: application/json"-XPUT"192.168.2.147:9200/pcap2json_index?pretty"--data-binary "@mapping.json"| jq% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed10047981009110047073116280:00:020:00:02--:--:--1659{"acknowledged": true,"shards_acknowledged": true,"index": "pcap2json_index"}fmadio@fmadio100v2-228U:/mnt/store0/tmp2$
Next push a small part of stdout file manually to ES as follows. This writes the first 10 lines in the JSON file to the ES cluster
head -n 10 stdout |/usr/local/bin/curl -H"Content-Type: application/json"-XPOST"192.168.1.100:9200/_bulk/?pretty"--data-binary "@-"| jq
The correct output showing indexing has been successful as below
If the above is functioning correctly, can next push the output to ES
Elastic Search Offline Mode
Pushing captures to ES in offline mode is good for lab/debug/troubleshooting a system. As its easier to control than the 24/7 running mode
Start by updating the config file /opt/fmadio/etc/pcap2json.lua as follows. The only real difference is "--output-espush" is set instead of "--output-stdout".
Ensure the "--es-host <es node hostname>:<port>:1e6" is set correctly