Stackdriver Monitoring V3 Client - Class NotificationChannelServiceClient (1.10.3)

Reference documentation and code samples for the Stackdriver Monitoring V3 Client class NotificationChannelServiceClient.

Service Description: The Notification Channel API provides access to configuration that controls how messages related to incidents are sent.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.

Namespace

Google \ Cloud \ Monitoring \ V3 \ Client

Methods

__construct

Constructor.

Parameters
Name Description
options array

Optional. Options for configuring the service API wrapper.

↳ apiEndpoint string

The address of the API remote host. May optionally include the port, formatted as "

↳ credentials string|array|FetchAuthTokenInterface|CredentialsWrapper

The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored.

↳ credentialsConfig array

Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() .

↳ disableRetries bool

Determines whether or not retries defined by the client configuration should be disabled. Defaults to false.

↳ clientConfig string|array

Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder.

↳ transport string|TransportInterface

The transport used for executing network requests. May be either the string rest or grpc. Defaults to grpc if gRPC support is detected on the system. Advanced usage: Additionally, it is possible to pass in an already instantiated Google\ApiCore\Transport\TransportInterface object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored.

↳ transportConfig array

Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options.

↳ clientCertSource callable

A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS.

createNotificationChannel

Creates a new notification channel, representing a single notification endpoint such as an email address, SMS number, or PagerDuty service.

Design your application to single-thread API calls that modify the state of notification channels in a single project. This includes calls to CreateNotificationChannel, DeleteNotificationChannel and UpdateNotificationChannel.

The async variant is Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient::createNotificationChannelAsync() .

Parameters
Name Description
request Google\Cloud\Monitoring\V3\CreateNotificationChannelRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Cloud\Monitoring\V3\NotificationChannel
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient;
use Google\Cloud\Monitoring\V3\CreateNotificationChannelRequest;
use Google\Cloud\Monitoring\V3\NotificationChannel;

/**
 * @param string $name The
 *                     [project](https://cloud.google.com/monitoring/api/v3#project_name) on which
 *                     to execute the request. The format is:
 *
 *                     projects/[PROJECT_ID_OR_NUMBER]
 *
 *                     This names the container into which the channel will be
 *                     written, this does not name the newly created channel. The resulting
 *                     channel's name will have a normalized version of this field as a prefix,
 *                     but will add `/notificationChannels/[CHANNEL_ID]` to identify the channel.
 */
function create_notification_channel_sample(string $name): void
{
    // Create a client.
    $notificationChannelServiceClient = new NotificationChannelServiceClient();

    // Prepare the request message.
    $notificationChannel = new NotificationChannel();
    $request = (new CreateNotificationChannelRequest())
        ->setName($name)
        ->setNotificationChannel($notificationChannel);

    // Call the API and handle any network failures.
    try {
        /** @var NotificationChannel $response */
        $response = $notificationChannelServiceClient->createNotificationChannel($request);
        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
{
    $name = '[NAME]';

    create_notification_channel_sample($name);
}

deleteNotificationChannel

Deletes a notification channel.

Design your application to single-thread API calls that modify the state of notification channels in a single project. This includes calls to CreateNotificationChannel, DeleteNotificationChannel and UpdateNotificationChannel.

The async variant is Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient::deleteNotificationChannelAsync() .

Parameters
Name Description
request Google\Cloud\Monitoring\V3\DeleteNotificationChannelRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Example
use Google\ApiCore\ApiException;
use Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient;
use Google\Cloud\Monitoring\V3\DeleteNotificationChannelRequest;

/**
 * @param string $formattedName The channel for which to execute the request. The format is:
 *
 *                              projects/[PROJECT_ID_OR_NUMBER]/notificationChannels/[CHANNEL_ID]
 *                              Please see {@see NotificationChannelServiceClient::notificationChannelName()} for help formatting this field.
 */
function delete_notification_channel_sample(string $formattedName): void
{
    // Create a client.
    $notificationChannelServiceClient = new NotificationChannelServiceClient();

    // Prepare the request message.
    $request = (new DeleteNotificationChannelRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        $notificationChannelServiceClient->deleteNotificationChannel($request);
        printf('Call completed successfully.' . PHP_EOL);
    } 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 = NotificationChannelServiceClient::notificationChannelName(
        '[PROJECT]',
        '[NOTIFICATION_CHANNEL]'
    );

    delete_notification_channel_sample($formattedName);
}

getNotificationChannel

Gets a single notification channel. The channel includes the relevant configuration details with which the channel was created. However, the response may truncate or omit passwords, API keys, or other private key matter and thus the response may not be 100% identical to the information that was supplied in the call to the create method.

The async variant is Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient::getNotificationChannelAsync() .

Parameters
Name Description
request Google\Cloud\Monitoring\V3\GetNotificationChannelRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Cloud\Monitoring\V3\NotificationChannel
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient;
use Google\Cloud\Monitoring\V3\GetNotificationChannelRequest;
use Google\Cloud\Monitoring\V3\NotificationChannel;

/**
 * @param string $formattedName The channel for which to execute the request. The format is:
 *
 *                              projects/[PROJECT_ID_OR_NUMBER]/notificationChannels/[CHANNEL_ID]
 *                              Please see {@see NotificationChannelServiceClient::notificationChannelName()} for help formatting this field.
 */
function get_notification_channel_sample(string $formattedName): void
{
    // Create a client.
    $notificationChannelServiceClient = new NotificationChannelServiceClient();

    // Prepare the request message.
    $request = (new GetNotificationChannelRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var NotificationChannel $response */
        $response = $notificationChannelServiceClient->getNotificationChannel($request);
        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 = NotificationChannelServiceClient::notificationChannelName(
        '[PROJECT]',
        '[NOTIFICATION_CHANNEL]'
    );

    get_notification_channel_sample($formattedName);
}

getNotificationChannelDescriptor

Gets a single channel descriptor. The descriptor indicates which fields are expected / permitted for a notification channel of the given type.

The async variant is Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient::getNotificationChannelDescriptorAsync() .

Parameters
Name Description
request Google\Cloud\Monitoring\V3\GetNotificationChannelDescriptorRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Cloud\Monitoring\V3\NotificationChannelDescriptor
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient;
use Google\Cloud\Monitoring\V3\GetNotificationChannelDescriptorRequest;
use Google\Cloud\Monitoring\V3\NotificationChannelDescriptor;

/**
 * @param string $formattedName The channel type for which to execute the request. The format is:
 *
 *                              projects/[PROJECT_ID_OR_NUMBER]/notificationChannelDescriptors/[CHANNEL_TYPE]
 *                              Please see {@see NotificationChannelServiceClient::notificationChannelDescriptorName()} for help formatting this field.
 */
function get_notification_channel_descriptor_sample(string $formattedName): void
{
    // Create a client.
    $notificationChannelServiceClient = new NotificationChannelServiceClient();

    // Prepare the request message.
    $request = (new GetNotificationChannelDescriptorRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var NotificationChannelDescriptor $response */
        $response = $notificationChannelServiceClient->getNotificationChannelDescriptor($request);
        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 = NotificationChannelServiceClient::notificationChannelDescriptorName(
        '[PROJECT]',
        '[CHANNEL_DESCRIPTOR]'
    );

    get_notification_channel_descriptor_sample($formattedName);
}

getNotificationChannelVerificationCode

Requests a verification code for an already verified channel that can then be used in a call to VerifyNotificationChannel() on a different channel with an equivalent identity in the same or in a different project. This makes it possible to copy a channel between projects without requiring manual reverification of the channel. If the channel is not in the verified state, this method will fail (in other words, this may only be used if the SendNotificationChannelVerificationCode and VerifyNotificationChannel paths have already been used to put the given channel into the verified state).

There is no guarantee that the verification codes returned by this method will be of a similar structure or form as the ones that are delivered to the channel via SendNotificationChannelVerificationCode; while VerifyNotificationChannel() will recognize both the codes delivered via SendNotificationChannelVerificationCode() and returned from GetNotificationChannelVerificationCode(), it is typically the case that the verification codes delivered via SendNotificationChannelVerificationCode() will be shorter and also have a shorter expiration (e.g. codes such as "G-123456") whereas GetVerificationCode() will typically return a much longer, websafe base 64 encoded string that has a longer expiration time.

The async variant is Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient::getNotificationChannelVerificationCodeAsync() .

Parameters
Name Description
request Google\Cloud\Monitoring\V3\GetNotificationChannelVerificationCodeRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Cloud\Monitoring\V3\GetNotificationChannelVerificationCodeResponse
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient;
use Google\Cloud\Monitoring\V3\GetNotificationChannelVerificationCodeRequest;
use Google\Cloud\Monitoring\V3\GetNotificationChannelVerificationCodeResponse;

/**
 * @param string $formattedName The notification channel for which a verification code is to be
 *                              generated and retrieved. This must name a channel that is already verified;
 *                              if the specified channel is not verified, the request will fail. Please see
 *                              {@see NotificationChannelServiceClient::notificationChannelName()} for help formatting this field.
 */
function get_notification_channel_verification_code_sample(string $formattedName): void
{
    // Create a client.
    $notificationChannelServiceClient = new NotificationChannelServiceClient();

    // Prepare the request message.
    $request = (new GetNotificationChannelVerificationCodeRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var GetNotificationChannelVerificationCodeResponse $response */
        $response = $notificationChannelServiceClient->getNotificationChannelVerificationCode($request);
        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 = NotificationChannelServiceClient::notificationChannelName(
        '[PROJECT]',
        '[NOTIFICATION_CHANNEL]'
    );

    get_notification_channel_verification_code_sample($formattedName);
}

listNotificationChannelDescriptors

Lists the descriptors for supported channel types. The use of descriptors makes it possible for new channel types to be dynamically added.

The async variant is Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient::listNotificationChannelDescriptorsAsync() .

Parameters
Name Description
request Google\Cloud\Monitoring\V3\ListNotificationChannelDescriptorsRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient;
use Google\Cloud\Monitoring\V3\ListNotificationChannelDescriptorsRequest;
use Google\Cloud\Monitoring\V3\NotificationChannelDescriptor;

/**
 * @param string $name The REST resource name of the parent from which to retrieve
 *                     the notification channel descriptors. The expected syntax is:
 *
 *                     projects/[PROJECT_ID_OR_NUMBER]
 *
 *                     Note that this
 *                     [names](https://cloud.google.com/monitoring/api/v3#project_name) the parent
 *                     container in which to look for the descriptors; to retrieve a single
 *                     descriptor by name, use the
 *                     [GetNotificationChannelDescriptor][google.monitoring.v3.NotificationChannelService.GetNotificationChannelDescriptor]
 *                     operation, instead.
 */
function list_notification_channel_descriptors_sample(string $name): void
{
    // Create a client.
    $notificationChannelServiceClient = new NotificationChannelServiceClient();

    // Prepare the request message.
    $request = (new ListNotificationChannelDescriptorsRequest())
        ->setName($name);

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

        /** @var NotificationChannelDescriptor $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
{
    $name = '[NAME]';

    list_notification_channel_descriptors_sample($name);
}

listNotificationChannels

Lists the notification channels that have been created for the project.

To list the types of notification channels that are supported, use the ListNotificationChannelDescriptors method.

The async variant is Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient::listNotificationChannelsAsync() .

Parameters
Name Description
request Google\Cloud\Monitoring\V3\ListNotificationChannelsRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient;
use Google\Cloud\Monitoring\V3\ListNotificationChannelsRequest;
use Google\Cloud\Monitoring\V3\NotificationChannel;

/**
 * @param string $name The
 *                     [project](https://cloud.google.com/monitoring/api/v3#project_name) on which
 *                     to execute the request. The format is:
 *
 *                     projects/[PROJECT_ID_OR_NUMBER]
 *
 *                     This names the container
 *                     in which to look for the notification channels; it does not name a
 *                     specific channel. To query a specific channel by REST resource name, use
 *                     the
 *                     [`GetNotificationChannel`][google.monitoring.v3.NotificationChannelService.GetNotificationChannel]
 *                     operation.
 */
function list_notification_channels_sample(string $name): void
{
    // Create a client.
    $notificationChannelServiceClient = new NotificationChannelServiceClient();

    // Prepare the request message.
    $request = (new ListNotificationChannelsRequest())
        ->setName($name);

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

        /** @var NotificationChannel $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
{
    $name = '[NAME]';

    list_notification_channels_sample($name);
}

sendNotificationChannelVerificationCode

Causes a verification code to be delivered to the channel. The code can then be supplied in VerifyNotificationChannel to verify the channel.

The async variant is Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient::sendNotificationChannelVerificationCodeAsync() .

Parameters
Name Description
request Google\Cloud\Monitoring\V3\SendNotificationChannelVerificationCodeRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Example
use Google\ApiCore\ApiException;
use Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient;
use Google\Cloud\Monitoring\V3\SendNotificationChannelVerificationCodeRequest;

/**
 * @param string $formattedName The notification channel to which to send a verification code. Please see
 *                              {@see NotificationChannelServiceClient::notificationChannelName()} for help formatting this field.
 */
function send_notification_channel_verification_code_sample(string $formattedName): void
{
    // Create a client.
    $notificationChannelServiceClient = new NotificationChannelServiceClient();

    // Prepare the request message.
    $request = (new SendNotificationChannelVerificationCodeRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        $notificationChannelServiceClient->sendNotificationChannelVerificationCode($request);
        printf('Call completed successfully.' . PHP_EOL);
    } 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 = NotificationChannelServiceClient::notificationChannelName(
        '[PROJECT]',
        '[NOTIFICATION_CHANNEL]'
    );

    send_notification_channel_verification_code_sample($formattedName);
}

updateNotificationChannel

Updates a notification channel. Fields not specified in the field mask remain unchanged.

Design your application to single-thread API calls that modify the state of notification channels in a single project. This includes calls to CreateNotificationChannel, DeleteNotificationChannel and UpdateNotificationChannel.

The async variant is Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient::updateNotificationChannelAsync() .

Parameters
Name Description
request Google\Cloud\Monitoring\V3\UpdateNotificationChannelRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Cloud\Monitoring\V3\NotificationChannel
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient;
use Google\Cloud\Monitoring\V3\NotificationChannel;
use Google\Cloud\Monitoring\V3\UpdateNotificationChannelRequest;

/**
 * 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 update_notification_channel_sample(): void
{
    // Create a client.
    $notificationChannelServiceClient = new NotificationChannelServiceClient();

    // Prepare the request message.
    $notificationChannel = new NotificationChannel();
    $request = (new UpdateNotificationChannelRequest())
        ->setNotificationChannel($notificationChannel);

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

verifyNotificationChannel

Verifies a NotificationChannel by proving receipt of the code delivered to the channel as a result of calling SendNotificationChannelVerificationCode.

The async variant is Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient::verifyNotificationChannelAsync() .

Parameters
Name Description
request Google\Cloud\Monitoring\V3\VerifyNotificationChannelRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Cloud\Monitoring\V3\NotificationChannel
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Monitoring\V3\Client\NotificationChannelServiceClient;
use Google\Cloud\Monitoring\V3\NotificationChannel;
use Google\Cloud\Monitoring\V3\VerifyNotificationChannelRequest;

/**
 * @param string $formattedName The notification channel to verify. Please see
 *                              {@see NotificationChannelServiceClient::notificationChannelName()} for help formatting this field.
 * @param string $code          The verification code that was delivered to the channel as
 *                              a result of invoking the `SendNotificationChannelVerificationCode` API
 *                              method or that was retrieved from a verified channel via
 *                              `GetNotificationChannelVerificationCode`. For example, one might have
 *                              "G-123456" or "TKNZGhhd2EyN3I1MnRnMjRv" (in general, one is only
 *                              guaranteed that the code is valid UTF-8; one should not
 *                              make any assumptions regarding the structure or format of the code).
 */
function verify_notification_channel_sample(string $formattedName, string $code): void
{
    // Create a client.
    $notificationChannelServiceClient = new NotificationChannelServiceClient();

    // Prepare the request message.
    $request = (new VerifyNotificationChannelRequest())
        ->setName($formattedName)
        ->setCode($code);

    // Call the API and handle any network failures.
    try {
        /** @var NotificationChannel $response */
        $response = $notificationChannelServiceClient->verifyNotificationChannel($request);
        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 = NotificationChannelServiceClient::notificationChannelName(
        '[PROJECT]',
        '[NOTIFICATION_CHANNEL]'
    );
    $code = '[CODE]';

    verify_notification_channel_sample($formattedName, $code);
}

createNotificationChannelAsync

Parameters
Name Description
request Google\Cloud\Monitoring\V3\CreateNotificationChannelRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

deleteNotificationChannelAsync

Parameters
Name Description
request Google\Cloud\Monitoring\V3\DeleteNotificationChannelRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

getNotificationChannelAsync

Parameters
Name Description
request Google\Cloud\Monitoring\V3\GetNotificationChannelRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

getNotificationChannelDescriptorAsync

Parameters
Name Description
request Google\Cloud\Monitoring\V3\GetNotificationChannelDescriptorRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

getNotificationChannelVerificationCodeAsync

Parameters
Name Description
request Google\Cloud\Monitoring\V3\GetNotificationChannelVerificationCodeRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

listNotificationChannelDescriptorsAsync

Parameters
Name Description
request Google\Cloud\Monitoring\V3\ListNotificationChannelDescriptorsRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

listNotificationChannelsAsync

Parameters
Name Description
request Google\Cloud\Monitoring\V3\ListNotificationChannelsRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

sendNotificationChannelVerificationCodeAsync

Parameters
Name Description
request Google\Cloud\Monitoring\V3\SendNotificationChannelVerificationCodeRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

updateNotificationChannelAsync

Parameters
Name Description
request Google\Cloud\Monitoring\V3\UpdateNotificationChannelRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

verifyNotificationChannelAsync

Parameters
Name Description
request Google\Cloud\Monitoring\V3\VerifyNotificationChannelRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

static::folderChannelDescriptorName

Formats a string containing the fully-qualified path to represent a folder_channel_descriptor resource.

Parameters
Name Description
folder string
channelDescriptor string
Returns
Type Description
string The formatted folder_channel_descriptor resource.

static::folderNotificationChannelName

Formats a string containing the fully-qualified path to represent a folder_notification_channel resource.

Parameters
Name Description
folder string
notificationChannel string
Returns
Type Description
string The formatted folder_notification_channel resource.

static::notificationChannelName

Formats a string containing the fully-qualified path to represent a notification_channel resource.

Parameters
Name Description
project string
notificationChannel string
Returns
Type Description
string The formatted notification_channel resource.

static::notificationChannelDescriptorName

Formats a string containing the fully-qualified path to represent a notification_channel_descriptor resource.

Parameters
Name Description
project string
channelDescriptor string
Returns
Type Description
string The formatted notification_channel_descriptor resource.

static::organizationChannelDescriptorName

Formats a string containing the fully-qualified path to represent a organization_channel_descriptor resource.

Parameters
Name Description
organization string
channelDescriptor string
Returns
Type Description
string The formatted organization_channel_descriptor resource.

static::organizationNotificationChannelName

Formats a string containing the fully-qualified path to represent a organization_notification_channel resource.

Parameters
Name Description
organization string
notificationChannel string
Returns
Type Description
string The formatted organization_notification_channel resource.

static::projectChannelDescriptorName

Formats a string containing the fully-qualified path to represent a project_channel_descriptor resource.

Parameters
Name Description
project string
channelDescriptor string
Returns
Type Description
string The formatted project_channel_descriptor resource.

static::projectNotificationChannelName

Formats a string containing the fully-qualified path to represent a project_notification_channel resource.

Parameters
Name Description
project string
notificationChannel string
Returns
Type Description
string The formatted project_notification_channel resource.

static::parseName

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported: Template: Pattern

  • folderChannelDescriptor: folders/{folder}/notificationChannelDescriptors/{channel_descriptor}
  • folderNotificationChannel: folders/{folder}/notificationChannels/{notification_channel}
  • notificationChannel: projects/{project}/notificationChannels/{notification_channel}
  • notificationChannelDescriptor: projects/{project}/notificationChannelDescriptors/{channel_descriptor}
  • organizationChannelDescriptor: organizations/{organization}/notificationChannelDescriptors/{channel_descriptor}
  • organizationNotificationChannel: organizations/{organization}/notificationChannels/{notification_channel}
  • projectChannelDescriptor: projects/{project}/notificationChannelDescriptors/{channel_descriptor}
  • projectNotificationChannel: projects/{project}/notificationChannels/{notification_channel}

The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.

Parameters
Name Description
formattedName string

The formatted name string

template string

Optional name of template to match

Returns
Type Description
array An associative array from name component IDs to component values.