2016-10-26 06:54:48 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* AlertingTest.php
|
|
|
|
*
|
|
|
|
* Tests for alerting functionality.
|
|
|
|
*
|
|
|
|
* 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/>.
|
2016-10-26 06:54:48 +00:00
|
|
|
*
|
2021-02-08 23:29:04 +00:00
|
|
|
* @link https://www.librenms.org
|
2021-09-10 18:09:53 +00:00
|
|
|
*
|
2016-10-26 06:54:48 +00:00
|
|
|
* @copyright 2016 Neil Lathwood
|
|
|
|
* @author Neil Lathwood <neil@lathwood.co.uk>
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace LibreNMS\Tests;
|
|
|
|
|
2018-07-21 19:34:59 +00:00
|
|
|
use RecursiveDirectoryIterator;
|
|
|
|
use RecursiveIteratorIterator;
|
|
|
|
use RegexIterator;
|
|
|
|
|
2020-04-03 22:13:18 +00:00
|
|
|
class AlertingTest extends TestCase
|
2016-10-26 06:54:48 +00:00
|
|
|
{
|
2023-05-23 14:25:17 +00:00
|
|
|
public function testJsonAlertCollection(): void
|
2016-10-26 06:54:48 +00:00
|
|
|
{
|
|
|
|
$rules = get_rules_from_json();
|
2019-02-12 23:45:04 +00:00
|
|
|
$this->assertIsArray($rules);
|
2016-10-26 06:54:48 +00:00
|
|
|
foreach ($rules as $rule) {
|
2019-02-12 23:45:04 +00:00
|
|
|
$this->assertIsArray($rule);
|
2016-10-26 06:54:48 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-21 19:34:59 +00:00
|
|
|
|
2023-05-23 14:25:17 +00:00
|
|
|
public function testTransports(): void
|
2018-07-21 19:34:59 +00:00
|
|
|
{
|
|
|
|
foreach ($this->getTransportFiles() as $file => $_unused) {
|
|
|
|
$parts = explode('/', $file);
|
|
|
|
$transport = ucfirst(str_replace('.php', '', array_pop($parts)));
|
|
|
|
$class = 'LibreNMS\\Alert\\Transport\\' . $transport;
|
2021-10-06 12:29:47 +00:00
|
|
|
$this->assertTrue(class_exists($class), "The transport $transport does not exist");
|
|
|
|
$this->assertInstanceOf(\LibreNMS\Interfaces\Alert\Transport::class, new $class);
|
2018-07-21 19:34:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-23 14:25:17 +00:00
|
|
|
private function getTransportFiles(): RegexIterator
|
2018-07-21 19:34:59 +00:00
|
|
|
{
|
|
|
|
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('LibreNMS/Alert/Transport'));
|
2020-09-21 12:54:51 +00:00
|
|
|
|
2023-05-23 14:25:17 +00:00
|
|
|
return new RegexIterator($iterator, '/^.+\.php$/i', RegexIterator::GET_MATCH);
|
2018-07-21 19:34:59 +00:00
|
|
|
}
|
2016-10-26 06:54:48 +00:00
|
|
|
}
|