Commit 78bacee5 authored by Reto Da Forno's avatar Reto Da Forno
Browse files

API extended with new command to query test information

parent 04b0232e
...@@ -131,7 +131,7 @@ def convert_serial(obsdata, observer_id, node_id): ...@@ -131,7 +131,7 @@ def convert_serial(obsdata, observer_id, node_id):
result = "%s,%s,%s,%s,%s\n" % (obsdata[2], observer_id, node_id, serialdict[obsdata[0]], obsdata[1].decode('utf8').rstrip()) result = "%s,%s,%s,%s,%s\n" % (obsdata[2], observer_id, node_id, serialdict[obsdata[0]], obsdata[1].decode('utf8').rstrip())
except UnicodeDecodeError: except UnicodeDecodeError:
# discard result, return empty string # discard result, return empty string
result = "\n" # "%s,%s,%s,%s,%s\n" % (obsdata[2], observer_id, node_id, serialdict[obsdata[0]], str(obsdata[1])) result = "%s,%s,%s,%s,\n" % (obsdata[2], observer_id, node_id, serialdict[obsdata[0]])
return result return result
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# -f <testid>: fetch via webdav # -f <testid>: fetch via webdav
# -o <platform>: get a list of the currently available (online) observers # -o <platform>: get a list of the currently available (online) observers
# -p: get a list of the available platforms # -p: get a list of the available platforms
# -i <testid>: get test info (title, desc, status, start time etc.)
# -h: display help # -h: display help
# #
# For the commands -g and -f, the download directory can be specified as an additional argument. # For the commands -g and -f, the download directory can be specified as an additional argument.
...@@ -32,7 +33,7 @@ SERVER_URL=https://flocklab.ethz.ch/user ...@@ -32,7 +33,7 @@ SERVER_URL=https://flocklab.ethz.ch/user
CURL_PARAMS='-sS -4 --insecure' CURL_PARAMS='-sS -4 --insecure'
FLAUTH_FILE=.flocklabauth FLAUTH_FILE=.flocklabauth
NETRC_FILE=$HOME/.netrc NETRC_FILE=$HOME/.netrc
DAV_URL=https://flocklab.ethz.ch/user/webdav DAV_URL=${SERVER_URL}/webdav
DAV_CLIENT=cadaver DAV_CLIENT=cadaver
if [ -f $FLAUTH_FILE ] if [ -f $FLAUTH_FILE ]
...@@ -55,6 +56,12 @@ then ...@@ -55,6 +56,12 @@ then
done < "$NETRC_FILE" done < "$NETRC_FILE"
fi fi
if [ -z "$USER" ] || [ -z "$PASSWORD" ]
then
echo "No username or password found. Add your credentials to ~/.flocklabauth."
exit 1
fi
usage() usage()
{ {
cat << EOF cat << EOF
...@@ -71,6 +78,7 @@ OPTIONS: ...@@ -71,6 +78,7 @@ OPTIONS:
-f <testid>: fetch test results (via webdav) -f <testid>: fetch test results (via webdav)
-o <platform>: get a list of currently available observers -o <platform>: get a list of currently available observers
-p: get a list of available platforms -p: get a list of available platforms
-i <testid>: get test info (title, desc, status, start time etc.)
-h: display this help page -h: display this help page
EOF EOF
} }
...@@ -141,7 +149,7 @@ then ...@@ -141,7 +149,7 @@ then
exit 1 exit 1
fi fi
while getopts “v:c:a:d:f:g:o:ph” OPTION while getopts “v:c:a:d:f:g:o:pi:h” OPTION
do do
case $OPTION in case $OPTION in
v) v)
...@@ -296,6 +304,13 @@ do ...@@ -296,6 +304,13 @@ do
echo $RESPONSE echo $RESPONSE
fi fi
;; ;;
i)
RESPONSE=`curl $CURL_PARAMS -o - -F username="$USER" -F password="$PASSWORD" -F q="testinfo" -F id=$OPTARG $SERVER_URL/api.php`
if [ $? -eq 0 ]
then
echo $RESPONSE
fi
;;
h) h)
usage usage
exit 0 exit 0
......
...@@ -68,6 +68,28 @@ ...@@ -68,6 +68,28 @@
echo json_encode(array('status' => 'ok', 'output' => join(" ", array_unique(array_filter($output))))); echo json_encode(array('status' => 'ok', 'output' => join(" ", array_unique(array_filter($output)))));
} }
} }
else if ($_POST['q'] == 'testinfo') {
if (!isset($_POST['id'])) {
echo json_encode(array('status' => 'error', 'output' => 'no test ID specified'));
exit();
}
$db = db_connect();
$sql = "SELECT title, description, test_status as status, UNIX_TIMESTAMP(time_start_wish) AS start_planned, UNIX_TIMESTAMP(time_start_act) AS start_act, UNIX_TIMESTAMP(time_end_wish) AS end_planned, UNIX_TIMESTAMP(time_end_act) AS end_act
FROM `flocklab`.`tbl_serv_tests`
WHERE serv_tests_key=".intval($_POST['id'])." AND owner_fk=$_SESSION[serv_users_key]";
$res = mysqli_query($db, $sql);
if (!$res) {
echo json_encode(array('status' => 'error', 'output' => mysqli_error($db)));
}
else {
$row = mysqli_fetch_assoc($res);
if ($row) {
echo json_encode(array('status' => 'ok', 'output' => array('title' => $row['title'], 'description' => $row['description'], 'status' => $row['status'], 'start_planned' => $row['start_planned'], 'start' => $row['start_act'], 'end_planned' => $row['end_planned'], 'end' => $row['end_act'])));
} else {
echo json_encode(array('status' => 'error', 'output' => 'test ID '.intval($_POST['id']).' not found'));
}
}
}
else { else {
echo json_encode(array('status' => 'error', 'output' => 'unknown query')); echo json_encode(array('status' => 'error', 'output' => 'unknown query'));
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment