Configurare un avviso basato su log per le risorse archiviate
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questa pagina spiega come configurare un avviso basato su log per le risorse protette
dalla pagina Esplora log nella console Google Cloud .
La pagina Esplora log ti guida nei seguenti passaggi per creare
e modificare gli avvisi basati sui log:
Specifica un nome e una descrizione per l'avviso.
Scegli i log per i quali vuoi ricevere una notifica.
Imposta l'intervallo di tempo tra le notifiche.
Imposta l'ora per la chiusura automatica degli incidenti.
Specifica a chi inviare la notifica.
Puoi configurare gli avvisi per le categorie di job di backup e ripristino: SCHEDULED_BACKUP,
ON_DEMAND_BACKUP e RESTORE.
Puoi anche configurare avvisi per le categorie di job del piano di backup e dell'associazione del piano di backup: UPDATE.
Gli stati del job disponibili sono: SUCCESSFUL, FAILED, SKIPPED e RUNNING.
Puoi configurare uno o piรน canali di notifica, ad esempio Google Chat, email, SMS
o canali di programmi di chat, per ricevere notifiche quando si verifica un avviso. Per istruzioni, consulta Crea e gestisci canali di notifica.
Per ricevere una notifica di un avviso, devi avere un canale di notifica.
Puoi creare il canale di notifica prima di creare un avviso o durante la creazione di quest'ultimo.
Segui queste istruzioni per creare un avviso basato su log.
Nella console Google Cloud , vai alla pagina Esplora log.
Nella sezione Scegli i log da includere nell'avviso, segui questi passaggi:
Fai clic su Anteprima dei log per controllare la query e i risultati. Se necessario, puoi anche modificare la query in questo riquadro.
Fai clic su Aggiungi un'etichetta ed esegui le seguenti operazioni. Le etichette
ti consentono di personalizzare le notifiche e renderle piรน informative.
Nel campo Nome visualizzato, inserisci un nome per l'etichetta.
Nell'elenco Nome campo log, seleziona un nome di campo log. Questi campi
vengono visualizzati in base al risultato della query selezionato.
Nel campo Espressione regolare, inserisci un'espressione per estrarre
un valore dal campo che deve contenere esattamente un gruppo di espressioni regolari.
Fai clic su Avanti.
Nella sezione Imposta la frequenza delle notifiche e la durata della chiusura automatica, segui questi passaggi:
Dall'elenco Tempo tra le notifiche, seleziona il tempo minimo tra le notifiche. Questo valore ti consente di controllare il numero di notifiche che ricevi da questo avviso se viene attivato piรน volte.
Nell'elenco Durata chiusura automatica incidenti, seleziona una durata dopo la quale
l'incidente verrร chiuso automaticamente quando non sono presenti voci di log corrispondenti.
Fai clic su Avanti.
Nell'elenco Canali di notifica, seleziona uno o piรน canali di notifica per il tuo avviso. Se non hai configurato un canale di notifica, fai clic su Gestisci canali di notifica per crearne uno. Per istruzioni, consulta Crea e gestisci canali di notifica.
Fai clic su Salva.
Verifica l'avviso basato su log
Per testare l'avviso basato su log che hai creato, puoi scrivere manualmente una voce di log
che corrisponda alla query.
Segui le istruzioni riportate di seguito per scrivere la voce di log.
Copia la voce di log che hai configurato in precedenza.
Nel riquadro Prova questa API, segui questi passaggi:
Nel campo Corpo della richiesta, sostituisci il contenuto con
la voce di log che hai copiato nel passaggio precedente.
Fai clic su Esegui. Se richiesto, segui il flusso di autenticazione.
Se la chiamata logEntries.write ha esito positivo, ricevi un codice di risposta HTTP 200 e un corpo della risposta vuoto, {}. Per saperne di piรน su Explorer API,
consulta Utilizzo di Explorer API.
La voce di log corrisponde al filtro specificato per l'avviso nei seguenti modi:
Il valore logName specifica i log dei job di backup o ripristino nel tuo progetto cloud.
jsonPayload contiene una categoria di job non riusciti, SCHEDULED_BACKUP, che
indica che il log รจ correlato a un backup pianificato da un piano di backup.
jsonPayload contiene lo stato del job come FAILED, il che
significa che il job non รจ riuscito.
Dopo aver scritto la voce di log, si verifica la seguente sequenza:
La nuova voce di log viene visualizzata in Esplora log e attiva l'avviso.
Viene aperto un incidente nella pagina Cloud Monitoring.
Ricevi una notifica relativa all'incidente. Se hai configurato un canale di notifica via email, la notifica viene visualizzata.
Puoi fare clic su Visualizza incidente nell'email per visualizzare l'incidente nella pagina
Cloud Monitoring. Per saperne di piรน sugli incidenti, incluso come riconoscerli e chiuderli, vedi Gestione degli incidenti relativi agli avvisi basati su log.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema รจ stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[[["\u003cp\u003eThis page provides instructions on how to configure log-based alerts for vaulted resources using the \u003cstrong\u003eLogs Explorer\u003c/strong\u003e in the Google Cloud console.\u003c/p\u003e\n"],["\u003cp\u003eYou can set up alerts for specific job categories like \u003ccode\u003eSCHEDULED_BACKUP\u003c/code\u003e, \u003ccode\u003eON_DEMAND_BACKUP\u003c/code\u003e, and \u003ccode\u003eRESTORE\u003c/code\u003e, as well as job statuses like \u003ccode\u003eSUCCESSFUL\u003c/code\u003e, \u003ccode\u003eFAILED\u003c/code\u003e, \u003ccode\u003eSKIPPED\u003c/code\u003e, and \u003ccode\u003eRUNNING\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe alert configuration includes setting an alert name, choosing the relevant logs, defining notification frequency, setting the incident auto-close duration, and adding notification channels like Google Chat, email, or SMS.\u003c/p\u003e\n"],["\u003cp\u003eThe process of creating an alert involves defining a query in the \u003cstrong\u003eLogs Explorer\u003c/strong\u003e, setting up an \u003cstrong\u003eAlert Policy\u003c/strong\u003e, adding labels, and managing notification frequency and incident auto-close.\u003c/p\u003e\n"],["\u003cp\u003eThe page also contains instructions on how to test the created log-based alert by manually writing a log entry that triggers the defined criteria.\u003c/p\u003e\n"]]],[],null,["# Configure a log-based alert for vaulted resources\n\nThis page explains how to configure a log-based alert for vaulted resources\nfrom the **Log Explorer** page in the Google Cloud console.\n\nThe **Logs Explorer** page guides you through the following steps to create\nand edit log-based alerts:\n\n- Provide a name and description for the alert.\n- Choose the logs you want to receive a notification for.\n- Set the time interval between notifications.\n- Set the time for automatic closure of incidents.\n- Specify whom to notify.\n\nYou can configure alerts for the job categories: `SCHEDULED_BACKUP`,\n`ON_DEMAND_BACKUP`, and `RESTORE`. You can also set alerts for the job status:\n`SUCCESSFUL`, `FAILED`, `SKIPPED`, and `RUNNING`.\n\nYou can configure one or more notification channels, such as Google chat, email, SMS,\nor chat program channels, to receive notifications when an alert occurs. For instructions,\nsee [Create and manage notification channels](/monitoring/support/notification-options).\n\nBefore you begin\n----------------\n\n- [Assign permissions for log-based alerting policies](/logging/docs/access-control#lba-permissions).\n\nCreate a log-based alert\n------------------------\n\nTo notify an alert, you need to have a [notification channel](/monitoring/support/notification-options).\nYou can create the notification channel before creating an alert or while creating an alert.\n\nUse the following instructions to create a log-based alert.\n\n1. In the Google Cloud console, go to the **Logs Explorer** page.\n\n [Go to Logs Explorer](https://console.cloud.google.com/logs/query)\n2. In the **Query** pane define the alert on which you want to be notified.\n\n The following query is an example to get notified whenever a scheduled backup job fails. \n\n logName=\"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/logs/backupdr.googleapis.com%2Fbdr_backup_restore_jobs\"\n jsonPayload.jobCategory=\"SCHEDULED_BACKUP\"\n jsonPayload.jobStatus=\"FAILED\"\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the name of the project.\n3. In the header of the **Query results** pane, click **Create alert**.\n\n4. In the **Alert details** section, do the following:\n\n 1. In the **Alert Policy Name** field, enter a name for your alert. This name gets displayed in the notification header.\n 2. In the **Documentation** field, enter the description for the alert. For information about how you can format and refine the content of this field, see [Using Markdown and variables in documentation templates](/monitoring/alerts/doc-variables).\n5. Click **Next**.\n\n6. In the **Choose logs to include in the alert** section, do the following:\n\n 1. Click **Preview logs** to check the query and results. You can also edit the query in this pane, if necessary.\n 2. Click **Add a label** and do the following. The [labels](/monitoring/alerts/labels)\n let you customize notifications and make them more informative.\n\n 1. In the **Display name** field**,** enter a name for the label.\n 2. From the **Log field name** list, select a log field name. These fields are displayed based on the selected query result.\n 3. In the **Regular expression** field, enter an expression to extract a value from the field that must contain exactly one regular expression group.\n7. Click **Next**.\n\n8. In the **Set notification frequency and autoclose duration** section, do the following:\n\n 1. From the **Time between notifications** list, select the minimum time between notifications. This value lets you control the number of notifications you get from this alert if it is triggered multiple times.\n 2. From the **Incident autoclose duration** list, select a duration after which the incident to be closed automatically when matching log entries are absent.\n9. Click **Next**.\n\n10. From the **Notification channels** list, select one or more notification\n channels for your alert. If you don't have a notification channel configured,\n click **Manage notification channels** to create one. For instructions,\n see [Create and manage notification channels](/monitoring/support/notification-options).\n\n11. Click **Save**.\n\nTest the log-based alert\n------------------------\n\nTo test the log-based alert you created, you can manually write a log entry\nthat matches the query.\n\nUse the following instructions to write the log entry.\n\n1. Go to the [`logEntries.write`](/logging/docs/reference/v2/rest/v2/entries/write) reference page.\n\n [Go to logEntries.write](/logging/docs/reference/v2/rest/v2/entries/write)\n2. Configure the following log entry by changing the \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\n variable to your project ID.\n\n {\n \"entries\": [\n {\n \"jsonPayload\": {\n \"jobCategory\": \"SCHEDULED_BACKUP\",\n \"jobStatus\": \"FAILED\"\n }\n }\n ],\n \"resource\": {\n \"type\": \"backupdr.googleapis.com/BackupDRProject\"\n },\n \"logName\": \"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/logs/backupdr.googleapis.com%2Fbdr_backup_restore_jobs\"\n }\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the name of the project.\n3. Copy the log entry you configured previously.\n\n4. In the **Try this API** pane, follow these steps:\n\n 1. In the **Request body** field, replace the content with the log entry you copied in the previous step.\n 2. Click **Execute**. If prompted, follow the authentication flow.\n5. If the `logEntries.write` call is successful, then you get an HTTP `200` response\n code and an empty response body, `{}`. For more information about **APIs Explorer** ,\n see [Using the APIs Explorer](/monitoring/api/apis-explorer).\n\n The log entry matches the filter specified for the alert in the following ways:\n - The `logName` value specifies the backup or restore job logs in your cloud project.\n - The `jsonPayload` contains a failed job category, `SCHEDULED_BACKUP`, which indicates that the log is related to a backup scheduled by a backup plan.\n - The `jsonPayload` contains the field job status as `FAILED`, which signifies that the job is failed.\n6. After you write the log entry, the following sequence occurs:\n\n 1. The new log entry appears in the Logs Explorer and triggers the alert.\n 2. An incident is opened in the **Cloud Monitoring** page.\n 3. You receive a notification for the incident. If you configured an email\n notification channel, then the notification displays.\n\n You can click **View incident** in the email to see the incident in the\n **Cloud Monitoring** page. For more information about incidents including\n how to acknowledge and close them, see [Manage incidents for log-based alerts](/logging/docs/alerting/log-based-incidents)."]]