diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8d2ecd847d3ac39814898592576afd2c23b32114..fb8cc0e57e72b615c17e8e0ac632169926da1565 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -35,7 +35,7 @@ compile: - make - cd .. - chmod +x generate_agent.sh - - ./generate_agent.sh -idp=1234 -ws=www.C3Sl.ufpr.br -pch=mumm -pcp=6666 -pcu=ninguem -pcpasswd=123mudar + - ./generate_agent.sh -idp=1234 -ws=www.C3Sl.ufpr.br -pch=mumm -pcp=6666 -pcu=ninguem -pcpasswd=123mudar -prj=simmc - chmod +x agent-1234.run testDebian: diff --git a/conf/datasid-conf.json b/conf/datasid-conf.json index dbffc3ef6cb0fa9cb1a9a38f2a7798abe0bfde1c..53fe43f6af284f318429ef66a7b67801ef45c27b 100644 --- a/conf/datasid-conf.json +++ b/conf/datasid-conf.json @@ -1,6 +1,7 @@ { -"idPoint" : "%d", -"proxyConf" : "%s", -"webService": "%s", -"version": "%s" + "idPoint" : "%d", + "proxyConf" : "%s", + "webService": "%s", + "version": "%s", + "project" : "%s" } diff --git a/generate_agent.sh b/generate_agent.sh index adea54808070038a9c0d263d1bfca77853847061..a2aa5b8ed02cae577b54cd07aac2c0a751243516 100755 --- a/generate_agent.sh +++ b/generate_agent.sh @@ -30,6 +30,7 @@ port="" usr="" passwd="" destination="./" +project="simmc" dir=$(dirname $0) cd $dir @@ -76,6 +77,10 @@ for i in $@; do version="${i#*=}" shift ;; + -prj=*) + project="${i#*=}" + shift + ;; *) echo "wrong usage\ntry -h or --help for help" exit 1 @@ -96,7 +101,7 @@ tmp=$(cat ../../../conf/proxy-conf.json) printf "$tmp\n" $host $port $usr $passwd > proxy.json tmp=$(cat ../../../conf/datasid-conf.json) -printf "$tmp\n" $idPoint /opt/agentC3SL/conf/proxy.json $webService $version > datasid-conf.json +printf "$tmp\n" $idPoint /opt/agentC3SL/conf/proxy.json $webService $version $project > datasid-conf.json cd ../../.. diff --git a/src/agent/main.cpp b/src/agent/main.cpp index 640bedd89be6e6f22efc3475289e90aeea1cb170..9eb639a25379646a8201250a200d831370c4887e 100644 --- a/src/agent/main.cpp +++ b/src/agent/main.cpp @@ -20,25 +20,34 @@ */ #include <agent/main.h> #include <string> +#include <iostream> std::string path_to_agent_tmp = // NOLINT(runtime/string) "/opt/agentC3SL/tmp/"; // NOLINT(runtime/string) std::string path_to_agent = "/opt/"; // NOLINT(runtime/string) std::string path_to_agent_conf = // NOLINT(runtime/string) "/opt/agentC3SL/conf/"; // NOLINT(runtime/string) +bool agent_send_inventory = false; +bool agent_send_net_band = false; +bool agent_send_user_hist = false; +bool agent_send_database = false; /** Run agent */ int run_agent(const sys::error_code& /*e*/, pt::ptime begin, bool print ) { pt::ptime now; now = pt::second_clock::local_time(); pt::time_duration t3 = now - begin; - if ((t3.minutes() % 5 == 0 )) { + if (agent_send_net_band && (t3.minutes() % 5 == 0 )) { send_net_bandwidth(print); } if ((t3.hours() % 24 == 0) && (t3.minutes() %60 == 0 )) { check_update(); - send_inventory(print); - send_user_history(print); + if (agent_send_inventory) { + send_inventory(print); + } + if (agent_send_user_hist) { + send_user_history(print); + } } return(0); } @@ -61,10 +70,18 @@ int set_begin(pt::ptime& begin, bool print) { // NOLINT (runtime/reference) myfile << "\n"; check_update(); - send_inventory(print); - send_net_bandwidth(print); - send_user_history(print); - + if (agent_send_inventory) { + send_inventory(print); + } + if (agent_send_net_band) { + send_net_bandwidth(print); + } + if (agent_send_user_hist) { + send_user_history(print); + } + if (agent_send_database) { + // get database for PInSIS + } myfile.close(); return(0); } else { @@ -76,6 +93,34 @@ int set_begin(pt::ptime& begin, bool print) { // NOLINT (runtime/reference) } } +/** Configurate the agent + * if the agent is added to more projects, this function may be edited +*/ +void config_agent() { + Json::Reader reader; + Json::Value conf; + 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; + } +} + /** Parse command line * - Options: * - Help - help message @@ -129,16 +174,26 @@ int main(int argc, char* argv[]) { int increment = 0; int lim = 1; bool print; + pt::ptime begin; if (parse_command_line(argc, argv, &increment, &lim, &print)) { return (1); } - pt::ptime begin; + config_agent(); if (set_begin(begin, print) && lim == 0) { check_update(); - send_inventory(print); - send_net_bandwidth(print); - send_user_history(print); + if (agent_send_inventory) { + send_inventory(print); + } + if (agent_send_net_band) { + send_net_bandwidth(print); + } + if (agent_send_user_hist) { + send_user_history(print); + } + if (agent_send_database) { + // get database for PInSIS + } return (0); }