Skip to content
Snippets Groups Projects
Commit 16618274 authored by rafaelatc3sl's avatar rafaelatc3sl
Browse files

Issue #17: Add bios date


Signed-off-by: default avatarrafaelatc3sl <rpd17@c3sl>
parent 3de80dc0
No related branches found
No related tags found
No related merge requests found
Pipeline #20534 failed
#pragma once
#include <fstream>
#include <string>
/**
* @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
......@@ -6,6 +6,7 @@
#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>
......
/* 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 = "";
file.open("/sys/devices/virtual/dmi/id/bios_date");
if (file.is_open()) {
getline(file, line);
d = line.substr(0, 2);
m = line.substr(3, 2);
y = line.substr(6, 4);
format = y + "-" + d + "-" + m;
} else {
std::string err;
err = "Could not open /sys/devices/virtual/dmi/id/bios_date";
throw err;
}
file.close();
return format;
#elif WIN32
std::string err = "Does not support windows";
throw err;
#endif
}
......@@ -151,6 +151,14 @@ Json::Value get_inventory(Agent* agent) {
inv["error_inventory"]["disk1_used"] = err;
}
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;
}
// hw info
/*
inv["disk1_used"] =
......
......@@ -43,6 +43,11 @@ function processor() {
[[ "$obj" != "null" ]]
}
function date_bios() {
obj=$(cat inventory.json | jq -r '.data_inventory.date_bios')
[[ "$obj" != "null" ]]
}
function bytes_received() {
obj=$(cat net.json | jq -r '.data_net.bytes_received')
[[ "$obj" -ge 0 ]]
......@@ -95,9 +100,9 @@ function id_point() {
setup() {
/opt/agentC3SL/agent-v* --print --once | head -n -1 > export.json
pt1=$(cat export.json | head -n -9)
pt1=$(jq "del(."data_net")" export.json | head -n -1)
echo $pt1 > inventory.json
pt2=$(cat export.json | tail -n 9)
pt2=$(jq "del(."data_inventory")" export.json | tail -n +2)
echo $pt2 > net.json
[ -s export.json ]
[ -s inventory.json ]
......@@ -121,6 +126,11 @@ teardown() {
[ "$status" -eq 0 ]
}
@test "date_bios" {
run date_bios
[ "$status" -eq 0 ]
}
@test "port" {
run port
[ "$status" -eq 0 ]
......
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