This section provides examples of fine-grain alert [queries](https://docs.cloud.google.com/logging/docs/view/logging-query-language.md.txt)
that you can use to filter Cloud Logging data. To learn more about query fields
specific to Unified Maintenance, see the [log schema](https://docs.cloud.google.com/unified-maintenance/docs/log-schema.md.txt).

## Alert on any new scheduled maintenance

To alert on any new scheduled maintenance, define the `logName` for maintenance
events in your project, and a `SCHEDULED` state. For example:

```sql
log_id("maintenance.googleapis.com/maintenance_events") AND
 jsonPayload.state = "SCHEDULED"
```

## Alert when maintenance is scheduled for a specific resource type

To alert on any new scheduled maintenance for a specific resource type, define
the `logName` for maintenance events in your project, a `SCHEDULED` state, and define
the `resource.type`. For example, a Cloud SQL instance:

```sql
log_id("maintenance.googleapis.com/maintenance_events") AND
 jsonPayload.state = "SCHEDULED" AND
 jsonPayload.resource.type = "sqladmin.googleapis.com/Instance"
```

## Alert when any maintenance starts in a specific location

To alert on any new maintenance starting in a specific location, define the
`logName` for maintenance events in your project, a `STARTED` state, and define
the location. For example, `us-central1`:

```sql
log_id("maintenance.googleapis.com/maintenance_events") AND
 jsonPayload.state = "STARTED" AND
 jsonPayload.resource.labels.location = "us-central1"
```

## Alert when maintenance is successful on a specific resource

To alert on any succeeded maintenance on a specific resource, define the `logName`
for maintenance events in your project, a `SUCCEEDED` state, and define the
`resourceName`. For example, `prod-db`:

```sql
log_id("maintenance.googleapis.com/maintenance_events") AND
 jsonPayload.state = "SUCCEEDED" AND
 jsonPayload.resource.resourceName = "//sqladmin.googleapis.com/projects/proj-1/instances/prod-db"
```

## Alert when there is a change to the scheduled start time of the maintenance

To alert when there is change to the scheduled start time, define the `logName`
for maintenance events in your project, and check for recent updates to the
`timeline.schedule.startTime field`. For example:

```sql
log_id("maintenance.googleapis.com/maintenance_events") AND
 labels."maintenance.googleapis.com/updated_fields" =~ "maintenanceScheduledStartTime"
```

## What's next

- Log schema [overview](https://docs.cloud.google.com/unified-maintenance/docs/log-schema.md.txt)
- Configure [alerts and notifications](https://docs.cloud.google.com/unified-maintenance/docs/configure-alerts-and-notifications.md.txt)
- Control [maintenance](https://docs.cloud.google.com/unified-maintenance/docs/reschedule-and-on-demand-updates.md.txt)