Add aaa-12 add log cmd remote
RCA: SOL: 修改人:zhangtao 检视人:
This commit is contained in:
parent
55671103ce
commit
4a819bb041
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include "ulog_api.h"
|
#include "ulog_api.h"
|
||||||
|
|
||||||
|
#define LOG_HOST_SZ 256
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
LOG_OFF = 0,
|
LOG_OFF = 0,
|
||||||
LOG_ON
|
LOG_ON
|
||||||
|
@ -24,7 +26,7 @@ typedef enum {
|
||||||
|
|
||||||
typedef struct _log_remote_host {
|
typedef struct _log_remote_host {
|
||||||
log_rfc_t rfc;
|
log_rfc_t rfc;
|
||||||
char host[256];
|
char host[LOG_HOST_SZ];
|
||||||
u16 port;
|
u16 port;
|
||||||
} log_remote_host_t;
|
} log_remote_host_t;
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
#define CONF_LOG_CONSOLE_FUNC "conf_log_console"
|
#define CONF_LOG_CONSOLE_FUNC "conf_log_console"
|
||||||
#define CONF_LOG_PTY_FUNC "conf_log_pty"
|
#define CONF_LOG_PTY_FUNC "conf_log_pty"
|
||||||
|
#define CONF_LOG_REMOTE_ADD_HOST "conf_log_add_remote"
|
||||||
|
#define CONF_LOG_REMOTE_DEL_HOST "conf_log_del_remote"
|
||||||
|
|
||||||
typedef struct _level_str {
|
typedef struct _level_str {
|
||||||
u32 level;
|
u32 level;
|
||||||
|
|
|
@ -172,8 +172,8 @@
|
||||||
LOG_CONFIG_REMOTE_ADD_HOST, \
|
LOG_CONFIG_REMOTE_ADD_HOST, \
|
||||||
CONFIG_FROM_WEB, \
|
CONFIG_FROM_WEB, \
|
||||||
FALSE, \
|
FALSE, \
|
||||||
log_remote_config_chk, \
|
log_remote_host_config_chk, \
|
||||||
log_remote_add_config_proc, \
|
log_remote_add_host_config_proc, \
|
||||||
NULL, \
|
NULL, \
|
||||||
NULL \
|
NULL \
|
||||||
},\
|
},\
|
||||||
|
@ -181,8 +181,8 @@
|
||||||
LOG_CONFIG_REMOTE_DEL_HOST, \
|
LOG_CONFIG_REMOTE_DEL_HOST, \
|
||||||
CONFIG_FROM_WEB, \
|
CONFIG_FROM_WEB, \
|
||||||
FALSE, \
|
FALSE, \
|
||||||
log_remote_config_chk, \
|
log_remote_host_config_chk, \
|
||||||
log_remote_del_config_proc, \
|
log_remote_del_host_config_proc, \
|
||||||
NULL, \
|
NULL, \
|
||||||
NULL \
|
NULL \
|
||||||
}\
|
}\
|
||||||
|
|
|
@ -19,13 +19,13 @@ ret_code log_monitor_config_chk(uint source, uint *config_type,
|
||||||
ret_code log_monitor_config_proc(uint source, uint config_type,
|
ret_code log_monitor_config_proc(uint source, uint config_type,
|
||||||
pointer input, int input_len,
|
pointer input, int input_len,
|
||||||
pointer output, int *output_len);
|
pointer output, int *output_len);
|
||||||
ret_code log_remote_config_chk(uint source, uint *config_type,
|
ret_code log_remote_host_config_chk(uint source, uint *config_type,
|
||||||
pointer input, int *input_len,
|
pointer input, int *input_len,
|
||||||
pointer output, int *output_len);
|
pointer output, int *output_len);
|
||||||
ret_code log_remote_add_config_proc(uint source, uint config_type,
|
ret_code log_remote_add_host_config_proc(uint source, uint config_type,
|
||||||
pointer input, int input_len,
|
pointer input, int input_len,
|
||||||
pointer output, int *output_len);
|
pointer output, int *output_len);
|
||||||
ret_code log_remote_del_config_proc(uint source, uint config_type,
|
ret_code log_remote_del_host_config_proc(uint source, uint config_type,
|
||||||
pointer input, int input_len,
|
pointer input, int input_len,
|
||||||
pointer output, int *output_len);
|
pointer output, int *output_len);
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
ret_code log_rpc_exec(char* service_name, char* method_name, pointer input, int input_len, int last_lenth)
|
ret_code log_rpc_exec(char* service_name, char* method_name, pointer input, int input_len, int last_lenth)
|
||||||
{
|
{
|
||||||
if ((input == NULL)
|
if ((input == NULL)
|
||||||
&& input_len < last_lenth /*sizeof(log_console_t) */) {
|
&& input_len < last_lenth /*sizeof(log_console_t) */) {
|
||||||
|
ULOG_ERR(g_log_h, "log rpc input actual length:%d, need length:%d", input_len, last_lenth);
|
||||||
return RET_INPUTERR;
|
return RET_INPUTERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,13 @@
|
||||||
#include "rpc_types.h"
|
#include "rpc_types.h"
|
||||||
#include "rpc_common.h"
|
#include "rpc_common.h"
|
||||||
|
|
||||||
#define TERMINAL_CHK(type, input, input_len, str_conf) { \
|
#define TERMINAL_GEN_JSON(s, o) { \
|
||||||
|
s2j_struct_get_basic_element(s, o, int, level); \
|
||||||
|
s2j_struct_get_basic_element(s, o, int, on); \
|
||||||
|
S2J_STRUCT_GET_STRING_ELEMENT_N(s, o, module, MAX_MODULE_NAME_SZ); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define COMMON_CHK(type, input, input_len, str_conf, cb) { \
|
||||||
ULOG_DEBUG(g_log_h, "Checking %s configuration:%s", str_conf, input); \
|
ULOG_DEBUG(g_log_h, "Checking %s configuration:%s", str_conf, input); \
|
||||||
if (input == NULL) { \
|
if (input == NULL) { \
|
||||||
ULOG_ERR(g_log_h, "input can't null"); \
|
ULOG_ERR(g_log_h, "input can't null"); \
|
||||||
|
@ -23,21 +29,23 @@
|
||||||
\
|
\
|
||||||
ULOG_DEBUG(g_log_h, "json input: %s", cJSON_Print(json_obj)); \
|
ULOG_DEBUG(g_log_h, "json input: %s", cJSON_Print(json_obj)); \
|
||||||
\
|
\
|
||||||
s2j_create_struct_obj(log_terminal, type /*log_console_t*/); \
|
s2j_create_struct_obj(st, type /*log_console_t*/); \
|
||||||
if(log_terminal == NULL) { \
|
if(st == NULL) { \
|
||||||
cJSON_Delete(json_obj); \
|
cJSON_Delete(json_obj); \
|
||||||
ULOG_ERR(g_log_h, "Creating log %s of object is failure", str_conf); \
|
ULOG_ERR(g_log_h, "Creating log %s of object is failure", str_conf); \
|
||||||
return RET_NOMEM; \
|
return RET_NOMEM; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
s2j_struct_get_basic_element(log_terminal, json_obj, int, level); \
|
cb(st, json_obj); \
|
||||||
s2j_struct_get_basic_element(log_terminal, json_obj, int, on); \
|
\
|
||||||
S2J_STRUCT_GET_STRING_ELEMENT_N(log_terminal, json_obj, module, MAX_MODULE_NAME_SZ); \
|
*input_len = sizeof(*st); \
|
||||||
\
|
memcpy(input, st, *input_len); \
|
||||||
*input_len = sizeof(*log_terminal); \
|
\
|
||||||
memcpy(input, log_terminal, *input_len); \
|
return RET_OK; \
|
||||||
\
|
}
|
||||||
return RET_OK; \
|
|
||||||
|
#define TERMINAL_CHK(type, input, input_len, str_conf) { \
|
||||||
|
COMMON_CHK(type, input, input_len, str_conf, TERMINAL_GEN_JSON) \
|
||||||
}
|
}
|
||||||
|
|
||||||
extern rpc_client *g_log_client;
|
extern rpc_client *g_log_client;
|
||||||
|
|
|
@ -1,25 +1,32 @@
|
||||||
#include "log_config.h"
|
#include "log_config.h"
|
||||||
#include "log_config_cm.h"
|
#include "log_config_cm.h"
|
||||||
|
|
||||||
ret_code log_remote_config_chk(uint source, uint *config_type,
|
#define REMOTE_HOST_JSON(s, o) { \
|
||||||
|
s2j_struct_get_basic_element(s, o, int, rfc); \
|
||||||
|
s2j_struct_get_basic_element(s, o, int, port); \
|
||||||
|
S2J_STRUCT_GET_STRING_ELEMENT_N(s, o, host, LOG_HOST_SZ); \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ret_code log_remote_host_config_chk(uint source, uint *config_type,
|
||||||
pointer input, int *input_len,
|
pointer input, int *input_len,
|
||||||
pointer output, int *output_len)
|
pointer output, int *output_len)
|
||||||
{
|
{
|
||||||
TERMINAL_CHK(log_console_t, input, input_len, "pty");
|
COMMON_CHK(log_remote_host_t, input, input_len, "remote host", REMOTE_HOST_JSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret_code log_remote_add_config_proc(uint source, uint config_type,
|
ret_code log_remote_add_host_config_proc(uint source, uint config_type,
|
||||||
pointer input, int input_len,
|
pointer input, int input_len,
|
||||||
pointer output, int *output_len)
|
pointer output, int *output_len)
|
||||||
{
|
{
|
||||||
return log_rpc_exec(SERVICE_LOG_PTY_NAME, CONF_LOG_PTY_FUNC, input, input_len, sizeof(log_console_t));
|
return log_rpc_exec(SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_ADD_HOST, input, input_len, sizeof(log_remote_host_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
ret_code log_remote_del_config_proc(uint source, uint config_type,
|
ret_code log_remote_del_host_config_proc(uint source, uint config_type,
|
||||||
pointer input, int input_len,
|
pointer input, int input_len,
|
||||||
pointer output, int *output_len)
|
pointer output, int *output_len)
|
||||||
{
|
{
|
||||||
return log_rpc_exec(SERVICE_LOG_PTY_NAME, CONF_LOG_PTY_FUNC, input, input_len, sizeof(log_console_t));
|
return log_rpc_exec(SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_DEL_HOST, input, input_len, sizeof(log_remote_host_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,10 +32,10 @@ static int conf_remote_by_config_id(cJSON *json_obj, const char *host, const u16
|
||||||
|
|
||||||
int ret = set_log_conf(json_obj, config_id);
|
int ret = set_log_conf(json_obj, config_id);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ULOG_ERR(g_log, "Host of log which is configured is failure");
|
ULOG_ERR(g_log, "Host of log which is configured is failure");
|
||||||
}
|
} else {
|
||||||
ULOG_DEBUG(g_log, "Host of log whice is configured is success");
|
ULOG_DEBUG(g_log, "Host of log whice is configured is success");
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,9 @@ int set_log_conf(cJSON *json_obj, uint64 config_id);
|
||||||
int ret = set_log_conf(json_obj, conf_id); \
|
int ret = set_log_conf(json_obj, conf_id); \
|
||||||
if (ret != 0) { \
|
if (ret != 0) { \
|
||||||
ULOG_ERR(g_log, "Setting terminal configure of log is failure"); \
|
ULOG_ERR(g_log, "Setting terminal configure of log is failure"); \
|
||||||
|
} else { \
|
||||||
|
ULOG_DEBUG(g_log, "Setting terminal configure of log is success"); \
|
||||||
} \
|
} \
|
||||||
ULOG_DEBUG(g_log, "Setting terminal configure of log is success"); \
|
|
||||||
return ret; \
|
return ret; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -267,7 +267,7 @@ static void cb_rsp_read(struct ev_loop *l, struct ev_io *watcher, int revents) {
|
||||||
//TODO why null
|
//TODO why null
|
||||||
//sessionpool has
|
//sessionpool has
|
||||||
req = (rpc_request*) rpc_sessionpool_get(th->req_pool, rsp->seq);
|
req = (rpc_request*) rpc_sessionpool_get(th->req_pool, rsp->seq);
|
||||||
if (req->seq != rsp->seq) {
|
if ((req == NULL) || (req->seq != rsp->seq)) {
|
||||||
fprintf(stderr, "seq not equal!\n");
|
fprintf(stderr, "seq not equal!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -421,7 +421,7 @@ void rpc_return_null(rpc_conn *conn) {
|
||||||
|
|
||||||
void rpc_return_error(rpc_conn *conn, ret_code err_code, char* err_message) {
|
void rpc_return_error(rpc_conn *conn, ret_code err_code, char* err_message) {
|
||||||
int len = strlen(err_message);
|
int len = strlen(err_message);
|
||||||
err_message[len]='\0';
|
//err_message[len]='\0';
|
||||||
len++;
|
len++;
|
||||||
rpc_send_response(conn, err_code, err_message, len);
|
rpc_send_response(conn, err_code, err_message, len);
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,7 @@ void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer
|
||||||
if (config_log_console((const log_console_t *)input) != 0) {
|
if (config_log_console((const log_console_t *)input) != 0) {
|
||||||
ULOG_ERR(g_log, "Configuring console of log is faiure");
|
ULOG_ERR(g_log, "Configuring console of log is faiure");
|
||||||
rpc_return_error(conn, RET_ERR, "Configuring console of log is faiure");
|
rpc_return_error(conn, RET_ERR, "Configuring console of log is faiure");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
rpc_return_null(conn);
|
rpc_return_null(conn);
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,7 @@ void rpc_conf_log_pty(rpc_conn *conn, pointer input, int input_len, pointer data
|
||||||
if (config_log_pty((const log_pty_t *)input) != 0) {
|
if (config_log_pty((const log_pty_t *)input) != 0) {
|
||||||
ULOG_ERR(g_log, "Configuring pty of log is faiure");
|
ULOG_ERR(g_log, "Configuring pty of log is faiure");
|
||||||
rpc_return_error(conn, RET_ERR, "Configuring pty of log is faiure");
|
rpc_return_error(conn, RET_ERR, "Configuring pty of log is faiure");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
rpc_return_null(conn);
|
rpc_return_null(conn);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define _LOG_PTY_H
|
#define _LOG_PTY_H
|
||||||
|
|
||||||
#include "log_console.h"
|
#include "log_console.h"
|
||||||
|
#include "rpc.h"
|
||||||
|
|
||||||
void rpc_conf_log_pty(rpc_conn *conn, pointer input, int input_len, pointer data);
|
void rpc_conf_log_pty(rpc_conn *conn, pointer input, int input_len, pointer data);
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ static int remote_conf_content(FILE *fp, const u8 level, const char *filter_mod,
|
||||||
while ((n = getline(&line, &n, bak_fp)) != -1) {
|
while ((n = getline(&line, &n, bak_fp)) != -1) {
|
||||||
int match = match_cb(line, arg);
|
int match = match_cb(line, arg);
|
||||||
if (match == -1) {
|
if (match == -1) {
|
||||||
ULOG_ERR(g_log, "Configure which is matched is failure");
|
ULOG_ERR(g_log, "Configuration which is matched is failure");
|
||||||
} else if (match == 0) {
|
} else if (match == 0) {
|
||||||
ULOG_DEBUG(g_log, "Be matched");
|
ULOG_DEBUG(g_log, "Be matched");
|
||||||
continue;
|
continue;
|
||||||
|
@ -203,7 +203,7 @@ static int get_log_level()
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t n, n1, n2;
|
ssize_t n, n1, n2;
|
||||||
char *line;
|
char *line = NULL;
|
||||||
u8 value;
|
u8 value;
|
||||||
while ((n1 = getline(&line, &n, g_conf_fp)) != -1) {
|
while ((n1 = getline(&line, &n, g_conf_fp)) != -1) {
|
||||||
n2 = sscanf(line, LOG_CONF_KEY_REMOTE_LEVEL"%u", &value);
|
n2 = sscanf(line, LOG_CONF_KEY_REMOTE_LEVEL"%u", &value);
|
||||||
|
@ -253,7 +253,7 @@ static int add_remote_host(const log_remote_host_t *conf)
|
||||||
|
|
||||||
static int del_remote_host(const log_remote_host_t *conf)
|
static int del_remote_host(const log_remote_host_t *conf)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = -1;
|
||||||
char prefix[1] = "";
|
char prefix[1] = "";
|
||||||
|
|
||||||
ULOG_INFO(g_log, "Deleting remote log server[%s:%u], rfc is %s", conf->host, conf->port, rfc_tbl[conf->rfc].fmt);
|
ULOG_INFO(g_log, "Deleting remote log server[%s:%u], rfc is %s", conf->host, conf->port, rfc_tbl[conf->rfc].fmt);
|
||||||
|
@ -264,13 +264,19 @@ static int del_remote_host(const log_remote_host_t *conf)
|
||||||
if (snprintf(redirect, sizeof(redirect), "%s@%s:%u:%s",
|
if (snprintf(redirect, sizeof(redirect), "%s@%s:%u:%s",
|
||||||
prefix, conf->host, conf->port, rfc_tbl[conf->rfc].fmt) < 0) {
|
prefix, conf->host, conf->port, rfc_tbl[conf->rfc].fmt) < 0) {
|
||||||
ULOG_ERR(g_log, "Setting remote redirect[%s:%u:%s] is faulure", conf->host, conf->port, rfc_tbl[conf->rfc].fmt);
|
ULOG_ERR(g_log, "Setting remote redirect[%s:%u:%s] is faulure", conf->host, conf->port, rfc_tbl[conf->rfc].fmt);
|
||||||
return -1;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (log_conf(7, LOG_CONF_PATH, LOG_CONF_REMOTE_FILE_NAME, NULL,
|
int level = get_log_level();
|
||||||
del_remote_conf_content, (void *)redirect) != 0) {
|
if (level == -1) {
|
||||||
|
ULOG_ERR(g_log, "Getting log level is failure");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
ret = log_conf(level, LOG_CONF_PATH, LOG_CONF_REMOTE_FILE_NAME, NULL,
|
||||||
|
del_remote_conf_content, (void *)redirect);
|
||||||
|
if (ret != 0) {
|
||||||
ULOG_ERR(g_log, "Adding remote server[%s:%u:%s] is faulure", conf->host, conf->port, rfc_tbl[conf->rfc].fmt);
|
ULOG_ERR(g_log, "Adding remote server[%s:%u:%s] is faulure", conf->host, conf->port, rfc_tbl[conf->rfc].fmt);
|
||||||
return -1;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -335,7 +341,12 @@ static void rpc_conf_log_remote(const log_op_t op, rpc_conn *conn, point
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
config_log_remote_host(op, (const log_remote_host_t *)input);
|
if (config_log_remote_host(op, (const log_remote_host_t *)input) != 0) {
|
||||||
|
ULOG_ERR(g_log, "Configuring remote of log is faiure");
|
||||||
|
rpc_return_error(conn, RET_ERR, "Configuring remote of log is faiure");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
rpc_return_null(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rpc_conf_log_add_remote(rpc_conn *conn, pointer input, int input_len, pointer data)
|
void rpc_conf_log_add_remote(rpc_conn *conn, pointer input, int input_len, pointer data)
|
||||||
|
|
|
@ -87,8 +87,8 @@ int main(int argc, char **argv)
|
||||||
rpc_server_regservice(server, SERVICE_LOG_FILE_NAME, "conf_log_file", rpc_conf_log_file);
|
rpc_server_regservice(server, SERVICE_LOG_FILE_NAME, "conf_log_file", rpc_conf_log_file);
|
||||||
rpc_server_regservice(server, SERIVCE_LOG_CONSOLE_NAME, CONF_LOG_CONSOLE_FUNC, rpc_conf_log_console);
|
rpc_server_regservice(server, SERIVCE_LOG_CONSOLE_NAME, CONF_LOG_CONSOLE_FUNC, rpc_conf_log_console);
|
||||||
rpc_server_regservice(server, SERVICE_LOG_PTY_NAME, CONF_LOG_PTY_FUNC, rpc_conf_log_pty);
|
rpc_server_regservice(server, SERVICE_LOG_PTY_NAME, CONF_LOG_PTY_FUNC, rpc_conf_log_pty);
|
||||||
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, "conf_log_add_remote", rpc_conf_log_add_remote);
|
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_ADD_HOST, rpc_conf_log_add_remote);
|
||||||
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, "conf_log_del_remote", rpc_conf_log_del_remote);
|
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_DEL_HOST, rpc_conf_log_del_remote);
|
||||||
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, "conf_log_remote_level", rpc_conf_log_remote_level);
|
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, "conf_log_remote_level", rpc_conf_log_remote_level);
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue