diff --git a/doc/01-About.md b/doc/01-About.md index 9b1708b..4d8d989 100644 --- a/doc/01-About.md +++ b/doc/01-About.md @@ -7,3 +7,6 @@ Please read the following chapters for more insights on this module: * [Installation](02-Installation.md#module-lshw-installation) * [Configuration](03-Configuration.md#module-lshw-configuration) * [Usage](04-Usage.md#module-lshw-usage) + + +![image_e](img/usage.png) diff --git a/doc/02-Installation.md b/doc/02-Installation.md index a61482d..17ec6a2 100644 --- a/doc/02-Installation.md +++ b/doc/02-Installation.md @@ -5,8 +5,9 @@ * Icinga Web 2 (>= 2.10.3) * Icinga Director (>= 1.9.1) * PHP (>= 7.3) +* php-json -The Icinga Web 2 `monitoring` module needs to be configured and enabled. +The Icinga Web 2 `monitoring` or `icingadb` module needs to be configured and enabled. ## Installation from .tar.gz @@ -23,5 +24,5 @@ icingacli module enable lshw Or go to your Icinga Web 2 frontend, choose `Configuration` -> `Modules`, chose the `lshw` module and `enable` it. -It might afterwards be necessary to refresh your web browser to be sure that +It might afterward be necessary to refresh your web browser to be sure that newly provided styling is loaded. \ No newline at end of file diff --git a/doc/03-Configuration.md b/doc/03-Configuration.md index 79b6518..731c038 100644 --- a/doc/03-Configuration.md +++ b/doc/03-Configuration.md @@ -1,26 +1,25 @@ # Configuration -## Module Configuration +## System Configuration -![image_a](img/image_a.png) +If you want all the systems details for linux you need run lshw as root. +Add the following line to your sudoes file: +``` +%nagios ALL=(ALL) NOPASSWD: /usr/bin/lshw -json +``` +If you are using an enterprise linux like redhat you user might me icinga instead of nagios. -| Option | Required | Description | -| --------------------- | -------- | ----------------------------------- | -| Name | **yes** | Name of something | -| xxxx | **yes** | Description of xxxx. | -| yyyy | no | Description of yyyy | +You have to configure this on agents too if you want to execute lshw with root permissions on an agent. -## Reference Urls +## Director Configuration -![image_b](img/image_b.png) +![director](img/director.png) -Some config references... +The module comes with all the command definitons for Icinga Director. -## Director Configuration +Just click on "Sync to director" to create the commands. -![image_c](img/image_c.png) +After that you can create your service-templates as usual. -If there is any configurtion inside of icinga director describe it here - -![image_d](img/image_d.png) +Don't forget to add "Run on Agent" if you want to execute the command on an agent node. \ No newline at end of file diff --git a/doc/04-Usage.md b/doc/04-Usage.md index 8edc8f4..7c183e6 100644 --- a/doc/04-Usage.md +++ b/doc/04-Usage.md @@ -2,12 +2,13 @@ ## Module Usage -![image_e](img/image_e.png) -Describe the usage... +The following commands are available for this speical rendering: +* lshw +* lshw-win +* lshw-unpriviledged -## Monitoring Host +The rendering will look like this: -![image_f](img/image_f.png) +![usage](img/usage.png) -Describe the usage... diff --git a/doc/img/director.png b/doc/img/director.png new file mode 100644 index 0000000..b2e4568 Binary files /dev/null and b/doc/img/director.png differ diff --git a/doc/img/image_a.png b/doc/img/image_a.png deleted file mode 100644 index ad18aa8..0000000 Binary files a/doc/img/image_a.png and /dev/null differ diff --git a/doc/img/image_b.png b/doc/img/image_b.png deleted file mode 100644 index a3dffb7..0000000 Binary files a/doc/img/image_b.png and /dev/null differ diff --git a/doc/img/image_c.png b/doc/img/image_c.png deleted file mode 100644 index e6e10fd..0000000 Binary files a/doc/img/image_c.png and /dev/null differ diff --git a/doc/img/image_d.png b/doc/img/image_d.png deleted file mode 100644 index a64be19..0000000 Binary files a/doc/img/image_d.png and /dev/null differ diff --git a/doc/img/image_e.png b/doc/img/image_e.png deleted file mode 100644 index 72a1072..0000000 Binary files a/doc/img/image_e.png and /dev/null differ diff --git a/doc/img/image_f.png b/doc/img/image_f.png deleted file mode 100644 index fe03f93..0000000 Binary files a/doc/img/image_f.png and /dev/null differ diff --git a/doc/img/usage.png b/doc/img/usage.png new file mode 100644 index 0000000..0da3134 Binary files /dev/null and b/doc/img/usage.png differ diff --git a/library/Lshw/ProvidedHook/Icingadb/ServiceDetailExtension.php b/library/Lshw/ProvidedHook/Icingadb/ServiceDetailExtension.php index 7eea630..f74ba9a 100644 --- a/library/Lshw/ProvidedHook/Icingadb/ServiceDetailExtension.php +++ b/library/Lshw/ProvidedHook/Icingadb/ServiceDetailExtension.php @@ -20,8 +20,9 @@ public function getHtmlForObject(Service $service): ValidHtml $div = Html::tag("div"); if($commandName == "lshw" || $commandName == "lshw-unprivileged" || $commandName == "lshw-win") { if(isset($service->state->output) && isset($service->state->long_output)){ - $test = json_decode($output); - if(is_array($test) && count($test)==1){ + $test = json_decode($output, true); + + if(is_array($test)){ $h2 = Html::tag("h2",null, "Hardware Info"); $div->add($h2); diff --git a/library/Lshw/ProvidedHook/Monitoring/DetailviewExtension.php b/library/Lshw/ProvidedHook/Monitoring/DetailviewExtension.php index bcabe35..35b4735 100644 --- a/library/Lshw/ProvidedHook/Monitoring/DetailviewExtension.php +++ b/library/Lshw/ProvidedHook/Monitoring/DetailviewExtension.php @@ -2,6 +2,7 @@ namespace Icinga\Module\Lshw\ProvidedHook\Monitoring; +use Icinga\Application\Logger; use Icinga\Module\Lshw\Web\Widget\LshwHardwareTree; use Icinga\Module\Monitoring\Hook\DetailviewExtensionHook; use Icinga\Module\Monitoring\Object\MonitoredObject; @@ -20,9 +21,9 @@ public function getHtmlForObject(MonitoredObject $service) $commandName = $service->service_check_command; if($commandName == "lshw" || $commandName == "lshw-unprivileged" || $commandName == "lshw-win") { if(isset($service->service_output) && isset($service->service_long_output)){ - $test = json_decode($output); + $test = json_decode($output, true); - if(is_array($test) && count($test)==1){ + if(is_array($test)){ $h2 = Html::tag("h2",null, "Hardware Info"); $div->add($h2); @@ -31,15 +32,20 @@ public function getHtmlForObject(MonitoredObject $service) }catch ( \Throwable $e) { $div->add(Html::tag("p",null,"Check Output unsupported:")); $div->add(Html::tag("p",null,"Output:\n".$output)); + Logger::debug('lshw: '. $e->getMessage()); + Logger::debug('lshw: '. $e->getTraceAsString()); } }else{ $div->add(Html::tag("p",null,"Check Output unsupported:")); $div->add(Html::tag("p",null,"Output:\n".$output)); + Logger::debug('lshw: '. 'falied decode'); return $div; } }else{ $div->add(Html::tag("p",null,"Check Output unsupported:")); $div->add(Html::tag("p",null,"Output:\n".$output)); + Logger::debug('lshw: '. 'something missing'); + return $div; } diff --git a/library/Lshw/Web/Widget/LshwHardwareTree.php b/library/Lshw/Web/Widget/LshwHardwareTree.php index 0eece8f..f479553 100644 --- a/library/Lshw/Web/Widget/LshwHardwareTree.php +++ b/library/Lshw/Web/Widget/LshwHardwareTree.php @@ -36,6 +36,9 @@ class LshwHardwareTree extends BaseHtmlElement public function __construct(string $json_string) { + if(strpos($json_string,"[") !== 0){ + $json_string = '[' . $json_string .']'; + } $this->data = json_decode($json_string); } @@ -72,6 +75,7 @@ function convertBytes($bytes,$si=false) protected function renderNodes($nodes, $level = 0) { $result = []; + foreach ($nodes as $child) { $result[] = $this->renderNode($child, $level + 1); } @@ -84,8 +88,14 @@ protected function renderNodes($nodes, $level = 0) } protected function renderDisk($device,$si){ - $desc = $this->renderDevice($device); - $desc .= " / Size: ".$this->convertBytes($device->size,$si); + $desc="unknown"; + if(isset($device->size)){ + $desc = $this->renderDevice($device); + $desc .= " / Size: ".$this->convertBytes($device->size,$si); + }else{ + $desc = $this->renderDevice($device); + } + return $desc; } protected function renderNic($device){