# Google Pub/Sub HTTP REST API

Starting with version 4.5.0, AxoSyslog can send data to [Google Cloud Pub/Sub](<https://cloud.google.com/pubsub?hl=en>) using its [HTTP REST API](<https://cloud.google.com/pubsub/docs/reference/rest>).

## Prerequisites

  * A [Google Pub/Sub subscription](<https://cloud.google.com/pubsub?hl=en>).
  * An [IAM service account](<https://cloud.google.com/iam/docs/service-account-overview>) that AxoSyslog uses for authentication.
  * A Google Cloud project that has the Pub/Sub API enabled.



For details, see the [Google Pub/Sub tutorial](<https://cloud.google.com/pubsub/docs/building-pubsub-messaging-system#before_you_begin>).

## Configuration

To configure AxoSyslog, you’ll need the name of the project and the topic where you want to send your data.

Minimal configuration:
```
 
    @include "scl.conf"
    # ...
    
    destination d_pubsub {
      google-pubsub(
        project("syslog-ng-project")
        topic("syslog-ng-topic")
        auth(
          service-account(
            key("/path/to/service-account-key.json")
          )
        )
      );
    };
    
```

This driver is actually a reusable configuration snippet configured to send log messages using the `http()` driver using a template. You can find the source of this configuration snippet on [GitHub](<https://github.com/axoflow/axosyslog/blob/master/scl/google/google-pubsub.conf>).

## Options

The following options are specific to the `google-pubsub()` destination. But since this destination is based on the `http()` destination, you can use the [options of the `http()` destination](../../docs/axosyslog-core/chapter-destinations/configuring-destinations-http-nonjava/reference-destination-http-nonjava/index.md) as well if needed.

> Note: The `google-pubsub()` destination automatically configures some of these `http()` destination options as required by the Google Pub/Sub API.

## attributes()

|   
---|---  
Type: | string  
Default: | `"--scope rfc5424,all-nv-pairs --exclude MESSAGE"`  
  
_Description:_ A JSON object representing key-value pairs for the Pub/Sub Event, formatted as [AxoSyslog value-pairs](../../docs/axosyslog-core/chapter-concepts/concepts-value-pairs/option-value-pairs/index.md). By default, the `google-pubsub()` destination sends the RFC5424 fields as attributes. If you want to send different fields, override the default template. By default, the message part is sent in the `data()` option.

## auth()

Options for cloud-related authentication. Currently only the [GCP Service Account authentication](<https://cloud.google.com/iam/docs/service-account-overview>) is supported.

Specify the JSON file storing the key to the service account like this:
```
 
    auth(
        service-account(
          key("/path/to/service-account-key.json")
        )
      )
    
```

#### service-account()

Authenticate to a service account using Service Account Key-Based Authentication. This method works both inside and outside GCP It uses a [service account key](<https://cloud.google.com/iam/docs/keys-create-delete>) generated and downloaded through the GCP IAM & Admin console. The long-term service account key is used to generate short-term tokens for authentication (also called [self-signed JWT](<https://google.aip.dev/auth/4111>)).

##### audience()

|   
---|---  
Type: | string  
Default: |   
  
Note

  * When using the `google-pubsub()` destination, the `audience()` option is set to `https://pubsub.googleapis.com/google.pubsub.v1.Publisher`. Don’t change it.
  * When using the `google-pubsub()-grpc` destination, you don’t need to set the `audience()` option because the underlying gRPC API recognizes it automatically.
  * You cannot use `audience()` and `scope()` together.



##### key()

|   
---|---  
Type: | string (path)  
Default: |   
  
Path to the service account key.

##### scope()

|   
---|---  
Type: | string  
Default: |   
  
Available in AxoSyslog version 4.15 and later.

URL for a scope claim for authentication [instead of audience](<https://google.aip.dev/auth/4111#scope-vs-audience>). For example:
```
 
      ...
      cloud-auth(
        gcp(
          service-account(
            key("/path/to/secret.json")
            scope("https://www.googleapis.com/auth/example-scope")
          )
        )
      )
    
```

Note You cannot use `audience()` and `scope()` together. 

##### token-validity-duration()

|   
---|---  
Type: | integer (seconds)  
Default: | `3600`  
  
#### user-managed-service-account()

Available in AxoSyslog version 4.6 and later.

Note The `user-managed-service-account()` method is only available for VMs running within GCP. 

Authenticate to a [user-managed service account](<https://cloud.google.com/iam/docs/service-account-types#user-managed>) of a GCP virtual machine using the VM Metadata Server Method. AxoSyslog interacts with the internal GCP metadata server, which provides an OAuth2 token for authentication. You can attach the [default service accounts](<https://cloud.google.com/iam/docs/service-account-types#default>) as well.

##### metadata-url()

|   
---|---  
Type: | string  
Default: | `http://metadata.google.internal/computeMetadata/v1/instance/service-accounts`  
  
The URL of the metadata server. When specifying the port, use the `URL:port` format.

##### name()

|   
---|---  
Type: | string  
Default: | `default`  
  
Name of the service account to use.

## data()

|   
---|---  
Type: | string/template  
Default: | `"${MESSAGE}"`  
  
_Description:_ The template to use as the data part of the Google Pub/Sub message.

## project()

|   
---|---  
Type: | string  
Default: | -  
  
_Description:_ The ID of the Google Cloud project where AxoSyslog sends the data. The Pub/Sub API must be enabled for the project.

## topic()

|   
---|---  
Type: | string  
Default: | -  
  
_Description:_ The name of the Google Pub/Sub topic where AxoSyslog sends the data.

## service_endpoint()

|   
---|---  
Type: | string  
Default: | `https://pubsub.googleapis.com`  
  
The service endpoint for the Pub/Sub API where AxoSyslog sends the data. For a list of locational endpoints, see the [official Pub/Sub APIs documentation](<https://cloud.google.com/pubsub/docs/reference/service_apis_overview#list_of_locational_endpoints>).

Last modified April 1, 2026: [Pubsub title typo fix (647ef56d)](<https://github.com/axoflow/axosyslog-core-docs/commit/647ef56dc301569154735973dfc3855a9d62a685>)