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 to url-encode values
* FEATURE: new Property Modifier: uppercase the first character of each word
* FEATURE: Kickstart Helper now also imports Event Commands (#1389)
### Internals
* FEATURE: Html/Attribute now allows boolean properties

View File

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

View File

@ -392,24 +392,16 @@ class KickstartHelper
$zdb = $db->getDbAdapter();
$zdb->beginTransaction();
/** @var IcingaObject $object */
foreach ($this->api()->setDb($db)->getCheckCommandObjects() as $object) {
if ($object::exists($object->object_name, $db)) {
$new = $object::load($object->getObjectName(), $db)->replaceWith($object);
} else {
$new = $object;
}
$new->store();
}
foreach (['Check', 'Notification', 'Event'] as $type) {
foreach ($this->api()->setDb($db)->getSpecificCommandObjects($type) as $object) {
if ($object::exists($object->object_name, $db)) {
$new = $object::load($object->getObjectName(), $db)->replaceWith($object);
} else {
$new = $object;
}
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();
}
$new->store();
}
$zdb->commit();