mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-18 06:20:42 +01:00
Merge pull request #1357 from GrayTShirt/mmdb-stylecheck
mmdblookup module cleanup
This commit is contained in:
commit
e318309c61
@ -1,42 +1,24 @@
|
||||
# rsyslog-maxminddb
|
||||
# Rsyslog - MMDBLookup
|
||||
|
||||
MaxMindDB is the new file format for storing information about IP addresses in a highly optimized, flexible database format. GeoIP2 Databases are available in the MaxMind DB format.
|
||||
Fast geoip lookups straight from Rsyslog.
|
||||
|
||||
MaxMindDB vs GeoIP:
|
||||
[Maxmind](https://www.maxmind.com/en/home) provides free and pay-for memmory mapped ip-lookup databases.
|
||||
The free city-level database is about 22 mB, and can be found on the [geolite page](http://dev.maxmind.com/geoip/geoip2/geolite2/).
|
||||
|
||||
1. 4 ~ 6 faster
|
||||
2. MaxMindDB Writer
|
||||
|
||||
## Compile
|
||||
|
||||
1. download and install libfastjson > 0.99.3 from https://github.com/rgerhards/libfastjson/commit/c437cad46af1998e3ad2dafa058c9e2c715df261
|
||||
```
|
||||
git clone https://github.com/rgerhards/libfastjson
|
||||
```
|
||||
|
||||
2. download rsyslog source
|
||||
```
|
||||
git clone https://github.com/rsyslog/rsyslog.git
|
||||
```
|
||||
|
||||
3. copy the code into rsyslog contrib path:
|
||||
```
|
||||
cp -r src/contrib/mmdblookup ../rsyslog/contrib/
|
||||
cp src/configure.ac ../rsyslog/
|
||||
cp src/Makefile.am ../rsyslog/
|
||||
cp src/libfastjson.env ../rsyslog/
|
||||
# cp src/tests ../rsyslog/
|
||||
```
|
||||
|
||||
4. configure
|
||||
1. Ensure you have [libfastjson](https://github.com/rgerhards/libfastjson/) installed, check your package manager or install from source.
|
||||
2. Ensure you have [libmaxminddb](https://github.com/maxmind/libmaxminddb) installed, check your package manager.
|
||||
3. configure
|
||||
```
|
||||
export PKG_CONFIG_PATH=/lib64/pkgconfig/
|
||||
yum install -y libestr liblogging libmaxminddb-devel
|
||||
yum install -y git-core valgrind autoconf automake flex bison json-c-devel libuuid-devel libgcrypt-devel zlib-devel openssl-devel libcurl-devel gnutls-devel mysql-devel postgresql-devel libdbi-dbd-mysql libdbi-devel net-snmp-devel
|
||||
yum install -y autoconf automake flex bison json-c-devel libuuid-devel libgcrypt-devel zlib-devel openssl-devel libcurl-devel gnutls-devel
|
||||
cd ../rsyslog
|
||||
source libfastjson.env
|
||||
autoconf
|
||||
./configure --enable-mmdblookup --enable-mmjsonparse --***
|
||||
./autogen.sh --enable-mmdblookup --enable-mmjsonparse --***
|
||||
make
|
||||
make install
|
||||
```
|
||||
|
||||
## Usage
|
||||
@ -49,28 +31,27 @@ module( load="mmdblookup" )
|
||||
module( load="mmjsonparse" )
|
||||
|
||||
input (
|
||||
type="imfile"
|
||||
File="/tmp/access.log"
|
||||
addMetadata="off"
|
||||
Severity="info"
|
||||
Facility="user"
|
||||
tag="test"
|
||||
ruleset="test"
|
||||
type="imfile"
|
||||
File="/tmp/access.log"
|
||||
addMetadata="off"
|
||||
Severity="info"
|
||||
Facility="user"
|
||||
tag="test"
|
||||
ruleset="test"
|
||||
)
|
||||
|
||||
template( type="string" string="{\"@timestamp\":\"%timereported:::date-rfc3339%\",\"host\":\"%hostname%\",\"geoip2\":%$!iplocation%,%msg:7:$%" name="clientlog" )
|
||||
ruleset ( name="test"){
|
||||
action( type="mmjsonparse" )
|
||||
if ( $parsesuccess == "OK" ) then {
|
||||
action( type="mmdblookup" mmdbfile="/etc/rsyslog.d/GeoLite2-City.mmdb" fields=["!continent!code","!location"] key="!clientip" )
|
||||
action(type="omfwd" Target="10.211.55.3" port="514" Protocol="tcp" template="clientlog")
|
||||
stop
|
||||
}
|
||||
|
||||
template ( type="string" string="{\"@timestamp\":\"%timereported:::date-rfc3339%\",\"host\":\"%hostname%\",\"geoip2\":%$!iplocation%,%msg:7:$%" name="clientlog" )
|
||||
ruleset ( name="test" ) {
|
||||
action ( type="mmjsonparse" )
|
||||
if ( $parsesuccess == "OK" ) then {
|
||||
action( type="mmdblookup" mmdbfile="/etc/rsyslog.d/GeoLite2-City.mmdb" fields=["!continent!code","!location"] key="!clientip" )
|
||||
action( type="omfwd" Target="10.211.55.3" port="514" Protocol="tcp" template="clientlog" )
|
||||
stop
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### test
|
||||
### Testing
|
||||
|
||||
```
|
||||
cat /root/a
|
||||
@ -89,4 +70,3 @@ get the result from logstash-input:
|
||||
"port" => 58199
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
export JSON_C_CFLAGS=-I/usr/local/include/libfastjson
|
||||
export JSON_C_LIBS="-L/usr/local/lib -Wl,-rpath,/usr/local/lib -lfastjson"
|
||||
@ -9,11 +9,11 @@
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* -or-
|
||||
* see COPYING.ASL20 in the source distribution
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@ -51,45 +51,53 @@ DEFobjCurrIf(errmsg);
|
||||
DEF_OMOD_STATIC_DATA
|
||||
|
||||
/* config variables */
|
||||
|
||||
typedef struct _instanceData {
|
||||
char *pszKey;
|
||||
char *pszMmdbFile;
|
||||
struct {
|
||||
int nmemb;
|
||||
uchar **name;
|
||||
} fieldList;
|
||||
char *pszKey;
|
||||
char *pszMmdbFile;
|
||||
struct {
|
||||
int nmemb;
|
||||
uchar **name;
|
||||
} fieldList;
|
||||
} instanceData;
|
||||
|
||||
typedef struct wrkrInstanceData {
|
||||
instanceData *pData;
|
||||
MMDB_s mmdb;
|
||||
instanceData *pData;
|
||||
MMDB_s mmdb;
|
||||
} wrkrInstanceData_t;
|
||||
|
||||
struct modConfData_s {
|
||||
rsconf_t *pConf; /* our overall config object */
|
||||
/* our overall config object */
|
||||
rsconf_t *pConf;
|
||||
};
|
||||
static modConfData_t *loadModConf = NULL;/* modConf ptr to use for the current load process */
|
||||
static modConfData_t *runModConf = NULL;/* modConf ptr to use for the current exec process */
|
||||
|
||||
/* modConf ptr to use for the current load process */
|
||||
static modConfData_t *loadModConf = NULL;
|
||||
/* modConf ptr to use for the current exec process */
|
||||
static modConfData_t *runModConf = NULL;
|
||||
|
||||
|
||||
/* tables for interfacing with the v6 config system */
|
||||
/* action (instance) parameters */
|
||||
/* tables for interfacing with the v6 config system
|
||||
* action (instance) parameters */
|
||||
static struct cnfparamdescr actpdescr[] = {
|
||||
{ "key", eCmdHdlrGetWord, 0 },
|
||||
{ "mmdbfile", eCmdHdlrGetWord, 0 },
|
||||
{ "fields", eCmdHdlrArray, 0 },
|
||||
{ "key", eCmdHdlrGetWord, 0 },
|
||||
{ "mmdbfile", eCmdHdlrGetWord, 0 },
|
||||
{ "fields", eCmdHdlrArray, 0 },
|
||||
};
|
||||
static struct cnfparamblk actpblk =
|
||||
{ CNFPARAMBLK_VERSION,
|
||||
sizeof(actpdescr)/sizeof(struct cnfparamdescr),
|
||||
actpdescr
|
||||
};
|
||||
static struct cnfparamblk actpblk = {
|
||||
CNFPARAMBLK_VERSION,
|
||||
sizeof(actpdescr)/sizeof(struct cnfparamdescr),
|
||||
actpdescr
|
||||
};
|
||||
|
||||
|
||||
/* protype functions */
|
||||
void str_split(char **membuf);
|
||||
|
||||
|
||||
BEGINbeginCnfLoad
|
||||
CODESTARTbeginCnfLoad
|
||||
loadModConf = pModConf;
|
||||
pModConf->pConf = pConf;
|
||||
loadModConf = pModConf;
|
||||
pModConf->pConf = pConf;
|
||||
ENDbeginCnfLoad
|
||||
|
||||
BEGINendCnfLoad
|
||||
@ -102,7 +110,7 @@ ENDcheckCnf
|
||||
|
||||
BEGINactivateCnf
|
||||
CODESTARTactivateCnf
|
||||
runModConf = pModConf;
|
||||
runModConf = pModConf;
|
||||
ENDactivateCnf
|
||||
|
||||
BEGINfreeCnf
|
||||
@ -116,15 +124,15 @@ ENDcreateInstance
|
||||
|
||||
BEGINcreateWrkrInstance
|
||||
CODESTARTcreateWrkrInstance
|
||||
int status = MMDB_open(pData->pszMmdbFile, MMDB_MODE_MMAP, &pWrkrData->mmdb);
|
||||
if(MMDB_SUCCESS != status) {
|
||||
dbgprintf("Can't open %s - %s\n", pData->pszMmdbFile, MMDB_strerror(status));
|
||||
if(MMDB_IO_ERROR == status) {
|
||||
dbgprintf(" IO error: %s\n", strerror(errno));
|
||||
}
|
||||
errmsg.LogError(0, RS_RET_SUSPENDED, "can not initialize maxminddb");
|
||||
// ABORT_FINALIZE(RS_RET_SUSPENDED);
|
||||
}
|
||||
int status = MMDB_open(pData->pszMmdbFile, MMDB_MODE_MMAP, &pWrkrData->mmdb);
|
||||
if (MMDB_SUCCESS != status) {
|
||||
dbgprintf("Can't open %s - %s\n", pData->pszMmdbFile, MMDB_strerror(status));
|
||||
if (MMDB_IO_ERROR == status) {
|
||||
dbgprintf(" IO error: %s\n", strerror(errno));
|
||||
}
|
||||
errmsg.LogError(0, RS_RET_SUSPENDED, "can not initialize maxminddb");
|
||||
/* ABORT_FINALIZE(RS_RET_SUSPENDED); */
|
||||
}
|
||||
ENDcreateWrkrInstance
|
||||
|
||||
|
||||
@ -140,65 +148,64 @@ ENDfreeInstance
|
||||
|
||||
BEGINfreeWrkrInstance
|
||||
CODESTARTfreeWrkrInstance
|
||||
MMDB_close(&pWrkrData->mmdb);
|
||||
MMDB_close(&pWrkrData->mmdb);
|
||||
ENDfreeWrkrInstance
|
||||
|
||||
static inline void
|
||||
setInstParamDefaults(instanceData *pData)
|
||||
{
|
||||
pData->pszKey = NULL;
|
||||
pData->pszMmdbFile = NULL;
|
||||
pData->fieldList.nmemb = 0;
|
||||
pData->pszKey = NULL;
|
||||
pData->pszMmdbFile = NULL;
|
||||
pData->fieldList.nmemb = 0;
|
||||
}
|
||||
|
||||
BEGINnewActInst
|
||||
struct cnfparamvals *pvals;
|
||||
int i;
|
||||
struct cnfparamvals *pvals;
|
||||
int i;
|
||||
CODESTARTnewActInst
|
||||
dbgprintf("newActInst (mmdblookup)\n");
|
||||
if((pvals = nvlstGetParams(lst, &actpblk, NULL)) == NULL) {
|
||||
ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS);
|
||||
}
|
||||
dbgprintf("newActInst (mmdblookup)\n");
|
||||
if ((pvals = nvlstGetParams(lst, &actpblk, NULL)) == NULL) {
|
||||
ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS);
|
||||
}
|
||||
|
||||
CODE_STD_STRING_REQUESTnewActInst(1)
|
||||
CHKiRet(OMSRsetEntry(*ppOMSR, 0, NULL, OMSR_TPL_AS_MSG));
|
||||
CHKiRet(createInstance(&pData));
|
||||
setInstParamDefaults(pData);
|
||||
CODE_STD_STRING_REQUESTnewActInst(1)
|
||||
CHKiRet(OMSRsetEntry(*ppOMSR, 0, NULL, OMSR_TPL_AS_MSG));
|
||||
CHKiRet(createInstance(&pData));
|
||||
setInstParamDefaults(pData);
|
||||
|
||||
for(i = 0 ; i < actpblk.nParams ; ++i) {
|
||||
if(!pvals[i].bUsed)
|
||||
continue;
|
||||
if(!strcmp(actpblk.descr[i].name, "key")) {
|
||||
pData->pszKey = es_str2cstr(pvals[i].val.d.estr, NULL);
|
||||
continue;
|
||||
}
|
||||
if(!strcmp(actpblk.descr[i].name, "mmdbfile")) {
|
||||
pData->pszMmdbFile = es_str2cstr(pvals[i].val.d.estr, NULL);
|
||||
continue;
|
||||
}
|
||||
if(!strcmp(actpblk.descr[i].name, "fields")) {
|
||||
pData->fieldList.nmemb = pvals[i].val.d.ar->nmemb;
|
||||
CHKmalloc(pData->fieldList.name = malloc(sizeof(uchar*) * pData->fieldList.nmemb));
|
||||
for(int j = 0 ; j < pvals[i].val.d.ar->nmemb ; ++j) {
|
||||
pData->fieldList.name[j] = (uchar*)es_str2cstr(pvals[i].val.d.ar->arr[j], NULL);
|
||||
}
|
||||
}
|
||||
dbgprintf("mmdblookup: program error, non-handled "
|
||||
"param '%s'\n", actpblk.descr[i].name);
|
||||
}
|
||||
for (i = 0; i < actpblk.nParams; ++i) {
|
||||
if (!pvals[i].bUsed)
|
||||
continue;
|
||||
if (!strcmp(actpblk.descr[i].name, "key")) {
|
||||
pData->pszKey = es_str2cstr(pvals[i].val.d.estr, NULL);
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(actpblk.descr[i].name, "mmdbfile")) {
|
||||
pData->pszMmdbFile = es_str2cstr(pvals[i].val.d.estr, NULL);
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(actpblk.descr[i].name, "fields")) {
|
||||
pData->fieldList.nmemb = pvals[i].val.d.ar->nmemb;
|
||||
CHKmalloc(pData->fieldList.name = malloc(sizeof(uchar *) * pData->fieldList.nmemb));
|
||||
for (int j = 0; j < pvals[i].val.d.ar->nmemb; ++j)
|
||||
pData->fieldList.name[j] = (uchar*)es_str2cstr(pvals[i].val.d.ar->arr[j], NULL);
|
||||
}
|
||||
dbgprintf("mmdblookup: program error, non-handled"
|
||||
" param '%s'\n", actpblk.descr[i].name);
|
||||
}
|
||||
|
||||
if(pData->pszKey == NULL) {
|
||||
dbgprintf("mmdblookup: action requires a key");
|
||||
ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS);
|
||||
}
|
||||
if (pData->pszKey == NULL) {
|
||||
dbgprintf("mmdblookup: action requires a key");
|
||||
ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS);
|
||||
}
|
||||
|
||||
if(pData->pszMmdbFile == NULL) {
|
||||
dbgprintf("mmdblookup: action requires a mmdbfile");
|
||||
ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS);
|
||||
}
|
||||
if (pData->pszMmdbFile == NULL) {
|
||||
dbgprintf("mmdblookup: action requires a mmdbfile");
|
||||
ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS);
|
||||
}
|
||||
|
||||
CODE_STD_FINALIZERnewActInst
|
||||
cnfparamvalsDestruct(pvals, &actpblk);
|
||||
cnfparamvalsDestruct(pvals, &actpblk);
|
||||
ENDnewActInst
|
||||
|
||||
|
||||
@ -210,90 +217,85 @@ ENDdbgPrintInstInfo
|
||||
BEGINtryResume
|
||||
CODESTARTtryResume
|
||||
ENDtryResume
|
||||
|
||||
|
||||
void str_split(char **membuf){
|
||||
char *buf = *membuf;
|
||||
char tempbuf[strlen(buf)] ;
|
||||
memset(tempbuf, 0, strlen(buf)) ;
|
||||
char tempbuf[strlen(buf)];
|
||||
memset(tempbuf, 0, strlen(buf));
|
||||
|
||||
while(*buf++ != '\0'){
|
||||
if (*buf == '\n' || *buf == '\t' || *buf == ' '){
|
||||
while (*buf++ != '\0') {
|
||||
if (*buf == '\n' || *buf == '\t' || *buf == ' ')
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
if (*buf == '<'){
|
||||
if (*buf == '<') {
|
||||
char *p = strchr(buf, '>');
|
||||
buf = buf + (int)(p - buf);
|
||||
strcat(tempbuf, ",");
|
||||
}
|
||||
else if( *buf == '}'){
|
||||
} else if (*buf == '}')
|
||||
strcat(tempbuf, "},");
|
||||
}
|
||||
else{
|
||||
else
|
||||
strncat(tempbuf, buf, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tempbuf[strlen(tempbuf) +1 ] = '\n';
|
||||
tempbuf[strlen(tempbuf) + 1] = '\n';
|
||||
memset(*membuf, 0, strlen(*membuf)) ;
|
||||
memcpy(*membuf, tempbuf, strlen(tempbuf));
|
||||
}
|
||||
|
||||
|
||||
|
||||
BEGINdoAction
|
||||
msg_t *pMsg;
|
||||
struct json_object *json = NULL;
|
||||
struct json_object *keyjson = NULL;
|
||||
char *pszValue;
|
||||
instanceData *const pData = pWrkrData->pData;
|
||||
BEGINdoAction_NoStrings
|
||||
smsg_t **ppMsg = (smsg_t **) pMsgData;
|
||||
smsg_t *pMsg = ppMsg[0];
|
||||
struct json_object *json = NULL;
|
||||
struct json_object *keyjson = NULL;
|
||||
char *pszValue;
|
||||
instanceData *const pData = pWrkrData->pData;
|
||||
CODESTARTdoAction
|
||||
pMsg = (msg_t*) ppString[0];
|
||||
json = json_object_new_object();
|
||||
|
||||
json = json_object_new_object();
|
||||
/* key is given, so get the property json */
|
||||
msgPropDescr_t pProp;
|
||||
msgPropDescrFill(&pProp, (uchar*)pData->pszKey, strlen(pData->pszKey));
|
||||
rsRetVal localRet = msgGetJSONPropJSON(pMsg, &pProp, &keyjson);
|
||||
msgPropDescrDestruct(&pProp);
|
||||
|
||||
/* key is given, so get the property json */
|
||||
msgPropDescr_t pProp;
|
||||
msgPropDescrFill(&pProp, (uchar*)pData->pszKey, strlen(pData->pszKey));
|
||||
rsRetVal localRet = msgGetJSONPropJSON(pMsg, &pProp, &keyjson);
|
||||
msgPropDescrDestruct(&pProp);
|
||||
|
||||
if(localRet != RS_RET_OK) {
|
||||
/* key not found in the message. nothing to do */
|
||||
ABORT_FINALIZE(RS_RET_OK);
|
||||
}
|
||||
/* key found, so get the value */
|
||||
pszValue = (char*)json_object_get_string(keyjson);
|
||||
if (localRet != RS_RET_OK) {
|
||||
/* key not found in the message. nothing to do */
|
||||
ABORT_FINALIZE(RS_RET_OK);
|
||||
}
|
||||
/* key found, so get the value */
|
||||
pszValue = (char*)json_object_get_string(keyjson);
|
||||
|
||||
int gai_err, mmdb_err;
|
||||
MMDB_lookup_result_s result = MMDB_lookup_string(&pWrkrData->mmdb, pszValue, &gai_err, &mmdb_err);
|
||||
|
||||
int gai_err, mmdb_err;
|
||||
MMDB_lookup_result_s result = MMDB_lookup_string(&pWrkrData->mmdb, pszValue, &gai_err, &mmdb_err);
|
||||
|
||||
if(0 != gai_err) {
|
||||
if (0 != gai_err) {
|
||||
dbgprintf("Error from call to getaddrinfo for %s - %s\n", pszValue, gai_strerror(gai_err));
|
||||
dbgprintf("aaaaa\n");
|
||||
ABORT_FINALIZE(RS_RET_OK);
|
||||
}
|
||||
if(MMDB_SUCCESS != mmdb_err) {
|
||||
}
|
||||
if (MMDB_SUCCESS != mmdb_err) {
|
||||
dbgprintf("Got an error from the maxminddb library: %s\n", MMDB_strerror(mmdb_err));
|
||||
dbgprintf("bbbbb\n");
|
||||
ABORT_FINALIZE(RS_RET_OK);
|
||||
}
|
||||
}
|
||||
|
||||
MMDB_entry_data_list_s *entry_data_list = NULL;
|
||||
MMDB_entry_data_list_s *entry_data_list = NULL;
|
||||
int status = MMDB_get_entry_data_list(&result.entry, &entry_data_list);
|
||||
|
||||
if (MMDB_SUCCESS != status){
|
||||
|
||||
if (MMDB_SUCCESS != status) {
|
||||
dbgprintf("Got an error looking up the entry data - %s\n", MMDB_strerror(status));
|
||||
ABORT_FINALIZE(RS_RET_OK);
|
||||
}
|
||||
|
||||
FILE *memstream;
|
||||
char *membuf;
|
||||
size_t memlen;
|
||||
size_t memlen;
|
||||
char *membuf;
|
||||
FILE *memstream;
|
||||
memstream = open_memstream(&membuf, &memlen);
|
||||
|
||||
if (entry_data_list != NULL && memstream != NULL){
|
||||
if (entry_data_list != NULL && memstream != NULL) {
|
||||
MMDB_dump_entry_data_list(memstream, entry_data_list, 2);
|
||||
fflush(memstream);
|
||||
str_split(&membuf);
|
||||
@ -301,71 +303,69 @@ CODESTARTdoAction
|
||||
|
||||
json_object *total_json = json_tokener_parse(membuf);
|
||||
fclose(memstream);
|
||||
|
||||
if (pData->fieldList.nmemb < 1){
|
||||
|
||||
if (pData->fieldList.nmemb < 1) {
|
||||
dbgprintf("fieldList.name is empty!...\n");
|
||||
ABORT_FINALIZE(RS_RET_OK);
|
||||
}
|
||||
|
||||
for (int i = 0 ; i < pData->fieldList.nmemb ; ++i){
|
||||
for (int i = 0 ; i < pData->fieldList.nmemb; ++i) {
|
||||
char buf[(strlen((char *)(pData->fieldList.name[i])))+1];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
strcpy(buf, (char *)pData->fieldList.name[i]);
|
||||
|
||||
struct json_object *json1[5] = {NULL};
|
||||
json_object *temp_json = total_json;
|
||||
json_object *sub_obj = temp_json;
|
||||
int j = 0;
|
||||
char *path[10] = {NULL};
|
||||
char *sep = "!";
|
||||
|
||||
char *path[10] = {NULL};
|
||||
const char *sep = "!";
|
||||
|
||||
char *s = strtok(buf, sep);
|
||||
for (; s != NULL; j++){
|
||||
for (; s != NULL; j++) {
|
||||
path[j] = s;
|
||||
s = strtok(NULL, sep);
|
||||
|
||||
json_object *sub_obj = json_object_object_get(temp_json, path[j]);
|
||||
|
||||
json_object_object_get_ex(temp_json, path[j], &sub_obj);
|
||||
temp_json = sub_obj;
|
||||
}
|
||||
|
||||
j--;
|
||||
for (;j >= 0 ;j--){
|
||||
if (j > 0){
|
||||
json1[j] = json_object_new_object();
|
||||
for (;j >= 0 ;j--) {
|
||||
if (j > 0) {
|
||||
json1[j] = json_object_new_object();
|
||||
json_object_object_add(json1[j], path[j], temp_json);
|
||||
temp_json = json1[j];
|
||||
}
|
||||
|
||||
else {
|
||||
} else
|
||||
json_object_object_add(json, path[j], temp_json);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
finalize_it:
|
||||
|
||||
if(json) {
|
||||
msgAddJSON(pMsg, (uchar *)JSON_IPLOOKUP_NAME, json, 0, 0);
|
||||
}
|
||||
if (json)
|
||||
msgAddJSON(pMsg, (uchar *)JSON_IPLOOKUP_NAME, json, 0, 0);
|
||||
|
||||
ENDdoAction
|
||||
|
||||
|
||||
BEGINparseSelectorAct
|
||||
CODESTARTparseSelectorAct
|
||||
CODE_STD_STRING_REQUESTparseSelectorAct(1)
|
||||
if(strncmp((char*) p, ":mmdblookup:", sizeof(":mmdblookup:") - 1)) {
|
||||
errmsg.LogError(0, RS_RET_LEGA_ACT_NOT_SUPPORTED,
|
||||
"mmdblookup supports only v6+ config format, use: "
|
||||
"action(type=\"mmdblookup\" ...)");
|
||||
}
|
||||
ABORT_FINALIZE(RS_RET_CONFLINE_UNPROCESSED);
|
||||
if (strncmp((char*) p, ":mmdblookup:", sizeof(":mmdblookup:") - 1)) {
|
||||
errmsg.LogError(0, RS_RET_LEGA_ACT_NOT_SUPPORTED,
|
||||
"mmdblookup supports only v6+ config format, use: "
|
||||
"action(type=\"mmdblookup\" ...)");
|
||||
}
|
||||
ABORT_FINALIZE(RS_RET_CONFLINE_UNPROCESSED);
|
||||
CODE_STD_FINALIZERparseSelectorAct
|
||||
ENDparseSelectorAct
|
||||
|
||||
|
||||
BEGINmodExit
|
||||
CODESTARTmodExit
|
||||
objRelease(errmsg, CORE_COMPONENT);
|
||||
objRelease(errmsg, CORE_COMPONENT);
|
||||
ENDmodExit
|
||||
|
||||
|
||||
@ -378,12 +378,11 @@ CODEqueryEtryPt_STD_CONF2_QUERIES
|
||||
ENDqueryEtryPt
|
||||
|
||||
|
||||
|
||||
BEGINmodInit()
|
||||
CODESTARTmodInit
|
||||
*ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */
|
||||
/* we only support the current interface specification */
|
||||
*ipIFVersProvided = CURR_MOD_IF_VERSION;
|
||||
CODEmodInit_QueryRegCFSLineHdlr
|
||||
dbgprintf("mmdblookup: module compiled with rsyslog version %s.\n", VERSION);
|
||||
CHKiRet(objUse(errmsg, CORE_COMPONENT));
|
||||
dbgprintf("mmdblookup: module compiled with rsyslog version %s.\n", VERSION);
|
||||
CHKiRet(objUse(errmsg, CORE_COMPONENT));
|
||||
ENDmodInit
|
||||
|
||||
|
||||
@ -476,10 +476,10 @@ TESTS += \
|
||||
json_var_case.sh
|
||||
endif
|
||||
|
||||
if ENABLE_MMDBLOOKUP
|
||||
TESTS += \
|
||||
mmdb.sh
|
||||
endif
|
||||
#if ENABLE_MMDBLOOKUP
|
||||
#TESTS += \
|
||||
# mmdb.sh
|
||||
#endif
|
||||
|
||||
if ENABLE_GNUTLS
|
||||
TESTS += \
|
||||
|
||||
0
tests/mmdb.sh
Normal file → Executable file
0
tests/mmdb.sh
Normal file → Executable file
@ -8,6 +8,16 @@ sudo apt-get install -qq --force-yes libestr-dev librelp-dev libfastjson-dev lib
|
||||
libcurl4-gnutls-dev
|
||||
sudo apt-get install -qq python-docutils
|
||||
|
||||
if [ "$DISTRIB_CODENAME" == "trusty" ] || [ "$DISTRIB_CODENAME" == "precise" ]; then
|
||||
set -ex
|
||||
WANT_MAXMIND=1.2.0
|
||||
curl -Ls https://github.com/maxmind/libmaxminddb/releases/download/${WANT_MAXMIND}/libmaxminddb-${WANT_MAXMIND}.tar.gz | tar -xz
|
||||
(cd libmaxminddb-${WANT_MAXMIND} ; ./configure --prefix=/usr CC=gcc CFLAGS="-Wall -Wextra -g -pipe -std=gnu99" ; sudo make install)
|
||||
set +x
|
||||
else
|
||||
sudo apt-get install -qq libmaxminddb-dev
|
||||
fi
|
||||
|
||||
if [ "x$ESTEST" == "xYES" ]; then sudo apt-get install -qq elasticsearch ; fi
|
||||
if [ "$DISTRIB_CODENAME" == "trusty" ]; then sudo apt-get install -qq libhiredis-dev; export HIREDIS_OPT="--enable-omhiredis"; fi
|
||||
if [ "$DISTRIB_CODENAME" == "trusty" ]; then sudo apt-get install -qq libsystemd-journal-dev; export JOURNAL_OPT="--enable-imjournal --enable-omjournal"; fi
|
||||
|
||||
@ -38,7 +38,7 @@ if [ "x$ESTEST" == "xYES" ]; then export ES_TEST_CONFIGURE_OPT="--enable-elastic
|
||||
if [ "$CC" == "clang" ] && [ "$DISTRIB_CODENAME" == "trusty" ]; then export CC="clang-3.6"; fi
|
||||
$CC -v
|
||||
env
|
||||
export CONFIG_FLAGS="--prefix=/opt/rsyslog --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc --localstatedir=/var/lib --disable-dependency-tracking --enable-silent-rules --libdir=/usr/lib64 --docdir=/usr/share/doc/rsyslog --disable-generate-man-pages --enable-testbench --enable-imdiag --enable-imfile --enable-impstats --enable-mmrm1stspace --enable-imptcp --enable-mmanon --enable-mmaudit --enable-mmfields --enable-mmjsonparse --enable-mmpstrucdata --enable-mmsequence --enable-mmutf8fix --enable-mail --enable-omprog --enable-omruleset --enable-omstdout --enable-omuxsock --enable-pmaixforwardedfrom --enable-pmciscoios --enable-pmcisconames --enable-pmlastmsg --enable-pmsnare --enable-libgcrypt --enable-mmnormalize --disable-omudpspoof --enable-relp --disable-snmp --disable-mmsnmptrapd --enable-gnutls --enable-mysql --enable-mysql-tests --enable-usertools --enable-gt-ksi --enable-libdbi --enable-pgsql --enable-omhttpfs --enable-elasticsearch --enable-valgrind --enable-ommongodb --enable-omamqp1 --enable-omrelp-default-port=13515 --enable-omtcl $JOURNAL_OPT $HIREDIS_OPT $ENABLE_KAFKA $NO_VALGRIND $GROK $ES_TEST_CONFIGURE_OPT $CONFIGURE_FLAGS"
|
||||
export CONFIG_FLAGS="--prefix=/opt/rsyslog --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc --localstatedir=/var/lib --disable-dependency-tracking --enable-silent-rules --libdir=/usr/lib64 --docdir=/usr/share/doc/rsyslog --disable-generate-man-pages --enable-testbench --enable-imdiag --enable-imfile --enable-impstats --enable-mmrm1stspace --enable-imptcp --enable-mmanon --enable-mmaudit --enable-mmfields --enable-mmjsonparse --enable-mmpstrucdata --enable-mmsequence --enable-mmutf8fix --enable-mail --enable-omprog --enable-omruleset --enable-omstdout --enable-omuxsock --enable-pmaixforwardedfrom --enable-pmciscoios --enable-pmcisconames --enable-pmlastmsg --enable-pmsnare --enable-libgcrypt --enable-mmnormalize --disable-omudpspoof --enable-relp --disable-snmp --disable-mmsnmptrapd --enable-gnutls --enable-mysql --enable-mysql-tests --enable-usertools --enable-gt-ksi --enable-libdbi --enable-pgsql --enable-omhttpfs --enable-elasticsearch --enable-valgrind --enable-ommongodb --enable-omamqp1 --enable-omrelp-default-port=13515 --enable-omtcl --enable-mmdblookup $JOURNAL_OPT $HIREDIS_OPT $ENABLE_KAFKA $NO_VALGRIND $GROK $ES_TEST_CONFIGURE_OPT $CONFIGURE_FLAGS"
|
||||
./configure $CONFIG_FLAGS
|
||||
export USE_AUTO_DEBUG="off" # set to "on" to enable this for travis
|
||||
make -j
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user