Skip to content
Snippets Groups Projects
Commit 42a6abb7 authored by Diego Giovane Pasqualin's avatar Diego Giovane Pasqualin
Browse files

Merge branch 'issue/44' into 'development'

Issue/44

See merge request !33
parents f6f9f1c7 4df1f2be
No related branches found
No related tags found
2 merge requests!51Merge development to master,!33Issue/44
Pipeline #
Showing
with 83 additions and 41 deletions
...@@ -13,7 +13,7 @@ pattern: ...@@ -13,7 +13,7 @@ pattern:
- apt-get update && apt-get install -y git python - apt-get update && apt-get install -y git python
- git clone https://github.com/google/styleguide - git clone https://github.com/google/styleguide
- cd styleguide/cpplint - cd styleguide/cpplint
- ./cpplint.py --filter=-whitespace/blank_line,-build/include_what_you_use ../../src/!(jsoncpp).cpp ../../src/linux/*.cpp ../../src/windows/*.cpp - ./cpplint.py --filter=-whitespace/blank_line,-build/include_what_you_use ../../src/agent/!(jsoncpp).cpp ../../src/agent/linux/*.cpp ../../src/agent/windows/*.cpp
compile: compile:
stage: build stage: build
......
...@@ -11,14 +11,14 @@ set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" ) ...@@ -11,14 +11,14 @@ set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
# src : main + jsoncpp library # src : main + jsoncpp library
file ( GLOB SOURCES src/*.cpp ) file ( GLOB SOURCES src/agent/*.cpp )
# src : collect functions - depend on OS # src : collect functions - depend on OS
if ( WIN32 ) if ( WIN32 )
file ( GLOB SOURCES ${SOURCES} src/windows/*.cpp ) file ( GLOB SOURCES ${SOURCES} src/agent/windows/*.cpp )
else () # if( UNIX ) else () # if( UNIX )
file ( GLOB SOURCES ${SOURCES} src/linux/*.cpp ) file ( GLOB SOURCES ${SOURCES} src/agent/linux/*.cpp )
endif () endif ()
...@@ -66,6 +66,13 @@ if ( PRINT_JSON ) ...@@ -66,6 +66,13 @@ if ( PRINT_JSON )
add_definitions ( -DPRINT_JSON ) add_definitions ( -DPRINT_JSON )
endif () endif ()
# test to update
option( UPDATE_JSON "Set to ON to print json objects before sending" OFF )
message(STATUS "${UPDATE_JSON}: ${${UPDATE_JSON}}")
if ( UPDATE_JSON )
add_definitions ( -DUPDATE_JSON )
endif ()
# compile # compile
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin" ) set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin" )
add_executable ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${SOURCES} ) add_executable ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${SOURCES} )
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
*/ */
#pragma once #pragma once
#include <iostream> #include <iostream>
#include <json/json.h>
class Agent{ class Agent{
private: private:
...@@ -43,6 +44,7 @@ class Agent{ ...@@ -43,6 +44,7 @@ class Agent{
std::string getVersion() const; std::string getVersion() const;
}; };
int datasid_agent(); int datasid_agent();
std::string getAbsolutePath( std::string str, int tot); std::string getAbsolutePath( std::string str, int tot);
bool prefixIsSet(std::string prefix); bool prefixIsSet(std::string prefix);
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "datasid-agent.h" #include "datasid-agent.h"
#include "datasid-conf.h" #include "datasid-conf.h"
#include "datasid-proxy.h" #include "datasid-proxy.h"
#include <json/json.h>
bool datasid_common(Conf* conf, Proxy* proxy, Agent* agent); bool datasid_common(Json::Value& inventory, Agent* agent, Conf* conf, Proxy* proxy);
bool fileExist(const char * file); bool fileExist(const char * file);
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <map> #include <map>
#include "datasid-agent.h" #include "datasid-agent.h"
#include "datasid-parse.h" #include "datasid-parse.h"
#include "json/json.h"
class Conf{ class Conf{
private: private:
...@@ -58,5 +59,5 @@ class Conf{ ...@@ -58,5 +59,5 @@ class Conf{
}; };
void datasid_conf(Agent* agent, Conf* conf); bool datasid_conf(Agent* agent, Conf* conf, Json::Value& update);
bool setConf(Conf* conf, Agent* agent, std::map<std::string, std::string>* content); bool setConf(Conf* conf, Agent* agent, std::map<std::string, std::string>* content);
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "datasid-agent.h" #include "datasid-agent.h"
#include "datasid-conf.h" #include "datasid-conf.h"
#include "datasid-parse.h" #include "datasid-parse.h"
#include "json/json.h"
class Proxy{ class Proxy{
private: private:
...@@ -43,5 +44,5 @@ class Proxy{ ...@@ -43,5 +44,5 @@ class Proxy{
std::string getPassword() const; std::string getPassword() const;
}; };
void datasid_proxy(Conf* conf, Proxy* proxy); bool datasid_proxy(Conf* conf, Proxy* proxy, Json::Value& update);
bool setProxy(Proxy* proxy, std::map<std::string, std::string>* content); bool setProxy(Proxy* proxy, std::map<std::string, std::string>* content);
#ifndef __main__ #pragma once
#define __main__
#include <cstring> #include <cstring>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
...@@ -9,5 +8,3 @@ ...@@ -9,5 +8,3 @@
#include "linux/datasid-conf.h" #include "linux/datasid-conf.h"
bool fileExist(const std::string& file); bool fileExist(const std::string& file);
int main();
#endif
File moved
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* USA. * USA.
*/ */
#include <string> #include <string>
#include "../../include/agent/main.h" #include "agent/main.h"
/* /*
* set Functions * set Functions
...@@ -94,20 +94,35 @@ bool prefixIsSet(std::string prefix) { ...@@ -94,20 +94,35 @@ bool prefixIsSet(std::string prefix) {
return true; return true;
} }
// NOLINTNEXTLINE(runtime/references)
int datasid_agent() { int datasid_agent() {
Agent agent; Agent agent;
Conf conf; Conf conf;
Proxy proxy; Proxy proxy;
Json::Value update;
/* Set agent prefix */ /* Set agent prefix */
agent.setPrefix(__FILE__, 3); agent.setPrefix(__FILE__, 4);
/* Set confif file */ /* Set confif file */
agent.setDefaultConf("/conf/datasid-conf.json"); agent.setDefaultConf("/conf/datasid-conf.json");
/* Run datasid-common.cpp */ /* Run datasid-common.cpp */
if (!datasid_common(&conf, &proxy, &agent)) if (datasid_common(update, &agent, &conf, &proxy)) {
exit(1); std::fstream logFile(agent.getLogFile().c_str(), std::fstream::app);
logFile << __DATE__ << " - Agent started." << std::endl;
logFile << __DATE__ << " - Start of update process execution."
<< std::endl;
}
#ifdef UPDATE_JSON
Json::StyledWriter styledWriter;
if (!update.isNull())
std::cout << styledWriter.write(update) << std::endl;
else
std::cout << "Empty updat object" << std::endl;
#endif
return 1; return 1;
} }
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* USA. * USA.
*/ */
#include <string> #include <string>
#include "../../include/agent/linux/datasid-common.h" #include "agent/linux/datasid-common.h"
/* /*
* fileExist Function * fileExist Function
...@@ -36,30 +36,43 @@ bool fileExist(const std::string& file) { ...@@ -36,30 +36,43 @@ bool fileExist(const std::string& file) {
return false; return false;
} }
// NOLINTNEXTLINE(runtime/references)
bool datasid_common(Conf* conf, Proxy* proxy, Agent* agent) { bool datasid_common(Json::Value& inventory, Agent* agent, Conf* conf,
Proxy* proxy) {
try { try {
prefixIsSet(agent->getPrefix()); prefixIsSet(agent->getPrefix());
} catch (const char* msg) { } catch (const char* msg) {
std::cout << __DATE__ << msg << std::endl; std::string var = __DATE__ + *msg;
inventory["data"]["prefix_not_set"] = var;
return false; return false;
} }
/* Read config file and declare only valid variables */ /* Read config file and declare only valid variables */
if (!fileExist(agent->getDefaultConf())) { if (!fileExist(agent->getDefaultConf())) {
std::cout << __DATE__ << "ERROR: Config file not found." << std::endl; std::string var = __DATE__ +
std::string(" - ERROR: Conf file not found.");
inventory["data"]["conf_file_not_found"] = var;
return false; return false;
} else { } else {
datasid_conf(agent, conf); if (!datasid_conf(agent, conf, inventory)) {
return false;
}
} }
/* Read proxy file and declare only valid variables */ /* Read proxy file and declare only valid variables */
if (!fileExist(conf->getProxyConf())) if (!fileExist(conf->getProxyConf())) {
std::cout << __DATE__ << "WARNING: Proxy file not found. " << std::endl; std::string var = __DATE__ +
else std::string(" - WARNING: Proxy file not found.");
datasid_proxy(conf, proxy);
inventory["data"]["proxy_file_not_found"] = var;
} else {
if (!datasid_proxy(conf, proxy, inventory)) {
return false;
}
}
return true; return true;
} }
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include <map> #include <map>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include "../../include/agent/linux/datasid-conf.h" #include "agent/linux/datasid-conf.h"
/* /*
* set Functions * set Functions
*/ */
...@@ -144,17 +144,19 @@ bool setConf(Conf* conf, Agent* agent, std::map<std::string, ...@@ -144,17 +144,19 @@ bool setConf(Conf* conf, Agent* agent, std::map<std::string,
return true; return true;
} }
void datasid_conf(Agent* agent, Conf* conf) { // NOLINTNEXTLINE(runtime/references)
bool datasid_conf(Agent* agent, Conf* conf, Json::Value& update) {
std::map<std::string, std::string> content; std::map<std::string, std::string> content;
if (readFile(agent->getDefaultConf(), &content)) { if (readFile(agent->getDefaultConf(), &content)) {
if (!setConf(conf, agent, &content)) { if (!setConf(conf, agent, &content)) {
std::cout << __DATE__ << " ERROR: to parse variables " << std::string var = __DATE__ +
"from config file." << std::endl; std::string(" - ERROR: to parse variables from config file.");
exit(1);
update["data"]["conf_file_not_found"] = var;
return false;
} }
} else {
std::cout << __DATE__ << " ERROR: config file not found." << std::endl;
exit(1);
} }
return true;
} }
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include <re2/re2.h> #include <re2/re2.h>
#include <map> #include <map>
#include <string> #include <string>
#include "../../include/agent/linux/datasid-parse.h" #include "agent/linux/datasid-parse.h"
/* /*
* trim Function * trim Function
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include <iostream> #include <iostream>
#include <map> #include <map>
#include <string> #include <string>
#include "../../include/agent/linux/datasid-proxy.h" #include "agent/linux/datasid-proxy.h"
/* /*
* set Functions * set Functions
...@@ -84,16 +84,19 @@ bool setProxy(Proxy* proxy, std::map<std::string, std::string>* content) { ...@@ -84,16 +84,19 @@ bool setProxy(Proxy* proxy, std::map<std::string, std::string>* content) {
return true; return true;
} }
void datasid_proxy(Conf* conf, Proxy* proxy) { // NOLINTNEXTLINE(runtime/references)
bool datasid_proxy(Conf* conf, Proxy* proxy, Json::Value& update) {
std::map<std::string, std::string> content; std::map<std::string, std::string> content;
if (readFile(conf->getProxyConf(), &content)) { if (readFile(conf->getProxyConf(), &content)) {
if (!setProxy(proxy, &content)) { if (!setProxy(proxy, &content)) {
std::cout << __DATE__ << " ERROR: to parse variables" << std::string var = __DATE__ +
" from proxy file." << std::endl; std::string(" - ERROR: to parse variables from proxy file.");
exit(1);
update["data"]["proxy_file_not_found"] = var;
return false;
} }
} else {
std::cout << __DATE__ << " WARNING: proxy file not found." << std::endl;
} }
return true;
} }
File moved
File moved
File moved
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment