suricata
output-json.c File Reference
#include "suricata-common.h"
#include "debug.h"
#include "detect.h"
#include "flow.h"
#include "conf.h"
#include "threads.h"
#include "tm-threads.h"
#include "threadvars.h"
#include "util-debug.h"
#include "util-unittest.h"
#include "util-unittest-helper.h"
#include "detect-parse.h"
#include "detect-engine.h"
#include "detect-engine-mpm.h"
#include "detect-reference.h"
#include "app-layer-parser.h"
#include "util-classification-config.h"
#include "util-syslog.h"
#include "output.h"
#include "output-json.h"
#include "util-byte.h"
#include "util-privs.h"
#include "util-print.h"
#include "util-proto-name.h"
#include "util-optimize.h"
#include "util-buffer.h"
#include "util-logopenfile.h"
#include "util-log-redis.h"
#include "util-device.h"
#include "util-validate.h"
#include "util-crypt.h"
#include "util-plugin.h"
#include "flow-var.h"
#include "flow-bit.h"
#include "flow-storage.h"
#include "source-pcap-file.h"
#include "suricata-plugin.h"
Include dependency graph for output-json.c:

Go to the source code of this file.

Data Structures

struct  JSONMACAddrInfo
 

Macros

#define DEFAULT_LOG_FILENAME   "eve.json"
 
#define DEFAULT_ALERT_SYSLOG_FACILITY_STR   "local0"
 
#define DEFAULT_ALERT_SYSLOG_FACILITY   LOG_LOCAL0
 
#define DEFAULT_ALERT_SYSLOG_LEVEL   LOG_INFO
 
#define MODULE_NAME   "OutputJSON"
 
#define MAX_JSON_SIZE   2048
 
#define COMMUNITY_ID_BUF_SIZE   64
 

Typedefs

typedef struct JSONMACAddrInfo JSONMACAddrInfo
 

Functions

void OutputJsonRegister (void)
 
json_t * SCJsonBool (int val)
 
void SCJsonDecref (json_t *json)
 
json_t * SCJsonString (const char *val)
 
void EveFileInfo (JsonBuilder *jb, const File *ff, const bool stored)
 
int CreateJSONEther (JsonBuilder *parent, const Packet *p, const MacSet *ms)
 
void EveAddCommonOptions (const OutputJsonCommonSettings *cfg, const Packet *p, const Flow *f, JsonBuilder *js)
 
void EvePacket (const Packet *p, JsonBuilder *js, unsigned long max_length)
 Jsonify a packet. More...
 
void EveTcpFlags (const uint8_t flags, JsonBuilder *js)
 jsonify tcp flags field Only add 'true' fields in an attempt to keep things reasonably compact. More...
 
void JsonAddrInfoInit (const Packet *p, enum OutputJsonLogDirection dir, JsonAddrInfo *addr)
 
void CreateEveFlowId (JsonBuilder *js, const Flow *f)
 
JsonBuilder * CreateEveHeader (const Packet *p, enum OutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr)
 
JsonBuilder * CreateEveHeaderWithTxId (const Packet *p, enum OutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, uint64_t tx_id)
 
int OutputJSONMemBufferCallback (const char *str, size_t size, void *data)
 
int OutputJSONBuffer (json_t *js, LogFileCtx *file_ctx, MemBuffer **buffer)
 
int OutputJsonBuilderBuffer (JsonBuilder *js, LogFileCtx *file_ctx, MemBuffer **buffer)
 
OutputInitResult OutputJsonInitCtx (ConfNode *conf)
 Create a new LogFileCtx for "fast" output style. More...
 

Variables

const JsonAddrInfo json_addr_info_zero
 

Detailed Description

Author
Tom DeCanio td@np.nosp@m.ulse.nosp@m.tech..nosp@m.com

Logs detection and monitoring events in JSON format.

Definition in file output-json.c.

Macro Definition Documentation

◆ COMMUNITY_ID_BUF_SIZE

#define COMMUNITY_ID_BUF_SIZE   64

Definition at line 633 of file output-json.c.

◆ DEFAULT_ALERT_SYSLOG_FACILITY

#define DEFAULT_ALERT_SYSLOG_FACILITY   LOG_LOCAL0

Definition at line 76 of file output-json.c.

◆ DEFAULT_ALERT_SYSLOG_FACILITY_STR

#define DEFAULT_ALERT_SYSLOG_FACILITY_STR   "local0"

Definition at line 75 of file output-json.c.

◆ DEFAULT_ALERT_SYSLOG_LEVEL

#define DEFAULT_ALERT_SYSLOG_LEVEL   LOG_INFO

Definition at line 77 of file output-json.c.

◆ DEFAULT_LOG_FILENAME

#define DEFAULT_LOG_FILENAME   "eve.json"

Definition at line 74 of file output-json.c.

◆ MAX_JSON_SIZE

#define MAX_JSON_SIZE   2048

Definition at line 80 of file output-json.c.

◆ MODULE_NAME

#define MODULE_NAME   "OutputJSON"

Definition at line 78 of file output-json.c.

Typedef Documentation

◆ JSONMACAddrInfo

Function Documentation

◆ CreateEveFlowId()

