Allow multiple templates per check command

This commit is contained in:
Alexander A. Klimov 2017-09-29 14:54:29 +02:00
parent 94345381ba
commit 6be7a01cec
2 changed files with 7 additions and 14 deletions

View file

@ -85,8 +85,8 @@ class Templates
*/
public function loadIni($path)
{
/** @var string[][][] $rawTemplates */
$rawTemplates = [];
/** @var string[][][] $templates */
$templates = [];
foreach (Config::fromIni($path) as $section => $options) {
/** @var ConfigObject $options */
@ -96,13 +96,10 @@ class Templates
throw new ConfigurationError('Bad section name "%s" in file "%s"', $section, $path);
}
$rawTemplates[$matches[1]][$matches[2]] = $options->toArray();
$templates[$matches[1]][$matches[2]] = $options->toArray();
}
/** @var Template[] $templates */
$templates = [];
foreach ($rawTemplates as $templateName => $template) {
foreach ($templates as $templateName => $template) {
if (! isset($template['graph']['check_command'])) {
throw new ConfigurationError(
'Icinga check command for template "%s" in file "%s" missing', $templateName, $path
@ -265,13 +262,13 @@ class Templates
}
}
$templates[$checkCommand] = (new Template())
$templates[$templateName] = (new Template())
->setCurves($curves)
->setUrlParams($urlParams);
}
foreach ($templates as $checkCommand => $template) {
$this->templates[$checkCommand] = $template;
foreach ($templates as $templateName => $template) {
$this->templates[$templateName] = $template;
}
return $this;

View file

@ -137,10 +137,6 @@ abstract class Graphs extends AbstractWidget
}
$result[] = '</div>';
// A monitored object has only one check command per definition of Icinga 2.
// And there is at most one graph template per check command per our definition.
break;
}
}
}