Skip to content
Snippets Groups Projects
Commit 3a694760 authored by Clara Daia Hilgenberg Daru's avatar Clara Daia Hilgenberg Daru
Browse files

Issue #46: Separate open_file from get_distro and add get_machine_processor function

parent a9ff3f59
No related branches found
No related tags found
2 merge requests!51Merge development to master,!24Issue/46
#pragma once
#include <sys/utsname.h>
#include <fstream>
#include <cstring>
#include "agent/linux/open_file.h"
int open_file(std::string name, std::ifstream& fstream);
std::string get_distro();
#pragma once
#include <fstream>
#include <string>
#include "agent/linux/open_file.h"
std::string get_processor_model();
......@@ -3,15 +3,12 @@
#include <time.h>
#include <iostream>
#include "agent/linux/get_date.h"
#include "agent/linux/get_distro.h"
#include "agent/linux/get_macaddr.h"
#include "agent/linux/get_machine_type.h"
#include "agent/linux/get_processor_model.h"
#include "agent/linux/get_time.h"
#include "agent/linux/get_user_count.h"
#include "json/json.h"
int open_file(std::string name, std::ifstream& fstream);
std::string get_distro();
std::string get_processor_model();
Json::Value get_inventory();
#pragma once
#include <fstream>
#include <string>
int open_file(std::string name, std::ifstream& fstream);
......@@ -20,14 +20,7 @@
*/
#include "agent/linux/get_distro.h"
int open_file(std::string name, std::ifstream& fstream) {
fstream.open(name);
if (fstream.is_open())
return 1;
else
return 0;
}
#include "agent/linux/open_file.h"
std::string get_distro() {
/* currently recorded distros are
......
/* Copyright (C) 2016 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/linux/get_processor_model.h"
std::string get_processor_model() {
std::ifstream cpuinfo_file;
std::string line;
if (open_file("/proc/cpuinfo", cpuinfo_file)) {
const std::string key = "model name";
std::size_t found;
while (getline(cpuinfo_file, line)) {
found = line.find(key);
if (found != std::string::npos) {
// remove ':' and space at the beginning
found = line.find(":");
return (line.substr(found+2));
}
}
throw std::string("Coudn't find model name in /proc/cpuinfo");
}
throw std::string("Coudn't open /proc/cpuinfo");
}
......@@ -21,12 +21,9 @@
#include "agent/linux/inventory.h"
std::string get_processor_model() {
return "unknown";
}
Json::Value get_inventory(){
Json::Value get_inventory() {
Json::Value inv;
Json::Value inv;
// os info
......@@ -46,9 +43,16 @@ Json::Value get_inventory() {
inv["data"]["os_kernel"] = sysinfo.release;
inv["data"]["mirror_timestamp"] = sysinfo.version;
try {
inv["data"]["processor"] = get_processor_model();
}
catch ( std::string err ) {
inv["data"]["processor"] = Json::nullValue;
inv["error"]["processor"] = err;
}
// hw info
/*
inv["processor"] =
inv["memory"] =
inv["disk1_model"] =
inv["disk1_size"] =
......
#include "agent/linux/open_file.h"
int open_file(std::string name, std::ifstream& fstream){
fstream.open(name);
if (fstream.is_open())
return 1;
else
return 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