diff --git a/CMakeLists.txt b/CMakeLists.txt index c4313ce3548ed8dd0a1f35cd24414ecd198597d3..da7d3ea459894bb2299e627859aa44674f7999c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/README.md b/README.md index dd146503d780fa03d8bea15195cadb1b777ff0fa..351199619def5f3afc2b9d6239082a0bea133306 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Using *Linux* as default - c++ compiler - cmake - libudev -- make-self +- makeself <a name="HeaderBuildingAndCompiling"></a> diff --git a/conf/datasid-conf.json b/conf/datasid-conf.json index 38348398eaee1e184cc45c1bb56bf429928757d2..4d0afac29b04226df1ba085b17336951631a8afe 100644 --- a/conf/datasid-conf.json +++ b/conf/datasid-conf.json @@ -3,5 +3,9 @@ "project" : "%s", "proxyConf" : "%s", "version" : "%s", - "webService" : "%s" -} \ No newline at end of file + "webService" : "%s", + "agent_send_inventory": "%s", + "agent_send_net_band" : "%s", + "agent_send_user_hist": "%s", + "agent_send_database" : "%s" +} diff --git a/generate_agent.sh b/generate_agent.sh index ff84715e597b2a8a25a729edbbe0420a8234a907..9e21a281912a7b7a7f45c1af600d6944e1ad2bad 100755 --- a/generate_agent.sh +++ b/generate_agent.sh @@ -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 ../../.. diff --git a/include/agent/inventory.h b/include/agent/inventory.h index e482d7c3ce3475690119a5889ed145f478996e1c..914dee8e4c4ef314ae252cff909ecd15d576adc5 100644 --- a/include/agent/inventory.h +++ b/include/agent/inventory.h @@ -16,7 +16,7 @@ #include <agent/get_user_count.h> #include <json/json.h> -/** +/** * @file inventory.h * @brief Collect all info from hardware, like processor, memory, mac adress, disks, machine type, os distro and so on. * - The data collected are saved in a json object: @@ -34,4 +34,4 @@ * - Mac address */ -Json::Value get_inventory(Agent*); \ No newline at end of file +Json::Value get_inventory(Agent*); diff --git a/include/agent/main.h b/include/agent/main.h index 5513bb72a65d3cac0eda3de3e11599ab4dace49a..f93024670ab86e49d26c39ff4d006f6446cd7866 100644 --- a/include/agent/main.h +++ b/include/agent/main.h @@ -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\\"; diff --git a/include/agent/network_bandwidth.h b/include/agent/network_bandwidth.h index a85f18c91c78cbe4689a7443a1b016918edd4788..6d032ade7c2183f2974898ce38198722baedcfd4 100644 --- a/include/agent/network_bandwidth.h +++ b/include/agent/network_bandwidth.h @@ -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*); diff --git a/install_agent.sh b/install_agent.sh index b643eb09c17046c4c320c14f2517438ca94102b4..74b52eb9f910f3a56666ffdacc164d9da701c952 100755 --- a/install_agent.sh +++ b/install_agent.sh @@ -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 diff --git a/src/agent/main.cpp b/src/agent/main.cpp index d70488614613929078b46861e4dc63c622909155..42ca28d260fd4d12b9a53727006109a09dcd88c1 100644 --- a/src/agent/main.cpp +++ b/src/agent/main.cpp @@ -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; - } - reader.parse(agent_conf, conf, false); - if (conf["project"].compare("simmc") == 0) { - agent_send_inventory = true; - agent_send_net_band = true; - agent_send_user_hist = true; - } else if (conf["project"].compare("pinsis") == 0) { - agent_send_database = true; - } -} + if (!agent_conf.fail()) { + reader.parse(agent_conf, conf, false); + + 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; + } + 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) */ @@ -211,8 +210,8 @@ int main(int argc, char* argv[]) { config_agent(); set_begin(begin); - /* make parse from config files. Case if ok, then send - * web service base url to send inventory, net bandwidth + /* make parse from config files. Case if ok, then send + * web service base url to send inventory, net bandwidth * and user history */ if (read_config_files(&agent)) { diff --git a/src/agent/network_bandwidth.cpp b/src/agent/network_bandwidth.cpp index 681ba0d7acf727fa499279e4c8bd5ab68bbac05c..eb9798a292a5cebcfe212cb5f32360ac41663dac 100644 --- a/src/agent/network_bandwidth.cpp +++ b/src/agent/network_bandwidth.cpp @@ -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; diff --git a/src/agent/parse_proxy_file.cpp b/src/agent/parse_proxy_file.cpp index 9b13e7cd459830b666fbc75bc49e88709bcd93fd..0df17a51174b271448182137a2aca034fa0f9a05 100644 --- a/src/agent/parse_proxy_file.cpp +++ b/src/agent/parse_proxy_file.cpp @@ -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 diff --git a/src/agent/post.cpp b/src/agent/post.cpp index 6c275b060d86eb65e41f4045fa86ad81c6969d3f..2510f005c6b141f28ea205aaa825e24336fb17dd 100644 --- a/src/agent/post.cpp +++ b/src/agent/post.cpp @@ -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) { diff --git a/test/returnTest.bats b/test/returnTest.bats index 92f95b49d8d6f9bf328a77473086e92ea5e8ac59..3b546afa617277e7f66f50fcea503d8305ddb517 100755 --- a/test/returnTest.bats +++ b/test/returnTest.bats @@ -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" ]] }