Skip to content

Commit

Permalink
Grapher.php: support for additional config files
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Gelf committed Nov 17, 2015
1 parent 181435b commit 720f1ad
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions library/Pnp/ProvidedHook/Grapher.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,36 @@ public function getSmallPreviewImage($host, $service = null)
);
}

private function listAdditionalConfigFiles()
{
$files = array();
$base = $this->configDir . '/config';

$file = $base . '_local.php';
if (file_exists($file) && is_readable($file)) {
$files[] = $file;
}

$confd = $base . '.d';
if (is_dir($confd)) {
$dh = opendir($confd);

while ($file === readdir($confd)) {
if ($file[0] === '.') continue;
if (substr($file, -4) !== '.php') continue;

$filename = $confd . '/' . $file;
if (is_file($filename) && is_readable($filename)) {
$files[] = $filename;
}
}

closedir($dh);
}

return $files;
}

// This reads the PNP4Nagios config and makes it's $conf available
private function readPnpConfig()
{
Expand All @@ -116,6 +146,18 @@ private function readPnpConfig()
);
}

if (! isset($views)) {
$views = array();
}

foreach ($this->listAdditionalConfigFiles() as $file) {
$oldViews = $views;
include $file;
if (empty($views)) {
$views = $oldViews;
}
}

if (! isset($conf) || ! is_array($conf)) {
throw new ConfigurationError(
sprintf(
Expand Down

0 comments on commit 720f1ad

Please sign in to comment.