diff --git a/lib/API.php b/lib/API.php index 502c62428399f49769ac38a609a1f42f2b97a3f1..be7d6dfea8901dc89589863550dd1895059783f4 100644 --- a/lib/API.php +++ b/lib/API.php @@ -95,6 +95,7 @@ class API { 'mod_time', 'lang', 'details', + 'valid_sec' ]; foreach ($supportedOptions as $opt) { @@ -303,7 +304,11 @@ class API { if ($optValue != 1) { $optValue = 0; } - + case 'valid_sec': + $optValue = filter_var($optValue, FILTER_SANITIZE_NUMBER_INT); + if ($optValue == '') { + $optValue = 0; + } default: } $this->opts[$optName] = $optValue; @@ -568,6 +573,18 @@ class API { 'arguments' => [ $this->addStdArgument('fed_id'), $this->addStdArgument('reg_auth'), + [ + 'arg' => 'only_errors', + 'required' => FALSE, + 'default' => '0', + 'values' => '0, 1', + 'description' => '0 - show all; 1 - only federations with feed problems including close to expiry'], + [ + 'arg' => 'valid_sec', + 'required' => FALSE, + 'default' => VALIDITY_WARNING_THRESHOLD . ' (108 hours or 4.5 days)', + 'values' => 'any non-negative integer', + 'description' => 'set the alert expiry time to this number of seconds'], $this->addStdArgument('format'), ], 'returns' => [ @@ -583,6 +600,7 @@ class API { when no federation code is present an array of code-indexed participating federations with details as described above' ], 'examples' => [ + ['opt' => ['only_errors'], 'title' => 'only fedrations with problems',], ['opt' => ['fed_id' => 'PIONIER-ID',],'title' => 'show status of PIONIER.Id',], ['opt' => ['fed_id' => 'PIONIER-ID',], 'format' => 'json', 'title' => 'show status of PIONIER.Id in JSON',] ] @@ -590,9 +608,25 @@ class API { if ($this->opts['help'] == 1) { return ""; } - $edugain = new eduGAIN(1, $this->fed_id, true); + Utils::debug(5, $this->opts, "OPTS: ", "\n"); + $edugain = new eduGAIN(5, $this->fed_id, true); $edugain->load_federations_state(); - $out = $edugain->FEDS; + if ($this->opts['only_errors'] == 1) { + $out = []; + if ($this->opts['valid_sec'] > 0) { + $sec = $this->opts['valid_sec']; + } else { + $sec = VALIDITY_WARNING_THRESHOLD; + } + foreach ($edugain->FEDS as $fed) { + if ($fed['feed_problem'] > 0 || $fed['valid_sec'] < $sec) { + $out[] = $fed; + } + } + + } else { + $out = $edugain->FEDS; + } return $out; }