Commit aa2f4e5bc2620e6bee46e020e646ed874a34a998
1 parent
18065fa9
Exists in
master
Coletando agora informação de BIOS e Motherboard no Linux.
Showing
3 changed files
with
87 additions
and
3 deletions
Show diff stats
src/cacic_hardware.cpp
@@ -8,6 +8,25 @@ void cacic_hardware::iniciaColeta() | @@ -8,6 +8,25 @@ void cacic_hardware::iniciaColeta() | ||
8 | #ifdef Q_OS_WIN | 8 | #ifdef Q_OS_WIN |
9 | this->coletaHardware = coletaWin(); | 9 | this->coletaHardware = coletaWin(); |
10 | #elif defined(Q_OS_LINUX) | 10 | #elif defined(Q_OS_LINUX) |
11 | + OperatingSystem operatingSystem; | ||
12 | + | ||
13 | + // se o shell retorna erro ao tentar utilizar o lshw ou o dmidecode, instala o mesmo | ||
14 | + if( console("lshw").contains("/bin/sh") ){ qDebug() << "lshw nao instalado."; | ||
15 | + if(operatingSystem.getIdOs() == OperatingSystem::LINUX_ARCH) | ||
16 | + console("pacman -S --needed --noconfirm lshw"); | ||
17 | + else if(operatingSystem.getIdOs() == OperatingSystem::LINUX_DEBIAN || | ||
18 | + operatingSystem.getIdOs() == OperatingSystem::LINUX_UBUNTU ) | ||
19 | + console("apt-get -y install lshw"); | ||
20 | + } | ||
21 | + | ||
22 | + if( console("dmidecode").contains("/bin/sh:") ){ qDebug() << "dmidecode nao instalado."; | ||
23 | + if(operatingSystem.getIdOs() == OperatingSystem::LINUX_ARCH) | ||
24 | + qDebug() << console("pacman -S --needed --noconfirm dmidecode"); | ||
25 | + else if(operatingSystem.getIdOs() == OperatingSystem::LINUX_DEBIAN || | ||
26 | + operatingSystem.getIdOs() == OperatingSystem::LINUX_UBUNTU ) | ||
27 | + console("apt-get -y install dmidecode"); | ||
28 | + } | ||
29 | + | ||
11 | this->coletaHardware = coletaLinux(); | 30 | this->coletaHardware = coletaLinux(); |
12 | #endif | 31 | #endif |
13 | } | 32 | } |
@@ -303,9 +322,6 @@ QJsonValue cacic_hardware::wmiSearch(QString classe, QStringList params) | @@ -303,9 +322,6 @@ QJsonValue cacic_hardware::wmiSearch(QString classe, QStringList params) | ||
303 | QJsonObject cacic_hardware::coletaLinux() | 322 | QJsonObject cacic_hardware::coletaLinux() |
304 | { | 323 | { |
305 | 324 | ||
306 | - OperatingSystem operatingSystem; | ||
307 | - ConsoleObject console; | ||
308 | - | ||
309 | QJsonObject hardware; | 325 | QJsonObject hardware; |
310 | 326 | ||
311 | QFile lshwFile("lshwJson.json"); | 327 | QFile lshwFile("lshwJson.json"); |
@@ -354,6 +370,10 @@ QJsonObject cacic_hardware::coletaLinux() | @@ -354,6 +370,10 @@ QJsonObject cacic_hardware::coletaLinux() | ||
354 | 370 | ||
355 | } | 371 | } |
356 | 372 | ||
373 | + if ( getuid() != 0 ) qDebug() << "Coleta de Bios e Motherboard requer root."; | ||
374 | + coletaLinuxBios(hardware); | ||
375 | + coletaLinuxMotherboard(hardware); | ||
376 | + | ||
357 | return hardware; | 377 | return hardware; |
358 | } | 378 | } |
359 | 379 | ||
@@ -421,6 +441,63 @@ void cacic_hardware::coletaLinuxPci(QJsonObject &hardware, const QJsonObject &pc | @@ -421,6 +441,63 @@ void cacic_hardware::coletaLinuxPci(QJsonObject &hardware, const QJsonObject &pc | ||
421 | } | 441 | } |
422 | } | 442 | } |
423 | } | 443 | } |
444 | + | ||
445 | +void cacic_hardware::coletaLinuxBios(QJsonObject &hardware) | ||
446 | +{ | ||
447 | + | ||
448 | + QJsonObject bios; | ||
449 | + QStringList consoleOutput; | ||
450 | + | ||
451 | + consoleOutput = console("dmidecode -t bios").split("\n"); | ||
452 | + foreach(QString line, consoleOutput){ | ||
453 | + if(line.contains("Vendor:") ){ | ||
454 | + bios["vendor"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ); | ||
455 | + } else if(line.contains("Version:")){ | ||
456 | + bios["version"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ); | ||
457 | + } else if(line.contains("Release Date:")){ | ||
458 | + bios["release_date"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ); | ||
459 | + } else if(line.contains("Runtime Size:")){ | ||
460 | + bios["runtime_size"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ); | ||
461 | + } else if(line.contains("ROM Size:")){ | ||
462 | + bios["rom_size"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ); | ||
463 | + } else if(line.contains("BIOS Revision:")){ | ||
464 | + bios["revision"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ); | ||
465 | + } | ||
466 | + } | ||
467 | + hardware["bios"] = bios; | ||
468 | +} | ||
469 | + | ||
470 | +void cacic_hardware::coletaLinuxMotherboard(QJsonObject &hardware) | ||
471 | +{ | ||
472 | + | ||
473 | + QJsonObject motherboard; | ||
474 | + QStringList consoleOutput; | ||
475 | + | ||
476 | + consoleOutput= console("dmidecode -t 2").split("\n"); | ||
477 | +// qDebug() << consoleOutput; | ||
478 | + foreach(QString line, consoleOutput){ | ||
479 | + if(line.contains("Manufacturer:") ){ | ||
480 | + motherboard["manufacturer"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ); | ||
481 | + } else if(line.contains("Product Name:")){ | ||
482 | + motherboard["product_name"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ); | ||
483 | + } else if(line.contains("Version:")){ | ||
484 | + motherboard["version"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ); | ||
485 | + } | ||
486 | + } | ||
487 | + | ||
488 | + consoleOutput= console("dmidecode -t 10").split("\n"); | ||
489 | + foreach(QString line, consoleOutput){ | ||
490 | + QJsonArray onboardCapabilities; | ||
491 | + | ||
492 | + if(line.contains("Type:") ) | ||
493 | + onboardCapabilities.append( QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ) ); | ||
494 | + | ||
495 | + motherboard["onboard_capabilities"] = onboardCapabilities; | ||
496 | + } | ||
497 | + | ||
498 | + hardware["motherboard"] = motherboard; | ||
499 | +} | ||
500 | + | ||
424 | #endif | 501 | #endif |
425 | QJsonObject cacic_hardware::toJsonObject() { | 502 | QJsonObject cacic_hardware::toJsonObject() { |
426 | return coletaHardware; | 503 | return coletaHardware; |
src/cacic_hardware.h
@@ -10,6 +10,8 @@ | @@ -10,6 +10,8 @@ | ||
10 | #ifdef Q_OS_WIN | 10 | #ifdef Q_OS_WIN |
11 | #include <windows.h> | 11 | #include <windows.h> |
12 | #include <ActiveQt/ActiveQt> | 12 | #include <ActiveQt/ActiveQt> |
13 | +#elif defined(Q_OS_LINUX) | ||
14 | + #include <unistd.h> | ||
13 | #endif | 15 | #endif |
14 | 16 | ||
15 | class cacic_hardware | 17 | class cacic_hardware |
@@ -25,10 +27,14 @@ private: | @@ -25,10 +27,14 @@ private: | ||
25 | QJsonValue wmiSearch(QString classe, QStringList params); | 27 | QJsonValue wmiSearch(QString classe, QStringList params); |
26 | 28 | ||
27 | #elif defined(Q_OS_LINUX) | 29 | #elif defined(Q_OS_LINUX) |
30 | + ConsoleObject console; | ||
31 | + | ||
28 | QJsonObject coletaLinux(); | 32 | QJsonObject coletaLinux(); |
29 | void coletaLinuxMem(QJsonObject &hardware, const QJsonObject &component); | 33 | void coletaLinuxMem(QJsonObject &hardware, const QJsonObject &component); |
30 | void coletaLinuxCpu(QJsonObject &hardware, const QJsonObject &component); | 34 | void coletaLinuxCpu(QJsonObject &hardware, const QJsonObject &component); |
31 | void coletaLinuxPci(QJsonObject &hardware, const QJsonObject &pciJson); | 35 | void coletaLinuxPci(QJsonObject &hardware, const QJsonObject &pciJson); |
36 | + void coletaLinuxBios(QJsonObject &hardware); | ||
37 | + void coletaLinuxMotherboard(QJsonObject &hardware); | ||
32 | #endif | 38 | #endif |
33 | 39 | ||
34 | CCacic oCacic; | 40 | CCacic oCacic; |
src/console.h
@@ -25,6 +25,7 @@ public: | @@ -25,6 +25,7 @@ public: | ||
25 | #endif | 25 | #endif |
26 | process->waitForFinished(); | 26 | process->waitForFinished(); |
27 | QString output = process->readAll(); | 27 | QString output = process->readAll(); |
28 | + output.append(process->readAllStandardError()); | ||
28 | // qDebug() << output; | 29 | // qDebug() << output; |
29 | 30 | ||
30 | delete process; | 31 | delete process; |