2017-02-23 22:45:50 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* RrdDefinitonTest.php
|
|
|
|
*
|
|
|
|
* -Description-
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-02-08 23:29:04 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-02-23 22:45:50 +00:00
|
|
|
*
|
2021-02-08 23:29:04 +00:00
|
|
|
* @link https://www.librenms.org
|
2021-09-10 18:09:53 +00:00
|
|
|
*
|
2017-02-23 22:45:50 +00:00
|
|
|
* @copyright 2017 Tony Murray
|
|
|
|
* @author Tony Murray <murraytony@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace LibreNMS\Tests;
|
|
|
|
|
2019-06-23 05:29:12 +00:00
|
|
|
use LibreNMS\Config;
|
2017-02-23 22:45:50 +00:00
|
|
|
use LibreNMS\RRD\RrdDefinition;
|
|
|
|
|
2017-12-20 14:36:49 +00:00
|
|
|
class RrdDefinitionTest extends TestCase
|
2017-02-23 22:45:50 +00:00
|
|
|
{
|
2023-05-24 20:21:54 +00:00
|
|
|
public function testEmpty(): void
|
2017-02-23 22:45:50 +00:00
|
|
|
{
|
|
|
|
$this->assertEmpty((string) new RrdDefinition());
|
|
|
|
}
|
|
|
|
|
2023-05-24 20:21:54 +00:00
|
|
|
public function testWrongType(): void
|
2017-02-23 22:45:50 +00:00
|
|
|
{
|
2020-04-21 12:27:13 +00:00
|
|
|
$this->expectException(\LibreNMS\Exceptions\InvalidRrdTypeException::class);
|
2019-06-23 05:29:12 +00:00
|
|
|
Config::set('rrd.step', 300);
|
|
|
|
Config::set('rrd.heartbeat', 600);
|
2017-02-23 22:45:50 +00:00
|
|
|
$def = new RrdDefinition();
|
|
|
|
$def->addDataset('badtype', 'Something unexpected');
|
|
|
|
}
|
|
|
|
|
2023-05-24 20:21:54 +00:00
|
|
|
public function testNameEscaping(): void
|
2017-02-23 22:45:50 +00:00
|
|
|
{
|
2019-06-23 05:29:12 +00:00
|
|
|
Config::set('rrd.step', 300);
|
|
|
|
Config::set('rrd.heartbeat', 600);
|
2017-02-23 22:45:50 +00:00
|
|
|
$expected = 'DS:bad_name-is_too_lon:GAUGE:600:0:100 ';
|
|
|
|
$def = RrdDefinition::make()->addDataset('b a%d$_n:a^me-is_too_lon%g.', 'GAUGE', 0, 100, 600);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, (string) $def);
|
|
|
|
}
|
|
|
|
|
2023-05-24 20:21:54 +00:00
|
|
|
public function testCreation(): void
|
2017-02-23 22:45:50 +00:00
|
|
|
{
|
2019-06-23 05:29:12 +00:00
|
|
|
Config::set('rrd.step', 300);
|
|
|
|
Config::set('rrd.heartbeat', 600);
|
2017-02-23 22:45:50 +00:00
|
|
|
$expected = 'DS:pos:COUNTER:600:0:125000000000 ' .
|
2019-06-23 05:29:12 +00:00
|
|
|
'DS:unbound:DERIVE:600:U:U ';
|
2017-02-23 22:45:50 +00:00
|
|
|
|
|
|
|
$def = new RrdDefinition();
|
|
|
|
$def->addDataset('pos', 'COUNTER', 0, 125000000000);
|
|
|
|
$def->addDataset('unbound', 'DERIVE');
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $def);
|
|
|
|
}
|
|
|
|
}
|