Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LibreNMS/Enum/ServiceStatus.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* ServiceStatus.php
*
Expand Down
1 change: 0 additions & 1 deletion LibreNMS/Exceptions/ServiceCheckNotExecutableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class ServiceCheckNotExecutableException extends ServiceException
{

}
1 change: 0 additions & 1 deletion LibreNMS/Exceptions/ServiceCheckNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class ServiceCheckNotFoundException extends ServiceException
{

}
1 change: 0 additions & 1 deletion LibreNMS/Exceptions/ServiceException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class ServiceException extends \Exception
{

}
22 changes: 11 additions & 11 deletions LibreNMS/Services/Checks/CheckIcmp.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* CheckIcmp.php
*
Expand Down Expand Up @@ -33,7 +34,6 @@

class CheckIcmp extends Service
{

public function parameters(): array
{
return [
Expand All @@ -53,8 +53,8 @@ public function parameters(): array
new ServiceOption('outgoing-ttl', 'l', ['outgoing-ttl' => 'int|min:0']),
new ServiceOption('timeout', 't'),
new ServiceOption('bytes', 'b'),
new ServiceOption('verbose', 'v', mode: InputOption::VALUE_NONE|InputOption::VALUE_IS_ARRAY),
new ServiceOption('Host', 'H', ['Host' => 'required|ip_or_hostname'], mode: InputOption::VALUE_IS_ARRAY)
new ServiceOption('verbose', 'v', mode: InputOption::VALUE_NONE | InputOption::VALUE_IS_ARRAY),
new ServiceOption('Host', 'H', ['Host' => 'required|ip_or_hostname'], mode: InputOption::VALUE_IS_ARRAY),
];
}

Expand Down Expand Up @@ -91,7 +91,7 @@ public function dataSets(string $rrd_filename = '', ?string $ds = null): array
]),
];

return array_filter($dataSets, fn($dataSet) => $ds === null || $ds === $dataSet->name);
return array_filter($dataSets, fn ($dataSet) => $ds === null || $ds === $dataSet->name);
}

public function graph(string $rrd_filename = ''): array
Expand All @@ -100,11 +100,11 @@ public function graph(string $rrd_filename = ''): array
'rta' => [
'unit' => 's',
'commands' => [
'DEF:DS0=' . $rrd_filename . ':rta:AVERAGE',
'LINE1.25:DS0#' . LibrenmsConfig::get('graph_colours.mixed.0') . ':' . str_pad(substr('Round Trip Average', 0, 15), 15),
'GPRINT:DS0:LAST:%5.2lf%s',
'GPRINT:DS0:AVERAGE:%5.2lf%s',
'GPRINT:DS0:MAX:%5.2lf%s\\l',
'DEF:DS0=' . $rrd_filename . ':rta:AVERAGE',
'LINE1.25:DS0#' . LibrenmsConfig::get('graph_colours.mixed.0') . ':' . str_pad(substr('Round Trip Average', 0, 15), 15),
'GPRINT:DS0:LAST:%5.2lf%s',
'GPRINT:DS0:AVERAGE:%5.2lf%s',
'GPRINT:DS0:MAX:%5.2lf%s\\l',
],
],
'rtmax' => [
Expand All @@ -115,7 +115,7 @@ public function graph(string $rrd_filename = ''): array
'GPRINT:DS1:LAST:%5.2lf%s',
'GPRINT:DS1:AVERAGE:%5.2lf%s',
'GPRINT:DS1:MAX:%5.2lf%s\\l',
]
],
],
'rtmin' => [
'unit' => 's',
Expand All @@ -133,7 +133,7 @@ public function graph(string $rrd_filename = ''): array
'GPRINT:DS0:LAST:%5.2lf%s',
'GPRINT:DS0:AVERAGE:%5.2lf%s',
'GPRINT:DS0:MAX:%5.2lf%s\\l',
]
],
];
}
}
33 changes: 17 additions & 16 deletions LibreNMS/Services/Checks/CheckLoad.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* CheckLoad.php
*
Expand Down Expand Up @@ -38,29 +39,29 @@ public function parameters(): array
new ServiceOption('warning', 'w', default: '5,5,5'),
new ServiceOption('critical', 'c', default: '10,10,10'),
new ServiceOption('percpu', 'p', ['percpu' => 'int']),
new ServiceOption('procs-to-show', )
new ServiceOption('procs-to-show'),
];
}