void CreateEveFlowId ( JsonBuilder *  js,
const Flow f 
)

Definition at line 760 of file output-json.c.

Referenced by CreateEveHeader().

Here is the caller graph for this function:

◆ CreateEveHeader()

JsonBuilder* CreateEveHeader ( const Packet p,
enum OutputJsonLogDirection  dir,
const char *  event_type,
JsonAddrInfo addr 
)

Definition at line 846 of file output-json.c.

References CreateEveFlowId(), CreateIsoTimeString(), Packet_::flow, Packet_::ts, and unlikely.

Referenced by CreateEveHeaderWithTxId(), JsonBuildFileInfoRecord(), and RulesDumpMatchArray().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateEveHeaderWithTxId()

JsonBuilder* CreateEveHeaderWithTxId ( const Packet p,
enum OutputJsonLogDirection  dir,
const char *  event_type,
JsonAddrInfo addr,
uint64_t  tx_id 
)

Definition at line 923 of file output-json.c.

References CreateEveHeader(), and unlikely.

Here is the call graph for this function:

◆ CreateJSONEther()

int CreateJSONEther ( JsonBuilder *  parent,
const Packet p,
const MacSet ms 
)

Definition at line 801 of file output-json.c.

References JSONMACAddrInfo::dst, MacSetForEach(), MacSetSize(), JSONMACAddrInfo::src, and unlikely.

Here is the call graph for this function:

◆ EveAddCommonOptions()

void EveAddCommonOptions ( const OutputJsonCommonSettings cfg,
const Packet p,
const Flow f,
JsonBuilder *  js 
)

Definition at line 444 of file output-json.c.

References OutputJsonCommonSettings_::include_metadata.

◆ EveFileInfo()

void EveFileInfo ( JsonBuilder *  jb,
const File ff,
const bool  stored 
)

◆ EvePacket()

void EvePacket ( const Packet p,
JsonBuilder *  js,
unsigned long  max_length 
)

Jsonify a packet.

Parameters
pPacket
jsJSON object
max_lengthIf non-zero, restricts the number of packet data bytes handled.

Definition at line 467 of file output-json.c.

References Base64Encode(), Packet_::datalink, GET_PKT_DATA, GET_PKT_LEN, len, and SC_BASE64_OK.

Here is the call graph for this function:

◆ EveTcpFlags()

void EveTcpFlags ( const uint8_t  flags,
JsonBuilder *  js 
)

jsonify tcp flags field Only add 'true' fields in an attempt to keep things reasonably compact.

Definition at line 488 of file output-json.c.

References flags, JB_SET_TRUE, TH_ACK, TH_CWR, TH_ECN, TH_FIN, TH_PUSH, TH_RST, TH_SYN, and TH_URG.

◆ JsonAddrInfoInit()

◆ OutputJSONBuffer()

◆ OutputJsonBuilderBuffer()

int OutputJsonBuilderBuffer ( JsonBuilder *  js,
LogFileCtx file_ctx,
MemBuffer **  buffer 
)

◆ OutputJsonInitCtx()

OutputInitResult OutputJsonInitCtx ( ConfNode conf)

Create a new LogFileCtx for "fast" output style.

Parameters
confThe configuration node for this output.
Returns
A LogFileCtx pointer on success, NULL on failure.

Definition at line 1010 of file output-json.c.

References ConfGet(), ConfNodeLookupChildValue(), OutputCtx_::data, OutputCtx_::DeInit, OutputJsonCtx_::file_ctx, LogFileFreeCtx(), LogFileNewCtx(), SC_ERR_DEPRECATED_CONF, SCCalloc, SCFree, SCLogDebug, SCLogWarning, SCStrdup, LogFileCtx_::sensor_name, and unlikely.

Referenced by OutputJsonRegister().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OutputJSONMemBufferCallback()

int OutputJSONMemBufferCallback ( const char *  str,
size_t  size,
void *  data 
)

Definition at line 936 of file output-json.c.

References OutputJSONMemBufferWrapper_::buffer, OutputJSONMemBufferWrapper_::expand_by, MEMBUFFER_OFFSET, MEMBUFFER_SIZE, MemBufferExpand(), MemBufferWriteRaw, and str.

Referenced by OutputJSONBuffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OutputJsonRegister()

void OutputJsonRegister ( void  )

Definition at line 91 of file output-json.c.

References MODULE_NAME, OutputJsonInitCtx(), and OutputRegisterModule().

Referenced by OutputRegisterLoggers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SCJsonBool()

json_t* SCJsonBool ( int  val)

Definition at line 99 of file output-json.c.

◆ SCJsonDecref()

void SCJsonDecref ( json_t *  json)

Wrap json_decref. This is mainly to expose this function to Rust as its defined in the Jansson header file as an inline function.

Definition at line 108 of file output-json.c.

◆ SCJsonString()

json_t* SCJsonString ( const char *  val)

Definition at line 113 of file output-json.c.

References MAX_JSON_SIZE, offset, and PrintBufferData.

Variable Documentation

◆ json_addr_info_zero

const JsonAddrInfo json_addr_info_zero

Definition at line 89 of file output-json.c.

Referenced by JsonBuildFileInfoRecord().