Commit b728c26a authored by Rafael Dias's avatar Rafael Dias

Merge branch 'revert-f18a6f53' into 'master'

Revert "Merge branch 'issue/22' into 'master'"

See merge request !119
parents f18a6f53 34f5ae4e
Pipeline #23477 failed with stages
in 27 minutes and 45 seconds
......@@ -9,7 +9,6 @@ stages:
pattern:
stage: lint
image: 'debian:stretch'
tags:
- regular
- debian
......@@ -22,13 +21,9 @@ pattern:
compileUnix:
stage: build
image: 'debian:stretch'
artifacts:
paths:
- agent-1234.run
- bin/agent-v0.0
- conf/datasid-conf.json
- conf/proxy-conf.json
tags:
- regular
- debian
......@@ -44,7 +39,7 @@ compileUnix:
- make
- cd ..
- chmod +x generate_agent.sh
- ./generate_agent.sh -idp=1234 -ws=www.C3Sl.ufpr.br -pch=simmcdev.c3sl.ufpr.br -pcp=3000 -pcu=ninguem -pcpasswd=123mudar -prj=simmc
- ./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
compileWin32:
......@@ -69,7 +64,7 @@ compileWin32:
- Xvfb :98 &
- export DISPLAY=:98
- cd /
- wine /home/inno/iscc ./builds/simmctic/agent/generate_agent.iss /Didp=1234 /Dws=www.C3Sl.ufpr.br /Dpch=simmcdev.c3sl.ufpr.br /Dpcp=3000 /Dpcu=ninguem /Dpcpasswd=123mudar /Dprj=simmc /Dversion=1.0.0
- wine /home/inno/iscc ./builds/simmctic/agent/generate_agent.iss /Didp=1234 /Dws=www.C3Sl.ufpr.br /Dpch=mumm /Dpcp=6666 /Dpcu=ninguem /Dpcpasswd=123mudar /Dprj=simmc /Dversion=1.0.0
- mv ./builds/simmctic/agent/agent-1234.exe ./builds/simmctic/agent/agent-32.exe
compileWin64:
......@@ -93,12 +88,11 @@ compileWin64:
- Xvfb :98 &
- export DISPLAY=:98
- cd /
- wine /home/inno/iscc ./builds/simmctic/agent/generate_agent.iss /Didp=1234 /Dws=www.C3Sl.ufpr.br /Dpch=simmcdev.c3sl.ufpr.br /Dpcp=3000 /Dpcu=ninguem /Dpcpasswd=123mudar /Dprj=simmc /Dversion=1.0.0
- wine /home/inno/iscc ./builds/simmctic/agent/generate_agent.iss /Didp=1234 /Dws=www.C3Sl.ufpr.br /Dpch=mumm /Dpcp=6666 /Dpcu=ninguem /Dpcpasswd=123mudar /Dprj=simmc /Dversion=1.0.0
- mv ./builds/simmctic/agent/agent-1234.exe ./builds/simmctic/agent/agent-64.exe
testDebian:
stage: test
image: 'debian:stretch'
tags:
- regular
- debian
......@@ -111,14 +105,12 @@ testDebian:
- cd ../test
- ./create_users.sh
- last -F
- ./init.sh
- ./returnTest.bats
dependencies:
- compileUnix
testUbuntu:
stage: test
image: 'ubuntu:16.04'
tags:
- ubuntu
- regular
......@@ -128,7 +120,6 @@ testUbuntu:
- cd test
- ./create_users.sh
- last -F
- ./init.sh
- ./returnTest.bats
dependencies:
- compileUnix
......@@ -139,7 +130,7 @@ testOpensuse:
- opensuse
script:
- zypper -n update
- zypper -n install bats jq libfaketime expect tar cron gzip
- zypper -n install bats jq libfaketime expect tar cron
- touch /var/log/wtmp
- chown root.tty /var/log/wtmp
- chmod 664 /var/log/wtmp
......@@ -147,7 +138,6 @@ testOpensuse:
- cd test
- ./create_users.sh
- last -F
- ./init.sh
- ./returnTest.bats
dependencies:
- compileUnix
......
{
"idPoint" : "%s",
"idPoint" : "%d",
"project" : "%s",
"proxyConf" : "%s",
"version" : "%s",
......
#pragma once
#include <fstream>
#include <string>
#define BIOS_DATE_PATH "/sys/devices/virtual/dmi/id"
/**
* @file get_bios_date.h
* @brief Get data from bios format (YYYY-MM-DD)
*/
std::string get_bios_date();
\ No newline at end of file
#pragma once
#include <fstream>
#include <string>
#define MACHINE_PATH "/sys/devices/virtual/dmi/id"
/**
* @file get_bios_date.h
* @brief Get data from the machine
*/
std::string get_product_name();
std::string get_product_version();
std::string get_product_serial();
std::string get_sys_vendor();
\ No newline at end of file
#pragma once
#include <fstream>
#include <string>
#define MOTHERBOARD_PATH "/sys/devices/virtual/dmi/id"
/**
* @file get_motherboard.h
* @brief Get data from the motherboard
*/
std::string get_board_vendor();
std::string get_board_serial();
std::string get_board_version();
std::string get_board_name();
\ No newline at end of file
......@@ -6,14 +6,11 @@
#include <iostream>
#include <agent/agent.h>
#include <agent/get_date.h>
#include <agent/get_bios_date.h>
#include <agent/get_disks_info.h>
#include <agent/get_distro.h>
#include <agent/get_macaddr.h>
#include <agent/get_machine.h>
#include <agent/get_machine_type.h>
#include <agent/get_memory_size.h>
#include <agent/get_motherboard.h>
#include <agent/get_processor_model.h>
#include <agent/get_time.h>
#include <agent/get_user_count.h>
......
......@@ -6,7 +6,7 @@
#include <agent/parse.h>
#include <json/json.h>
/**
/**
* @file parse_config_file.h
* @brief This file has a Conf class - The main purpose is get config file content and make parse to set in a conf object
*/
......@@ -15,20 +15,20 @@ class Agent;
class Conf{
private:
std::string idPoint;
int idPoint;
std::string pathProxyFile; /*!< Absolute path from proxy file. */
std::string webService; /*!< url from web service. */
std::string version; /*!< Current agent version */
std::string project;
public:
void setIdPoint(std::string);
void setIdPoint(int);
void setPathProxyFile(std::string);
void setWebService(std::string);
void setVersion(std::string);
void setProject(std::string);
std::string getIdPoint() const;
int getIdPoint() const;
std::string getPathProxyFile() const;
std::string getWebService() const;
std::string getVersion() const;
......@@ -38,7 +38,7 @@ class Conf{
bool parse_config_file(Agent*);
/**
/**
* @file parse_config_file.h
* @brief This file has a Conf class - The main purpose is get config file content and make parse to set in a conf object
*/
......
......@@ -140,7 +140,7 @@ bool get_agent_installer_name(Agent* agent, std::string* filename, bool opt) {
std::string ws = agent->getConf()->getWebService()
+ std::string("/api/agent/install/")
+ std::string(os) + std::string("/")
+ agent->getConf()->getIdPoint();
+ std::to_string(agent->getConf()->getIdPoint());
if (opt)
status_code = agent->getConnection()->getInstallerName(ws, agent, filename, opt); // NOLINT [whitespace/line_length]
......@@ -208,7 +208,7 @@ void execute_agent(Agent* agent, boost::filesystem::path tmp) {
}
/**
/**
* @file get.cpp
* @brief Check case if has a new agent version available
*/
/* Copyright (C) 2019 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.
*/
#include <agent/get_bios_date.h>
std::string get_bios_date() {
#ifdef __unix__
std::ifstream file;
std::string line, d, m, y, format = "", err;
file.open((std::string)BIOS_DATE_PATH + "/bios_date");
if (file.is_open()) {
getline(file, line);
if (line.empty()) {
err = "The file " + (std::string)BIOS_DATE_PATH \
+ "/bios_date is empty";
throw err;
}
m = line.substr(0, 2);
d = line.substr(3, 2);
y = line.substr(6, 4);
format = y + "-" + m + "-" + d;
} else {
err = "Could not open" + (std::string)BIOS_DATE_PATH \
+ "/bios_date";
throw err;
}
file.close();
return format;
#elif WIN32
std::string err = "Feature not supported on Windows";
throw err;
#endif
}
/* Copyright (C) 2019 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.
*/
#include <agent/get_machine.h>
std::string get_product_name() {
#ifdef __unix__
std::ifstream file;
std::string data = "", err;
file.open((std::string)MACHINE_PATH + "/product_name");
if (file.is_open()) {
getline(file, data);
if (data.empty()) {
err = "The file " + (std::string)MACHINE_PATH \
+ "/product_name is empty";
throw err;
}
} else {
err = "Could not open" + (std::string)MACHINE_PATH + "/product_name";
throw err;
}
file.close();
return data;
#elif WIN32
std::string err = "Feature not supported on Windows";
throw err;
#endif
}
std::string get_product_version() {
#ifdef __unix__
std::ifstream file;
std::string data = "", err;
file.open((std::string)MACHINE_PATH + "/product_version");
if (file.is_open()) {
getline(file, data);
if (data.empty()) {
err = "The file " + (std::string)MACHINE_PATH \
+ "/product_version is empty";
throw err;
}
} else {
err = "Could not open" + (std::string)MACHINE_PATH \
+ "/product_version";
throw err;
}
file.close();
return data;
#elif WIN32
std::string err = "Feature not supported on Windows";
throw err;
#endif
}
std::string get_product_serial() {
#ifdef __unix__
std::ifstream file;
std::string data = "", err;
file.open((std::string)MACHINE_PATH + "/product_serial");
if (file.is_open()) {
getline(file, data);
if (data.empty()) {
err = "The file " + (std::string)MACHINE_PATH \
+ "/product_serial is empty";
throw err;
}
} else {
err = "Could not open" + (std::string)MACHINE_PATH \
+ "/product_serial";
throw err;
}
file.close();
return data;
#elif WIN32
std::string err = "Feature not supported on Windows";
throw err;
#endif
}
std::string get_sys_vendor() {
#ifdef __unix__
std::ifstream file;
std::string data = "", err;
file.open((std::string)MACHINE_PATH + "/sys_vendor");
if (file.is_open()) {
getline(file, data);
if (data.empty()) {
err = "The file " + (std::string)MACHINE_PATH \
+ "/sys_vendor is empty";
throw err;
}
} else {
err = "Could not open" + (std::string)MACHINE_PATH \
+ "/sys_vendor";
throw err;
}
file.close();
return data;
#elif WIN32
std::string err = "Feature not supported on Windows";
throw err;
#endif
}
/* Copyright (C) 2019 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.
*/
#include <agent/get_motherboard.h>
std::string get_board_vendor() {
#ifdef __unix__
std::ifstream file;
std::string data = "", err;
file.open((std::string)MOTHERBOARD_PATH + "/board_vendor");
if (file.is_open()) {
getline(file, data);
if (data.empty()) {
err = "The file " + (std::string)MOTHERBOARD_PATH \
+ "/board_vendor is empty";
throw err;
}
} else {
err = "Could not open" + (std::string)MOTHERBOARD_PATH \
+ "/board_vendor";
throw err;
}
file.close();
return data;
#elif WIN32
std::string err = "Feature not supported on Windows";
throw err;
#endif
}
std::string get_board_serial() {
#ifdef __unix__
std::ifstream file;
std::string data = "", err;
file.open((std::string)MOTHERBOARD_PATH + "/board_serial");
if (file.is_open()) {
getline(file, data);
if (data.empty()) {
err = "The file " + (std::string)MOTHERBOARD_PATH \
+ "/board_serial is empty";
throw err;
}
} else {
err = "Could not open" + (std::string)MOTHERBOARD_PATH \
+ "/board_serial";
throw err;
}
file.close();
return data;
#elif WIN32
std::string err = "Feature not supported on Windows";
throw err;
#endif
}
std::string get_board_version() {
#ifdef __unix__
std::ifstream file;
std::string data = "", err;
file.open((std::string)MOTHERBOARD_PATH + "/board_version");
if (file.is_open()) {
getline(file, data);
if (data.empty()) {
err = "The file " + (std::string)MOTHERBOARD_PATH \
+ "/board_version is empty";
throw err;
}
} else {
err = "Could not open" + (std::string)MOTHERBOARD_PATH \
+ "/board_version";
throw err;
}
file.close();
return data;
#elif WIN32
std::string err = "Feature not supported on Windows";
throw err;
#endif
}
std::string get_board_name() {
#ifdef __unix__
std::ifstream file;
std::string data = "", err;
file.open((std::string)MOTHERBOARD_PATH + "/board_name");
if (file.is_open()) {
getline(file, data);
if (data.empty()) {
err = "The file " + (std::string)MOTHERBOARD_PATH \
+ "/board_name is empty";
throw err;
}
} else {
err = "Could not open" + (std::string)MOTHERBOARD_PATH \
+ "/board_name";
throw err;
}
file.close();
return data;
#elif WIN32
std::string err = "Feature not supported on Windows";
throw err;
#endif
}
......@@ -132,7 +132,7 @@ Json::Value get_inventory(Agent* agent) {
inv["data_inventory"]["disk1_size"] = Json::nullValue;
inv["data_inventory"]["disk2_model"] = Json::nullValue;
inv["data_inventory"]["disk2_size"] = Json::nullValue;
inv["data_inventory"]["extra_hds"] = 0;
inv["data_inventory"]["extra_hds"] = Json::nullValue;
inv["error_inventory"]["disk1_model"] = err;
inv["error_inventory"]["disk1_size"] = err;
......@@ -151,80 +151,18 @@ Json::Value get_inventory(Agent* agent) {
inv["error_inventory"]["disk1_used"] = err;
}
// hw info
/*
inv["disk1_used"] =
inv["disk2_used"] =
*/
// date bios
try {
inv["data_inventory"]["date_bios"] = get_bios_date();
} catch (std::string err) {
inv["data_inventory"]["date_bios"] = Json::nullValue;
inv["error_inventory"]["date_bios"] = err;
}
// board name
try {
inv["data_inventory"]["board_name"] = get_board_name();
} catch (std::string err) {
inv["data_inventory"]["board_name"] = Json::nullValue;
inv["error_inventory"]["board_name"] = err;
}
// board serial
try {
inv["data_inventory"]["board_serial"] = get_board_serial();
} catch (std::string err) {
inv["data_inventory"]["board_serial"] = Json::nullValue;
inv["error_inventory"]["board_serial"] = err;
}
// board vendor
try {
inv["data_inventory"]["board_vendor"] = get_board_vendor();
} catch (std::string err) {
inv["data_inventory"]["board_vendor"] = Json::nullValue;
inv["error_inventory"]["board_vendor"] = err;
}
// board version
try {
inv["data_inventory"]["board_version"] = get_board_version();
} catch (std::string err) {
inv["data_inventory"]["board_version"] = Json::nullValue;
// other
/*
inv["agent_version"] =
inv["contact_date"] =
*/
inv["error_inventory"]["board_version"] = err;
}
// product name
try {
inv["data_inventory"]["product_name"] = get_product_name();
} catch (std::string err) {
inv["data_inventory"]["product_name"] = Json::nullValue;
inv["error_inventory"]["product_name"] = err;
}
// product serial
try {
inv["data_inventory"]["product_serial"] = get_product_serial();
} catch (std::string err) {
inv["data_inventory"]["product_serial"] = Json::nullValue;
inv["error_inventory"]["product_serial"] = err;
}
// product version
try {
inv["data_inventory"]["product_version"] = get_product_version();
} catch (std::string err) {
inv["data_inventory"]["product_version"] = Json::nullValue;
inv["error_inventory"]["product_version"] = err;
}
// sys vendor
try {
inv["data_inventory"]["sys_vendor"] = get_sys_vendor();
} catch (std::string err) {
inv["data_inventory"]["sys_vendor"] = Json::nullValue;
inv["error_inventory"]["sys_vendor"] = err;
}
// machine type
#ifdef WIN32
......
......@@ -189,7 +189,6 @@ int main(int argc, char* argv[]) {
agent.setProxy(&proxy);
int increment = 0;
int bit_mask = 0;
int lim = 1;
bool print;
bool dev = false;
......@@ -218,19 +217,13 @@ int main(int argc, char* argv[]) {
if (read_config_files(&agent)) {
if (agent_send_inventory) {
if (!send_inventory(print, &agent)) {
bit_mask |= 1;
}
send_inventory(print, &agent);
}
if (agent_send_net_band) {
if (!send_net_bandwidth(print, &agent)) {
bit_mask |= 2;
}
send_net_bandwidth(print, &agent);
}
if (agent_send_user_hist) {
if (!send_user_history(print, &agent)) {
bit_mask |= 4;
}
send_user_history(print, &agent);
}
if (agent_send_database) {
// get database for PInSIS
......@@ -238,7 +231,7 @@ int main(int argc, char* argv[]) {
}
if (lim == 0) {
return bit_mask;
return (0);
}
int i = 0;
......
......@@ -29,7 +29,7 @@
/** Set id Point */
void Conf::setIdPoint(std::string i) {
void Conf::setIdPoint(int i) {
this->idPoint = i;
}
......@@ -43,7 +43,7 @@ void Conf::setWebService(std::string web) {
this->webService = web;
}
/** Get the agent version from config file, at conf directory,
/** Get the agent version from config file, at conf directory,
* and setted the version attribute. */
void Conf::setVersion(std::string v) {
this->version = v;
......@@ -55,7 +55,7 @@ void Conf::setProject(std::string p) {
}
/** Return id Point */
std::string Conf::getIdPoint() const {
int Conf::getIdPoint() const {
return this->idPoint;
}