blob: 136c1fd9507ffc8db06ab7dd9635ab118844962c [file] [log] [blame]
<%
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
include('metering-authentication.jag');
(function () {
var TIME_INTERVAL_1 = '30 Min';
var TIME_INTERVAL_2 = '1 Hour';
var TIME_INTERVAL_3 = '1 Day';
var TIME_INTERVAL_4 = '1 Week';
var TIME_INTERVAL_5 = '1 Month';
var TIME_INTERVAL_6 = '6 Month';
var TIME_INTERVAL_7 = '1 Year';
var ALL_CLUSTERS = 'All Clusters';
var db = new Database("WSO2_ANALYTICS_PROCESSED_DATA_STORE_DB");
try {
var result;
var timeInterval = request.getParameter("time");
var interval = 1800000;
if (timeInterval === TIME_INTERVAL_1) {
interval = 1800000;
} else if (timeInterval === TIME_INTERVAL_2) {
interval = 3600000;
} else if (timeInterval === TIME_INTERVAL_3) {
interval = 86400000;
} else if (timeInterval === TIME_INTERVAL_4) {
interval = 604800000;
} else if (timeInterval === TIME_INTERVAL_5) {
interval = 2419200000;
} else if (timeInterval === TIME_INTERVAL_6) {
interval = 2419200000 * 6;
} else if (timeInterval === TIME_INTERVAL_7) {
interval = 2419200000 * 12;
}
var applicationId = request.getParameter("applicationId");
var clusterId = request.getParameter("clusterId");
if (clusterId == ALL_CLUSTERS) {
result = db.query("SELECT FROM_UNIXTIME(Time/1000, '%Y:%m:%d %H:%i:%s') AS Time, MemberId, MemberStatus "
+ "FROM MEMBER_STATUS WHERE ApplicationId= ? AND Time > ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000 -'" +
interval + "') AND Time <= ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000) ORDER BY MemberID, Time", applicationId);
}else {
result = db.query("SELECT FROM_UNIXTIME(Time/1000, '%Y:%m:%d %H:%i:%s') AS Time, MemberId, MemberStatus "
+ "FROM MEMBER_STATUS WHERE ApplicationId= ? AND ClusterAlias= ? AND Time > ROUND(UNIX_TIMESTAMP(CURTIME "
+ "(4)) * 1000-'" + interval + "' ) AND Time <= ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000) ORDER BY "
+ "MemberID, Time", applicationId, clusterId);
}
print(result);
}
catch (e) {
print(e.toString());
}
finally {
db.close();
}
}());
%>