78 lines
2.5 KiB
C
78 lines
2.5 KiB
C
|
#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) {
|
||
|
ULOG_ERR(g_log, "Host of log which is configured is failure");
|
||
|
}
|
||
|
ULOG_DEBUG(g_log, "Host of log whice is configured is success");
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
|