コード例 #1
0
ファイル: templateTest.php プロジェクト: Griesbacher/histou
 public function testCompareTemplate()
 {
     $compareTests = array(array('expected' => new \histou\template\Rule('host', 'service', 'command', array(), ''), 'input' => array(new \histou\template\Rule('host', 'service', 'command', array(), ''))), array('expected' => new \histou\template\Rule('host', 'service', 'command', array('.*'), ''), 'input' => array(new \histou\template\Rule('host', 'service', 'command', array('p1'), ''), new \histou\template\Rule('host', 'service', 'command', array('p2'), ''), new \histou\template\Rule('host', 'service', 'command', array('.*'), ''), new \histou\template\Rule('host', 'service', 'command', array('p3'), ''))), array('expected' => new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2', 'p3'), ''), 'input' => array(new \histou\template\Rule('host', 'service', 'command', array('.*'), ''), new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2', 'p3'), ''))), array('expected' => new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2', 'p3'), ''), 'input' => array(new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2', 'p3'), ''), new \histou\template\Rule('host', 'service', 'command', array('.*'), ''))), array('expected' => new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2', 'p3'), ''), 'input' => array(new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2', 'p3'), ''), new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2', 'p3'), ''), new \histou\template\Rule('host', 'service', 'command', array('.*'), ''))), array('expected' => new \histou\template\Rule('host', 'service', 'command', array('.*'), ''), 'input' => array(new \histou\template\Rule('host', 'service', 'foo', array('p1', 'p2', 'p3'), ''), new \histou\template\Rule('host', 'service', 'command', array('.*'), ''))), array('expected' => new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2', 'p3'), ''), 'input' => array(new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2', 'p3', 'p4'), ''), new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2', 'p3'), ''), new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2'), ''))), array('expected' => new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2', 'p3'), ''), 'input' => array(new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2'), ''), new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2', 'p3'), ''), new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2', 'p3', 'p4'), ''))), array('expected' => new \histou\template\Rule('.*', '.*', '.*', array('p1', 'p2', 'p3'), ''), 'input' => array(new \histou\template\Rule('.*', '.*', '.*', array('p1', 'p2'), ''), new \histou\template\Rule('.*', '.*', '.*', array('p1', 'p2', 'p3'), ''), new \histou\template\Rule('.*', '.*', '.*', array('p1', 'p2', 'p3', 'p4'), ''))), array('expected' => new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2', 'p3'), ''), 'input' => array(new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2', 'p3'), ''), new \histou\template\Rule('host', 'service', '.*', array('p1', 'p2', 'p3'), ''))), array('expected' => new \histou\template\Rule('host', 'service', '.*', array('p1', 'p2', 'p3'), ''), 'input' => array(new \histou\template\Rule('host', 'service', 'foo', array('p1', 'p2', 'p3'), ''), new \histou\template\Rule('host', 'service', '.*', array('p1', 'p2', 'p3'), ''))), array('expected' => new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2', 'p3'), ''), 'input' => array(new \histou\template\Rule('host', 'service', '.*', array('p1', 'p2', 'p3'), ''), new \histou\template\Rule('host', 'service', 'command', array('p1', 'p2', 'p3'), ''))));
     \histou\template\Rule::setCheck('host', 'service', 'command', array('p1', 'p2', 'p3'));
     $i = 0;
     foreach ($compareTests as $test) {
         $templates = array();
         foreach ($test['input'] as $rule) {
             array_push($templates, static::createTemplate($rule));
         }
         usort($templates, '\\histou\\template\\Template::compare');
         $this->assertEquals($test['expected'], $templates[0]->getRule(), $i++ . ": " . $test['expected'] . "\n != \n" . $templates[0]->getRule());
     }
     foreach ($compareTests as $test) {
         $rules = array();
         foreach ($test['input'] as $rule) {
             array_push($rules, $rule);
         }
         usort($rules, '\\histou\\template\\Template::compare');
         $this->assertEquals($test['expected'], $rules[0]);
     }
 }
コード例 #2
0
ファイル: template.php プロジェクト: Griesbacher/histou
 /**
     Sort function to order the objects
     @param object $first  Template1.
     @param object $second Template2.
     @return int.
     **/
 public static function compare($first, $second)
 {
     return \histou\template\Rule::compare(static::getRuleFromX($first), static::getRuleFromX($second));
 }
コード例 #3
0
ファイル: index.php プロジェクト: Griesbacher/histou
            exit(1);
        }
    }
}
// load templates
$templateFiles = \histou\Folder::loadFolders(array(CUSTOM_TEMPLATE_FOLDER, DEFAULT_TEMPLATE_FOLDER));
$templateCache = new \histou\template\cache('templates');
$templates = $templateCache->loadTemplates($templateFiles, '\\histou\\template\\loader::loadTemplate');
if (sizeof($templates) == 0) {
    \histou\Basic::returnData(\histou\Debug::errorMarkdownDashboard('# Could not load templates!'), 1);
    exit(1);
}
if (\histou\Basic::$specificTemplate == "") {
    // search for the best
    //save databaseresult to rule
    \histou\template\Rule::setCheck($perfData['host'], $perfData['service'], $perfData['command'], array_keys($perfData['perfLabel']));
    usort($templates, '\\histou\\template\\Template::compare');
    $valid = $templates[0]->isValid();
    \histou\Debug::add("Template order:");
    foreach ($templates as $template) {
        \histou\Debug::add($template);
    }
    \histou\Debug::add("Is the first template valid: " . \histou\Debug::printBoolean($valid) . "\n");
    \histou\Debug::add("Data: " . print_r($perfData, true));
    if ($valid) {
        $template = $templates[0];
    } else {
        $template = \histou\template\Template::findDefaultTemplate($templates, 'default.php');
    }
} else {
    // find the one
コード例 #4
0
ファイル: rule_examinant.php プロジェクト: Griesbacher/histou
            $forecastTemplate = $forecastTemplates[0];
            $className = get_class($forecastTemplate);
            if ($className == 'histou\\template\\Rule') {
                $forecastTemplate = \histou\template\loader::loadForecastTemplate($forecastTemplate->getFileName(), true);
            }
            $result .= $forecastTemplate->getJSON();
        } else {
            $result .= "[]";
        }
        $result .= ",";
    }
    $result = rtrim($result, ",");
    $result .= "]";
    echo $result;
} else {
    \histou\template\Rule::setCheck(HOST, SERVICE, COMMAND, $PERF_LABEL);
    usort($forecastTemplates, '\\histou\\template\\Template::compare');
    $fValid = $forecastTemplates[0]->isValid();
    \histou\Debug::add("ForecastTemplate order:");
    foreach ($forecastTemplates as $ftemplate) {
        \histou\Debug::add($ftemplate);
    }
    \histou\Debug::add("Is the first ForecastTemplate valid: " . \histou\Debug::printBoolean($fValid) . "\n");
    if ($fValid) {
        $forecastTemplate = $forecastTemplates[0];
        $className = get_class($forecastTemplate);
        if ($className == 'histou\\template\\Rule') {
            $forecastTemplate = \histou\template\loader::loadForecastTemplate($forecastTemplate->getFileName(), true);
        }
        echo $forecastTemplate->getJSON();
    } else {