Updates: clean code for whitespace/standards...

...issues as reported by Travis. Add requirement for parent and child host
fields when setting up a Dependency Object (these fields are not necessarily
needed for Templates or Apply Rules). Renamed new table field to
'parent_service_by_name'... which is a bit more descriptive or what that
field is intended for.
This commit is contained in:
Marc DeTrano 2017-08-23 13:39:48 -06:00 committed by Thomas Gelf
parent 6bea1eff41
commit 708edfdebc
12 changed files with 34 additions and 47 deletions

View File

@ -23,7 +23,6 @@ class DependencyController extends ObjectController
$this->db() $this->db()
); );
} }
} }
protected function loadObject() protected function loadObject()
@ -54,7 +53,4 @@ class DependencyController extends ObjectController
$form->createApplyRuleFor($this->apply); $form->createApplyRuleFor($this->apply);
} }
} }
} }

View File

@ -127,7 +127,6 @@ class SuggestController extends ActionController
$r[]=$rule->name; $r[]=$rule->name;
} }
} }
} }
natcasesort($r); natcasesort($r);
return $r; return $r;
@ -288,8 +287,4 @@ class SuggestController extends ActionController
return $db->fetchAll($query); return $db->fetchAll($query);
} }
} }

View File

@ -14,8 +14,8 @@ class IcingaDependencyForm extends DirectorObjectForm
$this->setupDependencyElements(); $this->setupDependencyElements();
} }
protected function setupDependencyElements() { protected function setupDependencyElements()
{
$this->addObjectTypeElement(); $this->addObjectTypeElement();
if (! $this->hasObjectType()) { if (! $this->hasObjectType()) {
$this->groupMainProperties(); $this->groupMainProperties();
@ -112,7 +112,8 @@ class IcingaDependencyForm extends DirectorObjectForm
return $this; return $this;
} }
protected function addBooleanElements() { protected function addBooleanElements()
{
$this->addBoolean( $this->addBoolean(
'disable_checks', 'disable_checks',
@ -157,6 +158,7 @@ class IcingaDependencyForm extends DirectorObjectForm
'class' => "autosubmit director-suggest", 'class' => "autosubmit director-suggest",
'data-suggestion-context' => 'hostnames', 'data-suggestion-context' => 'hostnames',
'order' => 10, 'order' => 10,
'required' => $this->isObject(),
'value' => $this->getObject()->get('parent_host') 'value' => $this->getObject()->get('parent_host')
) )
@ -177,10 +179,8 @@ class IcingaDependencyForm extends DirectorObjectForm
'data-suggestion-for-host' => $sent_parent, 'data-suggestion-for-host' => $sent_parent,
'order' => 20, 'order' => 20,
'value' => $this->getObject()->get('parent_service') 'value' => $this->getObject()->get('parent_service')
) )
); );
} }
// If configuring Object, allow selection of child host and/or service, otherwise apply rules will determine child object. // If configuring Object, allow selection of child host and/or service, otherwise apply rules will determine child object.
@ -196,6 +196,7 @@ class IcingaDependencyForm extends DirectorObjectForm
'class' => "autosubmit director-suggest", 'class' => "autosubmit director-suggest",
'data-suggestion-context' => 'hostnames', 'data-suggestion-context' => 'hostnames',
'order' => 30, 'order' => 30,
'required' => $this->isObject(),
'value' => $this->getObject()->get('child_host') 'value' => $this->getObject()->get('child_host')
) )
); );
@ -216,11 +217,8 @@ class IcingaDependencyForm extends DirectorObjectForm
'data-suggestion-for-host' => $sent_child, 'data-suggestion-for-host' => $sent_child,
'order' => 40, 'order' => 40,
'value' => $this->getObject()->get('child_service') 'value' => $this->getObject()->get('child_service')
) )
); );
} }
} }
@ -247,6 +245,4 @@ class IcingaDependencyForm extends DirectorObjectForm
$object->object_name = $dependency->object_name; $object->object_name = $dependency->object_name;
return $this; return $this;
} }
} }

View File

