From 7c94240386650fba57325043177a52b26410cbca Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Mon, 21 May 2012 08:49:27 +0200 Subject: [PATCH 1/4] Chmod. --- ykval-munin-ksmlatency.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 ykval-munin-ksmlatency.php diff --git a/ykval-munin-ksmlatency.php b/ykval-munin-ksmlatency.php old mode 100644 new mode 100755 From f2b05822ef95769cb574f4b4ad704034e57bfe84 Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Mon, 21 May 2012 08:49:42 +0200 Subject: [PATCH 2/4] Silence PHP warnings. --- ykval-munin-queuelength.php | 4 +++- ykval-synclib.php | 2 +- ykval-verify.php | 24 ++++++++++++++++-------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ykval-munin-queuelength.php b/ykval-munin-queuelength.php index 8c08067..2ab2d8d 100755 --- a/ykval-munin-queuelength.php +++ b/ykval-munin-queuelength.php @@ -26,7 +26,9 @@ if ($argc==2 && strcmp($argv[1], "config") == 0) { } $sync = new SyncLib('ykval-verify:synclib'); -$sync->addField('ip', $_SERVER['REMOTE_ADDR']); +if (isset($_SERVER['REMOTE_ADDR'])) { + $sync->addField('ip', $_SERVER['REMOTE_ADDR']); +} $len = $sync->getQueueLength (); echo "queuelength.value $len\n"; diff --git a/ykval-synclib.php b/ykval-synclib.php index b8339e6..30834d7 100644 --- a/ykval-synclib.php +++ b/ykval-synclib.php @@ -538,7 +538,7 @@ class SyncLib while ($info = curl_multi_info_read($mh)) { debug ("YK-KSM multi", $info); - if ($info['result'] == CURL_OK) { + if ($info['result'] == CURLE_OK) { $str = curl_multi_getcontent($info['handle']); if (preg_match("/status=OK/", $str)) { $error = curl_error ($info['handle']); diff --git a/ykval-verify.php b/ykval-verify.php index 739ed38..ff145d9 100644 --- a/ykval-verify.php +++ b/ykval-verify.php @@ -39,7 +39,7 @@ $timestamp = getHttpVal('timestamp', 0); $extra=array(); if ($protocol_version>=2.0) { $extra['otp']=$otp; - } +} /* We have the OTP now, so let's add it to the logging */ @@ -59,7 +59,7 @@ if ($protocol_version>=2.0) { sendResp(S_MISSING_PARAMETER); exit; } - } +} /* Sanity check HTTP parameters @@ -75,10 +75,18 @@ if ($protocol_version>=2.0) { */ /* Change default protocol "strings" to numeric values */ -if (strcasecmp($sl, 'fast')==0) $sl=$baseParams['__YKVAL_SYNC_FAST_LEVEL__']; -if (strcasecmp($sl, 'secure')==0) $sl=$baseParams['__YKVAL_SYNC_SECURE_LEVEL__']; -if (!$sl) $sl=$baseParams['__YKVAL_SYNC_DEFAULT_LEVEL__']; -if (!$timeout) $timeout=$baseParams['__YKVAL_SYNC_DEFAULT_TIMEOUT__']; +if (isset($sl) && strcasecmp($sl, 'fast')==0) { + $sl=$baseParams['__YKVAL_SYNC_FAST_LEVEL__']; +} +if (isset($sl) && strcasecmp($sl, 'secure')==0) { + $sl=$baseParams['__YKVAL_SYNC_SECURE_LEVEL__']; +} +if (!isset($sl)) { + $sl=$baseParams['__YKVAL_SYNC_DEFAULT_LEVEL__']; +} +if (!isset($timeout)) { + $timeout=$baseParams['__YKVAL_SYNC_DEFAULT_TIMEOUT__']; +} if ($otp == '') { $myLog->log(LOG_NOTICE, 'OTP is missing'); @@ -110,13 +118,13 @@ if ($timeout && preg_match("/^[0-9]+$/", $timeout)==0) { exit; } -if ($nonce && preg_match("/^[A-Za-z0-9]+$/", $nonce)==0) { +if (isset($nonce) && preg_match("/^[A-Za-z0-9]+$/", $nonce)==0) { $myLog->log(LOG_NOTICE, 'NONCE is provided but not correct'); sendResp(S_MISSING_PARAMETER); exit; } -if ($nonce && (strlen($nonce) < 16 || strlen($nonce) > 40)) { +if (isset($nonce) && (strlen($nonce) < 16 || strlen($nonce) > 40)) { $myLog->log(LOG_NOTICE, 'Nonce too short or too long'); sendResp(S_MISSING_PARAMETER); exit; From 3954527d61b97c36de28e3ba0a346ae1bb82a24c Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Tue, 22 May 2012 10:16:18 +0200 Subject: [PATCH 3/4] Silence PHP warning. --- ykval-db.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ykval-db.php b/ykval-db.php index b133149..fb883b6 100644 --- a/ykval-db.php +++ b/ykval-db.php @@ -136,7 +136,8 @@ class Db */ public function updateBy($table, $k, $v, $values) { - + $query = ""; + foreach ($values as $key=>$value){ if (!is_null($value)) $query .= ' ' . $key . "='" . $value . "',"; else $query .= ' ' . $key . '=NULL,'; From 2c9b57a0a085a215e37888e0e4617aac106dafcb Mon Sep 17 00:00:00 2001 From: Fredrik Thulin Date: Tue, 22 May 2012 12:15:31 +0200 Subject: [PATCH 4/4] Detect timeouts and errors in curl (such as resolver failures). --- ykval-munin-ksmlatency.php | 6 ++++++ ykval-munin-vallatency.php | 14 ++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ykval-munin-ksmlatency.php b/ykval-munin-ksmlatency.php index 929fdf4..e43a88d 100755 --- a/ykval-munin-ksmlatency.php +++ b/ykval-munin-ksmlatency.php @@ -46,6 +46,12 @@ echo "multigraph yk_latency\n"; foreach ($ksms as $ksm) { $shortksm = url2shortname ($ksm); $time = `curl --silent --write-out '%{time_total}' --max-time 3 '$ksm' -o /dev/null`; + if (preg_match("/^3\./", $time)) { + $time = "timeout"; + } + if (preg_match("/^0\.000/", $time)) { + $time = "error"; + } echo "${shortksm}_avgwait.value $time\n"; } diff --git a/ykval-munin-vallatency.php b/ykval-munin-vallatency.php index dbf45c6..65baaa6 100755 --- a/ykval-munin-vallatency.php +++ b/ykval-munin-vallatency.php @@ -52,10 +52,16 @@ echo "multigraph ykval_latency\n"; foreach ($urls as $url) { $shortname = url2shortname ($url); $cmd = "--user-agent ykval-munin-vallatency/1.0 --silent --write-out '%{time_total}' --max-time 3 '$url' -o /dev/null"; - $ipv4time = `curl --ipv4 $cmd`; - echo "ipv4${shortname}_avgwait.value $ipv4time\n"; - $ipv6time = `curl --ipv6 $cmd`; - echo "ipv6${shortname}_avgwait.value $ipv6time\n"; + foreach (array('ipv4', 'ipv6') as $ipv) { + $time = `curl --$ipv $cmd`; + if (preg_match("/^3\./", $time)) { + $time = "timeout"; + } + if (preg_match("/^0\.000/", $time)) { + $time = "error"; + } + echo "$ipv${shortname}_avgwait.value $time\n"; + } } #%# family=auto