Skip to content
Snippets Groups Projects
Commit e384d9ce authored by Lucas Fernandes de Oliveira's avatar Lucas Fernandes de Oliveira
Browse files

Merge branch 'issue/19' into 'development'

Issue #19: Fix json and validate data

See merge request !115
parents bfefd363 e33c8b0f
No related branches found
No related tags found
2 merge requests!118Issue/22,!115Issue #19: Fix json and validate data
Pipeline #20820 failed
......@@ -39,7 +39,7 @@ compileUnix:
- make
- cd ..
- chmod +x generate_agent.sh
- ./generate_agent.sh -idp=1234 -ws=www.C3Sl.ufpr.br -pch=mumm -pcp=6666 -pcu=ninguem -pcpasswd=123mudar -prj=simmc
- ./generate_agent.sh -idp=1234 -ws=www.C3Sl.ufpr.br -pch=simmcdev.c3sl.ufpr.br -pcp=8000 -pcu=ninguem -pcpasswd=123mudar -prj=simmc
- chmod +x agent-1234.run
compileWin32:
......@@ -64,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=mumm /Dpcp=6666 /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=simmcdev.c3sl.ufpr.br /Dpcp=8000 /Dpcu=ninguem /Dpcpasswd=123mudar /Dprj=simmc /Dversion=1.0.0
- mv ./builds/simmctic/agent/agent-1234.exe ./builds/simmctic/agent/agent-32.exe
compileWin64:
......@@ -88,7 +88,7 @@ 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=mumm /Dpcp=6666 /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=simmcdev.c3sl.ufpr.br /Dpcp=8000 /Dpcu=ninguem /Dpcpasswd=123mudar /Dprj=simmc /Dversion=1.0.0
- mv ./builds/simmctic/agent/agent-1234.exe ./builds/simmctic/agent/agent-64.exe
testDebian:
......@@ -105,6 +105,7 @@ testDebian:
- cd ../test
- ./create_users.sh
- last -F
- ./init.sh
- ./returnTest.bats
dependencies:
- compileUnix
......@@ -120,6 +121,7 @@ testUbuntu:
- cd test
- ./create_users.sh
- last -F
- ./init.sh
- ./returnTest.bats
dependencies:
- compileUnix
......@@ -138,6 +140,7 @@ testOpensuse:
- cd test
- ./create_users.sh
- last -F
- ./init.sh
- ./returnTest.bats
dependencies:
- compileUnix
......
......@@ -189,6 +189,7 @@ int main(int argc, char* argv[]) {
agent.setProxy(&proxy);
int increment = 0;
int bit_mask = 0;
int lim = 1;
bool print;
bool dev = false;
......@@ -217,13 +218,19 @@ int main(int argc, char* argv[]) {
if (read_config_files(&agent)) {
if (agent_send_inventory) {
send_inventory(print, &agent);
if (!send_inventory(print, &agent)) {
bit_mask |= 1;
}
}
if (agent_send_net_band) {
send_net_bandwidth(print, &agent);
if (!send_net_bandwidth(print, &agent)) {
bit_mask |= 2;
}
}
if (agent_send_user_hist) {
send_user_history(print, &agent);
if (!send_user_history(print, &agent)) {
bit_mask |= 4;
}
}
if (agent_send_database) {
// get database for PInSIS
......@@ -231,7 +238,7 @@ int main(int argc, char* argv[]) {
}
if (lim == 0) {
return (0);
return bit_mask;
}
int i = 0;
......
......@@ -42,14 +42,16 @@ int send_inventory(bool print, Agent* agent) {
std::cout << "Empty inventory object" << std::endl;
}
if (agent->getConnection()->sendJson(agent,
fastWriter.write(inventory), 1, 0) == 200)
return 1;
else if (agent->getConnection()->sendJson(agent,
fastWriter.write(inventory), 1, 1) == 200)
return 1;
else
if (!inventory.isNull()) {
if (agent->getConnection()->sendJson(agent,
fastWriter.write(inventory), 1, 0) == 200)
return 1;
else if (agent->getConnection()->sendJson(agent,
fastWriter.write(inventory), 1, 1) == 200)
return 1;
} else {
return 0;
}
}
/***************************************
......@@ -73,14 +75,16 @@ int send_net_bandwidth(bool print, Agent* agent) {
std::cout << "Empty network_bandwidth object" << std::endl;
}
if (agent->getConnection()->sendJson(agent,
fastWriter.write(net), 2, 0) == 200)
return 1;
else if (agent->getConnection()->sendJson(agent,
fastWriter.write(net), 2, 1) == 200)
return 1;
else
if (!net.isNull()) {
if (agent->getConnection()->sendJson(agent,
fastWriter.write(net), 2, 0) == 200)
return 1;
else if (agent->getConnection()->sendJson(agent,
fastWriter.write(net), 2, 1) == 200)
return 1;
} else {
return 0;
}
}
/**********************************
......@@ -104,14 +108,16 @@ int send_user_history(bool print, Agent* agent) {
std::cout << "Empty user_history object" << std::endl;
}
if (agent->getConnection()->sendJson(agent,
fastWriter.write(u_h), 3, 0) == 200)
return 1;
else if (agent->getConnection()->sendJson(agent,
fastWriter.write(u_h), 3, 1) == 200)
return 1;
else
if (!u_h.isNull()) {
if (agent->getConnection()->sendJson(agent,
fastWriter.write(u_h), 3, 0) == 200)
return 1;
else if (agent->getConnection()->sendJson(agent,
fastWriter.write(u_h), 3, 1) == 200)
return 1;
} else {
return 0;
}
}
/**
......
#!/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
cat inventory.json
cat net.json
\ No newline at end of file
......@@ -80,12 +80,12 @@ function user () {
function port() {
obj=$(cat /opt/agentC3SL/conf/proxy-conf.json | jq -r '.port')
[[ "$obj" -eq 6666 ]]
[[ "$obj" -eq 8000 ]]
}
function host() {
obj=$(cat /opt/agentC3SL/conf/proxy-conf.json | jq -r '.host')
[[ "$obj" == "mumm" ]]
[[ "$obj" == "simmcdev.c3sl.ufpr.br" ]]
}
function web_service() {
......@@ -138,22 +138,29 @@ function 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=$(jq ."data_inventory" export.json | head -n -1)
echo $pt1 > inventory.json
pt2=$(jq ."data_net" export.json | tail -n +2)
echo $pt2 > net.json
[ -s export.json ]
[ -s inventory.json ]
[ -s net.json ]
cat export.json
[ -s net.json ]
}
teardown() {
rm -f export.json
rm -f inventory.json
rm -f net.json
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 ]
}
@test "Id Point" {
......
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