Commit e106e4e2 authored by Rafael Dias's avatar Rafael Dias Committed by rgcastro
Browse files

Issue/23: Add new fields on agent.

parent 1eef0cc5
Pipeline #23636 failed with stages
in 1 minute and 39 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
......
This diff is collapsed.
{
"idPoint" : "%s",
"idPoint" : "%d",
"project" : "%s",
"proxyConf" : "%s",
"version" : "%s",
......
This diff is collapsed.
......@@ -30,17 +30,19 @@ std::string get_date() {
char buffer[20];
time(&rawtime);
#ifdef __unix__
localtime_r(&rawtime, timeinfo);
#else
//#ifdef __unix__
// localtime_r(&rawtime, timeinfo);
//#else
timeinfo = localtime(&rawtime); // NOLINT(runtime/threadsafe_fn)
#endif // __unix__
//#endif // __unix__
// YYYY-MM-DD
strftime(buffer, 20, "%Y-%m-%d", timeinfo);
res = buffer;
return res;
}
/**
......
......@@ -29,11 +29,11 @@ std::string get_time() {
char buffer[20];
time(&rawtime);
#ifdef __unix__
localtime_r(&rawtime, timeinfo);
#else
//#ifdef __unix__
// localtime_r(&rawtime, timeinfo);
//#else
timeinfo = localtime(&rawtime); // NOLINT(runtime/threadsafe_fn)
#endif // __unix__
//#endif // __unix__
// HH:MM:SS
strftime(buffer, 20, "%H:%M:%S", timeinfo);
......
......@@ -216,7 +216,6 @@ int main(int argc, char* argv[]) {
* and user history
*/
if (read_config_files(&agent)) {
if (agent_send_inventory) {
if (!send_inventory(print, &agent)) {
bit_mask |= 1;
......
......@@ -74,12 +74,10 @@ Json::Value get_net_bandwidth(Agent* agent) {
std::string str;
std::fstream time_file;
reader.parse(net_band_file, net_band_all_time, false);
net_band_file.close();
unsigned long long b_rec, pack_rec, b_tr, pack_tr; // NOLINT (runtime/int)
unsigned long long b_rec_allt, pack_rec_allt, b_tr_allt, pack_tr_allt; // NOLINT (runtime/int)
if (net_band_all_time.isNull()) {
b_rec_allt = 0;
pack_rec_allt = 0;
......@@ -96,7 +94,6 @@ Json::Value get_net_bandwidth(Agent* agent) {
net_band_all_time["data_net"]["packets_transmitted"].asLargestUInt();
}
#ifdef __linux__
std::string full_line, line, tmp;
std::string net_interface_name;
......@@ -200,6 +197,5 @@ Json::Value get_net_bandwidth(Agent* agent) {
net_band["data_net"]["collect_time"] = get_time();
net_band["data_net"]["collect_date"] = get_date();
return (net_band);
}
......@@ -44,11 +44,13 @@ int send_inventory(bool print, Agent* agent) {
if (!inventory.isNull()) {
if (agent->getConnection()->sendJson(agent,
fastWriter.write(inventory), 1, 0) == 200)
fastWriter.write(inventory), 1, 0) == 200) {
return 1;
}
else if (agent->getConnection()->sendJson(agent,
fastWriter.write(inventory), 1, 1) == 200)
fastWriter.write(inventory), 1, 1) == 200) {
return 1;
}
}
return 0;
......@@ -66,7 +68,6 @@ int send_net_bandwidth(bool print, Agent* agent) {
std::string base_url = agent->getConf()->getWebService();
Json::Value net = get_net_bandwidth(agent);
Json::FastWriter fastWriter;
if (print == true) {
Json::StyledWriter styledWriter;
if (!net.isNull())
......
#!/bin/bash
/opt/agentC3SL/agent-v* --print --once > export.json
echo $? > exit_status
echo "{" > inventory.json && jq ."data_inventory" export.json | awk '/{/{flag=1;next}/}/{flag=0}flag' >> inventory.json && echo "}" >> inventory.json
echo "{" > net.json && jq ."data_net" export.json | awk '/{/{flag=1;next}/}/{flag=0}flag' >> net.json && echo "}" >> net.json
# retrieve data , clean data and turn into a clean json
########################################################
# debug only #
########################################################
# echo "export.json"
# cat export.json
# echo "inventory"
# cat inventory.json
# echo "net"
# cat net.json
##########################################################
# exit status #
##########################################################
echo "exit status"
cat exit_status
# exit status valures:
# 0 : all data was sent
# 1 : send_inventory was not sent
# 2 : net_bandwidth was not sent
# 3 : send_inventory and net_bandwidth was not sent
# 4 : user_history was not sent
# 5 : user_history and send_inventory was not sent
# 6 : user_history and net_bandwidth was not set
# 7 : all data was not sent
......@@ -2,69 +2,64 @@
function amount_users() {
expected_number_of_users=3
obj=$(cat inventory.json | jq -r '.amount_users')
obj=$(cat inventory.json | jq -r '.data_inventory.amount_users')
[[ "$obj" -eq "$expected_number_of_users" ]] && [[ "$obj" != "null" ]]
}
function mac_address() {
obj=$(cat inventory.json | jq -r '.mac_address')
obj=$(cat inventory.json | jq -r '.data_inventory.mac_address')
[[ "$obj" =~ ^(..:){5}..$ ]] && [[ "$obj" != "null" ]]
}
function machine_type() {
os=$(cat inventory.json | jq -r '.os_distro')
obj=$(cat inventory.json | jq -r '.machine_type')
os=$(cat inventory.json | jq -r '.data_inventory.os_distro')
obj=$(cat inventory.json | jq -r '.data_inventory.machine_type')
! [[ "$os" =~ .*Linux\ Comunicações.* ]] || ( [[ "$os" =~ .*Linux\ Comunicações.* ]] && [[ "$obj" != "null" ]] )
}
function memory() {
obj=$(cat inventory.json | jq -r '.memory')
obj=$(cat inventory.json | jq -r '.data_inventory.memory')
[[ "$obj" -eq "$obj" ]] && [[ "$obj" != "null" ]]
}
function os_distro() {
obj=$(cat inventory.json | jq -r '.os_distro')
obj=$(cat inventory.json | jq -r '.data_inventory.os_distro')
[[ "$obj" != "null" ]]
}
function os_kernel() {
obj=$(cat inventory.json | jq -r '.os_kernel')
obj=$(cat inventory.json | jq -r '.data_inventory.os_kernel')
[[ "$obj" != "null" ]]
}
function os_type() {
obj=$(cat inventory.json | jq -r '.os_type')
obj=$(cat inventory.json | jq -r '.data_inventory.os_type')
[[ "$obj" != "null" ]]
}
function processor() {
obj=$(cat inventory.json | jq -r '.processor')
obj=$(cat inventory.json | jq -r '.data_inventory.processor')
[[ "$obj" != "null" ]]
}
function date_bios() {
obj=$(cat inventory.json | jq -r '.date_bios')
[[ "$obj" != "04/01/2014" ]]
}
function bytes_received() {
obj=$(cat net.json | jq -r '.bytes_received')
obj=$(cat net.json | jq -r '.data_net.bytes_received')
[[ "$obj" -ge 0 ]]
}
function bytes_transmitted() {
obj=$(cat net.json | jq -r '.bytes_transmitted')
obj=$(cat net.json | jq -r '.data_net.bytes_transmitted')
[[ "$obj" -ge 0 ]]
}
function packets_received() {
obj=$(cat net.json | jq -r '.packets_received')
obj=$(cat net.json | jq -r '.data_net.packets_received')
[[ "$obj" -ge 0 ]]
}
function packets_transmitted() {
obj=$(cat net.json | jq -r '.packets_transmitted')
obj=$(cat net.json | jq -r '.data_net.packets_transmitted')
[[ "$obj" -ge 0 ]]
}
......@@ -80,12 +75,12 @@ function user () {
function port() {
obj=$(cat /opt/agentC3SL/conf/proxy-conf.json | jq -r '.port')
[[ "$obj" -eq 3000 ]]
[[ "$obj" -eq 6666 ]]
}
function host() {
obj=$(cat /opt/agentC3SL/conf/proxy-conf.json | jq -r '.host')
[[ "$obj" == "simmcdev.c3sl.ufpr.br" ]]
[[ "$obj" == "mumm" ]]
}
function web_service() {
......@@ -98,69 +93,22 @@ function id_point() {
[[ "$obj" -eq 1234 ]]
}
function board_name() {
obj=$(cat inventory.json | jq -r '.board_name')
[[ "$obj" -eq "null" ]]
}
function board_serial() {
obj=$(cat inventory.json | jq -r '.board_serial')
[[ "$obj" -eq "null" ]]
}
function board_vendor() {
obj=$(cat inventory.json | jq -r '.board_vendor')
[[ "$obj" -eq "null" ]]
}
function board_version() {
obj=$(cat inventory.json | jq -r '.board_version')
[[ "$obj" -eq "null" ]]
}
function product_name() {
obj=$(cat inventory.json | jq -r '.product_name')
[[ "$obj" == "Standard PC (i440FX + PIIX, 1996)" ]]
}
function product_serial() {
obj=$(cat inventory.json | jq -r '.product_serial')
[[ "$obj" -eq "null" ]]
}
function product_version() {
obj=$(cat inventory.json | jq -r '.product_version')
[[ "$obj" == "pc-i440fx-3.0" ]]
}
function sys_vendor() {
obj=$(cat inventory.json | jq -r '.sys_vendor')
[[ "$obj" == "QEMU" ]]
}
function exit_status() {
obj=$(cat exit_status)
[[ "$obj" -eq 4 ]]
}
setup() {
/opt/agentC3SL/agent-v* --print --once | head -n -1 > export.json
pt1=$(cat export.json | head -n -9)
echo $pt1 > inventory.json
pt2=$(cat export.json | tail -n 9)
echo $pt2 > net.json
[ -s export.json ]
[ -s inventory.json ]
[ -s net.json ]
[ -s net.json ]
cat export.json
}
teardown() {
if [[ "${#BATS_TEST_NAMES[@]}" -eq "$BATS_TEST_NUMBER" ]]; then
rm -f export.json
rm -f inventory.json
rm -f net.json
rm -f exit_status
fi
}
@test "Exit Status" {
run exit_status
[ "$status" -eq 0 ]
rm -f export.json
rm -f inventory.json
rm -f net.json
}
@test "Id Point" {
......@@ -173,11 +121,6 @@ teardown() {
[ "$status" -eq 0 ]
}
@test "date_bios" {
run date_bios
[ "$status" -eq 0 ]
}
@test "port" {
run port
[ "$status" -eq 0 ]
......@@ -257,43 +200,3 @@ teardown() {
run web_service
[ "$status" -eq 0 ]
}
@test "board_name" {
run board_name
[ "$status" -eq 0 ]
}
@test "board_serial" {
run board_serial
[ "$status" -eq 0 ]
}
@test "board_vendor" {
run board_vendor
[ "$status" -eq 0 ]
}
@test "board_version" {
run board_version
[ "$status" -eq 0 ]
}
@test "product_name" {
run product_name
[ "$status" -eq 0 ]
}
@test "product_serial" {
run product_serial
[ "$status" -eq 0 ]
}
@test "product_version" {
run product_version
[ "$status" -eq 0 ]
}
@test "sys_vendor" {
run sys_vendor
[ "$status" -eq 0 ]
}
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