diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml
new file mode 100644
index 0000000000..65b46b32a3
--- /dev/null
+++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml
@@ -0,0 +1,338 @@
+
+
+
+
+
+
+ org.wso2.carbon.devicemgt
+ grafana-mgt
+ 5.0.3-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ io.entgra.analytics.mgt.grafana.proxy.api
+ war
+ Entgra - Grafana Proxy API
+ Entgra - Grafana Proxy API
+ http://entgra.io
+
+
+
+
+ maven-compiler-plugin
+
+
+ 1.8
+
+
+
+ maven-war-plugin
+
+ WEB-INF/lib/*cxf*.jar
+ api#grafana-mgt#v1.0
+
+
+
+
+
+
+
+ deploy
+
+ compile
+
+
+ org.apache.maven.plugins
+ maven-antrun-plugin
+ 1.7
+
+
+ compile
+
+ run
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ org.testng
+ testng
+ test
+
+
+ org.springframework
+ spring-web
+ provided
+
+
+ org.apache.cxf
+ cxf-bundle
+ 3.0.0-milestone2
+ test
+
+
+ org.apache.cxf
+ cxf-bundle-jaxrs
+ provided
+
+
+ commons-httpclient.wso2
+ commons-httpclient
+ provided
+
+
+ org.wso2.carbon
+ org.wso2.carbon.utils
+ provided
+
+
+ org.wso2.carbon.identity.framework
+ org.wso2.carbon.user.mgt
+ provided
+
+
+ org.slf4j
+ slf4j-api
+
+
+ org.slf4j
+ jcl-over-slf4j
+
+
+
+
+ org.wso2.carbon
+ org.wso2.carbon.logging
+ provided
+
+
+ org.wso2.carbon.identity.inbound.auth.oauth2
+ org.wso2.carbon.identity.oauth.stub
+ provided
+
+
+ org.apache.axis2.wso2
+ axis2-client
+
+
+
+
+ org.json.wso2
+ json
+
+
+ commons-codec.wso2
+ commons-codec
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.certificate.mgt.core
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.core
+
+
+
+
+ io.swagger
+ swagger-annotations
+
+
+ io.swagger
+ swagger-core
+
+
+ com.fasterxml.jackson.module
+ jackson-module-jaxb-annotations
+
+
+ org.slf4j
+ slf4j-api
+
+
+ org.wso2.orbit.com.fasterxml.jackson.core
+ jackson-core
+
+
+
+
+ io.swagger
+ swagger-jaxrs
+
+
+ com.fasterxml.jackson.module
+ jackson-module-jaxb-annotations
+
+
+ org.slf4j
+ slf4j-api
+
+
+ org.wso2.orbit.com.fasterxml.jackson.core
+ jackson-core
+
+
+
+
+ javax.servlet
+ javax.servlet-api
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.apimgt.annotations
+ provided
+
+
+ org.wso2.orbit.com.fasterxml.jackson.core
+ jackson-annotations
+
+
+ org.hibernate
+ hibernate-validator
+
+
+ javax.ws.rs
+ javax.ws.rs-api
+ provided
+
+
+ javax.ws.rs
+ jsr311-api
+ provided
+
+
+ org.wso2.carbon.commons
+ org.wso2.carbon.application.mgt.stub
+ provided
+
+
+ org.wso2.carbon.analytics
+ org.wso2.carbon.analytics.api
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.identity.jwt.client.extension
+ provided
+
+
+ org.wso2.carbon
+ org.wso2.carbon.registry.core
+ provided
+
+
+ org.wso2.carbon.registry
+ org.wso2.carbon.registry.resource
+ provided
+
+
+ org.wso2.carbon.identity.framework
+ org.wso2.carbon.identity.user.store.count
+ ${carbon.identity.framework.version}
+ provided
+
+
+
+
+
+
+
+ org.wso2.carbon.analytics-common
+ org.wso2.carbon.event.receiver.stub
+ provided
+
+
+ org.wso2.carbon.analytics-common
+ org.wso2.carbon.event.stream.stub
+ provided
+
+
+ org.wso2.carbon.analytics-common
+ org.wso2.carbon.event.publisher.stub
+ provided
+
+
+ org.wso2.carbon.analytics-common
+ org.wso2.carbon.event.stream.persistence.stub
+ provided
+
+
+ org.powermock
+ powermock-module-testng
+ test
+
+
+ org.powermock
+ powermock-api-mockito
+ test
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.common
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.extensions
+ provided
+
+
+ org.wso2.carbon.identity.framework
+ org.wso2.carbon.identity.claim.metadata.mgt
+ ${carbon.identity.framework.version}
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ io.entgra.analytics.mgt.grafana.proxy.core
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.core
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ io.entgra.analytics.mgt.grafana.proxy.common
+ provided
+
+
+
+
diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/GrafanaAPIProxyService.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/GrafanaAPIProxyService.java
new file mode 100644
index 0000000000..3921e6fc34
--- /dev/null
+++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/GrafanaAPIProxyService.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
+ *
+ * Entgra (pvt) Ltd. 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.
+ */
+package io.entgra.analytics.mgt.grafana.proxy.api.service;
+
+import com.google.gson.JsonObject;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.Extension;
+import io.swagger.annotations.ExtensionProperty;
+import io.swagger.annotations.Info;
+import io.swagger.annotations.SwaggerDefinition;
+import io.swagger.annotations.Tag;
+import org.wso2.carbon.apimgt.annotations.api.Scope;
+import org.wso2.carbon.apimgt.annotations.api.Scopes;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+@SwaggerDefinition(
+ info = @Info(
+ version = "1.0.0",
+ title = "Grafana API Proxy Service",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = "name", value = "GrafanaAPIManagement"),
+ @ExtensionProperty(name = "context", value = "/api/grafana-mgt/v1.0/api"),
+ })
+ }
+ ),
+ tags = {
+ @Tag(name = "analytics_management", description = "")
+ }
+)
+@Scopes(
+ scopes = {
+ @Scope(
+ name = "Using Grafana APIs required for Grafana iframes",
+ description = "Grafana API proxy to validate requests.",
+ key = "perm:grafana:api:view",
+ roles = {"Internal/grafanamgt-user"},
+ permissions = {"/analytics-mgt/grafana-mgt/api/view"}
+ )
+ }
+)
+
+@Path("/api")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.MEDIA_TYPE_WILDCARD)
+@Api(value = "Grafana API Management", description = "Grafana api related operations can be found here.")
+public interface GrafanaAPIProxyService {
+
+ String SCOPE = "scope";
+
+ @POST
+ @Path("/ds/query")
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "POST",
+ value = "Grafana query API proxy",
+ tags = "Analytics",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = SCOPE, value = "perm:grafana:api:view")
+ })
+ }
+ )
+ Response queryDatasource(JsonObject body, @Context HttpHeaders headers, @Context UriInfo requestUriInfo);
+
+ @POST
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Path("/frontend-metrics")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "POST",
+ value = "Grafana frontend-metric API proxy",
+ tags = "Analytics",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = SCOPE, value = "perm:grafana:api:view")
+ })
+ }
+ )
+ Response frontendMetrics(JsonObject body, @Context HttpHeaders headers, @Context UriInfo requestUriInfo);
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/dashboards/uid/{uid}")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "POST",
+ value = "Grafana dashboard details API proxy",
+ tags = "Analytics",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = SCOPE, value = "perm:grafana:api:view")
+ })
+ }
+ )
+ Response getDashboard(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) throws ClassNotFoundException;
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Path("/annotations")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "GET",
+ value = "Grafana annotations API proxy",
+ tags = "Analytics",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = SCOPE, value = "perm:grafana:api:view")
+ })
+ }
+ )
+ Response getAnnotations(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) throws ClassNotFoundException;
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/alerts/states-for-dashboard")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "POST",
+ value = "Get Grafana alert states for dashboard details API proxy",
+ tags = "Analytics",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = SCOPE, value = "perm:grafana:api:view")
+ })
+ }
+ )
+ Response getAlertStateForDashboards(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) throws ClassNotFoundException;
+}
diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/addons/ApiOriginFilter.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/addons/ApiOriginFilter.java
new file mode 100644
index 0000000000..5562c40ad0
--- /dev/null
+++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/addons/ApiOriginFilter.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2021, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
+ *
+ * Entgra (Pvt) Ltd. 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.
+ */
+
+package io.entgra.analytics.mgt.grafana.proxy.api.service.addons;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+public class ApiOriginFilter implements Filter {
+
+ public void doFilter(ServletRequest request, ServletResponse response,
+ FilterChain chain) throws IOException, ServletException {
+ HttpServletResponse res = (HttpServletResponse) response;
+ res.addHeader("Access-Control-Allow-Origin", "*");
+ res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
+ res.addHeader("Access-Control-Allow-Headers", "Content-Type");
+ chain.doFilter(request, response);
+ }
+
+ public void destroy() {
+ //do nothing
+ }
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ //do nothing
+ }
+}
diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/addons/GsonMessageBodyHandler.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/addons/GsonMessageBodyHandler.java
new file mode 100644
index 0000000000..f786cf645e
--- /dev/null
+++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/analytics/mgt/grafana/proxy/api/service/addons/GsonMessageBodyHandler.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. 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.
+ */
+
+package io.entgra.analytics.mgt.grafana.proxy.api.service.addons;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+import java.io.*;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
+@Provider
+@Produces(APPLICATION_JSON)
+@Consumes(APPLICATION_JSON)
+public class GsonMessageBodyHandler implements MessageBodyWriter