Commit 2746cce4 authored by Diego Giovane Pasqualin's avatar Diego Giovane Pasqualin

Merge branch 'issue/141' into 'development'

SCRUM#140 - Add option to run agent.exe when update agent and make some comments…

See merge request !101
parents 8cc26d7f ff217103
Pipeline #12572 passed with stages
in 20 minutes and 43 seconds
......@@ -101,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 $project /opt/agentC3SL/conf/proxy-conf.json $version $webService > datasid-conf.json
printf "$tmp\n" $idPoint $project conf/proxy-conf.json $version $webService > datasid-conf.json
cd ../../..
......
......@@ -14,14 +14,16 @@
* @brief This file has the Agent class and in it is saved info about the current agent,
* like absolute path, current versio and so on.
* The Agent class has 8 attributes:
* - confDir - Absolute path from conf directory (/opt/agentc3sl/conf)
* - configFileName - Absolute path from config file (/opt/agentc3sl/conf/datasid-conf.json)
* - dirInstall - Absolute path from local to install agent (/opt/agentc3sl)
* - logFile - Absolute path from log file (/opt/agentc3sl/log/datasid-agent.log)
* - message - Success, warning and error messages to be setted in logfile
* - prefix - Absolute path from agent - get current local (path) of agent
* - version - Current agent version
* - runName Name of agent .run file
*
* - pathConfDir - Absolute path from conf directory (/opt/agentc3sl/conf)
* - pathConfigFile - Absolute path from config file (/opt/agentc3sl/conf/datasid-conf.json)
* - pathDirInstall - Absolute path from local to install agent (/opt/agentc3sl)
* - pathLogDir - Absolute path from log file (/opt/agentc3sl/log/datasid-agent.log)
* - prefix - Absolute path from agent - get current local (path) of agent
* - installerName Name of (agent.run) or (agent.exe) file
* - *connection Pointer from Connection object (make get or post request with or without proxy)
* - *conf Pointer from Conf object
* - *proxy Pointer from Proxy object
* <br><br>
*/
......@@ -38,9 +40,9 @@ class Agent{
std::string pathLogFile; /*!< Absolute path from log file */
std::string prefix; /*!< Absolute path from agent */
std::string installerName; /*!< Name of agent installer file */
Connection* connection;
Conf* conf;
Proxy* proxy;
Connection* connection; /*!< make get or post request with or without proxy */
Conf* conf; /*!< agent config */
Proxy* proxy; /*!< proxy config */
public:
// We can't return fstream type
......
......@@ -11,10 +11,10 @@
#include <json/json.h>
/**
* @file curl.h
* @brief This file has Curl class and the purpose is to make a get request to web service and download the agent zip file
* @file connection.h
* @brief This file has Curl class and the purpose is to make a get or post request to web service and download the agent zip file
* - Obs
* - Using libcurl to make a get request (curl/curl.h)
* - Using libcurl to make a get or post request (curl/curl.h)
*/
class Agent; // forward declarations
......@@ -33,7 +33,7 @@ class Connection{
int sendJsonByProxy(Agent*, std::string, int);
/** Default callback function that is necessary to make a curl request.
* @brief Obs:
* @brief get agent binary (agent.run or agent.exe)
* - Parameters from this method is define by curl lib (curl/curl.h);
*/
static size_t callBackDownload(void *ptr, size_t size, size_t nmemb,void* userdata) {
......@@ -46,6 +46,10 @@ class Connection{
return written;
}
/** Default callback function that is necessary to make a curl request.
* @brief get version agent or filename installer
* - Parameters from this method is define by curl lib (curl/curl.h);
*/
static size_t callback(void *contents, size_t size, size_t nmemb, void *userp) {
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
......
......@@ -25,5 +25,5 @@ int check_update(Agent*);
bool create_directories(std::string);
bool compare_version(Agent*, std::string);
bool download(Agent*, std::string, int);
void execute_agent(boost::filesystem::path);
void execute_agent(Agent*, boost::filesystem::path);
bool get_agent_installer_name(Agent*, std::string*, int);
......@@ -26,7 +26,6 @@ void Agent::setPathConfDir(std::string dir) {
this->pathConfDir = this->prefix + dir;
}
/** Set the absolute path of config filename */
void Agent::setPathConfigFile(std::string filename) {
this->pathConfigFile = this->prefix + filename;
......@@ -65,14 +64,17 @@ void Agent::setInstallerName(std::string i) {
this->installerName = i;
}
/** Set connection object */
void Agent::setConnection(Connection* c) {
this->connection = c;
}
/** Set conf object */
void Agent::setConf(Conf* conf) {
this->conf = conf;
}
/** Set proxy object */
void Agent::setProxy(Proxy* proxy) {
this->proxy = proxy;
}
......@@ -109,14 +111,17 @@ std::string Agent::getInstallerName() const {
return this->installerName;
}
/** Return connection object pointer */
Connection* Agent::getConnection() const {
return this->connection;
}
/** Return conf object pointer */
Conf* Agent::getConf() const {
return this->conf;
}
/** Return proxy object pointer */
Proxy* Agent::getProxy() const {
return this->proxy;
}
......@@ -132,13 +137,16 @@ void Agent::prefixISet() {
* @brief This file has the implementation from Agent's method and in it is saved info about the current agent,
* like absolute path, current version and so on.
* The Agent class has 8 attributes:
* - confDir - Absolute path from conf directory (/opt/agentc3sl/conf)
* - configFileName - Absolute path from config file (/opt/agentc3sl/conf/datasid-conf.json)
* - dirInstall - Absolute path from local to install agent (/opt/agentc3sl)
* - logFile - Absolute path from log file (/opt/agentc3sl/log/datasid-agent.log)
* - message - Success, warning and error messages to be setted in logfile
* - prefix - Absolute path from agent - get current local (path) of agent
* - version - Current agent version
*
* - pathConfDir - Absolute path from conf directory (/opt/agentc3sl/conf)
* - pathConfigFile - Absolute path from config file (/opt/agentc3sl/conf/datasid-conf.json)
* - pathDirInstall - Absolute path from local to install agent (/opt/agentc3sl)
* - pathLogDir - Absolute path from log file (/opt/agentc3sl/log/datasid-agent.log)
* - prefix - Absolute path from agent - get current local (path) of agent
* - version - Current agent version
* - installerName Name of agent installer
* - *connection Pointer from Connection object (make get or post request with or without proxy)
* - *conf Pointer from Conf object
* - *proxy Pointer from Proxy object
* <br><br>
*/
......@@ -27,10 +27,9 @@
* - Not downloading file from https protocol;
* - Is a get request.
*
* @param url references to webService
* @param agent object agent
* @param data json object to save success, error and warning messages
* @param logFile references from logfile to save success, error and warning messages
* @param url references to webService
* @param agent object agent
* @param option use proxy or not (option == 0 - use proxy)
*/
bool Connection::downloadAgent(std::string url, Agent* agent, int option) {
curl = curl_easy_init();
......@@ -121,7 +120,7 @@ bool Connection::downloadAgent(std::string url, Agent* agent, int option) {
fclose(fp);
// run agent.run on linux
execute_agent(file_installer);
execute_agent(agent, file_installer);
// remove agent tmp directory
boost::uintmax_t res = boost::filesystem::remove_all(tmp_dir_agent);
......@@ -139,6 +138,14 @@ bool Connection::downloadAgent(std::string url, Agent* agent, int option) {
return true;
}
/** Set curl default options
* @brief Obs:
* - Is a get request.
*
* @param url references to webService
* @param agent object agent
* @param version pointer variable thats receive version or filename from web service.
*/
void Connection::setCurlOption(std::string url, Agent* agent,
std::string* out) {
std::string::size_type sz; // NOLINT [runtime/int]
......@@ -167,6 +174,14 @@ void Connection::setCurlOption(std::string url, Agent* agent,
curl_easy_cleanup(curl);
}
/** Contact webservice server using proxy to get version.
* @brief Obs:
* - Is a get request.
*
* @param url references to webService
* @param agent object agent
* @param version pointer variable thats receive version from web service;
*/
bool Connection::getVersionByProxy(Agent* agent, std::string *version,
std::string url) {
struct curl_slist *headers = NULL;
......@@ -185,6 +200,14 @@ bool Connection::getVersionByProxy(Agent* agent, std::string *version,
return false;
}
/** Contact webservice server using proxy to get installer name.
* @brief Obs:
* - Is a get request.
*
* @param url references to webService
* @param agent object agent
* @param version pointer variable thats receive file name from web service;
*/
int Connection::getInstallerNameByProxy(std::string url, Agent* agent,
std::string* filename) {
curl = curl_easy_init();
......@@ -192,6 +215,14 @@ int Connection::getInstallerNameByProxy(std::string url, Agent* agent,
return httpCode;
}
/** Contact webservice server using proxy to send json (inventory, net_usage or user_history)
* @brief Obs:
* - Is a post request.
*
* @param agent object agent
* @param json references to json
* @param opt opt == 0 (send inventory) | opt == 2 (send net bandwidth) | otherwise (send user history)
*/
int Connection::sendJsonByProxy(Agent* agent, std::string json, int opt) {
std::string::size_type sz; // NOLINT [runtime/int]
long port; // NOLINT [runtime/int]
......@@ -238,15 +269,15 @@ int Connection::sendJsonByProxy(Agent* agent, std::string json, int opt) {
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
curl_easy_cleanup(curl);
return httpCode;
return this->httpCode;
}
/**
* @file curl.cpp
* @brief This file has implementation from Curl's method and the purpose is to make a get request to web
* @file connection.cpp
* @brief This file has implementation from Curl's method and the purpose is to make a get or post request to web
* service and download the agent zip file
* - Obs
* - Using libcurl to make a get request (curl/curl.h)
* - Using libcurl to make a get or post request (curl/curl.h)
*/
......@@ -27,7 +27,7 @@
*
* Get agent agent version from webService. Compare to cliente version;
* <br>
* Case if needed, making download from agent zipfile.
* Case if needed, making download from agent (.run) or (.exe)).
*/
int check_update(Agent* agent) {
......@@ -199,19 +199,24 @@ bool create_directories(std::string dir) {
}
/**
* Giving execute permission to agent.run and run it.
* Giving execute permission to agent.run and run it or run agent.exe
*/
void execute_agent(boost::filesystem::path tmp) {
#ifdef __linux__
// Execute permission to agent-0.run
std::string chmod = "chmod 777 " + std::string(tmp.c_str());
try {
void execute_agent(Agent* agent, boost::filesystem::path tmp) {
try {
#ifdef __linux__
std::string chmod = "chmod 777 " + std::string(tmp.c_str());
system(chmod.c_str());
exec(tmp.c_str());
} catch (std::string err) {
// something
}
#endif
#else
std::string cmd = tmp.string() +
std::string(" /SILENT /VERYSILENT");
exec(cmd.c_str());
#endif
} catch (std::string err) {
agent->logFile << __DATE__ + std::string(" - ERROR: Failed to ") +
std::string("execute (agent.run) or (agent.exe) update.")
<< std::endl;
}
}
......
......@@ -101,6 +101,7 @@ void get_scsi_disks(std::list<disk_t>& disks) { // NOLINT(runtime/references)
udev_unref(udev);
}
/** Get the disk used on Linux machine */
int get_disk_used() {
try {
std::string cmd = exec("df -h . | awk '{print $3}' | sed 1d");
......@@ -138,6 +139,7 @@ void get_scsi_disks(std::list<disk_t>& disks) { // NOLINT(runtime/references)
}
}
/** Get the disk used on Windows machine */
int get_disk_used() {
try {
std::string free_space, total_size, free_output, total_output;
......@@ -176,7 +178,7 @@ int get_disk_used() {
#endif
/** Get disks info (Model and size) */
/** Get disks info (Model, size and total disk used) */
void get_disks_info(std::list<disk_t>& disks) { // NOLINT(runtime/references)
get_scsi_disks(disks);
......
......@@ -27,6 +27,7 @@
* - Debian
* - Linux Comunicações
* - Linux Educacional
* - Windows distro
* - Get distro info also from
* - Fedora info at /etc/os-release file
* - OpenSUSE info at /etc/redhat-release file;
......
......@@ -20,7 +20,7 @@
*/
#include <agent/get_memory_size.h>
/** Get memory size info from /proc/meminfo file
/** Get memory size.
*/
int get_memory_size() {
std::string memsize;
......@@ -72,5 +72,5 @@ int get_memory_size() {
/**
* @file get_memory_size.cpp
* @brief Get memory size info from /proc/meminfo file
* @brief Get memory size info from /proc/meminfo file on linux machine. On windows, use wmic command.
*/
......@@ -20,7 +20,7 @@
*/
#include <agent/get_processor_model.h>
/** Get processor model info from /proc/cpuinfo file */
/** Get processor model info */
std::string get_processor_model() {
std::string line;
#ifdef __unix__
......@@ -55,5 +55,5 @@ std::string get_processor_model() {
}
/** @file get_processor_model.cpp
* @brief Case if linux OS, get processor model info from /proc/cpuinfo file
* @brief Case if linux OS, get processor model info from /proc/cpuinfo file. On windows, use wmic command.
*/
......@@ -144,6 +144,11 @@ int parse_command_line(int ac, char* av[], int *increment, int *lim,
return(0);
}
/** Read config file (datasid-conf.json and proxy-conf.json) and parse it to respective objects
* - Options:
* - *agent - pointer to agent object
*/
bool read_config_files(Agent* agent) {
/* Set conf's file */
agent->setPathConfDir("/conf");
......
......@@ -34,6 +34,9 @@ extern std::string path_to_agent_conf;
* - Packets recived
* - Bytes transmited
* - Packets transmited
* - date collected
* - time collected
* - id Point
* .
* Linux has a file (/proc/net/dev) that contain info about network bandwidth
* <br>
......
......@@ -54,7 +54,6 @@ void Conf::setProject(std::string p) {
this->project = p;
}
/** Return id Point */
int Conf::getIdPoint() const {
return this->idPoint;
......
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