feat: remove remote syslog support

This commit is contained in:
hxy7yx
2026-08-25 23:58:41 -07:00
parent f2c2a51f5c
commit 7cfad3f3f9
8 changed files with 16 additions and 166 deletions
-2
View File
@@ -6,8 +6,6 @@ file perms = 666
stdout_format = "%d:%ms [%V] [%c] %f:%L %m%n"
file_format = "%d:%ms [%V] %f:%L %m%n"
syslog = "<P>%d(%Y-%m-%dT%T%z) %H neuron[%p]: level=%v msg="[%c] %m" file="%f:%L"%n"
[rules]
*.* "./logs/%c.log", 50MB * 2 ~ "./logs/%c.#2r.log"; file_format
+1 -3
View File
@@ -2,10 +2,8 @@
"ip": "127.0.0.1",
"port": 7000,
"disable_auth": 0,
"syslog_host": "",
"syslog_port": 541,
"sub_filter_error": 0,
"modbus_simulator": {
"port": 502
}
}
}
+2 -65
View File
@@ -85,8 +85,6 @@ const char *usage_text =
" --config_file <PATH> startup parameter configuration file\n"
" --config_dir <DIR> directory from which neuron reads configuration\n"
" --plugin_dir <DIR> directory from which neuron loads plugin lib files\n"
" --syslog_host <HOST> syslog server host to which neuron will send logs\n"
" --syslog_port <PORT> syslog server port (default 541 if not provided)\n"
" --sub_filter_error The subscribe attribute only detects the last read value and does not report any error tags\n"
"\n";
// clang-format on
@@ -360,24 +358,6 @@ static inline int load_env(neu_cli_args_t *args, char **log_level_out,
*plugin_dir_out = strdup(plugin_dir);
}
char *syslog_host = getenv(NEU_ENV_SYSLOG_HOST);
if (NULL != syslog_host) {
if (NULL != args->syslog_host) {
free(args->syslog_host);
}
args->syslog_host = strdup(syslog_host);
}
char *syslog_port = getenv(NEU_ENV_SYSLOG_PORT);
if (NULL != syslog_port) {
int port = atoi(syslog_port);
if (port < 1 || 65535 < port) {
printf("neuron %s setting invalid!\n", NEU_ENV_SYSLOG_PORT);
ret = -1;
break;
}
args->syslog_port = port;
}
} while (0);
return ret;
@@ -419,8 +399,6 @@ static inline int load_config_file(int argc, char *argv[],
{ .name = "disable_auth", .t = NEU_JSON_INT },
{ .name = "ip", .t = NEU_JSON_STR },
{ .name = "port", .t = NEU_JSON_INT },
{ .name = "syslog_host", .t = NEU_JSON_STR },
{ .name = "syslog_port", .t = NEU_JSON_INT },
{ .name = "sub_filter_error", .t = NEU_JSON_INT },
};
@@ -484,27 +462,9 @@ static inline int load_config_file(int argc, char *argv[],
break;
}
if (elems[3].v.val_str != NULL) {
if (strlen(elems[3].v.val_str) > 0) {
args->syslog_host = strdup(elems[3].v.val_str);
}
} else {
printf("config file %s syslog_host setting error!\n",
config_file);
break;
}
if (0 < elems[4].v.val_int && elems[4].v.val_int < 65536) {
args->syslog_port = elems[4].v.val_int;
} else {
printf("config file %s syslog_port setting invalid!\n",
config_file);
break;
}
if (elems[5].v.val_int == 1) {
if (elems[3].v.val_int == 1) {
args->sub_filter_err = true;
} else if (elems[5].v.val_int == 0) {
} else if (elems[3].v.val_int == 0) {
args->sub_filter_err = false;
} else {
printf("config file %s sub_filter_error setting error!\n",
@@ -537,10 +497,6 @@ static inline int load_config_file(int argc, char *argv[],
free(elems[1].v.val_str);
}
if (elems[3].v.val_str != NULL) {
free(elems[3].v.val_str);
}
return ret;
}
@@ -565,8 +521,6 @@ void neu_cli_args_init(neu_cli_args_t *args, int argc, char *argv[])
{ "config_dir", required_argument, NULL, 'c' },
{ "plugin_dir", required_argument, NULL, 'p' },
{ "stop", no_argument, NULL, 's' },
{ "syslog_host", required_argument, NULL, 'S' },
{ "syslog_port", required_argument, NULL, 'P' },
{ "sub_filter_error", no_argument, NULL, 'f' },
{ "node", required_argument, NULL, 'n' },
{ NULL, 0, NULL, 0 },
@@ -646,22 +600,6 @@ void neu_cli_args_init(neu_cli_args_t *args, int argc, char *argv[])
}
plugin_dir = strdup(optarg);
break;
case 'P': {
int syslog_port = atoi(optarg);
if (syslog_port < 1 || 65535 < syslog_port) {
fprintf(stderr, "%s: option '--syslog_port' invalid : `%s`\n",
argv[0], optarg);
goto quit;
}
args->syslog_port = syslog_port;
break;
}
case 'S':
if (args->syslog_host) {
free(args->syslog_host);
}
args->syslog_host = strdup(optarg);
break;
case 'f':
args->sub_filter_err = true;
break;
@@ -756,6 +694,5 @@ void neu_cli_args_fini(neu_cli_args_t *args)
free(args->plugin_dir);
free(args->node_name);
free(args->ip);
free(args->syslog_host);
}
}
+13 -18
View File
@@ -33,8 +33,6 @@
#define NEU_ENV_DISABLE_AUTH "NEURON_DISABLE_AUTH"
#define NEU_ENV_CONFIG_DIR "NEURON_CONFIG_DIR"
#define NEU_ENV_PLUGIN_DIR "NEURON_PLUGIN_DIR"
#define NEU_ENV_SYSLOG_HOST "NEURON_SYSLOG_HOST"
#define NEU_ENV_SYSLOG_PORT "NEURON_SYSLOG_PORT"
#define NEU_ENV_SUB_FILTER_ERROR "NEURON_SUB_FILTER_ERROR"
#define NEURON_CONFIG_FNAME "./config/neuron.json"
@@ -44,7 +42,6 @@ extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
extern const char *g_config_dir;
@@ -53,21 +50,19 @@ extern const char *g_plugin_dir;
/** Neuron command line arguments.
*/
typedef struct {
bool daemonized; // flag indicating whether to run as daemon process
bool dev_log; // logging for development
size_t restart; // restart policy
bool disable_auth;
char * log_init_file;
char * config_dir;
char * plugin_dir;
bool stop;
bool node_stop;
char * node_name;
char * ip;
int port;
char * syslog_host;
uint16_t syslog_port;
bool sub_filter_err;
bool daemonized; // flag indicating whether to run as daemon process
bool dev_log; // logging for development
size_t restart; // restart policy
bool disable_auth;
char * log_init_file;
char * config_dir;
char * plugin_dir;
bool stop;
bool node_stop;
char * node_name;
char * ip;
int port;
bool sub_filter_err;
} neu_cli_args_t;
/** Parse command line arguments.
-72
View File
@@ -17,12 +17,8 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <signal.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -47,11 +43,6 @@ static bool sig_trigger = false;
int64_t global_timestamp = 0;
struct {
struct sockaddr_in addr;
int fd;
} g_remote_syslog_ctx;
static void sig_handler(int sig)
{
nlog_warn("recv sig: %d", sig);
@@ -69,63 +60,6 @@ static void sig_handler(int sig)
exit(-1);
}
static inline char syslog_priority(const char *level)
{
switch (level[0]) {
case 'D': // DEBUG
return '7';
case 'I': // INFO
return '6';
case 'N': // NOTICE
return '5';
case 'W': // WARN
return '4';
case 'E': // ERROR
return '3';
case 'F': // FATAL
return '2';
default: // UNKNOWN
return '1';
}
}
static int remote_syslog(zlog_msg_t *msg)
{
// fix priority
msg->buf[1] = syslog_priority(msg->path);
sendto(g_remote_syslog_ctx.fd, msg->buf, msg->len, 0,
(const struct sockaddr *) &g_remote_syslog_ctx.addr,
sizeof(g_remote_syslog_ctx.addr));
return 0;
}
static int config_remote_syslog(const char *host, uint16_t port)
{
g_remote_syslog_ctx.fd = socket(AF_INET, SOCK_DGRAM, 0);
if (g_remote_syslog_ctx.fd < 0) {
return -1;
}
g_remote_syslog_ctx.addr.sin_family = AF_INET;
g_remote_syslog_ctx.addr.sin_port = htons(port);
g_remote_syslog_ctx.addr.sin_addr.s_addr = inet_addr(host);
if (0 == inet_pton(AF_INET, host, &g_remote_syslog_ctx.addr.sin_addr)) {
// not an valid ip address, try resolve as host name
struct hostent *he = gethostbyname(host);
if (NULL == he) {
return -1;
}
memcpy(&g_remote_syslog_ctx.addr.sin_addr, he->h_addr_list[0],
he->h_length);
}
zlog_set_record("remote_syslog", remote_syslog);
return 0;
}
static int neuron_run(const neu_cli_args_t *args)
{
struct rlimit rl = { 0 };
@@ -190,12 +124,6 @@ int main(int argc, char *argv[])
zlog_init(args.log_init_file);
if (args.syslog_host && strlen(args.syslog_host) > 0 &&
0 != config_remote_syslog(args.syslog_host, args.syslog_port)) {
nlog_fatal("neuron setup remote syslog fail, exit.");
goto main_end;
}
neuron = zlog_get_category("neuron");
if (neuron) {
zlog_level_switch(neuron, default_log_level);
-2
View File
@@ -2,7 +2,5 @@
"ip": "0.0.0.0",
"port": 7000,
"disable_auth": 1,
"syslog_host": "",
"syslog_port": 541,
"sub_filter_error": 0
}
-2
View File
@@ -2,7 +2,5 @@
"ip": "0.0.0.0",
"port": 7000,
"disable_auth": 0,
"syslog_host": "",
"syslog_port": 541,
"sub_filter_error": 1
}
-2
View File
@@ -5,8 +5,6 @@ file perms = 666
[formats]
simple = "%d:%ms [%V] %f:%L %m%n"
syslog = "<P>%d(%Y-%m-%dT%T%z) %H neuron[%p]: level=%v msg="[%c] %m" file="%f:%L"%n"
[rules]
*.* "./logs/%c.log", 50MB * 2 ~ "./logs/%c.#2r.log"; simple