use of com.google.monitoring.v3.UpdateUptimeCheckConfigRequest in project java-monitoring by googleapis.
the class UptimeSample method updateUptimeCheck.
// [END monitoring_uptime_check_create]]
// [START monitoring_uptime_check_update]]
private static void updateUptimeCheck(String projectId, String displayName, String hostName, String pathName) throws IOException {
String fullCheckName = UptimeCheckConfigName.format(projectId, displayName);
UpdateUptimeCheckConfigRequest request = UpdateUptimeCheckConfigRequest.newBuilder().setUpdateMask(FieldMask.newBuilder().addPaths("http_check.path")).setUptimeCheckConfig(UptimeCheckConfig.newBuilder().setName(fullCheckName).setMonitoredResource(MonitoredResource.newBuilder().setType("uptime_url").putLabels("host", hostName)).setHttpCheck(HttpCheck.newBuilder().setPath(pathName).setPort(80)).setTimeout(Duration.newBuilder().setSeconds(10)).setPeriod(Duration.newBuilder().setSeconds(300))).build();
try (UptimeCheckServiceClient client = UptimeCheckServiceClient.create()) {
UptimeCheckConfig config = client.updateUptimeCheckConfig(request);
System.out.println("Uptime check updated: \n" + config.toString());
} catch (Exception e) {
usage("Exception updating uptime check: " + e.toString());
throw e;
}
}
use of com.google.monitoring.v3.UpdateUptimeCheckConfigRequest in project java-docs-samples by GoogleCloudPlatform.
the class UptimeSample method updateUptimeCheck.
// [END monitoring_uptime_check_create]]
// [START monitoring_uptime_check_update]]
private static void updateUptimeCheck(String projectId, String displayName, String hostName, String pathName) throws IOException {
String fullCheckName = UptimeCheckConfigName.format(projectId, displayName);
UpdateUptimeCheckConfigRequest request = UpdateUptimeCheckConfigRequest.newBuilder().setUpdateMask(FieldMask.newBuilder().addPaths("http_check.path")).setUptimeCheckConfig(UptimeCheckConfig.newBuilder().setName(fullCheckName).setMonitoredResource(MonitoredResource.newBuilder().setType("uptime_url").putLabels("host", hostName)).setHttpCheck(HttpCheck.newBuilder().setPath(pathName).setPort(80)).setTimeout(Duration.newBuilder().setSeconds(10)).setPeriod(Duration.newBuilder().setSeconds(300))).build();
try (UptimeCheckServiceClient client = UptimeCheckServiceClient.create()) {
UptimeCheckConfig config = client.updateUptimeCheckConfig(request);
System.out.println("Uptime check updated: \n" + config.toString());
} catch (Exception e) {
usage("Exception updating uptime check: " + e.toString());
throw e;
}
}
use of com.google.monitoring.v3.UpdateUptimeCheckConfigRequest in project java-monitoring by googleapis.
the class UptimeCheckServiceClientTest method updateUptimeCheckConfigTest.
@Test
public void updateUptimeCheckConfigTest() throws Exception {
UptimeCheckConfig expectedResponse = UptimeCheckConfig.newBuilder().setName(UptimeCheckConfigName.ofProjectUptimeCheckConfigName("[PROJECT]", "[UPTIME_CHECK_CONFIG]").toString()).setDisplayName("displayName1714148973").setPeriod(Duration.newBuilder().build()).setTimeout(Duration.newBuilder().build()).addAllContentMatchers(new ArrayList<UptimeCheckConfig.ContentMatcher>()).addAllSelectedRegions(new ArrayList<UptimeCheckRegion>()).setIsInternal(true).addAllInternalCheckers(new ArrayList<InternalChecker>()).build();
mockUptimeCheckService.addResponse(expectedResponse);
UptimeCheckConfig uptimeCheckConfig = UptimeCheckConfig.newBuilder().build();
UptimeCheckConfig actualResponse = client.updateUptimeCheckConfig(uptimeCheckConfig);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockUptimeCheckService.getRequests();
Assert.assertEquals(1, actualRequests.size());
UpdateUptimeCheckConfigRequest actualRequest = ((UpdateUptimeCheckConfigRequest) actualRequests.get(0));
Assert.assertEquals(uptimeCheckConfig, actualRequest.getUptimeCheckConfig());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations