Commit 3de80dc0 authored by Lucas Fernandes de Oliveira's avatar Lucas Fernandes de Oliveira

Merge branch 'adapt_for_lc' into 'development'

Adapted for lc and made repairs

See merge request !109
parents fef45e84 4af0cdcd
Pipeline #20515 passed with stages
in 67 minutes and 15 seconds
......@@ -26,7 +26,7 @@ if(WIN32)
set(Threads_FOUND TRUE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -lwinpthread -static-libstdc++ -static-libgcc")
else()
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lpthread " )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
endif()
......
......@@ -11,7 +11,7 @@ Using *Linux* as default
- c++ compiler
- cmake
- libudev
- make-self
- makeself
<a name="HeaderBuildingAndCompiling"></a>
......
......@@ -3,5 +3,9 @@
"project" : "%s",
"proxyConf" : "%s",
"version" : "%s",
"webService" : "%s"
"webService" : "%s",
"agent_send_inventory": "%s",
"agent_send_net_band" : "%s",
"agent_send_user_hist": "%s",
"agent_send_database" : "%s"
}
......@@ -31,6 +31,11 @@ usr=""
passwd=""
destination="./"
project="simmc"
asi="true" #agent_send_inventory
asnb="true" #agent_send_net_band
asuh="true" #agent_send_user_hist
asd="false" #agent_send_database
dir=$(dirname $0)
cd $dir
......@@ -47,9 +52,13 @@ for i in $@; do
;;
-h|--help)
echo "Usage: ";echo "generate agent.run with the desired setup";echo "options:"
echo " -idp=N: set idpoint as N";echo" -ws=s: set webService as s "
echo " -idp=N: set idpoint as N";echo " -ws=s: set webService as s "
echo " -pch=s: set proxyConf host as s";echo " -pcp=s: set proxyConf port as s"
echo " -pcu=s: set proxyConf user as s";echo " -pcpssd=s: set proxyConf password as s"
echo " -ver=s: set version as s";echo " -prj=s: set project name"
echo " -asi=true|false: set agent_send_inventory as true or false";echo " -asnb=true|false: set agent_send_net_band as true or false"
echo " -asuh=true|false: set agent_send_user_hist as true or false";echo " -asd=true|falses: set agent_send_database as true or false"
echo " -dest=d:set the agent directory as d"
echo " -h or --help: show this message"
exit 1
;;
......@@ -81,6 +90,22 @@ for i in $@; do
project="${i#*=}"
shift
;;
-asi=*)
asi="${i#*=}"
shift
;;
-asnb=*)
asnb="${i#*=}"
shift
;;
-asuh=*)
asuh="${i#*=}"
shift
;;
-asd=*)
asd="${i#*=}"
shift
;;
*)
echo "wrong usage\ntry -h or --help for help"
exit 1
......@@ -94,15 +119,13 @@ cp bin/agent-v0.0 $idPoint/agentC3SL/
mkdir $idPoint/agentC3SL/conf
cd $idPoint/agentC3SL/conf
touch datasid-conf.json
touch proxy.json
touch proxy-conf.json
tmp=$(cat ../../../conf/proxy-conf.json)
printf "$tmp\n" $host $port $usr $passwd > proxy.json
printf "$tmp\n" "$host" "$port" "$usr" "$passwd" > proxy-conf.json
tmp=$(cat ../../../conf/datasid-conf.json)
printf "$tmp\n" $idPoint $project conf/proxy-conf.json $version $webService > datasid-conf.json
printf "$tmp\n" "$idPoint" "$project" "conf/proxy-conf.json" "$version" "$webService" "$asi" "$asnb" "$asuh" "$asd" > datasid-conf.json
cd ../../..
......
......@@ -31,7 +31,7 @@ namespace fs = boost::filesystem;
std::string path_to_agent = "/opt/agentC3SL/"; // NOLINT(runtime/string)
//std::string path_to_agent_conf = // NOLINT(runtime/string)
//"/opt/agentC3SL/conf/"; // NOLINT(runtime/string)
std::string path_to_agent_conf = "/home/teste/Imagens/agent/conf/";
std::string path_to_agent_conf = "/opt/agentC3SL//conf/";
#else
// Temporary... Define agent path
std::string path_to_agent_tmp = "C:\\agentC3SL\\tmp\\";
......
......@@ -9,6 +9,7 @@
#include <agent/get_time.h>
#include <agent/helper.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <agent/agent.h>
/**
* @file network_bandwidth.h
......@@ -27,4 +28,4 @@
*/
std::string get_cutted_line(std::string, int);
Json::Value get_net_bandwidth();
Json::Value get_net_bandwidth(Agent*);
......@@ -20,17 +20,18 @@
# USA.
cd ..
mkdir tmp
cd tmp
temp_dir=$(mktemp -d)
if test -d /opt/agentC3SL; then
cp /opt/agentC3SL/conf/* . && rm ../agentC3SL/conf/* && mv ./* ../agentC3SL/conf/
cp /opt/agentC3SL/conf/* "$temp_dir" && rm conf/* && mv "$temp_dir"/* conf/
fi
cd ..
rm -rf tmp
rm -rf "$temp_dir"
rm -rf /opt/agentC3SL
cp -r agentC3SL /opt/
cd ..
mv agentC3SL /opt/
cd /opt/agentC3SL
if ! (crontab -l | grep -q agentC3SL) ;then
......
......@@ -81,25 +81,24 @@ void config_agent() {
std::ifstream agent_conf;
agent_conf.open(path_to_agent_conf + "datasid-conf.json",
std::ifstream::binary);
if (agent_conf.fail()) {
/* Nao conseguiu abrir o arquivo de configuracao.
Provavelmente está é um teste de desenvolvedor.
Assumindo que o projeto é o simmc.
*/
agent_send_inventory = true;
agent_send_net_band = true;
agent_send_user_hist = true;
}
if (!agent_conf.fail()) {
reader.parse(agent_conf, conf, false);
if (conf["project"].compare("simmc") == 0) {
if (conf["agent_send_inventory"].compare("true") == 0) {
agent_send_inventory = true;
}
if (conf["agent_send_net_band"].compare("true") == 0) {
agent_send_net_band = true;
}
if (conf["agent_send_user_hist"].compare("true") == 0) {
agent_send_user_hist = true;
} else if (conf["project"].compare("pinsis") == 0) {
}
if (conf["agent_send_database"].compare("true") == 0) {
agent_send_database = true;
}
}
}
}
/** Parse command line
* - Options:
* - Help - help message
......@@ -140,7 +139,7 @@ int parse_command_line(int ac, char* av[], int *increment, int *lim,
if (vm.count("uninstall")) {
// remove setup to run on boot
kill_agent(SIGTERM);
fs::remove_all(path_to_agent + "agentC3SL");
fs::remove_all(path_to_agent);
return (1);
}
#endif
......@@ -196,7 +195,7 @@ int main(int argc, char* argv[]) {
pt::ptime begin;
if (parse_command_line(argc, argv, &increment, &lim, &print, &dev)) {
return (1);
return (0);
}
/* Set agent prefix (agent folder) */
......
......@@ -63,15 +63,13 @@ std::string get_cutted_line(std::string line, int column) {
}
/** Get network bandwidth */
Json::Value get_net_bandwidth() {
Json::Value get_net_bandwidth(Agent* agent) {
Json::Value net_band;
Json::Value conf;
Json::Value net_band_all_time;
Json::Reader reader;
std::ofstream ofs;
std::ifstream net_band_file(path_to_agent_tmp + "net_band.json",
std::ifstream::binary);
std::ifstream agent_conf;
pt::ptime time;
std::string str;
std::fstream time_file;
......@@ -192,10 +190,7 @@ Json::Value get_net_bandwidth() {
// get id_point and mac_address
net_band["data_net"]["mac_address"] = get_macaddr();
agent_conf.open(path_to_agent_conf + "datasid-conf.json",
std::ifstream::binary);
reader.parse(agent_conf, conf , false);
net_band["data_net"]["id_point"] = conf["idPoint"];
net_band["data_net"]["id_point"] = agent->getConf()->getIdPoint();
// final data
net_band["data_net"]["bytes_received"] = b_rec - b_rec_allt;
......
......@@ -100,8 +100,8 @@ bool parse_proxy_file(Agent* agent) {
}
}
// Case windows, proxy.json values will be equals " "
// Case linux, proxy.json values will be equals ""
// Case windows, proxy-conf.json values will be equals " "
// Case linux, proxy-conf.json values will be equals ""
#ifdef WIN32
std::string find = " ";
#else
......
......@@ -62,7 +62,7 @@ int send_inventory(bool print, Agent* agent) {
*/
int send_net_bandwidth(bool print, Agent* agent) {
std::string base_url = agent->getConf()->getWebService();
Json::Value net = get_net_bandwidth();
Json::Value net = get_net_bandwidth(agent);
Json::FastWriter fastWriter;
if (print == true) {
......
......@@ -64,22 +64,22 @@ function packets_transmitted() {
}
function password() {
obj=$(cat /opt/agentC3SL/conf/proxy.json | jq -r '.password')
obj=$(cat /opt/agentC3SL/conf/proxy-conf.json | jq -r '.password')
[[ "$obj" == "123mudar" ]]
}
function user () {
obj=$(cat /opt/agentC3SL/conf/proxy.json | jq -r '.usr')
obj=$(cat /opt/agentC3SL/conf/proxy-conf.json | jq -r '.usr')
[[ "$obj" == "ninguem" ]]
}
function port() {
obj=$(cat /opt/agentC3SL/conf/proxy.json | jq -r '.port')
obj=$(cat /opt/agentC3SL/conf/proxy-conf.json | jq -r '.port')
[[ "$obj" -eq 6666 ]]
}
function host() {
obj=$(cat /opt/agentC3SL/conf/proxy.json | jq -r '.host')
obj=$(cat /opt/agentC3SL/conf/proxy-conf.json | jq -r '.host')
[[ "$obj" == "mumm" ]]
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment