Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [Monitoring] Added Snooze API support #5768

Merged
merged 2 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Monitoring/metadata/V3/Snooze.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions Monitoring/metadata/V3/SnoozeService.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 95 additions & 0 deletions Monitoring/samples/V3/SnoozeServiceClient/create_snooze.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/*
* Copyright 2023 Google LLC
*
* Licensed 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
*
* https://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.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START monitoring_v3_generated_SnoozeService_CreateSnooze_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Monitoring\V3\Snooze;
use Google\Cloud\Monitoring\V3\SnoozeServiceClient;
use Google\Cloud\Monitoring\V3\Snooze\Criteria;
use Google\Cloud\Monitoring\V3\TimeInterval;

/**
* Creates a `Snooze` that will prevent alerts, which match the provided
* criteria, from being opened. The `Snooze` applies for a specific time
* interval.
*
* @param string $formattedParent The
* [project](https://cloud.google.com/monitoring/api/v3#project_name) in which
* a `Snooze` should be created. The format is:
*
* projects/[PROJECT_ID_OR_NUMBER]
* Please see {@see SnoozeServiceClient::workspaceName()} for help formatting this field.
* @param string $snoozeName The name of the `Snooze`. The format is:
*
* projects/[PROJECT_ID_OR_NUMBER]/snoozes/[SNOOZE_ID]
*
* The ID of the `Snooze` will be generated by the system.
* @param string $snoozeDisplayName A display name for the `Snooze`. This can be, at most, 512
* unicode characters.
*/
function create_snooze_sample(
string $formattedParent,
string $snoozeName,
string $snoozeDisplayName
): void {
// Create a client.
$snoozeServiceClient = new SnoozeServiceClient();

// Prepare any non-scalar elements to be passed along with the request.
$snoozeCriteria = new Criteria();
$snoozeInterval = new TimeInterval();
$snooze = (new Snooze())
->setName($snoozeName)
->setCriteria($snoozeCriteria)
->setInterval($snoozeInterval)
->setDisplayName($snoozeDisplayName);

// Call the API and handle any network failures.
try {
/** @var Snooze $response */
$response = $snoozeServiceClient->createSnooze($formattedParent, $snooze);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = SnoozeServiceClient::workspaceName('[PROJECT]');
$snoozeName = '[NAME]';
$snoozeDisplayName = '[DISPLAY_NAME]';

create_snooze_sample($formattedParent, $snoozeName, $snoozeDisplayName);
}
// [END monitoring_v3_generated_SnoozeService_CreateSnooze_sync]
68 changes: 68 additions & 0 deletions Monitoring/samples/V3/SnoozeServiceClient/get_snooze.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/*
* Copyright 2023 Google LLC
*
* Licensed 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
*
* https://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.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START monitoring_v3_generated_SnoozeService_GetSnooze_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Monitoring\V3\Snooze;
use Google\Cloud\Monitoring\V3\SnoozeServiceClient;

/**
* Retrieves a `Snooze` by `name`.
*
* @param string $formattedName The ID of the `Snooze` to retrieve. The format is:
*
* projects/[PROJECT_ID_OR_NUMBER]/snoozes/[SNOOZE_ID]
* Please see {@see SnoozeServiceClient::snoozeName()} for help formatting this field.
*/
function get_snooze_sample(string $formattedName): void
{
// Create a client.
$snoozeServiceClient = new SnoozeServiceClient();

// Call the API and handle any network failures.
try {
/** @var Snooze $response */
$response = $snoozeServiceClient->getSnooze($formattedName);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = SnoozeServiceClient::snoozeName('[PROJECT]', '[SNOOZE]');

get_snooze_sample($formattedName);
}
// [END monitoring_v3_generated_SnoozeService_GetSnooze_sync]
76 changes: 76 additions & 0 deletions Monitoring/samples/V3/SnoozeServiceClient/list_snoozes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/*
* Copyright 2023 Google LLC
*
* Licensed 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
*
* https://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.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START monitoring_v3_generated_SnoozeService_ListSnoozes_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Monitoring\V3\Snooze;
use Google\Cloud\Monitoring\V3\SnoozeServiceClient;

/**
* Lists the `Snooze`s associated with a project. Can optionally pass in
* `filter`, which specifies predicates to match `Snooze`s.
*
* @param string $formattedParent The
* [project](https://cloud.google.com/monitoring/api/v3#project_name) whose
* `Snooze`s should be listed. The format is:
*
* projects/[PROJECT_ID_OR_NUMBER]
* Please see {@see SnoozeServiceClient::workspaceName()} for help formatting this field.
*/
function list_snoozes_sample(string $formattedParent): void
{
// Create a client.
$snoozeServiceClient = new SnoozeServiceClient();

// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $snoozeServiceClient->listSnoozes($formattedParent);

/** @var Snooze $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = SnoozeServiceClient::workspaceName('[PROJECT]');

list_snoozes_sample($formattedParent);
}
// [END monitoring_v3_generated_SnoozeService_ListSnoozes_sync]
Loading