输出非结构化日志。
This commit is contained in:
@@ -144,6 +144,10 @@ static void __promise_destroy(struct promise *p)
|
||||
|
||||
struct promise * future_to_promise(struct future * f)
|
||||
{
|
||||
if(f==NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
struct promise *p=__future_to_promise(f);
|
||||
p->ref_cnt++;
|
||||
assert(p->ref_cnt==2);
|
||||
|
||||
@@ -92,6 +92,7 @@ struct pangu_rt
|
||||
struct event* gcev;
|
||||
|
||||
int ca_store_reseting;
|
||||
|
||||
};
|
||||
struct pangu_rt * g_pangu_rt;
|
||||
|
||||
@@ -502,7 +503,6 @@ int pangu_http_init(struct tfe_proxy * proxy)
|
||||
}
|
||||
TFE_LOG_INFO(NULL, "Tango Cache Enabled.");
|
||||
}
|
||||
|
||||
TFE_LOG_INFO(NULL, "Pangu HTTP init success.");
|
||||
return 0;
|
||||
|
||||
@@ -532,6 +532,7 @@ struct pangu_http_ctx
|
||||
struct Maat_rule_t * enforce_rules;
|
||||
size_t n_enforce;
|
||||
char * enforce_para;
|
||||
struct evbuffer* log_req_body, *log_resp_body;
|
||||
|
||||
struct replace_ctx * rep_ctx;
|
||||
|
||||
@@ -547,6 +548,7 @@ struct pangu_http_ctx
|
||||
size_t cache_result_declared_sz, cache_result_actual_sz;
|
||||
struct cache_write_context* cache_write_ctx;
|
||||
int cache_wirte_result;
|
||||
|
||||
int thread_id;
|
||||
};
|
||||
|
||||
@@ -628,7 +630,16 @@ static void pangu_http_ctx_free(struct pangu_http_ctx * ctx)
|
||||
future_destroy(ctx->f_cache_pending);
|
||||
ctx->f_cache_pending=NULL;
|
||||
}
|
||||
|
||||
if(ctx->log_req_body)
|
||||
{
|
||||
evbuffer_free(ctx->log_req_body);
|
||||
ctx->log_req_body=NULL;
|
||||
}
|
||||
if(ctx->log_resp_body)
|
||||
{
|
||||
evbuffer_free(ctx->log_resp_body);
|
||||
ctx->log_resp_body=NULL;
|
||||
}
|
||||
ctx->magic_num=0;
|
||||
FREE(&ctx);
|
||||
}
|
||||
@@ -1141,6 +1152,25 @@ void enforce_control_policy(const struct tfe_stream * stream, const struct tfe_h
|
||||
default: assert(0);
|
||||
break;
|
||||
}
|
||||
if(ctx->action!=PG_ACTION_NONE && ctx->action!=PG_ACTION_WHITELIST)
|
||||
{
|
||||
if (events & EV_HTTP_REQ_BODY_BEGIN)
|
||||
{
|
||||
ctx->log_req_body=evbuffer_new();
|
||||
}
|
||||
if (events & EV_HTTP_RESP_BODY_BEGIN)
|
||||
{
|
||||
ctx->log_resp_body=evbuffer_new();
|
||||
}
|
||||
if(events & EV_HTTP_REQ_BODY_CONT)
|
||||
{
|
||||
evbuffer_add(ctx->log_req_body, body_frag, frag_size);
|
||||
}
|
||||
if(events & EV_HTTP_RESP_BODY_CONT)
|
||||
{
|
||||
evbuffer_add(ctx->log_resp_body, body_frag, frag_size);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
#define RESUMED_CB_NO_MORE_CALLS 0
|
||||
@@ -1478,7 +1508,8 @@ void pangu_on_http_end(const struct tfe_stream * stream,
|
||||
FREE(&(ctx->enforce_rules));
|
||||
}
|
||||
}
|
||||
struct pangu_log log_msg = {.stream=stream, .http=session, .result=ctx->enforce_rules, .result_num=ctx->n_enforce};
|
||||
struct pangu_log log_msg = {.stream=stream, .http=session, .result=ctx->enforce_rules, .result_num=ctx->n_enforce,
|
||||
.req_body= ctx->log_req_body, .resp_body=ctx->log_resp_body};
|
||||
if (ctx->action != PG_ACTION_NONE&& !(ctx->action == PG_ACTION_REPLACE && ctx->n_enforce==1 && ctx->rep_ctx->actually_replaced==0))
|
||||
{
|
||||
ret=pangu_send_log(g_pangu_rt->send_logger, &log_msg);
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include <tfe_utils.h>
|
||||
#include <cache_evbase_client.h>
|
||||
|
||||
#include "pangu_logger.h"
|
||||
|
||||
struct json_spec
|
||||
@@ -40,6 +42,8 @@ struct pangu_logger
|
||||
unsigned long long random_drop;
|
||||
unsigned long long user_abort;
|
||||
char local_log_path[TFE_STRING_MAX];
|
||||
struct cache_evbase_instance * log_file_upload_instance;
|
||||
|
||||
};
|
||||
|
||||
static unsigned int get_ip_by_eth_name(const char *ifname)
|
||||
@@ -101,6 +105,7 @@ struct pangu_logger* pangu_log_handle_create(const char* profile, const char* s
|
||||
{
|
||||
int ret=-1;
|
||||
char nic_name[64]={0};
|
||||
struct tango_cache_parameter *log_file_upload_para=NULL;
|
||||
|
||||
struct pangu_logger* instance=ALLOC(struct pangu_logger,1);
|
||||
instance->local_logger=local_logger;
|
||||
@@ -132,6 +137,10 @@ struct pangu_logger* pangu_log_handle_create(const char* profile, const char* s
|
||||
}
|
||||
instance->topic_name="PXY-HTTP-LOG";
|
||||
instance->kafka_topic = rd_kafka_topic_new(instance->kafka_handle,instance->topic_name, NULL);
|
||||
|
||||
log_file_upload_para=cache_evbase_parameter_new(profile, section, local_logger);
|
||||
|
||||
instance->log_file_upload_instance=cache_evbase_instance_new(log_file_upload_para, local_logger);
|
||||
pthread_mutex_init(&(instance->mutex), NULL);
|
||||
return instance;
|
||||
|
||||
@@ -149,6 +158,7 @@ int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg)
|
||||
char* log_payload=NULL;
|
||||
int kafka_status=0;
|
||||
int send_cnt=0;
|
||||
int tmp=0;
|
||||
time_t cur_time;
|
||||
char src_ip_str[MAX(INET6_ADDRSTRLEN,INET_ADDRSTRLEN)] = {0};
|
||||
char dst_ip_str[MAX(INET6_ADDRSTRLEN,INET_ADDRSTRLEN)] = {0};
|
||||
@@ -215,6 +225,63 @@ int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg)
|
||||
cJSON_AddStringToObject(common_obj,resp_fields[i].log_filed_name, tmp_val);
|
||||
}
|
||||
}
|
||||
char log_file_upload_path[TFE_STRING_MAX]={0}, cont_type_whole[TFE_STRING_MAX]={0};
|
||||
struct tango_cache_meta_put meta;
|
||||
char* log_file_key=NULL;;
|
||||
const char* cont_type_val;
|
||||
if(log_msg->req_body!=NULL)
|
||||
{
|
||||
memset(&meta, 0, sizeof(meta));
|
||||
asprintf(&log_file_key, "%s.reqbody", http->req->req_spec.url);
|
||||
meta.url=log_file_key;
|
||||
cont_type_val=tfe_http_std_field_read(http->req, TFE_HTTP_CONT_TYPE);
|
||||
if(cont_type_val!=NULL)
|
||||
{
|
||||
snprintf(cont_type_whole, sizeof(cont_type_whole), "Content-Type:%s", cont_type_val);
|
||||
meta.std_hdr[0]=cont_type_whole;
|
||||
}
|
||||
tmp=cache_evbase_upload_once_evbuf(handle->log_file_upload_instance, NULL,
|
||||
log_msg->req_body,
|
||||
&meta,
|
||||
log_file_upload_path, sizeof(log_file_upload_path));
|
||||
if(tmp==0)
|
||||
{
|
||||
cJSON_AddStringToObject(common_obj, "req_body", log_file_upload_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
TFE_LOG_ERROR(handle->local_logger, "Upload req_body failed.");
|
||||
}
|
||||
free(log_file_key);
|
||||
}
|
||||
if(log_msg->resp_body!=NULL)
|
||||
{
|
||||
memset(&meta, 0, sizeof(meta));
|
||||
asprintf(&log_file_key, "%s.respbody", http->req->req_spec.url);
|
||||
meta.url=log_file_key;
|
||||
cont_type_val=tfe_http_std_field_read(http->resp, TFE_HTTP_CONT_TYPE);
|
||||
if(cont_type_val!=NULL)
|
||||
{
|
||||
snprintf(cont_type_whole, sizeof(cont_type_whole), "Content-Type:%s", cont_type_val);
|
||||
meta.std_hdr[0]=cont_type_whole;
|
||||
}
|
||||
tmp=cache_evbase_upload_once_evbuf(handle->log_file_upload_instance, NULL,
|
||||
log_msg->resp_body,
|
||||
&meta,
|
||||
log_file_upload_path, sizeof(log_file_upload_path));
|
||||
|
||||
if(tmp==0)
|
||||
{
|
||||
cJSON_AddStringToObject(common_obj, "resp_body", log_file_upload_path);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
TFE_LOG_ERROR(handle->local_logger, "Upload resp_body failed.");
|
||||
}
|
||||
free(log_file_key);
|
||||
}
|
||||
|
||||
for(size_t i=0; i<log_msg->result_num; i++)
|
||||
{
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ struct pangu_log
|
||||
const struct tfe_http_session* http;
|
||||
const Maat_rule_t*result;
|
||||
size_t result_num;
|
||||
struct evbuffer* req_body, *resp_body;
|
||||
};
|
||||
struct pangu_logger;
|
||||
struct pangu_logger* pangu_log_handle_create(const char* profile, const char* section, void* local_logger);
|
||||
|
||||
Reference in New Issue
Block a user