Skip to content
Snippets Groups Projects
Commit b9c1c79c authored by Rafael S Castilho's avatar Rafael S Castilho
Browse files

SCRUM#82: created scripts to generate and install the agent

parent efc60514
No related branches found
No related tags found
2 merge requests!103Merge dev -> master,!49SCRUM#82: created scripts to generate and install the agent
{ {
"idPoint" : "1", "idPoint" : "%d",
"proxyConf" : "/conf/proxy.json", "proxyConf" : "%s",
"webService": "http://simmc.c3sl.ufpr.br/axis2/services/DataSID" "webService": "%s"
} }
{
"host" : "%s",
"port" : "%d",
"usr" : "%s",
"password" : "%s"
}
#!/bin/bash
# Copyright (C) 2016-2017 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of simmc-agent
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
mkdir agentC3SL
mkdir agentC3SL/tmp
cp bin/agent* agentC3SL/
mkdir agentC3SL/conf
cd agentC3SL/conf
touch datasid-conf.json
touch proxy.json
# idpoint proxyConf( host porta usr passwd ) webService
idPoint=""
webService=""
host=""
port=""
usr=""
passwd=""
for i in $@; do
case $i in
-idp=*)
idPoint="${i#*=}"
shift
;;
-ws=*)
webService="${i#*=}"
shift
;;
-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 " -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 " -h or --help: show this message"
exit 1
;;
-pch=*)
host="${i#*=}"
shift
;;
-pcp=*)
port="${i#*=}"
shift
;;
-pcu=*)
usr="${i#*=}"
shift
;;
-pcpssd=*)
passwd="${i#*=}"
shift
;;
*)
echo "wrong usage\ntry -h or --help for help"
exit 1
esac
done
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 > datasid-conf.json
cd ../../
cp install_agent.sh agentC3SL/
makeself --notemp --noprogress agentC3SL/ agent.run "" ./install_agent.sh
rm -rf agentC3SL
#!/bin/bash
# Copyright (C) 2016-2017 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of simmc-agent
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
cd ..
mv agentC3SL /opt/
cd /opt/agentC3SL
(crontab -l 2>/dev/null; echo "@reboot /opt/agentC3SL/agent-v*")| crontab -
...@@ -24,6 +24,10 @@ ...@@ -24,6 +24,10 @@
#include <string> #include <string>
/** Run agent */ /** Run agent */
std::string path_to_agent_tmp = // NOLINT(runtime/string)
"/opt/agentC3SL/tmp/"; // NOLINT(runtime/string)
std::string path_to_agent = "/opt/"; // NOLINT(runtime/string)
int run_agent(const sys::error_code& /*e*/, pt::ptime begin, bool print ) { int run_agent(const sys::error_code& /*e*/, pt::ptime begin, bool print ) {
pt::ptime now; pt::ptime now;
now = pt::second_clock::local_time(); now = pt::second_clock::local_time();
...@@ -43,7 +47,7 @@ int run_agent(const sys::error_code& /*e*/, pt::ptime begin, bool print ) { ...@@ -43,7 +47,7 @@ int run_agent(const sys::error_code& /*e*/, pt::ptime begin, bool print ) {
int set_begin(pt::ptime& begin, bool print) { // NOLINT (runtime/reference) int set_begin(pt::ptime& begin, bool print) { // NOLINT (runtime/reference)
std::string t; std::string t;
std::stringstream t2; std::stringstream t2;
std::fstream myfile("../build/time.txt", std::fstream myfile(path_to_agent_tmp + "time.txt",
std::fstream::app | std::fstream::in | std::fstream::out); std::fstream::app | std::fstream::in | std::fstream::out);
getline(myfile, t); getline(myfile, t);
if (t.size() == 0) { if (t.size() == 0) {
...@@ -102,7 +106,8 @@ int parse_command_line(int ac, char* av[], int *increment, int *lim, ...@@ -102,7 +106,8 @@ int parse_command_line(int ac, char* av[], int *increment, int *lim,
return (0); return (0);
if (vm.count("uninstall")) { if (vm.count("uninstall")) {
fs::remove_all("../../agent"); // remove setup to run on boot
fs::remove_all(path_to_agent + "agentC3SL");
return (1); return (1);
} }
return(0); return(0);
......
...@@ -21,6 +21,10 @@ ...@@ -21,6 +21,10 @@
#include "agent/network_bandwidth.h" #include "agent/network_bandwidth.h"
#include <string> #include <string>
extern std::string path_to_agent_tmp;
extern std::string path_to_agent;
/** /**
* @file network_bandwidth.cpp * @file network_bandwidth.cpp
* @brief Collect data from networkork bandwidth. * @brief Collect data from networkork bandwidth.
...@@ -45,10 +49,11 @@ Json::Value get_net_bandwidth() { ...@@ -45,10 +49,11 @@ Json::Value get_net_bandwidth() {
Json::Value net_band_all_time; Json::Value net_band_all_time;
Json::Reader reader; Json::Reader reader;
std::ofstream ofs; std::ofstream ofs;
std::ifstream net_band_file("net_band.json", std::ifstream::binary); std::ifstream net_band_file(path_to_agent_tmp + "net_band.json",
std::ifstream::binary);
pt::ptime time; pt::ptime time;
std::string str; std::string str;
std::fstream time_file("time_now.txt", std::ios::out|std::ios::trunc); std::fstream time_file;
#ifdef __linux__ #ifdef __linux__
// net_band_file >> net_band_all_time; // net_band_file >> net_band_all_time;
...@@ -201,21 +206,23 @@ Json::Value get_net_bandwidth() { ...@@ -201,21 +206,23 @@ Json::Value get_net_bandwidth() {
pack_tr = atoll(t.substr(j, len).c_str()); pack_tr = atoll(t.substr(j, len).c_str());
ofs.open("net_band.json", std::ios::trunc); ofs.open(path_to_agent_tmp + "net_band.json", std::ios::trunc);
net_band_all_time["data_net"]["bytes_received"] = b_rec; net_band_all_time["data_net"]["bytes_received"] = b_rec;
net_band_all_time["data_net"]["packets_received"] = pack_rec; net_band_all_time["data_net"]["packets_received"] = pack_rec;
net_band_all_time["data_net"]["bytes_transmitted"] = b_tr; net_band_all_time["data_net"]["bytes_transmitted"] = b_tr;
net_band_all_time["data_net"]["packets_tranmitted"] = pack_tr; net_band_all_time["data_net"]["packets_tranmitted"] = pack_tr;
ofs << net_band_all_time; ofs << net_band_all_time;
ofs.close(); ofs.close();
////////////////////////////////////////////////////
time_file.open(path_to_agent_tmp + "time_now.txt",
std::ios::out|std::ios::trunc);
time = pt::second_clock::local_time(); time = pt::second_clock::local_time();
time_file << time; time_file << time;
time_file.close(); time_file.close();
time_file.open("time_now.txt", std::ios::in); time_file.open(path_to_agent_tmp + "time_now.txt", std::ios::in);
getline(time_file, str); getline(time_file, str);
time_file.close(); time_file.close();
//////////////////////////////////////////////////////////////
net_band["data_net"]["bytes_received"] = b_rec - b_rec_allt; net_band["data_net"]["bytes_received"] = b_rec - b_rec_allt;
net_band["data_net"]["packets_received"] = pack_rec - pack_rec_allt; net_band["data_net"]["packets_received"] = pack_rec - pack_rec_allt;
net_band["data_net"]["bytes_transmitted"] = b_tr - b_tr_allt; net_band["data_net"]["bytes_transmitted"] = b_tr - b_tr_allt;
...@@ -223,5 +230,6 @@ Json::Value get_net_bandwidth() { ...@@ -223,5 +230,6 @@ Json::Value get_net_bandwidth() {
net_band["data_net"]["collect_time"] = str; net_band["data_net"]["collect_time"] = str;
myfile.close(); myfile.close();
return (net_band); return (net_band);
#endif #endif
} }
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