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:
- apt-get update && apt-get install -y git python
- git clone https://github.com/google/styleguide
- 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:
stage: build
......
......@@ -11,14 +11,14 @@ set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
# src : main + jsoncpp library
file ( GLOB SOURCES src/*.cpp )
file ( GLOB SOURCES src/agent/*.cpp )
# src : collect functions - depend on OS
if ( WIN32 )
file ( GLOB SOURCES ${SOURCES} src/windows/*.cpp )
file ( GLOB SOURCES ${SOURCES} src/agent/windows/*.cpp )
else () # if( UNIX )
file ( GLOB SOURCES ${SOURCES} src/linux/*.cpp )
file ( GLOB SOURCES ${SOURCES} src/agent/linux/*.cpp )
endif ()
......@@ -66,6 +66,13 @@ if ( PRINT_JSON )
add_definitions ( -DPRINT_JSON )
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
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin" )
add_executable ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${SOURCES} )
......
......@@ -20,6 +20,7 @@
*/
#pragma once
#include <iostream>
#include <json/json.h>
class Agent{
private:
......@@ -43,6 +44,7 @@ class Agent{
std::string getVersion() const;
};
int datasid_agent();
std::string getAbsolutePath( std::string str, int tot);
bool prefixIsSet(std::string prefix);
......@@ -23,6 +23,7 @@
#include "datasid-agent.h"
#include "datasid-conf.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);
......@@ -22,6 +22,7 @@
#include <map>
#include "datasid-agent.h"
#include "datasid-parse.h"
#include "json/json.h"
class Conf{
private:
......@@ -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);
......@@ -23,6 +23,7 @@
#include "datasid-agent.h"
#include "datasid-conf.h"
#include "datasid-parse.h"
#include "json/json.h"
class Proxy{
private:
......@@ -43,5 +44,5 @@ class Proxy{
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);
#ifndef __main__
#define __main__
#pragma once
#include <cstring>
#include <fstream>
#include <iostream>
......@@ -9,5 +8,3 @@
#include "linux/datasid-conf.h"
bool fileExist(const std::string& file);
int main();
#endif
File moved
......@@ -19,7 +19,7 @@
* USA.
*/
#include <string>
#include "../../include/agent/main.h"
#include "agent/main.h"
/*
* set Functions
......@@ -94,20 +94,35 @@ bool prefixIsSet(std::string prefix) {
return true;
}
// NOLINTNEXTLINE(runtime/references)
int datasid_agent() {
Agent agent;
Conf conf;
Proxy proxy;
Json::Value update;
/* Set agent prefix */
agent.setPrefix(__FILE__, 3);
agent.setPrefix(__FILE__, 4);
/* Set confif file */
agent.setDefaultConf("/conf/datasid-conf.json");
/* Run datasid-common.cpp */
if (!datasid_common(&conf, &proxy, &agent))
exit(1);
if (datasid_common(update, &agent, &conf, &proxy)) {
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;
}
......@@ -19,7 +19,7 @@
* USA.
*/
#include <string>
#include "../../include/agent/linux/datasid-common.h"
#include "agent/linux/datasid-common.h"
/*
* fileExist Function
......@@ -36,30 +36,43 @@ bool fileExist(const std::string& file) {
return false;
}
bool datasid_common(Conf* conf, Proxy* proxy, Agent* agent) {
// NOLINTNEXTLINE(runtime/references)
bool datasid_common(Json::Value& inventory, Agent* agent, Conf* conf,
Proxy* proxy) {
try {
prefixIsSet(agent->getPrefix());
} catch (const char* msg) {
std::cout << __DATE__ << msg << std::endl;
std::string var = __DATE__ + *msg;
inventory["data"]["prefix_not_set"] = var;
return false;
}
/* Read config file and declare only valid variables */
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;
} else {
datasid_conf(agent, conf);
if (!datasid_conf(agent, conf, inventory)) {
return false;
}
}
/* Read proxy file and declare only valid variables */
if (!fileExist(conf->getProxyConf()))
std::cout << __DATE__ << "WARNING: Proxy file not found. " << std::endl;
else
datasid_proxy(conf, proxy);
if (!fileExist(conf->getProxyConf())) {
std::string var = __DATE__ +
std::string(" - WARNING: Proxy file not found.");
inventory["data"]["proxy_file_not_found"] = var;
} else {
if (!datasid_proxy(conf, proxy, inventory)) {
return false;
}
}
return true;
}
......@@ -25,7 +25,7 @@
#include <map>
#include <sstream>
#include <string>
#include "../../include/agent/linux/datasid-conf.h"
#include "agent/linux/datasid-conf.h"
/*
* set Functions
*/
......@@ -144,17 +144,19 @@ bool setConf(Conf* conf, Agent* agent, std::map<std::string,
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;
if (readFile(agent->getDefaultConf(), &content)) {
if (!setConf(conf, agent, &content)) {
std::cout << __DATE__ << " ERROR: to parse variables " <<
"from config file." << std::endl;
exit(1);
std::string var = __DATE__ +
std::string(" - ERROR: to parse variables from config file.");
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 @@
#include <re2/re2.h>
#include <map>
#include <string>
#include "../../include/agent/linux/datasid-parse.h"
#include "agent/linux/datasid-parse.h"
/*
* trim Function
......
......@@ -21,7 +21,7 @@
#include <iostream>
#include <map>
#include <string>
#include "../../include/agent/linux/datasid-proxy.h"
#include "agent/linux/datasid-proxy.h"
/*
* set Functions
......@@ -84,16 +84,19 @@ bool setProxy(Proxy* proxy, std::map<std::string, std::string>* content) {
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;
if (readFile(conf->getProxyConf(), &content)) {
if (!setProxy(proxy, &content)) {
std::cout << __DATE__ << " ERROR: to parse variables" <<
" from proxy file." << std::endl;
exit(1);
std::string var = __DATE__ +
std::string(" - ERROR: to parse variables from proxy file.");
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