|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Icinga\Module\Icingadb\Model; |
| 4 | + |
| 5 | +use ipl\Orm\Relations; |
| 6 | +use ipl\Orm\UnionModel; |
| 7 | +use ipl\Sql\Expression; |
| 8 | + |
| 9 | +class HostSlaHistory extends UnionModel |
| 10 | +{ |
| 11 | + public function getTableName() |
| 12 | + { |
| 13 | + return 'host'; |
| 14 | + } |
| 15 | + |
| 16 | + public function getKeyName() |
| 17 | + { |
| 18 | + return 'host_id'; |
| 19 | + } |
| 20 | + |
| 21 | + public function getColumns() |
| 22 | + { |
| 23 | + return [ |
| 24 | + 'host_id', |
| 25 | + 'display_name', |
| 26 | + 'event_time', |
| 27 | + 'event_type', |
| 28 | + 'event_priority', |
| 29 | + 'hard_state', |
| 30 | + 'previous_hard_state' |
| 31 | + ]; |
| 32 | + } |
| 33 | + |
| 34 | + public function getUnions() |
| 35 | + { |
| 36 | + return [ |
| 37 | + [ |
| 38 | + Host::class, |
| 39 | + [ |
| 40 | + 'sla_history_downtime' |
| 41 | + ], |
| 42 | + [ |
| 43 | + 'display_name' => 'host.display_name', |
| 44 | + 'event_priority' => new Expression('1'), |
| 45 | + 'event_time' => 'sla_history_downtime.downtime_start', |
| 46 | + 'event_type' => new Expression('\'downtime_start\''), |
| 47 | + 'hard_state' => new Expression('NULL'), |
| 48 | + 'host_id' => 'id', |
| 49 | + 'previous_hard_state' => new Expression('NULL'), |
| 50 | + ] |
| 51 | + ], |
| 52 | + [ |
| 53 | + Host::class, |
| 54 | + [ |
| 55 | + 'sla_history_downtime' |
| 56 | + ], |
| 57 | + [ |
| 58 | + 'display_name' => 'host.display_name', |
| 59 | + 'event_priority' => new Expression('2'), |
| 60 | + 'event_time' => 'sla_history_downtime.downtime_end', |
| 61 | + 'event_type' => new Expression('\'downtime_end\''), |
| 62 | + 'hard_state' => new Expression('NULL'), |
| 63 | + 'host_id' => 'id', |
| 64 | + 'previous_hard_state' => new Expression('NULL'), |
| 65 | + ] |
| 66 | + ], |
| 67 | + [ |
| 68 | + Host::class, |
| 69 | + [ |
| 70 | + 'sla_history_state' |
| 71 | + ], |
| 72 | + [ |
| 73 | + 'display_name' => 'display_name', |
| 74 | + 'event_priority' => new Expression('0'), |
| 75 | + 'event_time' => 'sla_history_state.event_time', |
| 76 | + 'event_type' => new Expression('\'state_change\''), |
| 77 | + 'hard_state' => 'sla_history_state.hard_state', |
| 78 | + 'host_id' => 'id', |
| 79 | + 'previous_hard_state' => 'sla_history_state.previous_hard_state', |
| 80 | + ] |
| 81 | + ], |
| 82 | + // Fake result!! |
| 83 | + [ |
| 84 | + Host::class, |
| 85 | + [], |
| 86 | + [ |
| 87 | + 'display_name' => 'host.display_name', |
| 88 | + 'event_priority' => new Expression('3'), |
| 89 | + 'event_time' => new Expression('NULL'), |
| 90 | + 'event_type' => new Expression('\'end\''), |
| 91 | + 'hard_state' => new Expression('NULL'), |
| 92 | + 'host_id' => 'id', |
| 93 | + 'previous_hard_state' => new Expression('NULL'), |
| 94 | + ] |
| 95 | + ] |
| 96 | + ]; |
| 97 | + } |
| 98 | + |
| 99 | + public function getDefaultSort() |
| 100 | + { |
| 101 | + return ['display_name', 'event_time', 'event_priority']; |
| 102 | + } |
| 103 | + |
| 104 | + public function createRelations(Relations $relations) |
| 105 | + { |
| 106 | + (new Host())->createRelations($relations); |
| 107 | + } |
| 108 | +} |
0 commit comments