Commit c5a6cbac06d1c4acc2b3aa8f13d0adbdc2e132e3
Exists in
master
Merge branch 'master' of https://github.com/lightbase/cacic-agente
Conflicts: src/cacic_hardware.h
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 | 8 | #ifdef Q_OS_WIN |
9 | 9 | this->coletaHardware = coletaWin(); |
10 | 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 | 30 | this->coletaHardware = coletaLinux(); |
12 | 31 | #endif |
13 | 32 | } |
... | ... | @@ -217,9 +236,6 @@ QJsonObject cacic_hardware::coletaWin() |
217 | 236 | QJsonObject cacic_hardware::coletaLinux() |
218 | 237 | { |
219 | 238 | |
220 | - OperatingSystem operatingSystem; | |
221 | - ConsoleObject console; | |
222 | - | |
223 | 239 | QJsonObject hardware; |
224 | 240 | |
225 | 241 | QFile lshwFile("lshwJson.json"); |
... | ... | @@ -268,6 +284,10 @@ QJsonObject cacic_hardware::coletaLinux() |
268 | 284 | |
269 | 285 | } |
270 | 286 | |
287 | + if ( getuid() != 0 ) qDebug() << "Coleta de Bios e Motherboard requer root."; | |
288 | + coletaLinuxBios(hardware); | |
289 | + coletaLinuxMotherboard(hardware); | |
290 | + | |
271 | 291 | return hardware; |
272 | 292 | } |
273 | 293 | |
... | ... | @@ -335,6 +355,63 @@ void cacic_hardware::coletaLinuxPci(QJsonObject &hardware, const QJsonObject &pc |
335 | 355 | } |
336 | 356 | } |
337 | 357 | } |
358 | + | |
359 | +void cacic_hardware::coletaLinuxBios(QJsonObject &hardware) | |
360 | +{ | |
361 | + | |
362 | + QJsonObject bios; | |
363 | + QStringList consoleOutput; | |
364 | + | |
365 | + consoleOutput = console("dmidecode -t bios").split("\n"); | |
366 | + foreach(QString line, consoleOutput){ | |
367 | + if(line.contains("Vendor:") ){ | |
368 | + bios["vendor"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ); | |
369 | + } else if(line.contains("Version:")){ | |
370 | + bios["version"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ); | |
371 | + } else if(line.contains("Release Date:")){ | |
372 | + bios["release_date"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ); | |
373 | + } else if(line.contains("Runtime Size:")){ | |
374 | + bios["runtime_size"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ); | |
375 | + } else if(line.contains("ROM Size:")){ | |
376 | + bios["rom_size"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ); | |
377 | + } else if(line.contains("BIOS Revision:")){ | |
378 | + bios["revision"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ); | |
379 | + } | |
380 | + } | |
381 | + hardware["bios"] = bios; | |
382 | +} | |
383 | + | |
384 | +void cacic_hardware::coletaLinuxMotherboard(QJsonObject &hardware) | |
385 | +{ | |
386 | + | |
387 | + QJsonObject motherboard; | |
388 | + QStringList consoleOutput; | |
389 | + | |
390 | + consoleOutput= console("dmidecode -t 2").split("\n"); | |
391 | +// qDebug() << consoleOutput; | |
392 | + foreach(QString line, consoleOutput){ | |
393 | + if(line.contains("Manufacturer:") ){ | |
394 | + motherboard["manufacturer"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ); | |
395 | + } else if(line.contains("Product Name:")){ | |
396 | + motherboard["product_name"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ); | |
397 | + } else if(line.contains("Version:")){ | |
398 | + motherboard["version"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ); | |
399 | + } | |
400 | + } | |
401 | + | |
402 | + consoleOutput= console("dmidecode -t 10").split("\n"); | |
403 | + foreach(QString line, consoleOutput){ | |
404 | + QJsonArray onboardCapabilities; | |
405 | + | |
406 | + if(line.contains("Type:") ) | |
407 | + onboardCapabilities.append( QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) ) ); | |
408 | + | |
409 | + motherboard["onboard_capabilities"] = onboardCapabilities; | |
410 | + } | |
411 | + | |
412 | + hardware["motherboard"] = motherboard; | |
413 | +} | |
414 | + | |
338 | 415 | #endif |
339 | 416 | QJsonObject cacic_hardware::toJsonObject() { |
340 | 417 | return coletaHardware; | ... | ... |
src/cacic_hardware.h
... | ... | @@ -9,6 +9,8 @@ |
9 | 9 | #include <operatingsystem.h> |
10 | 10 | #ifdef Q_OS_WIN |
11 | 11 | #include <wmi.h> |
12 | +#elif defined(Q_OS_LINUX) | |
13 | + #include <unistd.h> | |
12 | 14 | #endif |
13 | 15 | |
14 | 16 | class cacic_hardware |
... | ... | @@ -23,10 +25,14 @@ private: |
23 | 25 | QJsonObject coletaWin(); |
24 | 26 | |
25 | 27 | #elif defined(Q_OS_LINUX) |
28 | + ConsoleObject console; | |
29 | + | |
26 | 30 | QJsonObject coletaLinux(); |
27 | 31 | void coletaLinuxMem(QJsonObject &hardware, const QJsonObject &component); |
28 | 32 | void coletaLinuxCpu(QJsonObject &hardware, const QJsonObject &component); |
29 | 33 | void coletaLinuxPci(QJsonObject &hardware, const QJsonObject &pciJson); |
34 | + void coletaLinuxBios(QJsonObject &hardware); | |
35 | + void coletaLinuxMotherboard(QJsonObject &hardware); | |
30 | 36 | #endif |
31 | 37 | |
32 | 38 | CCacic oCacic; | ... | ... |