public function dataSets(string $rrd_filename = '', ?string $ds = null): array
{
return [
new ServiceDataSet('load', 'processes', [
'DEF:DS0=' . $rrd_filename . ':load1:AVERAGE',
'LINE1.25:DS0#' . LibrenmsConfig::get('graph_colours.mixed.0') . ':' . str_pad(substr('Load 1', 0, 15), 15),
'GPRINT:DS0:LAST:%5.2lf%s',
'GPRINT:DS0:AVERAGE:%5.2lf%s',
'GPRINT:DS0:MAX:%5.2lf%s\\l',
'DEF:DS1=' . $rrd_filename . ':load5:AVERAGE',
'LINE1.25:DS1#' . LibrenmsConfig::get('graph_colours.mixed.1') . ':' . str_pad(substr('Load 5', 0, 15), 15),
'GPRINT:DS1:LAST:%5.2lf%s',
'GPRINT:DS1:AVERAGE:%5.2lf%s',
'GPRINT:DS1:MAX:%5.2lf%s\\l',
'DEF:DS2=' . $rrd_filename . ':load15:AVERAGE',
'LINE1.25:DS2#' . LibrenmsConfig::get('graph_colours.mixed.2') . ':' . str_pad(substr('Load 15', 0, 15), 15),
'GPRINT:DS2:LAST:%5.2lf%s',
'GPRINT:DS2:AVERAGE:%5.2lf%s',
'GPRINT:DS2:MAX:%5.2lf%s\\l',
'DEF:DS0=' . $rrd_filename . ':load1:AVERAGE',
'LINE1.25:DS0#' . LibrenmsConfig::get('graph_colours.mixed.0') . ':' . str_pad(substr('Load 1', 0, 15), 15),
'GPRINT:DS0:LAST:%5.2lf%s',
'GPRINT:DS0:AVERAGE:%5.2lf%s',
'GPRINT:DS0:MAX:%5.2lf%s\\l',
'DEF:DS1=' . $rrd_filename . ':load5:AVERAGE',
'LINE1.25:DS1#' . LibrenmsConfig::get('graph_colours.mixed.1') . ':' . str_pad(substr('Load 5', 0, 15), 15),
'GPRINT:DS1:LAST:%5.2lf%s',
'GPRINT:DS1:AVERAGE:%5.2lf%s',
'GPRINT:DS1:MAX:%5.2lf%s\\l',
'DEF:DS2=' . $rrd_filename . ':load15:AVERAGE',
'LINE1.25:DS2#' . LibrenmsConfig::get('graph_colours.mixed.2') . ':' . str_pad(substr('Load 15', 0, 15), 15),
'GPRINT:DS2:LAST:%5.2lf%s',
'GPRINT:DS2:AVERAGE:%5.2lf%s',
'GPRINT:DS2:MAX:%5.2lf%s\\l',
]),
];
}
Expand Down
3 changes: 2 additions & 1 deletion LibreNMS/Services/LegacyService.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* LegacyService.php
*
Expand Down Expand Up @@ -68,7 +69,7 @@ public function dataSets(string $rrd_filename = '', ?string $ds = null): array
$graphs = $vars['check_graph'] ?? [];
foreach ($sets as $name => $unit) {
$commands = $graphs[$name] ?? $this->defaultGraphCommands($rrd_filename, $name);
$dataSets[] = new ServiceDataSet($name, $unit,is_array($commands) ? $commands : [$commands]);
$dataSets[] = new ServiceDataSet($name, $unit, is_array($commands) ? $commands : [$commands]);
}

return $dataSets;
Expand Down
9 changes: 6 additions & 3 deletions LibreNMS/Services/Service.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Service.php
*
Expand Down Expand Up @@ -38,15 +39,17 @@

public function __construct(
public readonly string $type = '',
) {}
) {
}

