-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
501 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Tests\Icinga\Module\Icingadb\Lib; | ||
|
||
use Icinga\Module\Icingadb\ProvidedHook\Reporting\Common\SlaTimelines; | ||
|
||
class FakeReportData | ||
{ | ||
use SlaTimelines; | ||
|
||
public function setDimensions(array $_) | ||
{ | ||
} | ||
|
||
public function getDimensions() | ||
{ | ||
return []; | ||
} | ||
|
||
public function setRows(array $rows) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace Tests\Icinga\Module\Icingadb\Lib; | ||
|
||
use DateTime; | ||
use Icinga\Module\Icingadb\ProvidedHook\Reporting\Common\SlaReportUtils; | ||
use Icinga\Module\Icingadb\ProvidedHook\Reporting\Common\SlaTimeline; | ||
use ipl\Sql\Connection; | ||
|
||
class SlaReportWithCustomDb | ||
{ | ||
use SlaReportUtils; | ||
|
||
public const HOST_NAME = 'icinga2'; | ||
|
||
public const SERVICE_NAME = 'disk'; | ||
|
||
/** @var Connection */ | ||
protected static $conn; | ||
|
||
protected $reportType; | ||
|
||
protected static $dbConfiguration = [ | ||
'mysql' => [ | ||
'db' => 'mysql', | ||
'host' => '127.0.0.1', | ||
'port' => 3306, | ||
'dbname' => 'icingadb_web_unittest', | ||
'username' => 'root', | ||
'password' => 'password' | ||
] | ||
]; | ||
|
||
public function resetConn() | ||
{ | ||
static::$conn = null; | ||
} | ||
|
||
public function getDb(): Connection | ||
{ | ||
if (! static::$conn) { | ||
$config = static::$dbConfiguration['mysql']; | ||
$host = getenv('ICINGADBWEB_TEST_MYSQL_HOST'); | ||
if ($host) { | ||
$config['host'] = $host; | ||
} | ||
|
||
$port = getenv('ICINGADBWEB_TEST_MYSQL_PORT'); | ||
if ($port) { | ||
$config['port'] = $port; | ||
} | ||
|
||
static::$conn = new Connection($config); | ||
$fixtures = file_get_contents(__DIR__ . '/fixtures.sql'); | ||
static::$conn->exec($fixtures); | ||
} | ||
|
||
return static::$conn; | ||
} | ||
|
||
public function getReportType(): string | ||
{ | ||
return $this->reportType; | ||
} | ||
|
||
public function getSlaTimeline(DateTime $start, DateTime $end, string $type): SlaTimeline | ||
{ | ||
$this->reportType = $type; | ||
$name = $type === 'host' | ||
? static::HOST_NAME | ||
: static::HOST_NAME . static::$hostServiceSeparator . static::SERVICE_NAME; | ||
|
||
return $this->fetchReportData($start, $end, ['filter' => null])->getTimelines($name)[0]; | ||
} | ||
|
||
protected function createReportData() | ||
{ | ||
return new FakeReportData(); | ||
} | ||
|
||
protected function createReportRow($row) | ||
{ | ||
return 'NOPE!'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
CREATE TABLE host ( | ||
id binary(20) NOT NULL PRIMARY KEY, | ||
display_name varchar(254) NOT NULL | ||
); | ||
|
||
CREATE TABLE host_state ( | ||
id binary(20) NOT NULL, | ||
host_id binary(20) NOT NULL, | ||
hard_state TINYINT UNSIGNED NOT NULL, | ||
previous_hard_state TINYINT UNSIGNED DEFAULT NULL, | ||
|
||
PRIMARY KEY(id, host_id) | ||
); | ||
|
||
CREATE TABLE service ( | ||
id binary(20) NOT NULL, | ||
host_id binary(20) NOT NULL, | ||
display_name varchar(254) NOT NULL, | ||
|
||
PRIMARY KEY(id, host_id) | ||
); | ||
|
||
CREATE TABLE service_state ( | ||
id binary(20) NOT NULL PRIMARY KEY, | ||
host_id binary(20) NOT NULL, | ||
service_id binary(20) NOT NULL, | ||
hard_state TINYINT UNSIGNED NOT NULL, | ||
previous_hard_state TINYINT UNSIGNED DEFAULT NULL | ||
); | ||
|
||
CREATE TABLE sla_history_state ( | ||
id binary(20) NOT NULL PRIMARY KEY, | ||
environment_id binary(20) DEFAULT NULL, | ||
endpoint_id binary(20) DEFAULT NULL, | ||
object_type enum('host', 'service') NOT NULL, | ||
host_id binary(20) NOT NULL, | ||
service_id binary(20) DEFAULT NULL, | ||
|
||
event_time bigint unsigned NOT NULL, | ||
hard_state TINYINT UNSIGNED NOT NULL, | ||
previous_hard_state TINYINT UNSIGNED NOT NULL | ||
); | ||
|
||
CREATE TABLE sla_history_downtime ( | ||
id binary(20) NOT NULL PRIMARY KEY, | ||
environment_id binary(20) DEFAULT NULL, | ||
endpoint_id binary(20) DEFAULT NULL, | ||
object_type enum('host', 'service') NOT NULL, | ||
host_id binary(20) NOT NULL, | ||
service_id binary(20) DEFAULT NULL, | ||
|
||
downtime_id binary(20) NOT NULL, | ||
downtime_start BIGINT UNSIGNED NOT NULL, | ||
downtime_end BIGINT UNSIGNED NOT NULL | ||
); |
Oops, something went wrong.