Skip to content

Commit

Permalink
fix ubuntu24.04 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
moreamazingnick committed Nov 18, 2024
1 parent 535a5a4 commit 3d6df66
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 28 deletions.
3 changes: 3 additions & 0 deletions doc/01-About.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 3 additions & 2 deletions doc/02-Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a id="module-lshw-installation-manual"></a>

Expand All @@ -23,5 +24,5 @@ icingacli module enable lshw

Or go to your Icinga Web 2 frontend, choose `Configuration` -&gt; `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.
29 changes: 14 additions & 15 deletions doc/03-Configuration.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
# Configuration <a id="module-lshw-configuration"></a>

## Module Configuration <a id="module-lshw-configuration-module"></a>
## System Configuration <a id="module-lshw-configuration-module-system"></a>

![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 <a id="module-lshw-configuration-reference"></a>
## Director Configuration <a id="module-lshw-configuration-module-director"></a>

![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 <a id="module-lshw-configuration-director"></a>
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.
11 changes: 6 additions & 5 deletions doc/04-Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

## Module Usage <a id="module-lshw-usage-director"></a>

![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 <a id="module-lshw-usage-monitoring"></a>
The rendering will look like this:

![image_f](img/image_f.png)
![usage](img/usage.png)

Describe the usage...
Binary file added doc/img/director.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed doc/img/image_a.png
Binary file not shown.
Binary file removed doc/img/image_b.png
Binary file not shown.
Binary file removed doc/img/image_c.png
Binary file not shown.
Binary file removed doc/img/image_d.png
Binary file not shown.
Binary file removed doc/img/image_e.png
Binary file not shown.
Binary file removed doc/img/image_f.png
Binary file not shown.
Binary file added doc/img/usage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions library/Lshw/ProvidedHook/Icingadb/ServiceDetailExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 8 additions & 2 deletions library/Lshw/ProvidedHook/Monitoring/DetailviewExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;
}

Expand Down
14 changes: 12 additions & 2 deletions library/Lshw/Web/Widget/LshwHardwareTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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){
Expand Down

0 comments on commit 3d6df66

Please sign in to comment.