2015-06-03 14:34:54 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Forms;
|
|
|
|
|
|
|
|
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
|
|
|
|
|
|
|
class IcingaServiceForm extends DirectorObjectForm
|
|
|
|
{
|
|
|
|
public function setup()
|
|
|
|
{
|
2016-02-17 21:58:28 +01:00
|
|
|
$this->addObjectTypeElement();
|
|
|
|
|
2015-07-30 16:50:48 +02:00
|
|
|
$this->addElement('text', 'object_name', array(
|
|
|
|
'label' => $this->translate('Name'),
|
|
|
|
'required' => true,
|
|
|
|
'description' => $this->translate('Name for the Icinga object you are going to create')
|
2015-06-03 14:34:54 +02:00
|
|
|
));
|
|
|
|
|
2016-03-06 09:53:02 +01:00
|
|
|
// TODO: Should not be 'object' on new empty form:
|
|
|
|
if ($this->isObject()) {
|
|
|
|
$this->addElement('select', 'host_id', array(
|
|
|
|
'label' => $this->translate('Host'),
|
|
|
|
'required' => true,
|
|
|
|
'multiOptions' => $this->optionalEnum($this->enumHostsAndTemplates()),
|
|
|
|
'description' => $this->translate('Choose the host this single service should be assigned to')
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->addElement('extensibleSet', 'groups', array(
|
|
|
|
'label' => $this->translate('Groups'),
|
|
|
|
'multiOptions' => $this->optionallyAddFromEnum($this->enumServicegroups()),
|
|
|
|
'positional' => false,
|
|
|
|
'description' => $this->translate(
|
|
|
|
'Service groups that should be directly assigned to this service. Servicegroups can be useful'
|
|
|
|
. ' for various reasons. They are helpful to provided service-type specific view in Icinga Web 2,'
|
|
|
|
. ' either for custom dashboards or as an instrument to enforce restrictior. Service groups'
|
|
|
|
. ' can be directly assigned to single services or to service templates.'
|
|
|
|
)
|
2015-06-17 11:11:25 +02:00
|
|
|
));
|
2016-03-06 09:53:02 +01:00
|
|
|
|
2015-07-30 16:50:48 +02:00
|
|
|
$this->addImportsElement();
|
2016-02-17 20:10:22 +01:00
|
|
|
$this->addDisabledElement();
|
2015-12-02 03:07:28 +01:00
|
|
|
|
2016-03-06 09:53:02 +01:00
|
|
|
$elements = array(
|
|
|
|
'object_type',
|
|
|
|
'object_name',
|
|
|
|
'display_name',
|
|
|
|
'imports',
|
|
|
|
'host_id',
|
|
|
|
'groups',
|
|
|
|
'disabled',
|
|
|
|
);
|
|
|
|
$this->addDisplayGroup($elements, 'object_definition', array(
|
|
|
|
'decorators' => array(
|
|
|
|
'FormElements',
|
|
|
|
array('HtmlTag', array('tag' => 'dl')),
|
|
|
|
'Fieldset',
|
|
|
|
),
|
|
|
|
'order' => 20,
|
|
|
|
'legend' => $this->translate('Service properties')
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->addCheckCommandElements();
|
2015-06-26 16:20:16 +02:00
|
|
|
|
2015-07-30 16:50:48 +02:00
|
|
|
if ($this->isTemplate()) {
|
2015-07-31 16:59:56 +02:00
|
|
|
$this->addCheckExecutionElements();
|
2015-07-30 16:50:48 +02:00
|
|
|
}
|
2015-10-15 23:53:59 +02:00
|
|
|
|
2016-03-06 09:53:02 +01:00
|
|
|
if ($this->isTemplate()) {
|
|
|
|
$this->optionalBoolean(
|
|
|
|
'use_agent',
|
|
|
|
$this->translate('Run on agent'),
|
|
|
|
$this->translate('Whether the check commmand for this service should be executed on the Icinga agent')
|
|
|
|
);
|
|
|
|
$this->addZoneElement();
|
|
|
|
|
|
|
|
$elements = array(
|
|
|
|
'use_agent',
|
|
|
|
'zone_id',
|
|
|
|
);
|
|
|
|
$this->addDisplayGroup($elements, 'clustering', array(
|
|
|
|
'decorators' => array(
|
|
|
|
'FormElements',
|
|
|
|
array('HtmlTag', array('tag' => 'dl')),
|
|
|
|
'Fieldset',
|
|
|
|
),
|
|
|
|
'order' => 40,
|
|
|
|
'legend' => $this->translate('Icinga Agent and zone settings')
|
|
|
|
));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-10-15 23:53:59 +02:00
|
|
|
$this->setButtons();
|
2015-06-03 14:34:54 +02:00
|
|
|
}
|
2016-03-06 09:53:02 +01:00
|
|
|
|
|
|
|
protected function enumHostsAndTemplates()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
$this->translate('Templates') => $this->db->enumHostTemplates(),
|
|
|
|
$this->translate('Hosts') => $this->db->enumHosts(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function enumServicegroups()
|
|
|
|
{
|
|
|
|
$db = $this->db->getDbAdapter();
|
|
|
|
$select = $db->select()->from(
|
|
|
|
'icinga_servicegroup',
|
|
|
|
array(
|
|
|
|
'name' => 'object_name',
|
|
|
|
'display' => 'COALESCE(display_name, object_name)'
|
|
|
|
)
|
|
|
|
)->where('object_type = ?', 'object')->order('display');
|
|
|
|
|
|
|
|
return $db->fetchPairs($select);
|
|
|
|
}
|
2015-06-03 14:34:54 +02:00
|
|
|
}
|