/**
* @param Device $device
* @param \App\Models\Service $service
* @param Device $device
* @param \App\Models\Service $service
* @return string[]
*
* @throws ServiceException
*/
public function buildCommand(\App\Models\Service $service): array

Check failure on line 52 in LibreNMS/Services/Service.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

PHPDoc tag `@param` references unknown parameter: $device
{
$bin = $this->getExecutable();

Expand All @@ -60,8 +63,8 @@

$command = [$bin];
foreach ($this->parameters() as $parameter) {
if (isset($values[$parameter->name])) {

Check failure on line 66 in LibreNMS/Services/Service.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Variable $values in isset() is never defined.
$command = array_merge($command, $parameter->format($values[$parameter->name]));

Check failure on line 67 in LibreNMS/Services/Service.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Undefined variable: $values
}
}

Expand Down
1 change: 1 addition & 0 deletions LibreNMS/Services/ServiceArgument.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Parameter.php
*
Expand Down
4 changes: 3 additions & 1 deletion LibreNMS/Services/ServiceDataSet.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* ServiceDataSet.php
*
Expand Down Expand Up @@ -31,5 +32,6 @@ public function __construct(
public string $name,
public string $unit,
public array $graphCommands,
) {}
) {
}
}
1 change: 1 addition & 0 deletions LibreNMS/Services/ServiceFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* ServiceFactory.php
*
Expand Down
9 changes: 5 additions & 4 deletions LibreNMS/Services/ServiceOption.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Option.php
*
Expand Down Expand Up @@ -34,7 +35,7 @@
public mixed $default = null,
public int $mode = 0,
) {
if ($this->short === null && $this->long === null) {

Check failure on line 38 in LibreNMS/Services/ServiceOption.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Access to an undefined property LibreNMS\Services\ServiceOption::$long.
throw new \RuntimeException('Must have one of long or short option name');
}
}
Expand All @@ -45,13 +46,13 @@
*/
public function format(float|bool|int|string|null $value): array
{
if ($value)

if ($this->short) {
return [$this->short, (string) $value];
if ($value) {
if ($this->short) {
return [$this->short, (string) $value];
}
}

if ($this->long) {

Check failure on line 55 in LibreNMS/Services/ServiceOption.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Access to an undefined property LibreNMS\Services\ServiceOption::$long.
return ["$this->long=$value"];
}

Expand Down
3 changes: 1 addition & 2 deletions app/Models/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ protected function serviceParam(): Attribute

if (is_array($params)) {
return $params;
};
}

$params = [];
$values = explode(' ', $value);
foreach ($values as $index => $value) {
if (str_starts_with($value, '-')) {

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function up(): void
{
if (! Schema::hasColumn($this->table, 'updated_at')) {
Schema::table($this->table, function (Blueprint $table) {
$table->timestamps();
$table->timestamps();
});
}

Expand Down
2 changes: 1 addition & 1 deletion includes/services.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function add_service($device, $type, $desc, $ip = '', $param = '', $ignore = 0,
'service_ds' => '{}',
'service_disabled' => $disabled,
'service_template_id' => $template_id,
'service_name' => $name
'service_name' => $name,
]);
}

Expand Down
10 changes: 5 additions & 5 deletions lang/en/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
'load' => [
'options' => [
'warning' => [
'help' => 'Exit with WARNING status if load average exceeds WLOADn'
'help' => 'Exit with WARNING status if load average exceeds WLOADn',
],
'critical' => [
'help' => 'Exit with CRITICAL status if load average exceeds CLOADn'
'help' => 'Exit with CRITICAL status if load average exceeds CLOADn',
],
'percpu' => [
'help' => 'Divide the load averages by the number of CPUs (when possible)'
'help' => 'Divide the load averages by the number of CPUs (when possible)',
],
'procs-to-show' => [
'help' => "Number of processes to show when printing the top consuming processes.\nNUMBER_OF_PROCS=0 disables this feature. Default value is 0"
]
'help' => "Number of processes to show when printing the top consuming processes.\nNUMBER_OF_PROCS=0 disables this feature. Default value is 0",
],
],
],
];
Loading