mirror of
https://github.com/Yubico/yubikey-val.git
synced 2025-03-04 03:29:18 +01:00
Modify ykval-munin-vallatency plugin.
- use hostname (+ port if any) for graph name. i.e. if we have a sync URL: https://api.yubico.com:8080/wsapi/2.0/sync instead of having "api" as name, we have "api.yubico.com:8080". - also avoid using regex and use parse_url() from php core instead.
This commit is contained in:
parent
7940d1e6e7
commit
f2604e751a
@ -362,3 +362,23 @@ function total_time ($url)
|
|||||||
|
|
||||||
return $total_time;
|
return $total_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the hostname, and if defined the port, for a given URL.
|
||||||
|
*
|
||||||
|
* @argument $url string
|
||||||
|
* @return string|bool short name or false on failure
|
||||||
|
*/
|
||||||
|
function short_name ($url)
|
||||||
|
{
|
||||||
|
if (($url = parse_url($url)) === FALSE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (array_key_exists('host', $url) === FALSE || $url['host'] === NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (array_key_exists('port', $url) === TRUE && $url['port'] !== NULL)
|
||||||
|
return $url['host'] . ':' . $url['port'];
|
||||||
|
|
||||||
|
return $url['host'];
|
||||||
|
}
|
||||||
|
@ -37,20 +37,18 @@ set_include_path(implode(PATH_SEPARATOR, array(
|
|||||||
require_once 'ykval-config.php';
|
require_once 'ykval-config.php';
|
||||||
require_once 'ykval-common.php';
|
require_once 'ykval-common.php';
|
||||||
|
|
||||||
function url2shortname ($url)
|
$urls = $baseParams['__YKVAL_SYNC_POOL__'];
|
||||||
|
|
||||||
|
$shortnames = array_map("short_name", $urls);
|
||||||
|
foreach($shortnames as $val)
|
||||||
{
|
{
|
||||||
if (preg_match("/^[^\/]+\/\/([a-z0-9-]+)/", $url, $name) == 0)
|
if ($val === FALSE)
|
||||||
{
|
{
|
||||||
echo "Cannot match URL hostname: " . $url . "\n";
|
echo "Cannot parse URL from sync pool list\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $name[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$urls = $baseParams['__YKVAL_SYNC_POOL__'];
|
|
||||||
$shortnames = array_map("url2shortname", $urls);
|
|
||||||
|
|
||||||
if ($argc == 2 && strcmp($argv[1], "autoconf") == 0)
|
if ($argc == 2 && strcmp($argv[1], "autoconf") == 0)
|
||||||
{
|
{
|
||||||
print "yes\n";
|
print "yes\n";
|
||||||
@ -80,7 +78,7 @@ if ($argc == 2 && strcmp($argv[1], "config") == 0)
|
|||||||
echo "multigraph ykval_vallatency\n";
|
echo "multigraph ykval_vallatency\n";
|
||||||
foreach ($urls as $url)
|
foreach ($urls as $url)
|
||||||
{
|
{
|
||||||
$shortname = url2shortname($url);
|
$shortname = short_name($url);
|
||||||
|
|
||||||
if (($total_time = total_time($url)) === FALSE)
|
if (($total_time = total_time($url)) === FALSE)
|
||||||
$total_time = 'error';
|
$total_time = 'error';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user