2015-04-24 14:26:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Objects;
|
|
|
|
|
2015-06-11 22:44:17 +02:00
|
|
|
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
|
2015-06-11 22:01:12 +02:00
|
|
|
|
2015-04-24 15:57:01 +02:00
|
|
|
class IcingaCommand extends IcingaObject
|
2015-04-24 14:26:44 +02:00
|
|
|
{
|
|
|
|
protected $table = 'icinga_command';
|
|
|
|
|
2015-08-28 23:44:26 +02:00
|
|
|
protected $type = 'CheckCommand';
|
|
|
|
|
2015-04-24 14:26:44 +02:00
|
|
|
protected $defaultProperties = array(
|
|
|
|
'id' => null,
|
|
|
|
'object_name' => null,
|
2016-02-16 12:17:50 +01:00
|
|
|
'object_type' => null,
|
|
|
|
'disabled' => 'n',
|
2015-04-24 14:26:44 +02:00
|
|
|
'methods_execute' => null,
|
|
|
|
'command' => null,
|
|
|
|
'timeout' => null,
|
|
|
|
'zone_id' => null,
|
|
|
|
);
|
2015-06-11 22:01:12 +02:00
|
|
|
|
2015-06-24 10:13:27 +02:00
|
|
|
protected $supportsCustomVars = true;
|
|
|
|
|
2015-08-28 23:44:26 +02:00
|
|
|
protected $supportsFields = true;
|
|
|
|
|
2015-06-29 10:39:37 +02:00
|
|
|
protected $supportsImports = true;
|
|
|
|
|
2015-08-28 23:44:26 +02:00
|
|
|
protected $supportsArguments = true;
|
|
|
|
|
2016-03-09 18:12:01 +01:00
|
|
|
protected $intervalProperties = array(
|
|
|
|
'timeout' => 'timeout',
|
|
|
|
);
|
|
|
|
|
2015-12-02 03:20:55 +01:00
|
|
|
protected static $pluginDir;
|
|
|
|
|
2016-02-26 11:58:37 +01:00
|
|
|
/**
|
|
|
|
* Render the 'medhods_execute' property as 'execute'
|
|
|
|
*
|
|
|
|
* Execute is a reserved word in SQL, column name was prefixed
|
|
|
|
*
|
|
|
|
* Avoid complaints for method names with underscore:
|
|
|
|
* @codingStandardsIgnoreStart
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2015-06-11 22:01:12 +02:00
|
|
|
protected function renderMethods_execute()
|
|
|
|
{
|
2016-02-26 11:58:37 +01:00
|
|
|
// @codingStandardsIgnoreEnd
|
2015-06-11 23:02:43 +02:00
|
|
|
return c::renderKeyValue('execute', $this->methods_execute);
|
2015-06-11 22:01:12 +02:00
|
|
|
}
|
2015-10-16 18:13:42 +02:00
|
|
|
|
2015-12-02 03:20:55 +01:00
|
|
|
public function mungeCommand($value)
|
|
|
|
{
|
|
|
|
if (is_array($value)) {
|
|
|
|
$value = implode(' ', $value);
|
|
|
|
} elseif (is_object($value)) {
|
|
|
|
// { type => Function } -> really??
|
|
|
|
return null;
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self::$pluginDir !== null) {
|
|
|
|
if (($pos = strpos($value, self::$pluginDir)) === 0) {
|
|
|
|
$value = substr($value, strlen(self::$pluginDir) + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
2015-10-16 18:13:42 +02:00
|
|
|
protected function renderCommand()
|
|
|
|
{
|
2015-10-16 18:39:13 +02:00
|
|
|
$command = $this->command;
|
|
|
|
$prefix = '';
|
|
|
|
if (preg_match('~^([A-Z][A-Za-z0-9]+\s\+\s)(.+?)$~', $command, $m)) {
|
|
|
|
$prefix = $m[1];
|
|
|
|
$command = $m[2];
|
|
|
|
} elseif ($command[0] !== '/') {
|
|
|
|
$prefix = 'PluginDir + ';
|
2015-10-28 22:28:43 +01:00
|
|
|
$command = '/' . $command;
|
2015-10-16 18:39:13 +02:00
|
|
|
}
|
|
|
|
$parts = preg_split('/\s+/', $command, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
|
array_unshift($parts, c::alreadyRendered($prefix . c::renderString(array_shift($parts))));
|
|
|
|
|
|
|
|
return c::renderKeyValue('command', c::renderArray($parts));
|
2015-10-16 18:13:42 +02:00
|
|
|
}
|
2015-12-02 02:53:27 +01:00
|
|
|
|
2015-12-02 03:20:55 +01:00
|
|
|
public static function setPluginDir($pluginDir)
|
|
|
|
{
|
|
|
|
self::$pluginDir = $pluginDir;
|
|
|
|
}
|
2015-04-24 14:26:44 +02:00
|
|
|
}
|