diff --git a/Projects/argus/build b/Projects/argus/build index 8be76093..3bde7a64 100755 --- a/Projects/argus/build +++ b/Projects/argus/build @@ -6,4 +6,4 @@ make clean -e "CFG=Release" -#make -j4 -e "CFG=Release" +make -j4 -e "CFG=Release" diff --git a/Projects/argus/test_sha.php b/Projects/argus/test_sha.php index ff267255..e0f8cca8 100644 --- a/Projects/argus/test_sha.php +++ b/Projects/argus/test_sha.php @@ -1,6 +1,8 @@ \ No newline at end of file diff --git a/lib/components/base/basicTypes.h b/lib/components/base/basicTypes.h index 7c0bdd2e..b6457424 100644 --- a/lib/components/base/basicTypes.h +++ b/lib/components/base/basicTypes.h @@ -621,7 +621,17 @@ typedef struct S_SOL_PORT_SETTINGS{ typedef struct S_KAFKA_SETTINGS{ char brocker_addr[256]; uint16_t brocker_port; + bool use_ssl; + bool auth_by_cert; + bool auth_by_cred; + char vault_md5[33]; + bool truststore; // CA Root cert + bool certstore; // Client cert + bool keystore; // Client key + char cred_username[33]; + char cred_password[33]; }KAFKA_SETTINGS; + typedef struct S_KAFKA_TEMPLATE{ char topic[128]; CSTR tpl; diff --git a/lib/data/protocol/protocolKAFKA.cpp b/lib/data/protocol/protocolKAFKA.cpp index 2f32b7fe..a42bf37d 100644 --- a/lib/data/protocol/protocolKAFKA.cpp +++ b/lib/data/protocol/protocolKAFKA.cpp @@ -137,31 +137,32 @@ protocolKAFKA::protocolKAFKA( config_setting_t *Settings ){ protocolKAFKA::protocolKAFKA( KAFKA_SETTINGS *Settings ){ m_pLog = basicLogCollection::getInstance(); n_pProducer = NULL; - m_pServerIP = NULL; - memset( m_pKafkaBrokerSTR, 0 , sizeof( m_pKafkaBrokerSTR )); + //m_pServerIP = NULL; + m_pSettings = Settings; + //memset( m_pKafkaBrokerSTR, 0 , sizeof( m_pKafkaBrokerSTR )); if( Settings!= NULL ) { - m_pServerIP = (CSTR)malloc(OS_CEP_ADDRESS_SIZE); - if( m_pServerIP == NULL ) return; - memset( m_pServerIP, 0 , OS_CEP_ADDRESS_SIZE); - strncpy( m_pServerIP, Settings->brocker_addr, OS_CEP_ADDRESS_SIZE ); - m_nServerPort = Settings->brocker_port; - sprintf( m_pKafkaBrokerSTR, "%s:%d", m_pServerIP, m_nServerPort ); + //m_pServerIP = (CSTR)malloc(OS_CEP_ADDRESS_SIZE); + //if( m_pServerIP == NULL ) return; + //memset( m_pServerIP, 0 , OS_CEP_ADDRESS_SIZE); + //strncpy( m_pServerIP, Settings->brocker_addr, OS_CEP_ADDRESS_SIZE ); + //m_nServerPort = Settings->brocker_port; + //sprintf( m_pKafkaBrokerSTR, "%s:%d", m_pServerIP, m_nServerPort ); }; }; -protocolKAFKA::protocolKAFKA( CSTR ServerAddress, uint16_t Port ){ - m_pLog = basicLogCollection::getInstance(); - n_pProducer = NULL; - m_pServerIP = NULL; - if( ServerAddress == 0 || Port == 0 ) return; - m_pServerIP = (CSTR)malloc(OS_CEP_ADDRESS_SIZE); - if( m_pServerIP == NULL ) return; - memset( m_pServerIP, 0 , OS_CEP_ADDRESS_SIZE); - memset( m_pKafkaBrokerSTR, 0 , sizeof( m_pKafkaBrokerSTR )); - strncpy( m_pServerIP, ServerAddress, OS_CEP_ADDRESS_SIZE ); - m_nServerPort = Port; - sprintf( m_pKafkaBrokerSTR, "%s:%d", m_pServerIP, m_nServerPort ); -}; +//protocolKAFKA::protocolKAFKA( CSTR ServerAddress, uint16_t Port ){ +// m_pLog = basicLogCollection::getInstance(); +// n_pProducer = NULL; +// m_pServerIP = NULL; +// if( ServerAddress == 0 || Port == 0 ) return; +// m_pServerIP = (CSTR)malloc(OS_CEP_ADDRESS_SIZE); +// if( m_pServerIP == NULL ) return; +// memset( m_pServerIP, 0 , OS_CEP_ADDRESS_SIZE); +// memset( m_pKafkaBrokerSTR, 0 , sizeof( m_pKafkaBrokerSTR )); +// strncpy( m_pServerIP, ServerAddress, OS_CEP_ADDRESS_SIZE ); +// m_nServerPort = Port; +// sprintf( m_pKafkaBrokerSTR, "%s:%d", m_pServerIP, m_nServerPort ); +//}; /** * @brief Message delivery report callback. @@ -204,7 +205,7 @@ protocolKAFKA::~protocolKAFKA(){ //if( n_pProducerTopic!= NULL ) delete n_pProducerTopic; }; //if( m_pScannerName != NULL ) free(m_pScannerName); - if( m_pServerIP != NULL ) free(m_pServerIP); + //if( m_pServerIP != NULL ) free(m_pServerIP); //if( m_pAccessURL != NULL ) free(m_pAccessURL); }; //https://github.com/edenhill/librdkafka/blob/master/examples/producer.c @@ -229,15 +230,15 @@ void protocolKAFKA::dr_cb( RdKafka::Message &message ){ bool protocolKAFKA::init(){ RdKafka::Conf * tGlobalConf; + char zBuffer[CTEXT]; std::string tBuffer; - std::string brokers = m_pKafkaBrokerSTR; + std::string tValue; + if( m_pSettings == NULL ) return false; + tValue.reserve(256); #ifdef DEBUG_KAFKA LOG("INIT Begin"); #endif - if( strlen( m_pKafkaBrokerSTR ) == 0 ) { - LOG_ERROR("No Kafka Brokers are defined!"); - return false; - }; + tGlobalConf = RdKafka::Conf::create( RdKafka::Conf::CONF_GLOBAL ); if( tGlobalConf == NULL ) { LOG_ERROR("Eror Creating Producer Conf!"); @@ -245,36 +246,180 @@ bool protocolKAFKA::init(){ }; #ifdef DEBUG_KAFKA LOG("RdKafka::Conf::CONF_GLOBAL Created"); + std::string features; + tGlobalConf->get( "builtin.features", features ); + sprintf( zBuffer, "librdkafka version %s (0x%08x, builtin.features \"%s\")", RdKafka::version_str().c_str(), RdKafka::version(), features.c_str() ); + LOG( zBuffer ); #endif - if( tGlobalConf->set( "bootstrap.servers", brokers, tBuffer ) != RdKafka::Conf::CONF_OK ){ - LOG_ERROR( tBuffer.c_str() ); + if( strlen( m_pSettings->brocker_addr ) == 0 ) { + LOG_ERROR("No Kafka Brokers are defined!"); delete( tGlobalConf ); return false; }; - //std::string Kuser = ""; - //std::string Kpass = ""; - //if( tGlobalConf->set( "sasl.username", Kuser, tBuffer ) != RdKafka::Conf::CONF_OK ){ - // LOG_ERROR( tBuffer.c_str() ); - // delete( tGlobalConf ); - // return false; - //}; - //if( tGlobalConf->set( "sasl.password", Kuser, tBuffer ) != RdKafka::Conf::CONF_OK ){ - // LOG_ERROR( tBuffer.c_str() ); - // delete( tGlobalConf ); - // return false; - //}; + + sprintf( (char *)tValue.c_str(), "%s:%d", m_pSettings->brocker_addr, m_pSettings->brocker_port ); + if( tGlobalConf->set( "bootstrap.servers", tValue, tBuffer ) != RdKafka::Conf::CONF_OK ){ + LOG_ERROR( tBuffer.c_str() ); + delete( tGlobalConf ); + return false; #ifdef DEBUG_KAFKA - LOG( m_pKafkaBrokerSTR ); - LOG("bootstrap.servers is SET"); + } else { + LOG("bootstrap.servers is set"); #endif - if( tGlobalConf->set("metadata.broker.list", brokers, tBuffer ) != RdKafka::Conf::CONF_OK ){ + }; + + if( tGlobalConf->set("metadata.broker.list", tValue, tBuffer ) != RdKafka::Conf::CONF_OK ){ LOG_ERROR( tBuffer.c_str() ); delete( tGlobalConf ); return false; +#ifdef DEBUG_KAFKA + } else { + LOG( tValue.c_str() ); + LOG("metadata.broker.list is SET"); +#endif }; + + if( m_pSettings->use_ssl ) { + LOG( "USE SSL!"); + if (m_pSettings->auth_by_cred) { + sprintf((char *)tValue.c_str(), "SASL_SSL"); + if( tGlobalConf->set( "security.protocol", tValue, tBuffer ) != RdKafka::Conf::CONF_OK ){ + LOG_ERROR( tBuffer.c_str() ); + delete( tGlobalConf ); + return false; +#ifdef DEBUG_KAFKA + } else { + LOG("SEC Proto is SASL_SSL"); +#endif + }; + sprintf((char *)tValue.c_str(), "%s", m_pSettings->cred_username); + if( tGlobalConf->set( "sasl.username", tValue, tBuffer ) != RdKafka::Conf::CONF_OK ){ + LOG_ERROR( tBuffer.c_str() ); + delete( tGlobalConf ); + return false; +#ifdef DEBUG_KAFKA + } else { + LOG("SASL username is SET"); +#endif + }; + sprintf((char *)tValue.c_str(), "%s", m_pSettings->cred_password); + if( tGlobalConf->set( "sasl.password", tValue, tBuffer ) != RdKafka::Conf::CONF_OK ){ + LOG_ERROR( tBuffer.c_str() ); + delete( tGlobalConf ); + return false; +#ifdef DEBUG_KAFKA + } else { + LOG("SASL password is SET"); +#endif + }; + } else { + sprintf((char *)tValue.c_str(), "SSL"); + if( tGlobalConf->set( "security.protocol", tValue, tBuffer ) != RdKafka::Conf::CONF_OK ){ + LOG_ERROR( tBuffer.c_str() ); + delete( tGlobalConf ); + return false; +#ifdef DEBUG_KAFKA + } else { + LOG("SEC Proto is SSL"); +#endif + }; + }; + if ( m_pSettings->truststore ) { + sprintf((char *)tValue.c_str(), "./data/modules/VAULT/%s/%s.CA.pem", m_pSettings->vault_md5, m_pSettings->vault_md5 ); + if( tGlobalConf->set( "ssl.ca.location", tValue, tBuffer ) != RdKafka::Conf::CONF_OK ){ + LOG_ERROR( tBuffer.c_str() ); + delete( tGlobalConf ); + return false; #ifdef DEBUG_KAFKA - LOG("metadata.broker.list is SET"); + } else { + LOG("SSL CA Root is SET"); #endif + }; + }; + if ( m_pSettings->certstore ) { + sprintf((char *)tValue.c_str(), "./data/modules/VAULT/%s/%s.CERT.pem", m_pSettings->vault_md5, m_pSettings->vault_md5 ); + if( tGlobalConf->set( "ssl.certificate.location", tValue, tBuffer ) != RdKafka::Conf::CONF_OK ){ + LOG_ERROR( tBuffer.c_str() ); + delete( tGlobalConf ); + return false; +#ifdef DEBUG_KAFKA + } else { + LOG("SSL CERT is SET"); +#endif + }; + }; + if ( m_pSettings->keystore ) { + sprintf((char *)tValue.c_str(), "./data/modules/VAULT/%s/%s.key", m_pSettings->vault_md5, m_pSettings->vault_md5 ); + if( tGlobalConf->set( "ssl.key.location", tValue, tBuffer ) != RdKafka::Conf::CONF_OK ){ + LOG_ERROR( tBuffer.c_str() ); + delete( tGlobalConf ); + return false; + #ifdef DEBUG_KAFKA + } else { + LOG("SSL KEY is SET"); + #endif + }; + }; + if (strlen(m_pSettings->cred_password)) { + sprintf((char *)tValue.c_str(), m_pSettings->cred_password ); + if( tGlobalConf->set( "ssl.key.password", tValue, tBuffer ) != RdKafka::Conf::CONF_OK ){ + LOG_ERROR( tBuffer.c_str() ); + delete( tGlobalConf ); + return false; +#ifdef DEBUG_KAFKA + } else { + LOG("SSL KEY password is SET"); +#endif + }; + }; + } else { + if (m_pSettings->auth_by_cred) { + sprintf((char *)tValue.c_str(), "SASL"); + if( tGlobalConf->set( "security.protocol", tValue, tBuffer ) != RdKafka::Conf::CONF_OK ){ + LOG_ERROR( tBuffer.c_str() ); + delete( tGlobalConf ); + return false; +#ifdef DEBUG_KAFKA + } else { + LOG("SEC Proto is SASL"); +#endif + }; + sprintf((char *)tValue.c_str(), "PLAIN"); + if( tGlobalConf->set( "sasl.mechanisms", tValue, tBuffer ) != RdKafka::Conf::CONF_OK ){ + LOG_ERROR( tBuffer.c_str() ); + delete( tGlobalConf ); + return false; +#ifdef DEBUG_KAFKA + } else { + LOG("SASL mechanism is PLAIN"); +#endif + }; + sprintf((char *)tValue.c_str(), "%c", m_pSettings->cred_username); + if( tGlobalConf->set( "sasl.username", tValue, tBuffer ) != RdKafka::Conf::CONF_OK ){ + LOG_ERROR( tBuffer.c_str() ); + delete( tGlobalConf ); + return false; +#ifdef DEBUG_KAFKA + } else { + LOG("SASL username is SET"); +#endif + }; + sprintf((char *)tValue.c_str(), "%c", m_pSettings->cred_password); + if( tGlobalConf->set( "sasl.password", tValue, tBuffer ) != RdKafka::Conf::CONF_OK ){ + LOG_ERROR( tBuffer.c_str() ); + delete( tGlobalConf ); + return false; +#ifdef DEBUG_KAFKA + } else { + LOG("SASL password is SET"); +#endif + }; +#ifdef DEBUG_KAFKA + } else { + LOG("No Auth Settings!"); +#endif + }; + }; /* Set the delivery report callback. * This callback will be called once per message to inform * the application if delivery succeeded or failed. @@ -287,10 +432,11 @@ bool protocolKAFKA::init(){ LOG_ERROR( tBuffer.c_str() ); delete( tGlobalConf ); return false; - }; #ifdef DEBUG_KAFKA - LOG("dr_cb is SET"); + } else { + LOG("dr_cb is SET"); #endif + }; //if( tProducerConf->set("default_topic_conf", tTopicConf, tBuffer ) != RdKafka::Conf::CONF_OK ){ // LOG_ERROR( tBuffer.c_str() ); // delete( tProducerConf ); @@ -312,19 +458,21 @@ bool protocolKAFKA::init(){ LOG_ERROR( tBuffer.c_str() ); delete( tGlobalConf ); return false; - }; #ifdef DEBUG_KAFKA - LOG("RdKafka::Producer Created"); -#endif + } else { + LOG("RdKafka::Producer Created"); +#endif + }; if( tGlobalConf->set( "enable.partition.eof", "true", tBuffer ) != RdKafka::Conf::CONF_OK ){ delete( n_pProducer ); delete( tGlobalConf ); LOG_ERROR( tBuffer.c_str() ); return false; - }; #ifdef DEBUG_KAFKA - LOG("enable.partition.eof is SET"); + } else { + LOG("enable.partition.eof is SET"); #endif + }; m_pConsumer = RdKafka::Consumer::create( tGlobalConf, tBuffer ); if( m_pConsumer == NULL ){ delete( n_pProducer ); @@ -332,9 +480,12 @@ bool protocolKAFKA::init(){ LOG_ERROR( "Failed to create consumer:"); LOG_ERROR( tBuffer.c_str() ); return false; - } #ifdef DEBUG_KAFKA - LOG("RdKafka::Consumer Created"); + } else { + LOG("RdKafka::Consumer Created"); +#endif + }; +#ifdef DEBUG_KAFKA LOG("INIT Complete"); #endif delete( tGlobalConf ); diff --git a/lib/data/protocol/protocolKAFKA.h b/lib/data/protocol/protocolKAFKA.h index cacb8d2e..7b11f52c 100644 --- a/lib/data/protocol/protocolKAFKA.h +++ b/lib/data/protocol/protocolKAFKA.h @@ -30,20 +30,21 @@ class protocolKAFKA: public RdKafka::DeliveryReportCb, public RdKafka::ConsumeCb private: basicLogCollection * m_pLog; //config_setting_t * m_pSettings; - //rd_kafka_t * m_pKafka; /* Producer instance handle */ + //rd_kafka_t * m_pKafka; /* Producer instance handle */ RdKafka::Consumer * m_pConsumer; RdKafka::Producer * n_pProducer; /* Producer instance handle */ //rd_kafka_conf_t * m_pKafkaConf; /* Temporary configuration object */ //RdKafka::Conf * m_pKafkaConf; /* Temporary configuration object */ - char m_pKafkaBrokerSTR[OS_CEP_ADDRESS_SIZE]; + //---char m_pKafkaBrokerSTR[OS_CEP_ADDRESS_SIZE]; //CSTR m_pKafkaTopicSTR; //RdKafka::Topic * m_pKafkaTopic; - CSTR m_pServerIP; - int m_nServerPort; + KAFKA_SETTINGS * m_pSettings; + //CSTR m_pServerIP; + //int m_nServerPort; public: // Constructor explicit protocolKAFKA( KAFKA_SETTINGS *Settings ); - explicit protocolKAFKA( CSTR ServerAddr, uint16_t Port ); + //explicit protocolKAFKA( CSTR ServerAddr, uint16_t Port ); // Destructor virtual ~protocolKAFKA(); bool init(); diff --git a/lib/rgoose/rgooseDBConnector.cpp b/lib/rgoose/rgooseDBConnector.cpp index 56cb3110..b118065e 100644 --- a/lib/rgoose/rgooseDBConnector.cpp +++ b/lib/rgoose/rgooseDBConnector.cpp @@ -3459,7 +3459,7 @@ KAFKA_SETTINGS *argusDBC::getSettingsKAFKA( uint32_t ModuleID ){ if( m_bIsConnected ) { char tQBuf[CTEXT]; AAssoc *result; - sprintf( tQBuf, "SELECT brocker_address, brocker_port FROM modules_kafka WHERE module_id = %d", ModuleID ); + sprintf( tQBuf, "SELECT * FROM modules_kafka WHERE module_id = %d", ModuleID ); #ifdef DEBUG_ALL LOG(tQBuf); #endif @@ -3469,6 +3469,7 @@ KAFKA_SETTINGS *argusDBC::getSettingsKAFKA( uint32_t ModuleID ){ Assoc *cArr; tVal = (KAFKA_SETTINGS*) malloc(sizeof(KAFKA_SETTINGS)); if( tVal != NULL ) { + memset( tVal, 0, sizeof(KAFKA_SETTINGS) ); Assoc::iterator it; cArr = result->at(0); it = cArr->find("brocker_address"); @@ -3479,6 +3480,42 @@ KAFKA_SETTINGS *argusDBC::getSettingsKAFKA( uint32_t ModuleID ){ if( it != cArr->end() ){ tVal->brocker_port = atoi( it->second.c_str() ); }; + it = cArr->find("use_ssl"); + if( it != cArr->end() ){ + tVal->use_ssl = (bool)atoi( it->second.c_str() ); + }; + it = cArr->find("auth_cert"); + if( it != cArr->end() ){ + tVal->auth_by_cert = (bool)atoi( it->second.c_str() ); + }; + it = cArr->find("auth_cred"); + if( it != cArr->end() ){ + tVal->auth_by_cred = (bool)atoi( it->second.c_str() ); + }; + it = cArr->find("vault_md5"); + if( it != cArr->end() ){ + strncpy( tVal->vault_md5, it->second.c_str(), 32 ); + }; + it = cArr->find("truststore"); + if( it != cArr->end() ){ + tVal->truststore = (bool)atoi( it->second.c_str() ); + }; + it = cArr->find("certstore"); + if( it != cArr->end() ){ + tVal->certstore = (bool)atoi( it->second.c_str() ); + }; + it = cArr->find("keystore"); + if( it != cArr->end() ){ + tVal->keystore = (bool)atoi( it->second.c_str() ); + }; + it = cArr->find("cred_username"); + if( it != cArr->end() ){ + strncpy( tVal->cred_username, it->second.c_str(), 32 ); + }; + it = cArr->find("cred_password"); + if( it != cArr->end() ){ + strncpy( tVal->cred_password, it->second.c_str(), 32 ); + }; }; }; }; diff --git a/lib/rgoose/rgooseModuleKafka.cpp b/lib/rgoose/rgooseModuleKafka.cpp index 053daab3..ebafe721 100644 --- a/lib/rgoose/rgooseModuleKafka.cpp +++ b/lib/rgoose/rgooseModuleKafka.cpp @@ -34,7 +34,7 @@ argusModuleKafka::argusModuleKafka( uint32_t ModuleID ): argusKernelModule( Modu strncpy( m_sServerIP, TVAL, 48 ); free( TVAL ); } else { - LOG_ERROR("Error Get Server IP!"); + LOG_ERROR("Error Get Argus Server IP!"); strncpy( m_sServerIP, "192.168.0.127", 48 ); }; memset( m_sServerName, 0, 48 ); @@ -43,7 +43,7 @@ argusModuleKafka::argusModuleKafka( uint32_t ModuleID ): argusKernelModule( Modu strncpy( m_sServerName, TVAL, 48 ); free( TVAL ); } else { - LOG_ERROR("Error Get Server Name!"); + LOG_ERROR("Error Get Argus Server Name!"); strncpy( m_sServerName, "Argus Server", 48 ); }; diff --git a/lib/rgoose/rgooseNode2D.cpp b/lib/rgoose/rgooseNode2D.cpp index cdf85294..fd8d6ddd 100644 --- a/lib/rgoose/rgooseNode2D.cpp +++ b/lib/rgoose/rgooseNode2D.cpp @@ -795,7 +795,7 @@ void ARGUS_2DSensor::m_fThreadProc( void ){ break; }; case ANODE_WM_2D_WAIT_DEVICE_REPLAY: - m_bOpRetryCnt = 3; + m_bOpRetryCnt = 10; m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER; m_bWM = ANODE_WM_2D_WAIT_CHECK_REPLAY; case ANODE_WM_2D_WAIT_CHECK_REPLAY:{ @@ -1118,6 +1118,7 @@ bool ARGUS_2DSensor::packetHandler( protocolPackage *Package ){ } else { LOG_ERROR( m_sLRF_DATA.serial ); LOG_ERROR("SN is INVALID!"); + LOG_ERROR( m_tSN ); m_bSerialStringValid = false; }; @@ -1140,6 +1141,7 @@ bool ARGUS_2DSensor::packetHandler( protocolPackage *Package ){ } else { LOG_ERROR( m_sLRF_DATA.version ); LOG_ERROR("Version is INVALID!"); + LOG_ERROR( m_tSV ); m_bVersionStringValid = false; }; if( m_bVersionStringValid && m_bSerialStringValid ) { diff --git a/lib/rgoose/rgooseNode2D.h b/lib/rgoose/rgooseNode2D.h index f33263ad..2d832a51 100644 --- a/lib/rgoose/rgooseNode2D.h +++ b/lib/rgoose/rgooseNode2D.h @@ -14,9 +14,9 @@ #include "../alg/lgs/mask.h" #include "../data/protocol/protocolLGS2D.h" -#define LGS_DEFAULT_SLEEP_TIME 333 +#define LGS_DEFAULT_SLEEP_TIME 100 #define LGS_ALERT_SLEEP_TIME 1 -#define LGS_DEFAULT_TO_COUNTER 2 +#define LGS_DEFAULT_TO_COUNTER 10 #define LGS_INITIAL_FLIPS 8 #define ANODE_WM_2D_BEFORE_START 0