I am using Python3 to query Stackdriver for GCP logs. Unfortunately, the log entries that have important data are returned to me as "NoneType" instead of as a "dict" or a "str". The resulting "entry.payload" is type "None" and the "entry.payload_pb" has the data I want, but it is garbled.
Is there a way to get Stackdriver to return this data in a clean format, or is there a way I can parse it? If not, is there a way I should query this data that is better than what I am doing and yields clean data?
My code looks something like this:
#!/usr/bin/python3
from google.cloud.logging import Client, ASCENDING, DESCENDING
from google.oauth2.service_account import Credentials
projectName = 'my_project'
myFilter = 'logName="projects/' + projectName + '/logs/compute.googleapis.com%2Factivity_log"'
client = Client(project = projectName)
entries = client.list_entries(order_by=DESCENDING, page_size = 500, filter_ = myFilter)
for entry in entries:
if isinstance(entry.payload, dict):
print(entry.payload)
if isinstance(entry.payload, str):
print(entry.payload)
if isinstance(entry.payload, None):
print(entry.payload_pb)
The "entry.payload_pb" data always starts like this:
type_url: "type.googleapis.com/google.cloud.audit.AuditLog"
value: "\032;\[email protected]"I\n\r129.105.16.28\0228