function check_x($x)
 {
     $y = 'whatever';
     // This function only has access to the parameter, '$x', and the locally
     // declared variable, '$y'.
     // Whilst 'run_check' has access to several global variables, the current
     // function does not. For it to access the global variable, '$condition',
     // it must be declared 'global'
     run_check();
     global $condition;
     // 'run_check' will have updated, '$condition', and since it has been
     // declared 'global' here, it is accessable
     if ($condition) {
         // ...
     }
 }
Exemplo n.º 2
0
        if (file_put_contents($file_report, $line, FILE_APPEND) === FALSE) {
            exit('error: file_put_contents failed' . NL);
        }
        sleep(5 * 60);
    }
    my_kill($binary);
    return $latency;
}
if ($argc != 3 || is_numeric($argv[1]) === FALSE || is_numeric($argv[2]) === FALSE) {
    usage($argv[0]);
}
my_system('pkill -TERM ' . basename(BIN_NAGIOS));
my_system('pkill -TERM ' . basename(BIN_CENTENGINE));
$time = intval($argv[1]);
$nb_check = intval($argv[2]);
$nagios_latency = 0;
$centengine_latency = 0;
$timeout = $time / 2;
while ($nagios_latency < $timeout || $centengine_latency < $timeout) {
    if (($config = generate_configuration($nb_check)) === FALSE) {
        exit('error: generate_configuration failed' . NL);
    }
    $filename_report = date('m_d_y_H_i_s') . '_' . $nb_check;
    if ($nagios_latency < $timeout) {
        $nagios_latency = run_check(FILE_NAGIOS_SERVICES, FILE_NAGIOS_CONFIGURATION, $config, BIN_NAGIOS, BIN_NAGIOSTATS, DIR_NAGIOS_REPORT . '/' . $filename_report, DIR_NAGIOS_VAR, $nb_check, $time);
    }
    if ($centengine_latency < $timeout) {
        $centengine_latency = run_check(FILE_CENTENGINE_SERVICES, FILE_CENTENGINE_CONFIGURATION, $config, BIN_CENTENGINE, BIN_CENTENGINESTATS, DIR_CENTENGINE_REPORT . '/' . $filename_report, DIR_CENTENGINE_VAR, $nb_check, $time);
    }
    $nb_check *= 2;
}
Exemplo n.º 3
0
$snmpsim = check_opt($options, 'snmpsim');
$ret = 0;
$completed_tests = array('lint' => false, 'style' => false, 'unit' => false);
$all = !check_opt($options, 'l', 'lint', 's', 'style', 'u', 'unit');
if ($all) {
    // no test specified, run all tests in this order
    $options += array('u' => false, 's' => false, 'l' => false);
}
// run tests in the order they were specified
foreach (array_keys($options) as $opt) {
    if ($opt == 'l' || $opt == 'lint') {
        $ret += run_check('lint', $passthru, $command_only);
    } elseif ($opt == 's' || $opt == 'style') {
        $ret += run_check('style', $passthru, $command_only);
    } elseif ($opt == 'u' || $opt == 'unit') {
        $ret += run_check('unit', $passthru, $command_only, $snmpsim);
    }
}
// output Tests ok, if no arguments passed
if ($all && $ret === 0) {
    echo "Tests ok, submit away :) \n";
}
exit($ret);
//return the combined/single return value of tests
/**
 * Run the specified check and return the return value.
 * Make sure it isn't skipped by SKIP_TYPE_CHECK env variable and hasn't been run already
 *
 * @param string $type type of check lint, style, or unit
 * @param bool $passthru display the output as comes in
 * @param bool $command_only only display the intended command, no checks