Stackdriver Monitoring V3 Client - Class NotificationChannelServiceClient (1.2.2)

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. Sample code to get started:

$notificationChannelServiceClient = new Google\Cloud\Monitoring\V3\NotificationChannelServiceClient();
try {
    $name = 'name';
    $notificationChannel = new Google\Cloud\Monitoring\V3\NotificationChannel();
    $response = $notificationChannelServiceClient->createNotificationChannel($name, $notificationChannel);
} finally {
    $notificationChannelServiceClient->close();
}

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.

Methods

projectName

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

Parameter
NameDescription
project string
Returns
TypeDescription
stringThe formatted project resource.

folderChannelDescriptorName

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

Parameters
NameDescription
folder string
channelDescriptor string
Returns
TypeDescription
stringThe formatted folder_channel_descriptor resource.

folderNotificationChannelName

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

Parameters
NameDescription
folder string
notificationChannel string
Returns
TypeDescription
stringThe formatted folder_notification_channel resource.

notificationChannelName

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

Parameters
NameDescription
project string
notificationChannel string
Returns
TypeDescription
stringThe formatted notification_channel resource.

notificationChannelDescriptorName

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

Parameters
NameDescription
project string
channelDescriptor string
Returns
TypeDescription
stringThe formatted notification_channel_descriptor resource.

organizationChannelDescriptorName

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

Parameters
NameDescription
organization string
channelDescriptor string
Returns
TypeDescription
stringThe formatted organization_channel_descriptor resource.

organizationNotificationChannelName

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

Parameters
NameDescription
organization string
notificationChannel string
Returns
TypeDescription
stringThe formatted organization_notification_channel resource.

projectChannelDescriptorName

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

Parameters
NameDescription
project string
channelDescriptor string
Returns
TypeDescription
stringThe formatted project_channel_descriptor resource.

projectNotificationChannelName

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

Parameters
NameDescription
project string
notificationChannel string
Returns
TypeDescription
stringThe formatted project_notification_channel resource.

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
NameDescription
formattedName string

The formatted name string

template string

Optional name of template to match

Returns
TypeDescription
arrayAn associative array from name component IDs to component values.

__construct

Constructor.

Parameters
NameDescription
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 {@see} object or {@see} 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 {@see} .

↳ 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 {@see} 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 {@see} and {@see} 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.

Parameters
NameDescription
name string

Required. The project 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.

notificationChannel Google\Cloud\Monitoring\V3\NotificationChannel

Required. The definition of the NotificationChannel to create.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
TypeDescription
Google\Cloud\Monitoring\V3\NotificationChannel
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Monitoring\V3\NotificationChannel;
use Google\Cloud\Monitoring\V3\NotificationChannelServiceClient;

