'How can I transfer logs from Logs Viewer of GCP to Slack or email?

I have been exploring to transfer the JsonPayload message field from Logs viewer service (which are syslogs of a service) of GCP to a slack network, but owing to this I am not able to find any predefined services (like alerting policies to transfer Payload) available on Stackdriver. I have been able to create a counter or distribution user-metrics for logs but this will only provide me with some int64 value instead of a string value or the actual message body. Is there a way in GCP to actually send a payload of logs over slack or any email?



Solution 1:[1]

We had a similar issue where we wanted to be able to send certain events to slack and for fatal issues trigger an issue with our ops team via VictorOps.

Couldn't find anything out there to fit our needs so we just created our own slack / VictorOps Cloudfunction.

https://github.com/patiently/gcloud-slack-logger

Solution 2:[2]

In GCP, you can export logs to Pub/Sub, Cloud Storage, or BigQuery. There is no other way within GCP to export logs at the moment.

Solution 3:[3]

As of 2022, I found this can be done as follows:

In GCP Logs viewer (not legacy version) choose the create alert button.List item. One of the options here is a GCP notification channel, which supports slack. Some points here:

  • The slack channel can't be private as far as I can tell
  • Slack channel must be in your correct slack space. If your org has multiple slack spaces, make sure GCP is trying to connect to correct one.

Put in the log query criteria you want. THen go into Monitoring and you will see this in Alerting dropdown.

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman
Solution 2 Jason Gawrych
Solution 3 Adam Hughes