@ -50,7 +50,6 @@ class IcingaDependencyTable extends IcingaObjectTable
array('apply' => $row->dependency, 'type' => 'apply'), array('apply' => $row->dependency, 'type' => 'apply'),
array('class' => 'icon-plus') array('class' => 'icon-plus')
); );
} else { } else {
$htm .= '. Related apply rules: <ul class="apply-rules">'; $htm .= '. Related apply rules: <ul class="apply-rules">';
foreach ($extra as $id => $dependency) { foreach ($extra as $id => $dependency) {

View File

@ -8,7 +8,6 @@ use Icinga\Exception\NotFoundError;
use Icinga\Data\Filter\Filter; use Icinga\Data\Filter\Filter;
use Icinga\Module\Director\Objects\HostApplyMatches; use Icinga\Module\Director\Objects\HostApplyMatches;
class IcingaDependency extends IcingaObject class IcingaDependency extends IcingaObject
{ {
protected $table = 'icinga_dependency'; protected $table = 'icinga_dependency';
@ -29,7 +28,7 @@ class IcingaDependency extends IcingaObject
'period_id' => null, 'period_id' => null,
'zone_id' => null, 'zone_id' => null,
'assign_filter' => null, 'assign_filter' => null,
'parent_service_s' => null, 'parent_service_by_name' => null,
); );
protected $supportsCustomVars = false; protected $supportsCustomVars = false;
@ -88,7 +87,6 @@ class IcingaDependency extends IcingaObject
c::renderString($this->getObjectName()), c::renderString($this->getObjectName()),
ucfirst($to) ucfirst($to)
); );
} else { } else {
return parent::renderObjectHeader(); return parent::renderObjectHeader();
} }
@ -114,13 +112,13 @@ class IcingaDependency extends IcingaObject
protected function renderAssignments() protected function renderAssignments()
{ {
if ($this->hasBeenAssignedToServiceApply()) { if ($this->hasBeenAssignedToServiceApply()) {
$tmpService= $this->getRelatedObject('child_service', $this->child_service_id); $tmpService= $this->getRelatedObject('child_service', $this->child_service_id);
$assigns = $tmpService->assignments()->toConfigString(); $assigns = $tmpService->assignments()->toConfigString();
$filter = sprintf( $filter = sprintf(
'%s && service.name == "%s"', '%s && service.name == "%s"',
trim($assigns), $this->child_service trim($assigns),
$this->child_service
); );
return "\n " . $filter . "\n"; return "\n " . $filter . "\n";
} }
@ -128,7 +126,8 @@ class IcingaDependency extends IcingaObject
if ($this->hasBeenAssignedToHostTemplateService()) { if ($this->hasBeenAssignedToHostTemplateService()) {
$filter = sprintf( $filter = sprintf(
'assign where "%s" in host.templates && service.name == "%s"', 'assign where "%s" in host.templates && service.name == "%s"',
$this->child_host, $this->child_service $this->child_host,
$this->child_service
); );
return "\n " . $filter . "\n"; return "\n " . $filter . "\n";
} }
@ -177,7 +176,9 @@ class IcingaDependency extends IcingaObject
protected function hasBeenAssignedToHostTemplateService() protected function hasBeenAssignedToHostTemplateService()
{ {
if (!$this->hasBeenAssignedToHostTemplate()) return false; if (!$this->hasBeenAssignedToHostTemplate()) {
return false;
}
try { try {
return $this->child_service_id && $this->getRelatedObject( return $this->child_service_id && $this->getRelatedObject(
'child_service', 'child_service',
@ -276,9 +277,9 @@ class IcingaDependency extends IcingaObject
} }
//special case for parent service set as plain string for Apply rules //special case for parent service set as plain string for Apply rules
public function renderParent_service_s() public function renderParent_service_by_name()
{ {
return "\n parent_service_name = \"" . $this->parent_service_s ."\"\n"; return "\n parent_service_name = \"" . $this->parent_service_by_name ."\"\n";
} }
public function isApplyRule() public function isApplyRule()
@ -311,14 +312,14 @@ class IcingaDependency extends IcingaObject
if ($class == "Icinga\Module\Director\Objects\IcingaService" ) { if ($class == "Icinga\Module\Director\Objects\IcingaService" ) {
if ($name == "parent_service_id" && $this->object_type == 'apply' ) { //special case , parent service can be set as simple string for Apply if ($name == "parent_service_id" && $this->object_type == 'apply' ) { //special case , parent service can be set as simple string for Apply
if ($this->properties['parent_host_id']==null) { if ($this->properties['parent_host_id']==null) {
$this->reallySet('parent_service_s', $this->unresolvedRelatedProperties[$name]); $this->reallySet('parent_service_by_name', $this->unresolvedRelatedProperties[$name]);
$this->reallySet('parent_service_id',null); $this->reallySet('parent_service_id',null);
unset($this->unresolvedRelatedProperties[$name]); unset($this->unresolvedRelatedProperties[$name]);
return; return;
} }
} }
$this->reallySet('parent_service_s',null); $this->reallySet('parent_service_by_name',null);
$host_id_prop=str_replace("service","host",$name); $host_id_prop=str_replace("service","host",$name);
if (isset($this->properties[$host_id_prop])) { if (isset($this->properties[$host_id_prop])) {
$obj_key=array("host_id" => $this->properties[$host_id_prop], "object_name" => $this->unresolvedRelatedProperties[$name]); $obj_key=array("host_id" => $this->properties[$host_id_prop], "object_name" => $this->unresolvedRelatedProperties[$name]);
@ -410,8 +411,8 @@ class IcingaDependency extends IcingaObject
return $object->get('object_name'); return $object->get('object_name');
} else { } else {
// handle special case for plain string parent service on Dependency Apply rules // handle special case for plain string parent service on Dependency Apply rules
if ($key == 'parent_service' && $this->get('parent_service_s') != null) { if ($key == 'parent_service' && $this->get('parent_service_by_name') != null) {
return $this->get('parent_service_s'); return $this->get('parent_service_by_name');
} }
} }

View File

@ -1,2 +1,2 @@
ALTER TABLE icinga_dependency ADD COLUMN parent_service_s VARCHAR(255); ALTER TABLE icinga_dependency ADD COLUMN parent_service_by_name VARCHAR(255);

View File

@ -1591,7 +1591,7 @@ CREATE TABLE icinga_dependency (
period_id INT(10) UNSIGNED DEFAULT NULL, period_id INT(10) UNSIGNED DEFAULT NULL,
zone_id INT(10) UNSIGNED DEFAULT NULL, zone_id INT(10) UNSIGNED DEFAULT NULL,
assign_filter TEXT DEFAULT NULL, assign_filter TEXT DEFAULT NULL,
parent_service_s VARCHAR(255) DEFAULT NULL, parent_service_by_name VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (id), PRIMARY KEY (id),
CONSTRAINT icinga_dependency_parent_host CONSTRAINT icinga_dependency_parent_host
FOREIGN KEY parent_host (parent_host_id) FOREIGN KEY parent_host (parent_host_id)