/**
 * @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 any non-scalar elements to be passed along with the request.
    $notificationChannel = new NotificationChannel();

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

/**
 * 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.

Parameters
NameDescription
name string

Required. The channel for which to execute the request. The format is: projects/[PROJECT_ID_OR_NUMBER]/notificationChannels/[CHANNEL_ID]

optionalArgs array

Optional.

↳ force bool

If true, the notification channel will be deleted regardless of its use in alert policies (the policies will be updated to remove the channel). If false, channels that are still referenced by an existing alerting policy will fail to be deleted in a delete operation.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

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

/**
 * @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();

    // Call the API and handle any network failures.
    try {
        $notificationChannelServiceClient->deleteNotificationChannel($formattedName);
        printf('Call completed successfully.' . PHP_EOL);
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * 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.

Parameters
NameDescription
name string

Required. The channel for which to execute the request. The format is: projects/[PROJECT_ID_OR_NUMBER]/notificationChannels/[CHANNEL_ID]

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
TypeDescription
Google\Cloud\Monitoring\V3\NotificationChannel
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Monitoring\V3\NotificationChannel;
use Google\Cloud\Monitoring\V3\NotificationChannelServiceClient;

/**
 * @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();

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

/**
 * 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.

Parameters
NameDescription
name string

Required. The channel type for which to execute the request. The format is: projects/[PROJECT_ID_OR_NUMBER]/notificationChannelDescriptors/[CHANNEL_TYPE]

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
TypeDescription
Google\Cloud\Monitoring\V3\NotificationChannelDescriptor
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Monitoring\V3\NotificationChannelDescriptor;
use Google\Cloud\Monitoring\V3\NotificationChannelServiceClient;

/**
 * @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();

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

/**
 * 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.

Parameters
NameDescription
name string

Required. 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.

optionalArgs array

Optional.

↳ expireTime Timestamp

The desired expiration time. If specified, the API will guarantee that the returned code will not be valid after the specified timestamp; however, the API cannot guarantee that the returned code will be valid for at least as long as the requested time (the API puts an upper bound on the amount of time for which a code may be valid). If omitted, a default expiration will be used, which may be less than the max permissible expiration (so specifying an expiration may extend the code's lifetime over omitting an expiration, even though the API does impose an upper limit on the maximum expiration that is permitted).

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
TypeDescription
Google\Cloud\Monitoring\V3\GetNotificationChannelVerificationCodeResponse
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Monitoring\V3\GetNotificationChannelVerificationCodeResponse;
use Google\Cloud\Monitoring\V3\NotificationChannelServiceClient;

/**
 * @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();

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

/**
 * 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.

Parameters
NameDescription
name string

Required. 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 the parent container in which to look for the descriptors; to retrieve a single descriptor by name, use the GetNotificationChannelDescriptor operation, instead.

optionalArgs array

Optional.

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Monitoring\V3\NotificationChannelDescriptor;
use Google\Cloud\Monitoring\V3\NotificationChannelServiceClient;

/**
 * @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();

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

        /** @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());
    }
}

/**
 * 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.

Parameters
NameDescription
name string

Required. The project 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 operation.

optionalArgs array

Optional.

↳ filter string

If provided, this field specifies the criteria that must be met by notification channels to be included in the response. For more details, see sorting and filtering.

↳ orderBy string

A comma-separated list of fields by which to sort the result. Supports the same set of fields as in filter. Entries can be prefixed with a minus sign to sort in descending rather than ascending order. For more details, see sorting and filtering.

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Monitoring\V3\NotificationChannel;
use Google\Cloud\Monitoring\V3\NotificationChannelServiceClient;

/**
 * @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();

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

        /** @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());
    }
}

/**
 * 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.

Parameters
NameDescription
name string

Required. The notification channel to which to send a verification code.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

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

/**
 * @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();

    // Call the API and handle any network failures.
    try {
        $notificationChannelServiceClient->sendNotificationChannelVerificationCode($formattedName);
        printf('Call completed successfully.' . PHP_EOL);
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * 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.

Parameters
NameDescription
notificationChannel Google\Cloud\Monitoring\V3\NotificationChannel

Required. A description of the changes to be applied to the specified notification channel. The description must provide a definition for fields to be updated; the names of these fields should also be included in the update_mask.

optionalArgs array

Optional.

↳ updateMask FieldMask

The fields to update.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
TypeDescription
Google\Cloud\Monitoring\V3\NotificationChannel
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Monitoring\V3\NotificationChannel;
use Google\Cloud\Monitoring\V3\NotificationChannelServiceClient;

/**
 * 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 any non-scalar elements to be passed along with the request.
    $notificationChannel = new NotificationChannel();

    // Call the API and handle any network failures.
    try {
        /** @var NotificationChannel $response */
        $response = $notificationChannelServiceClient->updateNotificationChannel($notificationChannel);
        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.

Parameters
NameDescription
name string

Required. The notification channel to verify.

code string

Required. 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).

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
TypeDescription
Google\Cloud\Monitoring\V3\NotificationChannel
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Monitoring\V3\NotificationChannel;
use Google\Cloud\Monitoring\V3\NotificationChannelServiceClient;

/**
 * @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();

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

/**
 * 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);
}

Constants

SERVICE_NAME

Value: 'google.monitoring.v3.NotificationChannelService'

The name of the service.

SERVICE_ADDRESS

Value: 'monitoring.googleapis.com'

The default address of the service.

DEFAULT_SERVICE_PORT

Value: 443

The default port of the service.

CODEGEN_NAME

Value: 'gapic'

The name of the code generator, to be included in the agent header.