Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Commit

Permalink
* Fixed role deactivation being ignored by user principals
Browse files Browse the repository at this point in the history
* Fixed pgsql date format in service grid
* Added unhandled/handled problems to tactical overview (fixes #1952)
  • Loading branch information
Jannis Mosshammer committed Nov 22, 2011
1 parent 61164f4 commit 2135bc8
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 60 deletions.
8 changes: 7 additions & 1 deletion app/modules/AppKit/lib/database/models/NsmUser.php
Expand Up @@ -336,10 +336,15 @@ public function getUserPrincipalsList() {
private function getRoleIds() {
$ids = array();
foreach($this->NsmRole as $role) {
if($role->role_disabled)
continue;
$ids[] = $role->role_id;

while ($role->hasParent()){
$role = $role->parent;
$ids[] = $role->role_id;
if($role->role_disabled)
continue;
$ids[] = $role->role_id;
}
}

Expand All @@ -359,6 +364,7 @@ public function getPrincipals($userOnly= false) {
->select('p.*')
->from('NsmPrincipal p INDEXBY p.principal_id')
->andWhereIn('p.principal_role_id',$roles)

->orWhere('p.principal_user_id = ?',$this->user_id)
->execute();

Expand Down
2 changes: 1 addition & 1 deletion app/modules/Cronks/lib/js/Cronks/CronkPortal.js
Expand Up @@ -51,7 +51,7 @@ Ext.ns('Icinga.Cronks.System');
items: [{
xtype: 'cronk',
crname: 'icingaOverallStatus',
width: 620
width: 720
}, {
xtype: 'cronk',
crname: 'icingaMonitorPerformance',
Expand Down
22 changes: 19 additions & 3 deletions app/modules/Cronks/lib/js/Cronks/StatusOverall.js
Expand Up @@ -5,13 +5,29 @@ Ext.ns('Icinga.Cronks.System.StatusOverall');
"use strict";

Icinga.Cronks.System.StatusOverall.renderer = {
itemTpl: new Ext.XTemplate(
'<tpl if="!this.isSimple(state)">',
"<span qTip='Resolved / Open Problems / Overall '>",
"{resolved} / {open} / {count}",
"</span>",
"</tpl>",
'<tpl if="this.isSimple(state)">',
"{count}",
"</tpl>", {
isSimple: function(v) {
var nr = parseInt(v,10);
return (nr == 99 || nr == 0)
}
}
),

prepareData: function (data, recordIndex, record) {
data.state_org = data.state;

var r = Icinga.Cronks.System.StatusOverall.renderer.itemTpl; // just as a shortcut
if (data.count === 0) {
data.state = Icinga.StatusData.wrapElement(data.type, data.state, data.count + ' {0}', Icinga.DEFAULTS.STATUS_DATA.servicestatusClass[100]);
data.state = Icinga.StatusData.wrapElement(data.type, data.state, r.apply(data)+" {0}" , Icinga.DEFAULTS.STATUS_DATA.servicestatusClass[100]);
} else {
data.state = Icinga.StatusData.wrapElement(data.type, data.state, data.count + ' {0}');
data.state = Icinga.StatusData.wrapElement(data.type, data.state, r.apply(data)+" {0}");
}

return data;
Expand Down
2 changes: 0 additions & 2 deletions app/modules/Cronks/lib/js/Cronks/Tackle/ObjectGrid.js
Expand Up @@ -117,7 +117,6 @@ Icinga.Cronks.Tackle.ObjectGrid = Ext.extend(Ext.grid.GridPanel, {
pageSize:50
});
},
sm : new Ext.grid.CheckboxSelectionModel(),
refreshLocked: false,
lockRefresh: function() {
if(this.refreshLocked)
Expand Down Expand Up @@ -189,7 +188,6 @@ Icinga.Cronks.Tackle.ObjectGrid = Ext.extend(Ext.grid.GridPanel, {

this.cm = new Ext.grid.ColumnModel({
columns : [
this.sm,
{
dataIndex : 'HOST_CURRENT_STATE',
columnWidth: 25,
Expand Down
8 changes: 6 additions & 2 deletions app/modules/Cronks/lib/js/Cronks/Tackle/ServicesSubGrid.js
Expand Up @@ -180,8 +180,12 @@ Icinga.Cronks.Tackle.ServicesSubGrid = Ext.extend(Ext.grid.GridPanel, {
renderer: function(value,meta,record) {
var str = AppKit.util.Date.getElapsedString(value);
var now = new Date();
var lastCheckDate = Date.parseDate(value,'Y-m-d H:i:s');
var nextCheckDate = Date.parseDate(record.get('SERVICE_NEXT_CHECK'),'Y-m-d H:i:s');
var lastCheckDate = Date.parseDate(value,'Y-m-d H:i:s')
|| Date.parseDate(value,'Y-m-d H:i:sP')
|| Date.parseDate(value+":00",'Y-m-d H:i:sP');
var nextCheckDate = Date.parseDate(record.get('SERVICE_NEXT_CHECK'),'Y-m-d H:i:s')
|| Date.parseDate(value,'Y-m-d H:i:sP')
|| Date.parseDate(value+":00",'Y-m-d H:i:sP');
var elapsed = parseInt(now.getElapsed(lastCheckDate)/1000,10);

if(!now.between(lastCheckDate,nextCheckDate.add(Date.SECOND,30)))
Expand Down
138 changes: 87 additions & 51 deletions app/modules/Cronks/models/System/StatusOverallModel.class.php
Expand Up @@ -9,7 +9,10 @@ class Cronks_System_StatusOverallModel extends CronksBaseModel {

const TYPE_HOST = 'host';
const TYPE_SERVICE = 'service';

// indizes for the output
const IDX_NO_PROBLEM = "RESOLVED";
const IDX_OPEN_PROBLEM = "OPEN_PROBLEM";
const IDX_SUM = "OVERALL";
/**
*
* @var Web_Icinga_ApiContainerModel
Expand All @@ -24,11 +27,11 @@ public function initialize(AgaviContext $context, array $parameters = array()) {
private function getData() {

$sources = array(
IcingaApiConstants::TARGET_HOST_STATUS_SUMMARY =>
array(self::TYPE_HOST, IcingaHostStateInfo::Create()->getStateList()),
IcingaApiConstants::TARGET_SERVICE_STATUS_SUMMARY =>
array(self::TYPE_SERVICE, IcingaServiceStateInfo::Create()->getStateList())
);
IcingaApiConstants::TARGET_HOST_STATUS_SUMMARY =>
array(self::TYPE_HOST, IcingaHostStateInfo::Create()->getStateList()),
IcingaApiConstants::TARGET_SERVICE_STATUS_SUMMARY =>
array(self::TYPE_SERVICE, IcingaServiceStateInfo::Create()->getStateList())
);

$target = array();

Expand All @@ -46,13 +49,33 @@ private function getData() {

}

private function normalizeData(array &$data, $state_field, $count_field='COUNT') {
$out = array();
foreach($data as $k=>$v) {
if (array_key_exists($state_field, $v) && array_key_exists($count_field, $v)) {
if(!isset($out[$v[$state_field]]))
$out[$v[$state_field]] = 0;
$out[ $v[$state_field] ] += $v[ $count_field ];
private function normalizeData(array &$data, $state_field, $count_field='COUNT',$dtime,$ack) {
$out = array(

);

foreach($data as $index=>$currentStateSummary) {

if (isset($currentStateSummary[$state_field]) && isset($currentStateSummary[$count_field])) {
// no entries -> state count is 0
if(!isset($out[$currentStateSummary[$state_field]]))
$out[$currentStateSummary[$state_field]] = array(
self::IDX_NO_PROBLEM => 0,
self::IDX_OPEN_PROBLEM => 0,
self::IDX_SUM => 0
);
$currentStateField = $out[$currentStateSummary[$state_field]];
// otherwise fill in the state count
$currentStateField[self::IDX_SUM] += $currentStateSummary[ $count_field ];

// get problem count
if(isset($currentStateSummary[$ack]) && isset($currentStateSummary[$dtime])) {
if($currentStateSummary[$ack] == 1 || $currentStateSummary[$dtime] == 1)
$currentStateField[self::IDX_NO_PROBLEM] = $currentStateSummary[$count_field];
else
$currentStateField[self::IDX_OPEN_PROBLEM] = $currentStateSummary[$count_field];
}
$out[$currentStateSummary[$state_field]] = $currentStateField;
}
}
return $out;
Expand All @@ -61,34 +84,47 @@ private function normalizeData(array &$data, $state_field, $count_field='COUNT')
private function buildDataArray(&$search, $type, array $states, array &$target,$stype) {
$field = sprintf('%s_CURRENT_STATE', strtoupper($type));
$pendingField = sprintf('%s_IS_PENDING', strtoupper($type));

$search->setResultColumns(array($field,$pendingField));
$dtimeField = sprintf('%s_SCHEDULED_DOWNTIME_DEPTH', strtoupper($type));
$ackField = sprintf('%s_PROBLEM_HAS_BEEN_ACKNOWLEDGED', strtoupper($type));

$search->setResultColumns(array($field,$pendingField,$dtimeField,$ackField));
$search->setSearchGroup(sprintf('%s_IS_PENDING', strtoupper($type)));
$data = $search->setResultType(IcingaApiConstants::RESULT_ARRAY)->fetch()->getAll();

$data = $this->normalizeData($data, $field);
$sum = 0;

$data = $this->normalizeData($data, $field,'COUNT',$dtimeField,$ackField);

$sum_total = 0;
$sum_resolved = 0;
$sum_open = 0;

foreach($states as $sid=>$sname) {
$count = 0;

if (array_key_exists($sid, $data)) {
$count = $data[$sid];
$entry = $data[$sid];
}

$sum += $count;
$target[] = array(
'type' => $type,
'state' => $sid,
'count' => $count
);
$sum_total += $entry[self::IDX_SUM];
$sum_resolved += $entry[self::IDX_NO_PROBLEM];
$sum_open += $entry[self::IDX_OPEN_PROBLEM];
$targetEntry = array(
'type' => $type,
'state' => $sid,
'open' => $entry[self::IDX_OPEN_PROBLEM],
'resolved' => $entry[self::IDX_NO_PROBLEM],
'count' => $entry[self::IDX_SUM],
);

$target[] = $targetEntry;
}

$target[] = array(
'type' => $type,
'state' => 100,
'count' => $sum
);
'type' => $type,
'state' => 100,
'open' => $sum_open,
'resolved' => $sum_resolved,
'count' => $sum_total
);
}

protected function addPending(&$data,$stype) {
Expand All @@ -113,44 +149,44 @@ protected function addPending(&$data,$stype) {

$data[] = $result;
}

protected function getInstanceDataStatus() {
$model = $this->getContext()->getModel('ApiDataRequest','Api');

$r = $model->createRequestDescriptor();
$instances = $r->select('p.programstatus_id, p.instance_id, p.last_command_check, i.instance_name')
->from('IcingaProgramstatus p')
->innerJoin('p.instance i')->execute();
->from('IcingaProgramstatus p')
->innerJoin('p.instance i')->execute();

$checkTime = 300;

$diff = 0;

$out = array();

$status = false;

foreach ($instances as $instance) {

$date = (int)strtotime($instance->last_command_check);
$diff = (time()-$date);

if ($diff < $checkTime && $instance->is_currently_running) {
$status = true;
} else {
$status = false;
}

$out[] = array (
'instance' => $instance->instance->instance_name,
'status' => $status,
'last_check' => $instance->last_command_check,
'start' => $instance->program_start_time,
'diff' => $diff,
'check' => $checkTime
'instance' => $instance->instance->instance_name,
'status' => $status,
'last_check' => $instance->last_command_check,
'start' => $instance->program_start_time,
'diff' => $diff,
'check' => $checkTime
);
}

return $out;
}

Expand All @@ -168,9 +204,9 @@ public function &getJson() {
$json->setSuccess(true);
$json->setData($data);
$json->setSortinfo('type');

$json->addMiscData('rowsInstanceStatus', $this->getInstanceDataStatus());

return $json;
}

Expand Down

0 comments on commit 2135bc8

Please sign in to comment.