mirror of
https://github.com/Yubico/yubikey-val.git
synced 2025-03-15 18:29:17 +01:00
Refactor out function into library.
This commit is contained in:
parent
f2483a6ff9
commit
5381074a73
@ -35,36 +35,9 @@ set_include_path(implode(PATH_SEPARATOR, array(
|
|||||||
)));
|
)));
|
||||||
|
|
||||||
require_once 'ykval-config.php';
|
require_once 'ykval-config.php';
|
||||||
require_once 'ykval-db.php';
|
|
||||||
require_once 'ykval-common.php';
|
require_once 'ykval-common.php';
|
||||||
|
require_once 'ykval-synclib.php';
|
||||||
|
|
||||||
function get_db_counters()
|
|
||||||
{
|
|
||||||
$db = Db::GetDatabaseHandle($baseParams, 'ykval-munin-queuelength');
|
|
||||||
|
|
||||||
if (!$db->connect())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
$result = $db->customQuery('
|
|
||||||
SELECT server,
|
|
||||||
COUNT(server) as count
|
|
||||||
FROM queue
|
|
||||||
GROUP BY server');
|
|
||||||
|
|
||||||
if ($result)
|
|
||||||
$result = $result->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
$counters = array();
|
|
||||||
|
|
||||||
foreach ($result as $row)
|
|
||||||
{
|
|
||||||
$counters[$row['server']] = $row['count'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $counters;
|
|
||||||
}
|
|
||||||
|
|
||||||
$urls = $baseParams['__YKVAL_SYNC_POOL__'];
|
$urls = $baseParams['__YKVAL_SYNC_POOL__'];
|
||||||
|
|
||||||
@ -104,11 +77,8 @@ if ($argc == 2 && strcmp($argv[1], 'config') == 0)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($counters = get_db_counters()) === FALSE)
|
$sync = new SyncLib('ykval-synclib:munin');
|
||||||
{
|
$queuelength = $sync->getQueueLengthByServer();
|
||||||
echo "Error fetching data from database\n";
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($endpoints as $endpoint)
|
foreach ($endpoints as $endpoint)
|
||||||
{
|
{
|
||||||
@ -116,8 +86,8 @@ foreach ($endpoints as $endpoint)
|
|||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
|
||||||
if (array_key_exists($url, $counters))
|
if (array_key_exists($url, $queuelength))
|
||||||
$count = $counters[$url];
|
$count = $queuelength[$url];
|
||||||
|
|
||||||
echo "${internal}_queuelength.value $count\n";
|
echo "${internal}_queuelength.value $count\n";
|
||||||
}
|
}
|
||||||
|
@ -102,6 +102,27 @@ class SyncLib
|
|||||||
return count($this->db->findBy('queue', null, null, null));
|
return count($this->db->findBy('queue', null, null, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getQueueLengthByServer()
|
||||||
|
{
|
||||||
|
$counters = array();
|
||||||
|
|
||||||
|
foreach ($this->syncServers as $server)
|
||||||
|
{
|
||||||
|
$counters[$server] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->db->customQuery('SELECT server, COUNT(server) as count FROM queue GROUP BY server');
|
||||||
|
|
||||||
|
while ($row = $this->db->fetchArray($result))
|
||||||
|
{
|
||||||
|
$counters[$row['server']] = $row['count'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->closeCursor($result);
|
||||||
|
|
||||||
|
return $counters;
|
||||||
|
}
|
||||||
|
|
||||||
public function queue($otpParams, $localParams)
|
public function queue($otpParams, $localParams)
|
||||||
{
|
{
|
||||||
$info = $this->createInfoString($otpParams, $localParams);
|
$info = $this->createInfoString($otpParams, $localParams);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user