2019-08-13 08:25:43 +00:00
|
|
|
#include "cmd_remote.h"
|
|
|
|
#include "logging_common.h"
|
|
|
|
#include "common_types.h"
|
|
|
|
#include "log_types.h"
|
|
|
|
#include "ulog_in.h"
|
|
|
|
#include "s2j/s2j.h"
|
|
|
|
|
|
|
|
#define DEFAULT_REMOTE_HOST 514
|
|
|
|
|
|
|
|
static log_rfc_t get_rfc_by_name(const char *name)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < (sizeof(rfc_tbl) / sizeof(rfc_key_fmt)); i++) {
|
|
|
|
if (strcasecmp(name, rfc_tbl[i].fmt) == 0) {
|
|
|
|
return rfc_tbl[i].rfc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return LOG_RFC_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int conf_remote_by_config_id(cJSON *json_obj, const char *host, const u16 port, const log_rfc_t rfc, uint64 config_id)
|
|
|
|
{
|
|
|
|
log_remote_host_t remote;
|
|
|
|
|
|
|
|
strncpy(remote.host, host, sizeof(remote.host));
|
|
|
|
remote.port = port;
|
|
|
|
remote.rfc = rfc;
|
|
|
|
|
|
|
|
s2j_json_set_basic_element(json_obj, &remote, int, port);
|
|
|
|
s2j_json_set_basic_element(json_obj, &remote, int, rfc);
|
|
|
|
s2j_json_set_basic_element(json_obj, &remote, string, host);
|
|
|
|
|
|
|
|
int ret = set_log_conf(json_obj, config_id);
|
|
|
|
if (ret != 0) {
|
2019-08-13 10:22:20 +00:00
|
|
|
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");
|
|
|
|
}
|
2019-08-13 08:25:43 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int conf_remote(cJSON *json_obj, int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
uint64 config_id;
|
|
|
|
|
|
|
|
if (argc <= 3) {
|
|
|
|
ULOG_WARNING(g_log, "Parameter too less");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcasecmp(argv[2], "add") == 0) {
|
|
|
|
config_id = LOG_CONFIG_REMOTE_ADD_HOST;
|
|
|
|
} else if (strcasecmp(argv[2], "del") == 0) {
|
|
|
|
config_id = LOG_CONFIG_REMOTE_DEL_HOST;
|
|
|
|
} else {
|
|
|
|
ULOG_WARNING(g_log, "Unknown operation command:%s", argv[2]);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *host = argv[3];
|
|
|
|
u16 port = DEFAULT_REMOTE_HOST;
|
|
|
|
if (argc >= 5) {
|
|
|
|
port= atoi(argv[4]);
|
|
|
|
}
|
|
|
|
|
|
|
|
log_rfc_t rfc = LOG_RFC_3164;
|
|
|
|
if (argc >= 6) {
|
|
|
|
rfc = get_rfc_by_name(argv[5]);
|
|
|
|
if (rfc == LOG_RFC_UNKNOWN) {
|
|
|
|
ULOG_WARNING(g_log, "Unknown rfc standard:%s of log", argv[5]);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return conf_remote_by_config_id(json_obj, host, port, rfc, config_id);
|
|
|
|
}
|
|
|
|
|
2019-08-14 09:17:18 +00:00
|
|
|
int conf_remote_level(cJSON *json_obj, int argc, char **argv)
|
|
|
|
{
|
|
|
|
if (argc < 3) {
|
|
|
|
ULOG_WARNING(g_log, "Not input log level");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int level;
|
|
|
|
|
|
|
|
if ((level = log_str_to_level(argv[2])) < 0) {
|
|
|
|
ULOG_WARNING(g_log, "Unknown log level:%s", argv[2]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
log_remote_level_t log_level;
|
|
|
|
|
|
|
|
log_level.level = (u8)level;
|
|
|
|
s2j_json_set_basic_element(json_obj, &log_level, int, level);
|
|
|
|
int ret = set_log_conf(json_obj, LOG_CONFIG_REMOTE_LEVEL);
|
|
|
|
if (ret != 0) {
|
|
|
|
ULOG_ERR(g_log, "Remote level of log which is configured is failure");
|
|
|
|
} else {
|
|
|
|
ULOG_DEBUG(g_log, "Remote level of log whice is configured is success");
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|