-
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.
Models for the new schema additions described here: Icinga/icingadb#347 (comment)
- Loading branch information
Showing
10 changed files
with
619 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,95 @@ | ||
<?php | ||
|
||
/* Icinga DB Web | (c) 2024 Icinga GmbH | GPLv2 */ | ||
|
||
namespace Icinga\Module\Icingadb\Model; | ||
|
||
use Icinga\Module\Icingadb\Model\Behavior\Bitmask; | ||
use ipl\Orm\Behavior\Binary; | ||
use ipl\Orm\Behavior\BoolCast; | ||
use ipl\Orm\Behaviors; | ||
use ipl\Orm\Model; | ||
use ipl\Orm\Query; | ||
use ipl\Orm\Relations; | ||
|
||
/** | ||
* Dependency model. | ||
* | ||
* @property string $id | ||
* @property string $name | ||
* @property string $display_name | ||
* @property ?string $redundancy_group_id | ||
* @property bool $disable_checks | ||
* @property bool $disable_notifications | ||
* @property bool $ignore_soft_states | ||
* @property ?string $timeperiod_id | ||
* @property string[] $states | ||
* | ||
* @property (?Timeperiod)|Query $timeperiod | ||
* @property (?RedundancyGroup)|Query $redundancy_group | ||
* @property (?DependencyState)|Query $state | ||
* @property DependencyEdge|Query $edge | ||
*/ | ||
class Dependency extends Model | ||
{ | ||
public function getTableName(): string | ||
{ | ||
return 'dependency'; | ||
} | ||
|
||
public function getKeyName(): string | ||
{ | ||
return 'id'; | ||
} | ||
|
||
public function getColumns(): array | ||
{ | ||
return [ | ||
'name', | ||
'display_name', | ||
'redundancy_group_id', | ||
'disable_checks', | ||
'disable_notifications', | ||
'ignore_soft_states', | ||
'timeperiod_id', | ||
'states' | ||
]; | ||
} | ||
|
||
public function createBehaviors(Behaviors $behaviors): void | ||
{ | ||
$behaviors->add(new Binary([ | ||
'id', | ||
'redundancy_group_id', | ||
'timeperiod_id' | ||
])); | ||
$behaviors->add(new BoolCast([ | ||
'disable_checks', | ||
'disable_notifications', | ||
'ignore_soft_states' | ||
])); | ||
$behaviors->add(new Bitmask([ | ||
'states' => [ | ||
'ok' => 1, | ||
'warning' => 2, | ||
'critical' => 4, | ||
'unknown' => 8, | ||
'up' => 16, | ||
'down' => 32 | ||
], | ||
])); | ||
} | ||
|
||
public function createRelations(Relations $relations): void | ||
{ | ||
$relations->belongsTo('timeperiod', Timeperiod::class) | ||
->setJoinType('LEFT'); | ||
$relations->belongsTo('redundancy_group', RedundancyGroup::class) | ||
->setJoinType('LEFT'); | ||
|
||
$relations->hasOne('state', DependencyState::class) | ||
->setJoinType('LEFT'); | ||
|
||
$relations->hasOne('edge', DependencyEdge::class); | ||
} | ||
} |
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,63 @@ | ||
<?php | ||
|
||
/* Icinga DB Web | (c) 2024 Icinga GmbH | GPLv2 */ | ||
|
||
namespace Icinga\Module\Icingadb\Model; | ||
|
||
use ipl\Orm\Behavior\Binary; | ||
use ipl\Orm\Behaviors; | ||
use ipl\Orm\Model; | ||
use ipl\Orm\Query; | ||
use ipl\Orm\Relations; | ||
|
||
/** | ||
* Dependency edge model. | ||
* | ||
* @property string $to_node_id | ||
* @property string $from_node_id | ||
* @property ?string $dependency_id | ||
* | ||
* @property DependencyNode|Query $from | ||
* @property DependencyNode|Query $to | ||
* @property (?Dependency)|Query $dependency | ||
*/ | ||
class DependencyEdge extends Model | ||
{ | ||
public function getTableName(): string | ||
{ | ||
return 'dependency_edge'; | ||
} | ||
|
||
public function getKeyName(): array | ||
{ | ||
return ['to_node_id', 'from_node_id']; | ||
} | ||
|
||
public function getColumns(): array | ||
{ | ||
return [ | ||
'to_node_id', | ||
'from_node_id', | ||
'dependency_id' | ||
]; | ||
} | ||
|
||
public function createBehaviors(Behaviors $behaviors): void | ||
{ | ||
$behaviors->add(new Binary([ | ||
'to_node_id', | ||
'from_node_id', | ||
'dependency_id' | ||
])); | ||
} | ||
|
||
public function createRelations(Relations $relations): void | ||
{ | ||
$relations->belongsTo('from', DependencyNode::class) | ||
->setCandidateKey('from_node_id'); | ||
$relations->belongsTo('to', DependencyNode::class) | ||
->setCandidateKey('to_node_id'); | ||
$relations->belongsTo('dependency', Dependency::class) | ||
->setJoinType('LEFT'); | ||
} | ||
} |
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,88 @@ | ||
<?php | ||
|
||
/* Icinga DB Web | (c) 2024 Icinga GmbH | GPLv2 */ | ||
|
||
namespace Icinga\Module\Icingadb\Model; | ||
|
||
use ipl\Orm\Behavior\Binary; | ||
use ipl\Orm\Behaviors; | ||
use ipl\Orm\Model; | ||
use ipl\Orm\Query; | ||
use ipl\Orm\Relations; | ||
|
||
/** | ||
* Dependency node model. | ||
* | ||
* @property string $id | ||
* @property ?string $host_id | ||
* @property ?string $service_id | ||
* @property ?string $redundancy_group_id | ||
* | ||
* @property (?Host)|Query $host | ||
* @property (?Service)|Query $service | ||
* @property (?RedundancyGroup)|Query $redundancy_group | ||
* @property (?DependencyEdge)|Query $from | ||
* @property (?DependencyEdge)|Query $to | ||
* @property (?DependencyNode)|Query $child | ||
* @property (?DependencyNode)|Query $parent | ||
*/ | ||
class DependencyNode extends Model | ||
{ | ||
public function getTableName(): string | ||
{ | ||
return 'dependency_node'; | ||
} | ||
|
||
public function getKeyName(): string | ||
{ | ||
return 'id'; | ||
} | ||
|
||
public function getColumns(): array | ||
{ | ||
return [ | ||
'id', | ||
'host_id', | ||
'service_id', | ||
'redundancy_group_id' | ||
]; | ||
} | ||
|
||
public function createBehaviors(Behaviors $behaviors): void | ||
{ | ||
$behaviors->add(new Binary([ | ||
'id', | ||
'host_id', | ||
'service_id', | ||
'redundancy_group_id' | ||
])); | ||
} | ||
|
||
public function createRelations(Relations $relations): void | ||
{ | ||
$relations->belongsTo('host', Host::class) | ||
->setJoinType('LEFT'); | ||
$relations->belongsTo('service', Service::class) | ||
->setJoinType('LEFT'); | ||
$relations->belongsTo('redundancy_group', RedundancyGroup::class) | ||
->setJoinType('LEFT'); | ||
|
||
$relations->hasMany('from', DependencyEdge::class) | ||
->setForeignKey('from_node_id') | ||
->setJoinType('LEFT'); | ||
$relations->hasMany('to', DependencyEdge::class) | ||
->setForeignKey('to_node_id') | ||
->setJoinType('LEFT'); | ||
|
||
$relations->belongsToMany('child', self::class) | ||
->through(DependencyEdge::class) | ||
->setForeignKey('to_node_id') | ||
->setTargetForeignKey('from_node_id') | ||
->setJoinType('LEFT'); | ||
$relations->belongsToMany('parent', self::class) | ||
->through(DependencyEdge::class) | ||
->setForeignKey('from_node_id') | ||
->setTargetForeignKey('to_node_id') | ||
->setJoinType('LEFT'); | ||
} | ||
} |
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,58 @@ | ||
<?php | ||
|
||
/* Icinga DB Web | (c) 2024 Icinga GmbH | GPLv2 */ | ||
|
||
namespace Icinga\Module\Icingadb\Model; | ||
|
||
use ipl\Orm\Behavior\Binary; | ||
use ipl\Orm\Behavior\BoolCast; | ||
use ipl\Orm\Behaviors; | ||
use ipl\Orm\Model; | ||
use ipl\Orm\Query; | ||
use ipl\Orm\Relations; | ||
|
||
/** | ||
* Dependency state model. | ||
* | ||
* @property string $id | ||
* @property string $dependency_id | ||
* @property bool $failed | ||
* | ||
* @property Dependency|Query $dependency | ||
*/ | ||
class DependencyState extends Model | ||
{ | ||
public function getTableName(): string | ||
{ | ||
return 'dependency_state'; | ||
} | ||
|
||
public function getKeyName(): string | ||
{ | ||
return 'id'; | ||
} | ||
|
||
public function getColumns(): array | ||
{ | ||
return [ | ||
'dependency_id', | ||
'failed' | ||
]; | ||
} | ||
|
||
public function createBehaviors(Behaviors $behaviors): void | ||
{ | ||
$behaviors->add(new Binary([ | ||
'id', | ||
'dependency_id' | ||
])); | ||
$behaviors->add(new BoolCast([ | ||
'failed' | ||
])); | ||
} | ||
|
||
public function createRelations(Relations $relations): void | ||
{ | ||
$relations->belongsTo('dependency', Dependency::class); | ||
} | ||
} |
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
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,67 @@ | ||
<?php | ||
|
||
/* Icinga DB Web | (c) 2024 Icinga GmbH | GPLv2 */ | ||
|
||
namespace Icinga\Module\Icingadb\Model; | ||
|
||
use Icinga\Module\Icingadb\Model\Behavior\ReRoute; | ||
use ipl\Orm\Behavior\Binary; | ||
use ipl\Orm\Behavior\BoolCast; | ||
use ipl\Orm\Behaviors; | ||
use ipl\Orm\Model; | ||
use ipl\Orm\Query; | ||
use ipl\Orm\Relations; | ||
|
||
/** | ||
* Redundancy group model. | ||
* | ||
* @property string $id | ||
* @property string $name | ||
* @property string $display_name | ||
* | ||
* @property (?RedundancyGroupState)|Query $state | ||
* @property Dependency|Query $dependency | ||
*/ | ||
class RedundancyGroup extends Model | ||
{ | ||
public function getTableName(): string | ||
{ | ||
return 'redundancy_group'; | ||
} | ||
|
||
public function getKeyName(): string | ||
{ | ||
return 'id'; | ||
} | ||
|
||
public function getColumns(): array | ||
{ | ||
return [ | ||
'name', | ||
'display_name' | ||
]; | ||
} | ||
|
||
public function createBehaviors(Behaviors $behaviors): void | ||
{ | ||
$behaviors->add(new Binary([ | ||
'id' | ||
])); | ||
$behaviors->add(new ReRoute([ | ||
'child' => 'dependency_node.child', | ||
'parent' => 'dependency_node.parent' | ||
])); | ||
} | ||
|
||
public function createRelations(Relations $relations): void | ||
{ | ||
$relations->belongsTo('dependency_node', DependencyNode::class) | ||
->setForeignKey('redundancy_group_id') | ||
->setCandidateKey('id'); | ||
|
||
$relations->hasOne('state', RedundancyGroupState::class) | ||
->setJoinType('LEFT'); | ||
|
||
$relations->hasMany('dependency', Dependency::class); | ||
} | ||
} |
Oops, something went wrong.