Skip to content

Commit

Permalink
Merge pull request #32 from Icinga/fix-flapping-history-visual
Browse files Browse the repository at this point in the history
Fix flapping history visual
  • Loading branch information
nilmerg authored Mar 13, 2020
2 parents 91cc441 + 774593e commit 06680c4
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 8 deletions.
1 change: 1 addition & 0 deletions application/controllers/HistoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function indexAction()
'service.state',
'comment',
'downtime',
'flapping',
'notification',
'acknowledgement',
'state'
Expand Down
1 change: 1 addition & 0 deletions library/Icingadb/Model/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function createRelations(Relations $relations)
$relations->hasMany('eventcommand_argument', EventcommandArgument::class);
$relations->hasMany('eventcommand_customvar', EventcommandCustomvar::class);
$relations->hasMany('eventcommand_envvar', EventcommandEnvvar::class);
$relations->hasMany('flapping_history', FlappingHistory::class);
$relations->hasMany('history', History::class);
$relations->hasMany('host', Host::class);
$relations->hasMany('host_customvar', HostCustomvar::class);
Expand Down
61 changes: 61 additions & 0 deletions library/Icingadb/Model/FlappingHistory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Icinga\Module\Icingadb\Model;

use Icinga\Module\Icingadb\Model\Behavior\BoolCast;
use Icinga\Module\Icingadb\Model\Behavior\Timestamp;
use ipl\Orm\Behaviors;
use ipl\Orm\Model;
use ipl\Orm\Relations;

/**
* Model for table `flapping_history`
*
* Please note that using this model will fetch history entries for decommissioned services. To avoid this,
* the query needs a `flapping_history.service_id IS NULL OR flapping_history_service.id IS NOT NULL` where.
*/
class FlappingHistory extends Model
{
public function getTableName()
{
return 'flapping_history';
}

public function getKeyName()
{
return 'id';
}

public function getColumns()
{
return [
'environment_id',
'endpoint_id',
'object_type',
'host_id',
'service_id',
'start_time',
'end_time',
'percent_state_change_start',
'percent_state_change_end',
'flapping_threshold_low',
'flapping_threshold_high'
];
}

public function createBehaviors(Behaviors $behaviors)
{
$behaviors->add(new Timestamp([
'start_time',
'end_time'
]));
}

public function createRelations(Relations $relations)
{
$relations->belongsTo('endpoint', Endpoint::class);
$relations->belongsTo('environment', Environment::class);
$relations->belongsTo('host', Host::class);
$relations->belongsTo('service', Service::class)->setJoinType('LEFT');
}
}
25 changes: 19 additions & 6 deletions library/Icingadb/Model/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,34 @@ public function createBehaviors(Behaviors $behaviors)

public function createRelations(Relations $relations)
{
// @TODO(el): Add relation for flapping_history_id
$relations->belongsTo('endpoint', Endpoint::class);
$relations->belongsTo('environment', Environment::class);
$relations->belongsTo('host', Host::class);
$relations->belongsTo('service', Service::class)->setJoinType('LEFT');
$relations->belongsTo('comment', CommentHistory::class)

$relations->hasOne('comment', CommentHistory::class)
->setCandidateKey('comment_history_id')
->setForeignKey('comment_id')
->setJoinType('LEFT');
$relations->belongsTo('downtime', DowntimeHistory::class)
$relations->hasOne('downtime', DowntimeHistory::class)
->setCandidateKey('downtime_history_id')
->setForeignKey('downtime_id')
->setJoinType('LEFT');
$relations->belongsTo('notification', NotificationHistory::class)->setJoinType('LEFT');
$relations->belongsTo('acknowledgement', AcknowledgementHistory::class)->setJoinType('LEFT');
$relations->belongsTo('state', StateHistory::class)->setJoinType('LEFT');
$relations->hasOne('flapping', FlappingHistory::class)
->setCandidateKey('flapping_history_id')
->setForeignKey('id')
->setJoinType('LEFT');
$relations->hasOne('notification', NotificationHistory::class)
->setCandidateKey('notification_history_id')
->setForeignKey('id')
->setJoinType('LEFT');
$relations->hasOne('acknowledgement', AcknowledgementHistory::class)
->setCandidateKey('acknowledgement_history_id')
->setForeignKey('id')
->setJoinType('LEFT');
$relations->hasOne('state', StateHistory::class)
->setCandidateKey('state_history_id')
->setForeignKey('id')
->setJoinType('LEFT');
}
}
43 changes: 41 additions & 2 deletions library/Icingadb/Widget/ItemList/HistoryListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Icinga\Module\Icingadb\Common\Icons;
use Icinga\Module\Icingadb\Common\ServiceLink;
use Icinga\Module\Icingadb\Common\ServiceStates;
use Icinga\Module\Icingadb\Date\DateFormatter;
use Icinga\Module\Icingadb\Widget\CheckAttempt;
use Icinga\Module\Icingadb\Widget\CommonListItem;
use Icinga\Module\Icingadb\Widget\StateChange;
Expand Down Expand Up @@ -42,6 +43,29 @@ protected function assembleCaption(BaseHtmlElement $caption)
$this->item->downtime->comment
]);

break;
case 'flapping_start':
$caption
->add(
'State Change Rate: ' . $this->item->flapping->percent_state_change_start
. '%; Start Threshold: ' . $this->item->host->flapping_threshold_high . '%'
)
->getAttributes()
->add('class', 'plugin-output');

break;
case 'flapping_end':
$caption
->add(
'State Change Rate: ' . $this->item->host->flapping_threshold_low
. '%; End Threshold: ' . $this->item->host->flapping_threshold_high
. '%; Flapping for ' . DateFormatter::formatDuration(
$this->item->flapping->end_time - $this->item->flapping->start_time
)
)
->getAttributes()
->add('class', 'plugin-output');

break;
case 'ack_clear':
if (! empty($this->item->acknowledgement->cleared_by)) {
Expand Down Expand Up @@ -114,6 +138,13 @@ protected function assembleVisual(BaseHtmlElement $visual)
Html::tag('div', ['class' => 'icon-ball ball-size-xl'], new Icon(Icons::IS_ACKNOWLEDGED))
);

break;
case 'flapping_end':
case 'flapping_start':
$visual->add(
Html::tag('div', ['class' => 'icon-ball ball-size-xl'], new Icon(Icons::IS_FLAPPING))
);

break;
case 'notification':
$visual->add(
Expand Down Expand Up @@ -164,13 +195,21 @@ protected function assembleTitle(BaseHtmlElement $title)
case 'downtime_start':
$title->add('Downtime started');

break;
case 'flapping_start':
$title->add('Flapping started');

break;
case 'flapping_end':
$title->add('Flapping ended');

break;
case 'ack_set':
$title->add('Acknowledgement Set');
$title->add('Acknowledgement set');

break;
case 'ack_clear':
$title->add('Acknowledgement Cleared');
$title->add('Acknowledgement cleared');

break;
case 'notification':
Expand Down

0 comments on commit 06680c4

Please sign in to comment.