mirror of https://github.com/tstack/lnav
[config] externalize file format detection
parent
ff0b112728
commit
2e09202ff5
@ -0,0 +1,63 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2023, Timothy Stack
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of Timothy Stack nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
|
||||||
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef lnav_file_format_cfg_hh
|
||||||
|
#define lnav_file_format_cfg_hh
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "yajlpp/yajlpp.hh"
|
||||||
|
|
||||||
|
namespace lnav {
|
||||||
|
namespace file_formats {
|
||||||
|
|
||||||
|
struct header_exprs {
|
||||||
|
std::map<std::string, std::string> he_exprs;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct header {
|
||||||
|
header_exprs h_exprs;
|
||||||
|
size_t h_size{32};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct format_def {
|
||||||
|
std::string fd_title;
|
||||||
|
header fd_header;
|
||||||
|
positioned_property<std::string> fd_converter;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct config {
|
||||||
|
std::map<std::string, format_def> c_defs;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace file_formats
|
||||||
|
} // namespace lnav
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Check that tshark is installed and return a nice message.
|
||||||
|
if ! command -v tshark; then
|
||||||
|
echo "pcap support requires 'tshark' v3+ to be installed" > /dev/stderr
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use tshark to convert the pcap file into a JSON-lines log file
|
||||||
|
exec tshark -T ek -P -V -t ad -r $2
|
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://lnav.org/schemas/config-v1.schema.json",
|
||||||
|
"tuning": {
|
||||||
|
"file-format": {
|
||||||
|
"application/vnd.example.com": {
|
||||||
|
"title": "example",
|
||||||
|
"header": {
|
||||||
|
"expr": {
|
||||||
|
"default": ":header REGEXP 'foobar"
|
||||||
|
},
|
||||||
|
"size": 8
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"application/vnd.example2.com": {
|
||||||
|
"title": "example"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
Row 0:
|
||||||
|
Column encode('hi' || char(10), 'hex'): 68690a
|
Loading…
Reference in New Issue