KickstartHelper: import Event Commands

fixes #1389
This commit is contained in:
Thomas Gelf 2018-02-20 12:33:43 +01:00
parent 97ce0b6024
commit e879b02875
3 changed files with 28 additions and 32 deletions

View File

@ -29,6 +29,7 @@ before switching to a new version.
* FEATURE: new Property Modifier for IPs formatted as number in Excel files (#1296) * FEATURE: new Property Modifier for IPs formatted as number in Excel files (#1296)
* FEATURE: new Property Modifier to url-encode values * FEATURE: new Property Modifier to url-encode values
* FEATURE: new Property Modifier: uppercase the first character of each word * FEATURE: new Property Modifier: uppercase the first character of each word
* FEATURE: Kickstart Helper now also imports Event Commands (#1389)
### Internals ### Internals
* FEATURE: Html/Attribute now allows boolean properties * FEATURE: Html/Attribute now allows boolean properties

View File

@ -501,30 +501,33 @@ constants
*/ */
public function getCheckCommandObjects() public function getCheckCommandObjects()
{ {
IcingaCommand::setPluginDir($this->getConstant('PluginDir')); return $this->getSpecificCommandObjects('Command');
$objects = $this->getDirectorObjects('Command', 'CheckCommand', 'CheckCommands', array(
'arguments' => 'arguments',
// 'env' => 'env',
'timeout' => 'timeout',
'command' => 'command',
'vars' => 'vars'
));
foreach ($objects as $obj) {
$obj->methods_execute = 'PluginCheck';
}
return $objects;
} }
/** /**
* @return IcingaCommand[] * @return IcingaCommand[]
*/ */
public function getNotificationCommandObjects() public function getNotificationCommandObjects()
{
return $this->getSpecificCommandObjects('Notification');
}
/**
* @return IcingaCommand[]
*/
public function getEventCommandObjects()
{
return $this->getSpecificCommandObjects('Event');
}
/**
* @return IcingaCommand[]
*/
public function getSpecificCommandObjects($type)
{ {
IcingaCommand::setPluginDir($this->getConstant('PluginDir')); IcingaCommand::setPluginDir($this->getConstant('PluginDir'));
$objects = $this->getDirectorObjects('Command', 'NotificationCommand', 'NotificationCommands', array( $objects = $this->getDirectorObjects('Command', "${type}Command", "${type}Commands", array(
'arguments' => 'arguments', 'arguments' => 'arguments',
// 'env' => 'env', // 'env' => 'env',
'timeout' => 'timeout', 'timeout' => 'timeout',
@ -532,7 +535,7 @@ constants
'vars' => 'vars' 'vars' => 'vars'
)); ));
foreach ($objects as $obj) { foreach ($objects as $obj) {
$obj->methods_execute = 'PluginNotification'; $obj->methods_execute = "Plugin$type";
} }
return $objects; return $objects;

View File

@ -392,7 +392,8 @@ class KickstartHelper
$zdb = $db->getDbAdapter(); $zdb = $db->getDbAdapter();
$zdb->beginTransaction(); $zdb->beginTransaction();
/** @var IcingaObject $object */ /** @var IcingaObject $object */
foreach ($this->api()->setDb($db)->getCheckCommandObjects() as $object) { foreach (['Check', 'Notification', 'Event'] as $type) {
foreach ($this->api()->setDb($db)->getSpecificCommandObjects($type) as $object) {
if ($object::exists($object->object_name, $db)) { if ($object::exists($object->object_name, $db)) {
$new = $object::load($object->getObjectName(), $db)->replaceWith($object); $new = $object::load($object->getObjectName(), $db)->replaceWith($object);
} else { } else {
@ -401,15 +402,6 @@ class KickstartHelper
$new->store(); $new->store();
} }
foreach ($this->api()->setDb($db)->getNotificationCommandObjects() as $object) {
if ($object::exists($object->object_name, $db)) {
$new = $object::load($object->getObjectName(), $db)->replaceWith($object);
} else {
$new = $object;
}
$new->store();
} }
$zdb->commit(); $zdb->commit();