Commit 31adb381 authored by rafaelatc3sl's avatar rafaelatc3sl

Issue #18: Add motherboard information

Signed-off-by: default avatarrafaelatc3sl <rpd17@c3sl>
parent f2de0931
Pipeline #20754 passed with stages
in 26 minutes and 1 second
......@@ -130,7 +130,7 @@ testOpensuse:
- opensuse
script:
- zypper -n update
- zypper -n install bats jq libfaketime expect tar cron
- zypper -n install bats jq libfaketime expect tar cron gzip
- touch /var/log/wtmp
- chown root.tty /var/log/wtmp
- chmod 664 /var/log/wtmp
......
#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
......@@ -10,8 +10,10 @@
#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>
......
......@@ -25,18 +25,23 @@ std::string get_bios_date() {
#ifdef __unix__
std::ifstream file;
std::string line, d, m, y, format = "";
file.open("/sys/devices/virtual/dmi/id/bios_date");
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;
}
d = line.substr(0, 2);
m = line.substr(3, 2);
y = line.substr(6, 4);
format = y + "-" + m + "-" + d;
} else {
std::string err;
err = "Could not open /sys/devices/virtual/dmi/id/bios_date";
err = "Could not open" + (std::string)BIOS_DATE_PATH \
+ "/bios_date";
throw err;
}
......
/* 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
}
......@@ -152,6 +152,7 @@ Json::Value get_inventory(Agent* agent) {
inv["error_inventory"]["disk1_used"] = err;
}
// date bios
try {
inv["data_inventory"]["date_bios"] = get_bios_date();
} catch (std::string err) {
......@@ -159,18 +160,71 @@ Json::Value get_inventory(Agent* agent) {
inv["error_inventory"]["date_bios"] = err;
}
// hw info
/*
inv["disk1_used"] =
inv["disk2_used"] =
*/
// other
/*
inv["agent_version"] =
inv["contact_date"] =
*/
// 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;
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
......
......@@ -2,69 +2,69 @@
function amount_users() {
expected_number_of_users=3
obj=$(cat inventory.json | jq -r '.data_inventory.amount_users')
obj=$(cat inventory.json | jq -r '.amount_users')
[[ "$obj" -eq "$expected_number_of_users" ]] && [[ "$obj" != "null" ]]
}
function mac_address() {
obj=$(cat inventory.json | jq -r '.data_inventory.mac_address')
obj=$(cat inventory.json | jq -r '.mac_address')
[[ "$obj" =~ ^(..:){5}..$ ]] && [[ "$obj" != "null" ]]
}
function machine_type() {
os=$(cat inventory.json | jq -r '.data_inventory.os_distro')
obj=$(cat inventory.json | jq -r '.data_inventory.machine_type')
os=$(cat inventory.json | jq -r '.os_distro')
obj=$(cat inventory.json | jq -r '.machine_type')
! [[ "$os" =~ .*Linux\ Comunicações.* ]] || ( [[ "$os" =~ .*Linux\ Comunicações.* ]] && [[ "$obj" != "null" ]] )
}
function memory() {
obj=$(cat inventory.json | jq -r '.data_inventory.memory')
obj=$(cat inventory.json | jq -r '.memory')
[[ "$obj" -eq "$obj" ]] && [[ "$obj" != "null" ]]
}
function os_distro() {
obj=$(cat inventory.json | jq -r '.data_inventory.os_distro')
obj=$(cat inventory.json | jq -r '.os_distro')
[[ "$obj" != "null" ]]
}
function os_kernel() {
obj=$(cat inventory.json | jq -r '.data_inventory.os_kernel')
obj=$(cat inventory.json | jq -r '.os_kernel')
[[ "$obj" != "null" ]]
}
function os_type() {
obj=$(cat inventory.json | jq -r '.data_inventory.os_type')
obj=$(cat inventory.json | jq -r '.os_type')
[[ "$obj" != "null" ]]
}
function processor() {
obj=$(cat inventory.json | jq -r '.data_inventory.processor')
obj=$(cat inventory.json | jq -r '.processor')
[[ "$obj" != "null" ]]
}
function date_bios() {
obj=$(cat inventory.json | jq -r '.data_inventory.date_bios')
[[ "$obj" != "null" ]]
obj=$(cat inventory.json | jq -r '.date_bios')
[[ "$obj" != "04/01/2014" ]]
}
function bytes_received() {
obj=$(cat net.json | jq -r '.data_net.bytes_received')
obj=$(cat net.json | jq -r '.bytes_received')
[[ "$obj" -ge 0 ]]
}
function bytes_transmitted() {
obj=$(cat net.json | jq -r '.data_net.bytes_transmitted')
obj=$(cat net.json | jq -r '.bytes_transmitted')
[[ "$obj" -ge 0 ]]
}
function packets_received() {
obj=$(cat net.json | jq -r '.data_net.packets_received')
obj=$(cat net.json | jq -r '.packets_received')
[[ "$obj" -ge 0 ]]
}
function packets_transmitted() {
obj=$(cat net.json | jq -r '.data_net.packets_transmitted')
obj=$(cat net.json | jq -r '.packets_transmitted')
[[ "$obj" -ge 0 ]]
}
......@@ -98,11 +98,51 @@ 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" ]]
}
setup() {
/opt/agentC3SL/agent-v* --print --once | head -n -1 > export.json
pt1=$(jq "del(."data_net")" export.json | head -n -1)
pt1=$(jq ."data_inventory" export.json | head -n -1)
echo $pt1 > inventory.json
pt2=$(jq "del(."data_inventory")" export.json | tail -n +2)
pt2=$(jq ."data_net" export.json | tail -n +2)
echo $pt2 > net.json
[ -s export.json ]
[ -s inventory.json ]
......@@ -210,3 +250,43 @@ 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