diff --git a/src/main/java/com/appnexus/grafana/client/GrafanaClient.java b/src/main/java/com/appnexus/grafana/client/GrafanaClient.java index a76a3cd..22d2a9b 100644 --- a/src/main/java/com/appnexus/grafana/client/GrafanaClient.java +++ b/src/main/java/com/appnexus/grafana/client/GrafanaClient.java @@ -9,6 +9,7 @@ import com.appnexus.grafana.client.models.DashboardSuccessfulDelete; import com.appnexus.grafana.client.models.GrafanaDashboard; import com.appnexus.grafana.client.models.GrafanaMessage; +import com.appnexus.grafana.client.models.GrafanaSearchResult; import com.appnexus.grafana.configuration.GrafanaConfiguration; import com.appnexus.grafana.exceptions.GrafanaDashboardCouldNotDeleteException; import com.appnexus.grafana.exceptions.GrafanaDashboardDoesNotExistException; @@ -274,4 +275,18 @@ public DashboardPanelAlert getAlert(Integer id) throws GrafanaException, IOExcep throw GrafanaException.withErrorBody(response.errorBody()); } } + + public List search( + String query, String tag, Boolean starred, Boolean tagcloud) + throws GrafanaException, IOException { + + Response> response = + service.search(apiKey, query, tag, starred, tagcloud).execute(); + + if (response.isSuccessful()) { + return response.body(); + } else { + throw GrafanaException.withErrorBody(response.errorBody()); + } + } } diff --git a/src/main/java/com/appnexus/grafana/client/GrafanaService.java b/src/main/java/com/appnexus/grafana/client/GrafanaService.java index a0b3d9f..46de7ca 100644 --- a/src/main/java/com/appnexus/grafana/client/GrafanaService.java +++ b/src/main/java/com/appnexus/grafana/client/GrafanaService.java @@ -7,6 +7,7 @@ import com.appnexus.grafana.client.models.DashboardSuccessfulDelete; import com.appnexus.grafana.client.models.GrafanaDashboard; import com.appnexus.grafana.client.models.GrafanaMessage; +import com.appnexus.grafana.client.models.GrafanaSearchResult; import java.util.List; import retrofit2.Call; import retrofit2.http.Body; @@ -16,11 +17,13 @@ import retrofit2.http.POST; import retrofit2.http.PUT; import retrofit2.http.Path; +import retrofit2.http.Query; public interface GrafanaService { String GRAFANA_DASHBOARDS = "api/dashboards/db/"; String GRAFANA_NOTIFICATIONS = "api/alert-notifications/"; String GRAFANA_ALERTS = "api/alerts/"; + String GRAFANA_SEARCH = "api/search/"; String AUTHORIZATION = "Authorization"; @@ -63,4 +66,13 @@ Call deleteNotification( @GET(GRAFANA_ALERTS + "{id}") Call getAlert( @Header(AUTHORIZATION) String authorization, @Path("id") Integer id); + + // Search + @GET(GRAFANA_SEARCH) + Call> search( + @Header(AUTHORIZATION) String authorization, + @Query("query") String query, + @Query("tag") String tag, + @Query("starred") Boolean starred, + @Query("tagcloud") Boolean tagcloud); } diff --git a/src/main/java/com/appnexus/grafana/client/models/GrafanaSearchResult.java b/src/main/java/com/appnexus/grafana/client/models/GrafanaSearchResult.java new file mode 100644 index 0000000..219ae12 --- /dev/null +++ b/src/main/java/com/appnexus/grafana/client/models/GrafanaSearchResult.java @@ -0,0 +1,17 @@ +/* Licensed under Apache-2.0 */ +package com.appnexus.grafana.client.models; + +import java.util.List; +import lombok.Data; +import lombok.experimental.Accessors; + +@Data +@Accessors(fluent = true) +public class GrafanaSearchResult { + Long id; + String title; + String uri; + String type; + List tags; + Boolean isStarred; +}