29
29
import com .google .monitoring .v3 .UpdateUptimeCheckConfigRequest ;
30
30
import com .google .monitoring .v3 .UptimeCheckConfig ;
31
31
import com .google .monitoring .v3 .UptimeCheckConfig .HttpCheck ;
32
- import com .google .monitoring .v3 .UptimeCheckConfigName ;
33
32
import com .google .monitoring .v3 .UptimeCheckIp ;
34
33
import com .google .protobuf .Duration ;
35
34
import com .google .protobuf .FieldMask ;
@@ -119,7 +118,6 @@ public static void main(String... args) throws IOException {
119
118
break ;
120
119
case "update" :
121
120
updateUptimeCheck (
122
- projectId ,
123
121
cl .getOptionValue (DISPLAY_NAME_OPTION .getOpt (), "new uptime check" ),
124
122
cl .getOptionValue (HOST_NAME_OPTION .getOpt (), "example.com" ),
125
123
cl .getOptionValue (PATH_NAME_OPTION .getOpt (), "/" ));
@@ -131,12 +129,11 @@ public static void main(String... args) throws IOException {
131
129
listUptimeCheckIps ();
132
130
break ;
133
131
case "get" :
134
- getUptimeCheckConfig (
135
- projectId , cl .getOptionValue (DISPLAY_NAME_OPTION .getOpt (), "new uptime check" ));
132
+ getUptimeCheckConfig (cl .getOptionValue (DISPLAY_NAME_OPTION .getOpt (), "new uptime check" ));
136
133
break ;
137
134
case "delete" :
138
135
deleteUptimeCheckConfig (
139
- projectId , cl .getOptionValue (DISPLAY_NAME_OPTION .getOpt (), "new uptime check" ));
136
+ cl .getOptionValue (DISPLAY_NAME_OPTION .getOpt (), "new uptime check" ));
140
137
break ;
141
138
default :
142
139
usage (null );
@@ -162,7 +159,7 @@ private static void createUptimeCheck(
162
159
.build ();
163
160
try (UptimeCheckServiceClient client = UptimeCheckServiceClient .create ()) {
164
161
UptimeCheckConfig config = client .createUptimeCheckConfig (request );
165
- System .out .println ("Uptime check created: " + config .getDisplayName ());
162
+ System .out .println ("Uptime check created: " + config .getName ());
166
163
} catch (Exception e ) {
167
164
usage ("Exception creating uptime check: " + e .toString ());
168
165
throw e ;
@@ -171,16 +168,15 @@ private static void createUptimeCheck(
171
168
// [END monitoring_uptime_check_create]]
172
169
173
170
// [START monitoring_uptime_check_update]]
174
- private static void updateUptimeCheck (
175
- String projectId , String displayName , String hostName , String pathName ) throws IOException {
176
- String fullCheckName = UptimeCheckConfigName .format (projectId , displayName );
171
+ private static void updateUptimeCheck (String checkName , String hostName , String pathName )
172
+ throws IOException {
177
173
178
174
UpdateUptimeCheckConfigRequest request =
179
175
UpdateUptimeCheckConfigRequest .newBuilder ()
180
176
.setUpdateMask (FieldMask .newBuilder ().addPaths ("http_check.path" ))
181
177
.setUptimeCheckConfig (
182
178
UptimeCheckConfig .newBuilder ()
183
- .setName (fullCheckName )
179
+ .setName (checkName )
184
180
.setMonitoredResource (
185
181
MonitoredResource .newBuilder ()
186
182
.setType ("uptime_url" )
@@ -231,7 +227,7 @@ private static void listUptimeCheckIps() throws IOException {
231
227
// [END monitoring_uptime_check_list_ips]]
232
228
233
229
// [START monitoring_uptime_check_get]]
234
- private static void getUptimeCheckConfig (String projectId , String checkName ) throws IOException {
230
+ private static void getUptimeCheckConfig (String checkName ) throws IOException {
235
231
// Create UptimeCheckServiceSettings instance for add retry mechanism
236
232
UptimeCheckServiceSettings .Builder uptimeCheckServiceSettingsBuilder =
237
233
UptimeCheckServiceSettings .newBuilder ();
@@ -257,13 +253,11 @@ private static void getUptimeCheckConfig(String projectId, String checkName) thr
257
253
// create UptimeCheckServiceClient with retry setting
258
254
try (UptimeCheckServiceClient client =
259
255
UptimeCheckServiceClient .create (uptimeCheckServiceSettings )) {
260
- String fullCheckName = UptimeCheckConfigName .format (projectId , checkName );
261
- UptimeCheckConfig config = client .getUptimeCheckConfig (fullCheckName );
256
+ UptimeCheckConfig config = client .getUptimeCheckConfig (checkName );
262
257
if (config != null ) {
263
258
System .out .println (config .toString ());
264
259
} else {
265
- System .out .println (
266
- "No uptime check config found with name " + checkName + " in project " + projectId );
260
+ System .out .println ("No uptime check config found with ID " + checkName );
267
261
}
268
262
} catch (Exception e ) {
269
263
usage ("Exception getting uptime check: " + e .toString ());
@@ -273,10 +267,9 @@ private static void getUptimeCheckConfig(String projectId, String checkName) thr
273
267
// [END monitoring_uptime_check_get]]
274
268
275
269
// [START monitoring_uptime_check_delete]]
276
- private static void deleteUptimeCheckConfig (String projectId , String checkName )
277
- throws IOException {
270
+ private static void deleteUptimeCheckConfig (String checkName ) throws IOException {
278
271
try (UptimeCheckServiceClient client = UptimeCheckServiceClient .create ()) {
279
- client .deleteUptimeCheckConfig (UptimeCheckConfigName . format ( projectId , checkName ) );
272
+ client .deleteUptimeCheckConfig (checkName );
280
273
} catch (Exception e ) {
281
274
usage ("Exception deleting uptime check: " + e .toString ());
282
275
throw e ;
0 commit comments