IcingaCommand: pathes prefixed with Windows ENV

...variables are considered to be absolute

fixes #1469
This commit is contained in:
Thomas Gelf 2018-06-01 11:33:39 +02:00
parent 808a9df13e
commit a005ac3228
2 changed files with 30 additions and 16 deletions

View File

@ -536,7 +536,7 @@ abstract class DbObject
* *
* // TODO: may conflict with ->id * // TODO: may conflict with ->id
* *
* @return string * @return string|array
*/ */
public function getId() public function getId()
{ {
@ -549,6 +549,7 @@ abstract class DbObject
} }
$id[$key] = $this->properties[$key]; $id[$key] = $this->properties[$key];
} }
return $id; return $id;
} else { } else {
if (isset($this->properties[$this->keyName])) { if (isset($this->properties[$this->keyName])) {

View File

@ -15,7 +15,7 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments
protected $type = 'CheckCommand'; protected $type = 'CheckCommand';
protected $defaultProperties = array( protected $defaultProperties = [
'id' => null, 'id' => null,
'object_name' => null, 'object_name' => null,
'object_type' => null, 'object_type' => null,
@ -24,7 +24,7 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments
'command' => null, 'command' => null,
'timeout' => null, 'timeout' => null,
'zone_id' => null, 'zone_id' => null,
); ];
protected $supportsCustomVars = true; protected $supportsCustomVars = true;
@ -34,17 +34,17 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments
protected $supportedInLegacy = true; protected $supportedInLegacy = true;
protected $intervalProperties = array( protected $intervalProperties = [
'timeout' => 'timeout', 'timeout' => 'timeout',
); ];
protected $relations = array( protected $relations = [
'zone' => 'IcingaZone', 'zone' => 'IcingaZone',
); ];
protected static $pluginDir; protected static $pluginDir;
protected $hiddenExecuteTemplates = array( protected $hiddenExecuteTemplates = [
'PluginCheck' => 'plugin-check-command', 'PluginCheck' => 'plugin-check-command',
'PluginNotification' => 'plugin-notification-command', 'PluginNotification' => 'plugin-notification-command',
'PluginEvent' => 'plugin-event-command', 'PluginEvent' => 'plugin-event-command',
@ -56,7 +56,7 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments
'IdoCheck' => 'ido-check-command', 'IdoCheck' => 'ido-check-command',
'RandomCheck' => 'random-check-command', 'RandomCheck' => 'random-check-command',
'CrlCheck' => 'clr-check-command', 'CrlCheck' => 'clr-check-command',
); ];
/** /**
* Render the 'medhods_execute' property as 'execute' * Render the 'medhods_execute' property as 'execute'
@ -76,10 +76,10 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments
protected function renderObjectHeader() protected function renderObjectHeader()
{ {
if ($this->methods_execute) { if ($execute = $this->get('methods_execute')) {
$itlImport = sprintf( $itlImport = sprintf(
' import "%s"' . "\n", ' import "%s"' . "\n",
$this->hiddenExecuteTemplates[$this->methods_execute] $this->hiddenExecuteTemplates[$execute]
); );
} else { } else {
$itlImport = ''; $itlImport = '';
@ -95,6 +95,10 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments
} }
} }
/**
* @param $type
* @return string
*/
protected function renderObjectHeaderWithType($type) protected function renderObjectHeaderWithType($type)
{ {
return sprintf( return sprintf(
@ -112,7 +116,7 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments
} elseif (is_object($value)) { } elseif (is_object($value)) {
// { type => Function } -> really?? // { type => Function } -> really??
return null; return null;
return $value; // return $value;
} }
if (self::$pluginDir !== null) { if (self::$pluginDir !== null) {
@ -150,6 +154,10 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments
return true; return true;
} }
/**
* @return string
* @throws \Zend_Db_Select_Exception
*/
public function countDirectUses() public function countDirectUses()
{ {
$db = $this->getDb(); $db = $this->getDb();
@ -180,6 +188,10 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments
)); ));
} }
/**
* @return bool
* @throws \Zend_Db_Select_Exception
*/
public function isInUse() public function isInUse()
{ {
return $this->countDirectUses() > 0; return $this->countDirectUses() > 0;
@ -187,7 +199,7 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments
protected function renderCommand() protected function renderCommand()
{ {
$command = $this->command; $command = $this->get('command');
$prefix = ''; $prefix = '';
if (preg_match('~^([A-Z][A-Za-z0-9_]+\s\+\s)(.+?)$~', $command, $m)) { if (preg_match('~^([A-Z][A-Za-z0-9_]+\s\+\s)(.+?)$~', $command, $m)) {
$prefix = $m[1]; $prefix = $m[1];
@ -206,7 +218,8 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments
{ {
return $path[0] === '/' return $path[0] === '/'
|| $path[0] === '\\' || $path[0] === '\\'
|| preg_match('/^[A-Za-z]:\\\/', substr($path, 0, 3)); || preg_match('/^[A-Za-z]:\\\/', substr($path, 0, 3))
|| preg_match('/^%[A-Z][A-Za-z0-9\(\)-]*%/', $path);
} }
public static function setPluginDir($pluginDir) public static function setPluginDir($pluginDir)
@ -222,7 +235,7 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments
protected function renderLegacyCommand() protected function renderLegacyCommand()
{ {
$command = $this->command; $command = $this->get('command');
if (preg_match('~^(\$USER\d+\$/?)(.+)$~', $command)) { if (preg_match('~^(\$USER\d+\$/?)(.+)$~', $command)) {
// should be fine, since the user decided to use a macro // should be fine, since the user decided to use a macro
} elseif (! $this->isAbsolutePath($command)) { } elseif (! $this->isAbsolutePath($command)) {