|
40 | 40 | import org.springframework.http.ResponseEntity;
|
41 | 41 | import org.springframework.stereotype.Service;
|
42 | 42 | import org.springframework.transaction.annotation.Transactional;
|
| 43 | +import org.springframework.web.client.HttpClientErrorException; |
43 | 44 | import org.springframework.web.client.RestTemplate;
|
44 | 45 | import lombok.extern.slf4j.Slf4j;
|
45 | 46 |
|
@@ -71,6 +72,11 @@ public class DashboardService {
|
71 | 72 | */
|
72 | 73 | @Transactional(rollbackFor = Exception.class)
|
73 | 74 | public ResponseEntity<?> createOrUpdateDashboard(String dashboardJson, Long monitorId) {
|
| 75 | + if (!grafanaProperties.enabled()) { |
| 76 | + log.info("HertzBeat Grafana config not enabled"); |
| 77 | + throw new RuntimeException("HertzBeat Grafana config not enabled"); |
| 78 | + } |
| 79 | + |
74 | 80 | String token = serviceAccountService.getToken();
|
75 | 81 | String url = grafanaProperties.getPrefix() + grafanaProperties.getUrl() + CREATE_DASHBOARD_API;
|
76 | 82 |
|
@@ -103,6 +109,12 @@ public ResponseEntity<?> createOrUpdateDashboard(String dashboardJson, Long moni
|
103 | 109 | log.error("create dashboard error: {}", response.getStatusCode());
|
104 | 110 | throw new RuntimeException("create dashboard error");
|
105 | 111 | }
|
| 112 | + } catch (HttpClientErrorException.Forbidden ex) { |
| 113 | + log.error("Grafana Access denied to save dashboard", ex); |
| 114 | + throw new RuntimeException("Grafana Access denied to save dashboard", ex); |
| 115 | + } catch (HttpClientErrorException.NotFound ex){ |
| 116 | + log.error("Grafana Dashboard not found", ex); |
| 117 | + throw new RuntimeException("Grafana Dashboard not found", ex); |
106 | 118 | } catch (Exception ex) {
|
107 | 119 | log.error("create dashboard error", ex);
|
108 | 120 | throw new RuntimeException("create dashboard error", ex);
|
|
0 commit comments