mirror of
https://github.com/Icinga/icingadb-web.git
synced 2026-05-28 04:36:06 -04:00
This was easy because only README.md and doc/01-About.md were redacted manually, everything else via: git ls-files -z |xargs -0 perl -pi -e 's/Icinga GmbH \| GPLv2/Icinga GmbH | GPLv2+/' This is legal because we have only merged PRs with label:cla/signed or made by Icinga staff: https://github.com/Icinga/icingadb-web/pulls?page=1&q=is%3Apr+is%3Aclosed+-label%3Acla%2Fsigned+-author%3Anilmerg This has no risk for us in people distributing their own version under GPLv3 only. After all, we won't take their patches anyway, unless they sign our CLA. This is the cleanest solution for having e.g. these in one address space: * Icinga Web, GPLv2+ * K8s Web, AGPLv3 * Thirdparty, some LGPLv3 and Apache-2.0 Apropos, K8s Web is even v3-licensed on purpose, to have a stronger protection against cloud ops.
174 lines
6.4 KiB
PHP
174 lines
6.4 KiB
PHP
<?php
|
|
|
|
/* Icinga DB Web | (c) 2021 Icinga GmbH | GPLv2+ */
|
|
|
|
namespace Tests\Icinga\Modules\Icingadb\Common;
|
|
|
|
use Icinga\Module\Icingadb\Common\Macros;
|
|
use Icinga\Module\Icingadb\Compat\CompatHost;
|
|
use Icinga\Module\Icingadb\Compat\CompatService;
|
|
use Icinga\Module\Icingadb\Model\Host;
|
|
use Icinga\Module\Icingadb\Model\Service;
|
|
use ipl\Orm\Query;
|
|
use ipl\Orm\ResultSet;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class MacrosTest extends TestCase
|
|
{
|
|
use Macros;
|
|
|
|
const VARS = [
|
|
'os' => "Ubuntu",
|
|
'days[0]' => 'mo',
|
|
'days[1]' => 'tue',
|
|
'days[2]' => 'wed',
|
|
'days[3]' => 'thu',
|
|
'days[4]' => 'fr'
|
|
];
|
|
|
|
public function testHostMacros()
|
|
{
|
|
$host = new Host();
|
|
$host->name = 'test';
|
|
$host->address = '1.1.1.1';
|
|
$host->address6 = '::1';
|
|
$host->vars = self::VARS;
|
|
|
|
$host->hostgroup = new Query();
|
|
|
|
$this->performHostMacroTests($host, $host);
|
|
}
|
|
|
|
public function testHostMacrosOnCompatObject()
|
|
{
|
|
if (! class_exists('Icinga\Module\Monitoring\Object\Host')) {
|
|
$this->markTestSkipped('This test requires the monitoring module');
|
|
}
|
|
|
|
$host = new Host();
|
|
$host->name = 'test';
|
|
$host->address = '1.1.1.1';
|
|
$host->address6 = '::1';
|
|
$host->vars = self::VARS;
|
|
|
|
$host->hostgroup = new Query();
|
|
|
|
$compatHost = new CompatHost($host);
|
|
|
|
$this->performHostMacroTests($compatHost, $host);
|
|
}
|
|
|
|
protected function performHostMacroTests($host, $source)
|
|
{
|
|
$this->assertEquals($source->name, $this->expandMacros('$host.name$', $host));
|
|
$this->assertEquals($source->name, $this->expandMacros('$name$', $host));
|
|
$this->assertEquals($source->address, $this->expandMacros('$host.address$', $host));
|
|
$this->assertEquals($source->address6, $this->expandMacros('$host.address6$', $host));
|
|
|
|
// A Host can have more than one hostgroups
|
|
$this->assertEquals('$host.hostgroup$', $this->expandMacros('$host.hostgroup$', $host));
|
|
$this->assertEquals('$host.hostgroup.name$', $this->expandMacros('$host.hostgroup.name$', $host));
|
|
|
|
// Host custom vars
|
|
$this->assertEquals($source->vars['os'], $this->expandMacros('$host.vars.os$', $host));
|
|
$this->assertEquals($source->vars['os'], $this->expandMacros('$vars.os$', $host));
|
|
$this->assertEquals($source->vars['days[2]'], $this->expandMacros('$vars.days[2]$', $host));
|
|
$this->assertEquals($source->vars['days[4]'], $this->expandMacros('$host.vars.days[4]$', $host));
|
|
|
|
// Host to service relation
|
|
$this->assertEquals('$service.name$', $this->expandMacros('$service.name$', $host));
|
|
$this->assertEquals('$service.address$', $this->expandMacros('$service.address$', $host));
|
|
|
|
// Service custom vars
|
|
$this->assertEquals('$service.vars.os$', $this->expandMacros('$service.vars.os$', $host));
|
|
$this->assertEquals('$service.vars.days[0]$', $this->expandMacros('$service.vars.days[0]$', $host));
|
|
$this->assertEquals('$service.vars.days[2]$', $this->expandMacros('$service.vars.days[2]$', $host));
|
|
}
|
|
|
|
public function testServiceMacros()
|
|
{
|
|
$service = new Service();
|
|
$service->name = 'test-service';
|
|
$service->description = 'A test service';
|
|
$service->vars = self::VARS;
|
|
|
|
$service->servicegroup = new Query();
|
|
|
|
$host = new Host();
|
|
$host->name = 'test';
|
|
$host->address = '1.1.1.1';
|
|
$host->hostgroup = new ResultSet(new \ArrayIterator());
|
|
$host->vars = self::VARS;
|
|
|
|
$service->host = $host;
|
|
|
|
$this->performServiceMacroTests($service, $service);
|
|
}
|
|
|
|
public function testServiceMacrosOnCompatObject()
|
|
{
|
|
if (! class_exists('Icinga\Module\Monitoring\Object\Service')) {
|
|
$this->markTestSkipped('This test requires the monitoring module');
|
|
}
|
|
|
|
$service = new Service();
|
|
$service->name = 'test-service';
|
|
$service->description = 'A test service';
|
|
$service->vars = self::VARS;
|
|
|
|
$service->servicegroup = new Query();
|
|
|
|
$host = new Host();
|
|
$host->name = 'test';
|
|
$host->address = '1.1.1.1';
|
|
$host->hostgroup = new ResultSet(new \ArrayIterator());
|
|
$host->vars = self::VARS;
|
|
|
|
$service->host = $host;
|
|
|
|
$compatService = new CompatService($service);
|
|
|
|
$this->performServiceMacroTests($compatService, $service);
|
|
}
|
|
|
|
protected function performServiceMacroTests($service, $source)
|
|
{
|
|
$this->assertEquals($source->name, $this->expandMacros('$service.name$', $service));
|
|
$this->assertEquals($source->name, $this->expandMacros('$name$', $service));
|
|
$this->assertEquals($source->description, $this->expandMacros('$service.description$', $service));
|
|
|
|
// A Service can have more than one hostgroups
|
|
$this->assertEquals(
|
|
'$service.servicegroup$',
|
|
$this->expandMacros('$service.servicegroup$', $service)
|
|
);
|
|
$this->assertEquals(
|
|
'$service.servicegroup.name$',
|
|
$this->expandMacros('$service.servicegroup.name$', $service)
|
|
);
|
|
|
|
// Service custom vars
|
|
$this->assertEquals($source->vars['os'], $this->expandMacros('$service.vars.os$', $service));
|
|
$this->assertEquals($source->vars['os'], $this->expandMacros('$vars.os$', $service));
|
|
$this->assertEquals($source->vars['days[2]'], $this->expandMacros('$vars.days[2]$', $service));
|
|
$this->assertEquals($source->vars['days[4]'], $this->expandMacros('$service.vars.days[4]$', $service));
|
|
|
|
$this->assertEquals($source->host->name, $this->expandMacros('$host.name$', $service));
|
|
$this->assertEquals($source->host->address, $this->expandMacros('$host.address$', $service));
|
|
|
|
// Host custom vars
|
|
$this->assertEquals($source->host->vars['os'], $this->expandMacros('$host.vars.os$', $service));
|
|
$this->assertEquals($source->host->vars['days[0]'], $this->expandMacros('$host.vars.days[0]$', $service));
|
|
$this->assertEquals($source->host->vars['days[3]'], $this->expandMacros('$host.vars.days[3]$', $service));
|
|
|
|
// A Host can have more than one hostgroups
|
|
$this->assertEquals(
|
|
'$host.hostgroup$',
|
|
$this->expandMacros('$host.hostgroup$', $service)
|
|
);
|
|
$this->assertEquals(
|
|
'$host.hostgroup.name$',
|
|
$this->expandMacros('$host.hostgroup.name$', $service)
|
|
);
|
|
}
|
|
}
|