Commit cab21cf4 authored by Reto Da Forno's avatar Reto Da Forno

shell tool updated, first API command added

parent 498343e6
<?php include_once('include/presets.php');?>
<?php
if (isset($_POST['q'])) {
if ($_POST['q'] == 'obs') {
// return a list of the currently available observers
$db = db_connect();
$sql = "SELECT obs.observer_id, slot1.name AS name1, slot1.description AS desc1,
slot2.name AS name2, slot2.description AS desc2,
slot3.name AS name3, slot3.description AS desc3,
slot4.name AS name4, slot4.description AS desc4
FROM `flocklab`.`tbl_serv_observer` AS obs
LEFT JOIN `flocklab`.`tbl_serv_tg_adapt_list` AS a ON obs.slot_1_tg_adapt_list_fk = a.serv_tg_adapt_list_key
LEFT JOIN `flocklab`.`tbl_serv_tg_adapt_types` AS slot1 ON a.tg_adapt_types_fk = slot1.serv_tg_adapt_types_key
LEFT JOIN `flocklab`.`tbl_serv_tg_adapt_list` AS b ON obs.slot_2_tg_adapt_list_fk = b.serv_tg_adapt_list_key
LEFT JOIN `flocklab`.`tbl_serv_tg_adapt_types` AS slot2 ON b.tg_adapt_types_fk = slot2.serv_tg_adapt_types_key
LEFT JOIN `flocklab`.`tbl_serv_tg_adapt_list` AS c ON obs.slot_3_tg_adapt_list_fk = c.serv_tg_adapt_list_key
LEFT JOIN `flocklab`.`tbl_serv_tg_adapt_types` AS slot3 ON c.tg_adapt_types_fk = slot3.serv_tg_adapt_types_key
LEFT JOIN `flocklab`.`tbl_serv_tg_adapt_list` AS d ON obs.slot_4_tg_adapt_list_fk = d.serv_tg_adapt_list_key
LEFT JOIN `flocklab`.`tbl_serv_tg_adapt_types` AS slot4 ON d.tg_adapt_types_fk = slot4.serv_tg_adapt_types_key
WHERE obs.status='online'
ORDER BY obs.observer_id;";
$res = mysql_query($sql);
if (!$res) {
echo json_encode(array('status' => 'error', 'output' => mysql_error()));
}
else {
if (isset($_POST['platform'])) {
$platform = mysql_real_escape_string($_POST['platform']);
}
$output = "";
while ($row = mysql_fetch_assoc($res)) {
if ($platform == "" || !strcasecmp($platform, $row['name1']) || !strcasecmp($platform, $row['name2']) || !strcasecmp($platform, $row['name3']) || !strcasecmp($platform, $row['name4'])) {
$output .= $row['observer_id']." ";
}
}
echo json_encode(array('status' => 'ok', 'output' => trim($output)));
}
}
else {
echo json_encode(array('status' => 'error', 'output' => 'unknown query'));
}
} else {
echo json_encode(array('status' => 'error', 'output' => 'invalid API usage'));
}
?>
......@@ -2,7 +2,7 @@
#
# ------------------------------
# Command line tool for FlockLab
# v1.2
# v1.3
#
# Usage:
#
......@@ -12,6 +12,7 @@
# -d <testid>: delete
# -g <testid>: get via https
# -f <testid>: fetch via webdav
# -o <platform>: get a list of the currently available (online) observers
# -h: display help
#
# Your FlockLab login credentials need to be stored in .flocklabauth in your home directory as follows:
......@@ -65,6 +66,7 @@ OPTIONS:
-d <testid>: delete test
-g <testid>: get test results (via https)
-f <testid>: fetch test results (via webdav)
-o <platform>: get the list of currently available observers
EOF
}
......@@ -134,7 +136,7 @@ then
exit 1
fi
while getopts “v:c:a:d:f:g:h” OPTION
while getopts “v:c:a:d:f:g:o:h” OPTION
do
case $OPTION in
v)
......@@ -271,6 +273,13 @@ do
echo "Fetching results for test $OPTARG ..."
fetchtest
;;
o)
RESPONSE=`curl $CURL_PARAMS -o - -F username="$USER" -F password="$PASSWORD" -F q="obs" -F platform=$OPTARG $SERVER_URL/api.php`
if [ $? -eq 0 ]
then
echo $RESPONSE
fi
;;
h)
usage
exit 0
......
Markdown is supported
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