diff --git a/src/proto/gdt.pb.cc b/src/proto/gdt.pb.cc index 19f2b48..1c624f3 100644 --- a/src/proto/gdt.pb.cc +++ b/src/proto/gdt.pb.cc @@ -188,46 +188,46 @@ const char descriptor_table_protodef_gdt_2eproto[] PROTOBUF_SECTION_VARIABLE(pro "\022\021\n\rCMD_RUN_RULES\020\n\022\022\n\016CMD_LOAD_RULES\020\013\022" "\014\n\010CMD_AUTH\020\014\022\024\n\020CMD_SOCKET_PROXY\020\r\022\027\n\023C" "MD_FIRMWARE_UPDATE\020\016\022\024\n\020CMD_SYSLOG_START" - "\020\017\022\023\n\017CMD_SYSLOG_STOP\020\020*\346\010\n\rParameterTyp" + "\020\017\022\023\n\017CMD_SYSLOG_STOP\020\020*\213\t\n\rParameterTyp" "e\022\025\n\021UNKNWON_PARAMETER\020\000\022\022\n\rPT_MINK_DTYP" "E\020\360.\022\020\n\013PT_MINK_DID\020\361.\022\022\n\rPT_MINK_ERROR\020" "\200/\022\026\n\021PT_MINK_ERROR_MSG\020\201/\022\023\n\016PT_MINK_ST" - "ATUS\020\202/\022\027\n\022PT_MINK_STATUS_MSG\020\203/\022\030\n\023PT_C" - "PU_USER_PERCENT\020\250F\022\030\n\023PT_CPU_NICE_PERCEN" - "T\020\251F\022\032\n\025PT_CPU_SYSTEM_PERCENT\020\252F\022\031\n\024PT_S" - "I_LOAD_AVG_1_MIN\020\253F\022\031\n\024PT_SI_LOAD_AVG_5_" - "MIN\020\254F\022\032\n\025PT_SI_LOAD_AVG_15_MIN\020\255F\022\024\n\017PT" - "_SI_MEM_TOTAL\020\256F\022\023\n\016PT_SI_MEM_FREE\020\257F\022\026\n" - "\021PT_SI_MEM_BUFFERS\020\260F\022\031\n\024PT_SI_MEM_SWAP_" - "TOTAL\020\261F\022\030\n\023PT_SI_MEM_SWAP_FREE\020\262F\022\031\n\024PT" - "_SI_MEM_HIGH_TOTAL\020\263F\022\030\n\023PT_SI_MEM_HIGH_" - "FREE\020\264F\022\030\n\023PT_SI_MEM_UNIT_SIZE\020\265F\022\020\n\013PT_" - "MI_TOTAL\020\266F\022\017\n\nPT_MI_FREE\020\267F\022\022\n\rPT_MI_BU" - "FFERS\020\270F\022\021\n\014PT_MI_CACHED\020\271F\022\023\n\016PT_UNM_SY" - "SNAME\020\272F\022\024\n\017PT_UNM_NODENAME\020\273F\022\023\n\016PT_UNM" - "_RELEASE\020\274F\022\023\n\016PT_UNM_VERSION\020\275F\022\023\n\016PT_U" - "NM_MACHINE\020\276F\022\016\n\tPT_PL_CMD\020\277F\022\016\n\tPT_PL_T" - "ID\020\300F\022\017\n\nPT_PL_PPID\020\301F\022\023\n\016PT_PL_RESIDENT" - "\020\302F\022\020\n\013PT_PL_UTIME\020\303F\022\020\n\013PT_PL_STIME\020\304F\022" - "\026\n\021PT_OWRT_UBUS_PATH\020\305F\022\030\n\023PT_OWRT_UBUS_" - "METHOD\020\306F\022\025\n\020PT_OWRT_UBUS_ARG\020\307F\022\030\n\023PT_O" - "WRT_UBUS_RESULT\020\310F\022\021\n\014PT_SHELL_CMD\020\311F\022\024\n" - "\017PT_SHELL_STDOUT\020\312F\022\024\n\017PT_SHELL_STDERR\020\313" - "F\022\027\n\022PT_SHELL_EXIT_CODE\020\314F\022\017\n\nPT_SP_TYPE" - "\020\315F\022\017\n\nPT_SP_PATH\020\316F\022\022\n\rPT_SP_PAYLOAD\020\317F" - "\022\017\n\nPT_FU_DATA\020\320F\022\020\n\013PT_FU_FSIZE\020\321F\022\022\n\rP" - "T_SL_LOGLINE\020\322F\022\017\n\nPT_SL_PORT\020\323F2\323\001\n\023Sys" - "agentGrpcService\022\?\n\013GetCpuStats\022\027.gdt_gr" - "pc.CommonRequest\032\025.gdt_grpc.CommonReply\"" - "\000\022>\n\nGetSysinfo\022\027.gdt_grpc.CommonRequest" - "\032\025.gdt_grpc.CommonReply\"\000\022;\n\007GetData\022\027.g" - "dt_grpc.CommonRequest\032\025.gdt_grpc.CommonR" - "eply\"\000B\032\n\006io.gdtB\010GDTProtoP\001\242\002\003GDTb\006prot" - "o3" + "ATUS\020\202/\022\027\n\022PT_MINK_STATUS_MSG\020\203/\022#\n\036PT_M" + "INK_PERSISTENT_CORRELATION\020\204/\022\030\n\023PT_CPU_" + "USER_PERCENT\020\250F\022\030\n\023PT_CPU_NICE_PERCENT\020\251" + "F\022\032\n\025PT_CPU_SYSTEM_PERCENT\020\252F\022\031\n\024PT_SI_L" + "OAD_AVG_1_MIN\020\253F\022\031\n\024PT_SI_LOAD_AVG_5_MIN" + "\020\254F\022\032\n\025PT_SI_LOAD_AVG_15_MIN\020\255F\022\024\n\017PT_SI" + "_MEM_TOTAL\020\256F\022\023\n\016PT_SI_MEM_FREE\020\257F\022\026\n\021PT" + "_SI_MEM_BUFFERS\020\260F\022\031\n\024PT_SI_MEM_SWAP_TOT" + "AL\020\261F\022\030\n\023PT_SI_MEM_SWAP_FREE\020\262F\022\031\n\024PT_SI" + "_MEM_HIGH_TOTAL\020\263F\022\030\n\023PT_SI_MEM_HIGH_FRE" + "E\020\264F\022\030\n\023PT_SI_MEM_UNIT_SIZE\020\265F\022\020\n\013PT_MI_" + "TOTAL\020\266F\022\017\n\nPT_MI_FREE\020\267F\022\022\n\rPT_MI_BUFFE" + "RS\020\270F\022\021\n\014PT_MI_CACHED\020\271F\022\023\n\016PT_UNM_SYSNA" + "ME\020\272F\022\024\n\017PT_UNM_NODENAME\020\273F\022\023\n\016PT_UNM_RE" + "LEASE\020\274F\022\023\n\016PT_UNM_VERSION\020\275F\022\023\n\016PT_UNM_" + "MACHINE\020\276F\022\016\n\tPT_PL_CMD\020\277F\022\016\n\tPT_PL_TID\020" + "\300F\022\017\n\nPT_PL_PPID\020\301F\022\023\n\016PT_PL_RESIDENT\020\302F" + "\022\020\n\013PT_PL_UTIME\020\303F\022\020\n\013PT_PL_STIME\020\304F\022\026\n\021" + "PT_OWRT_UBUS_PATH\020\305F\022\030\n\023PT_OWRT_UBUS_MET" + "HOD\020\306F\022\025\n\020PT_OWRT_UBUS_ARG\020\307F\022\030\n\023PT_OWRT" + "_UBUS_RESULT\020\310F\022\021\n\014PT_SHELL_CMD\020\311F\022\024\n\017PT" + "_SHELL_STDOUT\020\312F\022\024\n\017PT_SHELL_STDERR\020\313F\022\027" + "\n\022PT_SHELL_EXIT_CODE\020\314F\022\017\n\nPT_SP_TYPE\020\315F" + "\022\017\n\nPT_SP_PATH\020\316F\022\022\n\rPT_SP_PAYLOAD\020\317F\022\017\n" + "\nPT_FU_DATA\020\320F\022\020\n\013PT_FU_FSIZE\020\321F\022\022\n\rPT_S" + "L_LOGLINE\020\322F\022\017\n\nPT_SL_PORT\020\323F2\323\001\n\023Sysage" + "ntGrpcService\022\?\n\013GetCpuStats\022\027.gdt_grpc." + "CommonRequest\032\025.gdt_grpc.CommonReply\"\000\022>" + "\n\nGetSysinfo\022\027.gdt_grpc.CommonRequest\032\025." + "gdt_grpc.CommonReply\"\000\022;\n\007GetData\022\027.gdt_" + "grpc.CommonRequest\032\025.gdt_grpc.CommonRepl" + "y\"\000B\032\n\006io.gdtB\010GDTProtoP\001\242\002\003GDTb\006proto3" ; static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_gdt_2eproto_once; const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_gdt_2eproto = { - false, false, 2282, descriptor_table_protodef_gdt_2eproto, "gdt.proto", + false, false, 2319, descriptor_table_protodef_gdt_2eproto, "gdt.proto", &descriptor_table_gdt_2eproto_once, nullptr, 0, 6, schemas, file_default_instances, TableStruct_gdt_2eproto::offsets, file_level_metadata_gdt_2eproto, file_level_enum_descriptors_gdt_2eproto, file_level_service_descriptors_gdt_2eproto, @@ -304,6 +304,7 @@ bool ParameterType_IsValid(int value) { case 6017: case 6018: case 6019: + case 6020: case 9000: case 9001: case 9002: diff --git a/src/proto/gdt.pb.enums_only.h b/src/proto/gdt.pb.enums_only.h index 1682873..820ef67 100644 --- a/src/proto/gdt.pb.enums_only.h +++ b/src/proto/gdt.pb.enums_only.h @@ -21,6 +21,7 @@ namespace gdt_grpc { PT_MINK_ERROR_MSG = 6017, PT_MINK_STATUS = 6018, PT_MINK_STATUS_MSG = 6019, + PT_MINK_PERSISTENT_CORRELATION = 6020, PT_CPU_USER_PERCENT = 9000, PT_CPU_NICE_PERCENT = 9001, PT_CPU_SYSTEM_PERCENT = 9002, @@ -74,6 +75,7 @@ namespace gdt_grpc { {PT_MINK_ERROR_MSG, "PT_MINK_ERROR_MSG"}, {PT_MINK_STATUS, "PT_MINK_STATUS"}, {PT_MINK_STATUS_MSG, "PT_MINK_STATUS_MSG"}, + {PT_MINK_PERSISTENT_CORRELATION, "PT_MINK_PERSISTENT_CORRELATION"}, {PT_CPU_USER_PERCENT, "PT_CPU_USER_PERCENT"}, {PT_CPU_NICE_PERCENT, "PT_CPU_NICE_PERCENT"}, {PT_CPU_SYSTEM_PERCENT, "PT_CPU_SYSTEM_PERCENT"}, diff --git a/src/proto/gdt.pb.h b/src/proto/gdt.pb.h index e2db0ae..81c0a47 100644 --- a/src/proto/gdt.pb.h +++ b/src/proto/gdt.pb.h @@ -158,6 +158,7 @@ enum ParameterType : int { PT_MINK_ERROR_MSG = 6017, PT_MINK_STATUS = 6018, PT_MINK_STATUS_MSG = 6019, + PT_MINK_PERSISTENT_CORRELATION = 6020, PT_CPU_USER_PERCENT = 9000, PT_CPU_NICE_PERCENT = 9001, PT_CPU_SYSTEM_PERCENT = 9002, diff --git a/src/proto/gdt.proto b/src/proto/gdt.proto index 2ba66eb..0e7e685 100644 --- a/src/proto/gdt.proto +++ b/src/proto/gdt.proto @@ -63,6 +63,7 @@ enum ParameterType { PT_MINK_ERROR_MSG = 6017; PT_MINK_STATUS = 6018; PT_MINK_STATUS_MSG = 6019; + PT_MINK_PERSISTENT_CORRELATION = 6020; // cpu info PT_CPU_USER_PERCENT = 9000; PT_CPU_NICE_PERCENT = 9001; diff --git a/src/services/json_rpc/events.cpp b/src/services/json_rpc/events.cpp index 06d027f..159ab85 100644 --- a/src/services/json_rpc/events.cpp +++ b/src/services/json_rpc/events.cpp @@ -158,8 +158,7 @@ void EVSrvcMsgRecv::run(gdt::GDTCallbackArgs *args){ gdt::ServiceMessage* smsg = args->get(gdt::GDT_CB_INPUT_ARGS, gdt::GDT_CB_ARGS_SRVC_MSG); auto dd = static_cast(mink::CURRENT_DAEMON); - auto gdt_stream = args->get(gdt::GDT_CB_INPUT_ARGS, - gdt::GDT_CB_ARG_STREAM); + // check for missing params if (smsg->missing_params) { // TODO stats diff --git a/src/services/sysagent/plugins/syslog/plg_sysagent_syslog.cpp b/src/services/sysagent/plugins/syslog/plg_sysagent_syslog.cpp index 6ae4b89..ee81a3d 100644 --- a/src/services/sysagent/plugins/syslog/plg_sysagent_syslog.cpp +++ b/src/services/sysagent/plugins/syslog/plg_sysagent_syslog.cpp @@ -12,6 +12,7 @@ #include "mink_err_codes.h" #include "mink_utils.h" #include +#include #include #include #include @@ -79,7 +80,12 @@ std::atomic_bool running; GdtLogSentCb gdt_log_sent_cb; // permanent stream guid mink_utils::Guid guid; +int udp_port = -1; + +/**********************/ +/* zLib error handler */ +/**********************/ static void handle_zlib_error(gdt::ServiceMsgManager *smsgm, gdt::ServiceMessage *smsg, EVUserCB *ev_usr_cb){ @@ -97,7 +103,8 @@ static void gdt_push(const std::string data, gdt::ServiceMsgManager *smsgm, const std::string &d_type, const std::string &d_id, - const mink_utils::Guid &guid){ + const mink_utils::Guid &guid, + const bool last){ // get daemon pointer auto dd = static_cast(mink::CURRENT_DAEMON); @@ -169,8 +176,8 @@ static void gdt_push(const std::string data, // set guid smsg->vpmap.set_octets(asn1::ParameterType::_pt_mink_guid, guid.data(), 16); // persistent guid - smsg->vpmap.set_cstr(asn1::ParameterType::_pt_mink_persistent_correlation, - std::to_string(1).c_str()); + if (!last) smsg->vpmap.set_cstr(asn1::ParameterType::_pt_mink_persistent_correlation, + std::to_string(1).c_str()); // set source daemon type smsg->vpmap.set_cstr(asn1::ParameterType::_pt_mink_daemon_type, @@ -197,9 +204,7 @@ static void gdt_push(const std::string data, } - /************************/ - /* send service message */ - /************************/ + // send service message int r = smsgm->send(smsg, gdtc, d_type.c_str(), @@ -218,11 +223,14 @@ static void gdt_push(const std::string data, } +/*****************/ +/* Syslog thread */ +/*****************/ static void thread_syslog(gdt::ServiceMsgManager *smsgm, const std::string src_dtype, const std::string src_did, const mink_utils::VariantParam *vp_guid, - const int udp_port){ + const int port){ using boost::asio::ip::udp; @@ -233,7 +241,7 @@ static void thread_syslog(gdt::ServiceMsgManager *smsgm, udp::endpoint endp; std::size_t l; boost::asio::io_context io_ctx; - udp::socket s(io_ctx, udp::endpoint(udp::v4(), udp_port)); + udp::socket s(io_ctx, udp::endpoint(udp::v4(), port)); // start receiving syslog packets while (!mink::CURRENT_DAEMON->DAEMON_TERMINATED && running.load()) { @@ -241,7 +249,7 @@ static void thread_syslog(gdt::ServiceMsgManager *smsgm, l = s.receive_from(boost::asio::buffer(data, sizeof(data)), endp); data[l] = '\0'; // push - gdt_push(data, smsgm, src_dtype, src_did, guid); + gdt_push(data, smsgm, src_dtype, src_did, guid, !running.load()); }catch(std::exception &e){ mink::CURRENT_DAEMON->log(mink::LLT_ERROR, @@ -249,6 +257,7 @@ static void thread_syslog(gdt::ServiceMsgManager *smsgm, e.what()); } } + udp_port = -1; } @@ -267,8 +276,24 @@ extern "C" int terminate(mink_utils::PluginManager *pm, mink_utils::PluginDescri return 0; } +static int vp_str_to_port(const mink_utils::VariantParam *vp){ + if (!vp) return -1; + // port + int port = -1; + try { + port = std::stoi(static_cast(*vp)); + + } catch (std::exception &e) { + return -1; + } + + return port; +} + -// Implementation of "start" command +/*************************************/ +/* Implementation of "start" command */ +/*************************************/ static void impl_syslog_start(gdt::ServiceMessage *smsg){ using boost::asio::ip::udp; using Vp = mink_utils::VariantParam; @@ -292,8 +317,26 @@ static void impl_syslog_start(gdt::ServiceMessage *smsg){ // save source daemon address std::string src_type(static_cast(*vp_src_type)); std::string src_id(static_cast(*vp_src_id)); + + // already running + if (udp_port != -1) { + mink::CURRENT_DAEMON->log(mink::LLT_ERROR, + "plg_syslog: already running"); + smsg->vpmap.set_cstr(gdt_grpc::PT_MINK_ERROR, + std::to_string(mink::error::EC_UNKNOWN).c_str()); + return; + } + // port - int udp_port = std::stoi(static_cast(*vp_port)); + int port = vp_str_to_port(vp_port); + if (port == -1){ + mink::CURRENT_DAEMON->log(mink::LLT_ERROR, + "plg_syslog: invalid UDP port value"); + smsg->vpmap.set_cstr(gdt_grpc::PT_MINK_ERROR, + std::to_string(mink::error::EC_UNKNOWN).c_str()); + return; + + } // check if already running if (running.load()) { @@ -306,13 +349,14 @@ static void impl_syslog_start(gdt::ServiceMessage *smsg){ // setup listener thread try{ + udp_port = port; running.store(true); std::thread th(&thread_syslog, smsg->get_smsg_manager(), src_type, src_id, vp_guid, - udp_port); + port); th.detach(); smsg->vpmap.set_cstr(asn1::ParameterType::_pt_mink_persistent_correlation, std::to_string(1).c_str()); @@ -327,7 +371,9 @@ static void impl_syslog_start(gdt::ServiceMessage *smsg){ } -// Implementation of "stop" command +/************************************/ +/* Implementation of "stop" command */ +/************************************/ static void impl_syslog_stop(gdt::ServiceMessage *smsg){ using boost::asio::ip::udp; using Vp = mink_utils::VariantParam; @@ -335,7 +381,17 @@ static void impl_syslog_stop(gdt::ServiceMessage *smsg){ // port const Vp *vp_port = smsg->vpget(gdt_grpc::PT_SL_PORT); if (vp_port == nullptr) return; - int udp_port = std::stoi(static_cast(*vp_port)); + + // port + int port = vp_str_to_port(vp_port); + if (port == -1 || port != udp_port){ + mink::CURRENT_DAEMON->log(mink::LLT_ERROR, + "plg_syslog: invalid UDP port value"); + smsg->vpmap.set_cstr(gdt_grpc::PT_MINK_ERROR, + std::to_string(mink::error::EC_UNKNOWN).c_str()); + return; + + } running.store(false); boost::asio::io_context io_ctx;