Commit 854543f1 authored by Diego Giovane Pasqualin's avatar Diego Giovane Pasqualin
Browse files

Merge branch 'development' into 'master'

Merge development to master

See merge request !51
parents 1f77d3a5 efc60514
Pipeline #10277 passed with stages
in 18 minutes and 43 seconds
build/*
bin/*
test/docker/*/agent/*
test/docker/*/*.sh
log/*
styleguide/*
Documentation/*
stages:
- lint
- build
- test
pattern:
stage: lint
tags:
- regular
- debian
script:
- shopt -s extglob
- apt-get update && apt-get install -y git python
- git clone https://github.com/google/styleguide
- cd styleguide/cpplint
- ./cpplint.py --filter=-whitespace/blank_line,-build/include_what_you_use ../../src/agent/!(jsoncpp).cpp
compile:
stage: build
artifacts:
paths:
- bin/
tags:
- regular
- debian
script:
- echo "Estágio 'build'"
- apt-get update && apt-get install -y build-essential cmake git makeself
libudev-dev
- git submodule init
- git submodule update --init --recursive
- mkdir build
- cd build
- cmake -DCURL_STATICLIB=ON ..
- make
- cd ..
- makeself --notemp --noprogress bin/ agent.run "" ./agent-v0.0 --once --print
- chmod +x agent.run
- mv agent.run bin/
testDebian:
stage: test
tags:
- regular
- debian
script:
- apt-get update && apt-get install -y git jq faketime expect
- git clone https://github.com/sstephenson/bats.git
- cd bats
- ./install.sh /usr
- cd ../test
- ./create_users.sh
- last -F
- ./returnTest.bats
dependencies:
- compile
testUbuntu:
stage: test
tags:
- ubuntu
- regular
script:
- apt-get update && apt-get install -y bats jq faketime expect
- cd test
- ./create_users.sh
- last -F
- ./returnTest.bats
dependencies:
- compile
testOpensuse:
stage: test
tags:
- opensuse
script:
- zypper -n update
- zypper -n install bats jq libfaketime expect tar
- touch /var/log/wtmp
- chown root.tty /var/log/wtmp
- chmod 664 /var/log/wtmp
- cd test
- ./create_users.sh
- last -F
- ./returnTest.bats
dependencies:
- compile
[submodule "lib/cpr"]
path = lib/cpr
url = https://github.com/whoshuu/cpr.git
[submodule "lib/jsoncpp"]
path = lib/jsoncpp
url = https://github.com/open-source-parsers/jsoncpp.git
cmake_minimum_required( VERSION 2.6 )
cmake_minimum_required( VERSION 2.8.7 )
project( simmc-agent )
......@@ -9,18 +9,10 @@ set ( VERSION_MINOR 0 )
# cpr requires c++11
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
# src : main + jsoncpp library
file ( GLOB SOURCES src/*.cpp )
# src : collect functions - depend on OS
if ( WIN32 )
file ( GLOB SOURCES ${SOURCES} src/windows/*.cpp )
else () # if( UNIX )
file ( GLOB SOURCES ${SOURCES} src/linux/*.cpp )
endif ()
# src : main, collect functions + jsoncpp library
file ( GLOB SOURCES src/agent/*.cpp )
# src : curl requests
......@@ -32,38 +24,39 @@ option( BUILD_CPR_TESTS "Set to ON to build cpr tests." OFF )
# options for curl
# avoid building tests
option( BUILD_CURL_TESTS "Set to ON to build cURL tests." ON )
option( BUILD_CURL_TESTS "Set to ON to build cURL tests." OFF )
# avoid running tests - set ON again in download version or if errors occur
option( RUN_CURL_TESTS "Set to ON to run cURL tests." ON )
option( RUN_CURL_TESTS "Set to ON to run cURL tests." OFF )
option( CURL_STATICLIB "Set to ON to generated curl statically." ON )
add_subdirectory ( lib/cpr )
include_directories ( ${CPR_INCLUDE_DIRS} )
include_directories ( ${CURL_INCLUDE_DIRS} )
# src : DtWinVer - Windows Version/Edition class
if ( WIN32 )
add_subdirectory ( lib/dtwinver )
add_subdirectory ( lib/dtwinver )
endif ()
# headers
include_directories ( "include" )
# include headers from boost lib
include_directories ( "${CMAKE_BINARY_DIR}/include" )
# test
option( PRINT_JSON "Set to ON to print json objects before sending" OFF )
message(STATUS "${PRINT_JSON}: ${${PRINT_JSON}}")
if ( PRINT_JSON )
add_definitions ( -DPRINT_JSON )
endif ()
# scr = libboost
include ( "modules/boost.cmake" )
# compile
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin" )
add_executable ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${SOURCES} )
target_link_libraries ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${CPR_LIBRARIES} ${CURL_LIBRARIES} ${FILESYSTEM_LIB} ${SYSTEM_LIB} ${REGEX_LIB} ${PROGRAM_OPTIONS_LIB})
target_link_libraries ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${CPR_LIBRARIES} )
add_dependencies ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} Boost)
if ( WIN32 )
target_link_libraries ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} dtwinver )
endif()
target_link_libraries ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} dtwinver )
else ()
# libudev
target_link_libraries ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} udev )
endif ()
This diff is collapsed.
This diff is collapsed.
......@@ -5,7 +5,9 @@ The agent for the SIMMC - Sistema de Monitoramento do Ministério das Comunicaç
requirements
------------
c++ compiler
cmake
libudev
building and compiling
----------------------
......@@ -18,7 +20,7 @@ to generate a `Makefile`, library objects and misterious CMake files, then
$ make
to compile. The resulting executable `agent-vx.x` 'will be in `agent/bin`.
to compile. The resulting executable `agent-vx.x` will be in `agent/bin`.
Run it with
$ ./agent-vx.x
......@@ -57,6 +59,41 @@ at something that was already corrected, run
inside the `build` directory and cmake again.
### building and compiling ###
As above.
When compiling and executing the agent locally, in order to see the resulting
JSON objects, run cmake with the option `PRINT_JSON`
$ cmake -DPRINT_JSON=ON ..
You may also set the `Debug` flag if using gdb
$ cmake -DCMAKE_BUILD_TYPE=Debug -DPRINT_JSON=ON ..
documentation
-------------
Clone doxygen project from github
$ git clone https://github.com/doxygen/doxygen
requirements - flex lib
-----------------------
$ apt-get install flex
Building and compiling
----------------------
$ cd doxygen
$ mkdir build
$ cmake -G "Unix Makefiles" ..
$ make
Testing
-------
Execute doxygen to generate the simmc-agent documentation
$ doxygen Doxyfile
Will be generated a Documentation directory that contains HTML pages for each file from agent
TODO: add DEBUG or DEV option.
{
"idPoint" : "1",
"proxyConf" : "/conf/proxy.json",
"webService": "http://simmc.c3sl.ufpr.br/axis2/services/DataSID"
}
#pragma once
#include <iostream>
#include <fstream>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include <json/json.h>
/**
* @file agent.h
* @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
* <br><br>
*/
class Agent{
private:
std::string confDir; /*!< Absolute path from conf directory */
std::string configFile; /*!< Absolute path from config file */
std::string dirInstall; /*!< Absolute path from local to install agent */
std::string logDir; /*!< Absolute path from log directory */
std::string logFile; /*!< Absolute path from log file */
std::string message; /*!< Success, warning and error messages to be setted in logfile */
std::string prefix; /*!< Absolute path from agent */
std::string version; /*!< Current agent version */
std::string runName; /*!< Name of agent .run file */
public:
void setConfDir(std::string);
void setConfigFile(std::string);
void setDirInstall(std::string);
void setLogDir(std::string);
void setLogFile(std::string);
void setMessage(std::string);
void setPrefix(std::string, int);
void setVersion(std::string);
void setRunName(std::string);
std::string getConfDir() const;
std::string getConfigFile() const;
std::string getDirInstall() const;
std::string getLogDir() const;
std::string getLogFile() const;
std::string getMessage() const;
std::string getPrefix() const;
std::string getVersion() const;
std::string getRunName() const;
void prefixISet();
};
\ No newline at end of file
#pragma once
#include <fstream>
#include <sys/stat.h>
#include <agent/agent.h>
#include <agent/parse_config_file.h>
#include <agent/parse_proxy_file.h>
#include <boost/filesystem.hpp>
#include <json/json.h>
/** @file common.h
* @brief This file has a purpose to make parse from config and proxy file.
* Config file is required
* Proxy file is optional
*/
/**
* Check if version file exist and set currrent version to agent object.
* Otherwise, setted 0.0.0.
*/
bool check_version_file_exist(Agent*);
/**
* To make parsing from config and proxy file.
*/
bool common(std::fstream*, Agent*, Conf*, Proxy*);
/**
* Check if a file exist.
*/
bool file_exist(const char*);
#pragma once
#include <cstring>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <agent/agent.h>
#include <agent/parse_config_file.h>
#include <boost/filesystem.hpp>
#include <curl/curl.h>
#include <agent/get.h>
#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
* - Obs
* - Using libcurl to make a get request (curl/curl.h)
*/
class Curl{
private:
CURL *curl; /*!< Curl object */
CURLcode response; /*!< Response from webService */
long httpCode = 0; /*!< Code return from webSerice (200, 404, 502 and so on) */
public:
bool downloadAgent (std::string, std::fstream*, Agent*);
/** Default callback function that is necessary to make a curl request.
* @brief Obs:
* - 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) {
FILE* stream = (FILE*)userdata;
if (!stream)
return 0;
size_t written = fwrite((FILE*)ptr, size, nmemb, stream);
return written;
}
};
/*---------------------------------------------------------------------
* Function: mkdtemp
* Summary: Create a new and unique temporary directory in /tmp
*/
template<class T>
char *mkdtemp(T *tmpDir);
#pragma once
#include <iostream>
#include <sys/utsname.h>
#include <fstream>
#include <cpr/cpr.h>
#include <json/json.h>
#include <agent/agent.h>
#include <agent/common.h>
#include <agent/curl.h>
#include <agent/parse_config_file.h>
#include <agent/parse_proxy_file.h>
#include <agent/rotate_log_file.h>
const std::string url = "http://localhost:3001";
/**
* @file get.h
* @brief Check case if has a new agent version available
*/
int check_update();
void create_directories(Agent);
bool compare_version(Agent*, std::string, std::fstream*);
bool copy_bin_file_to_destiny_directory(std::fstream*, Agent*, boost::filesystem::path);
bool download(Conf, Agent*, std::fstream*);
\ No newline at end of file
......@@ -2,4 +2,9 @@
#include <time.h>
#include <string>
/**
* @file get_date.h
* @brief Get current date from system (YYYY-MM-DD)
*/
std::string get_date();
#pragma once
#include <libudev.h>
#include <iostream>
#include <fstream>
#include <list>
#include <string>
/**
* @file get_disks_info.h
* @brief Get 2 disks info (Model and size for each one)
*/
/** struct disk contain model and size from a disk */
struct disk {
std::string model;
long long size;
};
typedef struct disk disk_t;
void get_scsi_disks(std::list<disk_t>&);
void get_disks_info(std::list<disk_t>&);
\ No newline at end of file
#pragma once
#include <sys/utsname.h>
#include <agent/open_file.h>
/**
* @file get_distro.h
* @brief Get info from Ubuntu, debian, Linux Comunicações, Linux Educacional, fedora and OpenSUSE distro; windows use dtwinver
*/
std::string get_distro();
\ No newline at end of file
#pragma once
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <cstring>
#ifdef WIN32
#include <Windows.h>
#include <Iphlpapi.h>
#include <Assert.h>
#pragma comment(lib, "iphlpapi.lib")
#endif
/**
* @file get_macaddr.h
* @brief Case if linux OS, get macaddress info from /proc/net/rout file
*/
std::string get_macaddr();
#pragma once
#include <stdlib.h>
#include <cstring>
#include <iostream>
#include <stdio.h>
#ifdef WIN32
#define _WIN32_WINNT 0x0500
#include <tchar.h>
#include <windows.h>
#else
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#endif
/**
* @file get_machine_type.h
* @brief Get machine type - return Server or Client
*/
std::string get_machine_type();
\ No newline at end of file
#pragma once
#include <fstream>
#include <string>
#include <agent/open_file.h>
#include <algorithm>
/**
* @file get_memory_size.h
* @brief Get memory size info
*/
int get_memory_size();
\ No newline at end of file
#pragma once
#include <fstream>
#include <string>
#include <agent/open_file.h>
/**
* @file get_processor_model.h
* @brief Get processor model info
*/
std::string get_processor_model();
\ No newline at end of file
......@@ -2,4 +2,9 @@
#include <time.h>
#include <string>
/**
* @file get_time.h
* @brief Get current time from system (HH:MM:SS)
*/
std::string get_time();
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