Prashast Kumar
Prashast Kumar

Reputation: 31

API Call for Cloud Security Command Center

I am using list_findings() API for listing the security issues identified in Cloud Security command center. I want to list the findings every 5 minutes.

 c = (datetime.utcnow() - timedelta(minutes =5)).replace(tzinfo=pytz.UTC, microsecond =0)
 project_filter = (
     "state = \"ACTIVE\" AND create_time > \"2020-02-19T15:20:10-00:00\""
 )
 finding_result_iterator = client.list_findings(source_name, filter_ = project_filter)

How can I pass the value of c in the project_filter? I don't want to hard code the value of create_time. It should automatically take the time from the variable c in every run of the script. I tried different ways to pass the value to create_time but its not working. Could someone please help. Here is the link for the doc provided by google https://cloud.google.com/security-command-center/docs/how-to-api-list-findings

I am trying to use something like this but its giving error

project_filter = (
    "state = \"ACTIVE\" AND create_time >\'c\'"
)

Error -

google.api_core.exceptions.InvalidArgument: 400 Invalid Filter. Filter must be non-null and filter upon a field in the request. Example: "event_time = 123 OR event_time >= 123 OR event_time <= 123"

Upvotes: 0

Views: 308

Answers (1)

Prashast Kumar
Prashast Kumar

Reputation: 31

Actually project_filter is a string, so string concatenation worked.

project_filter = (
    "state = \"ACTIVE\" AND create_time > \"" + c + "\"" 
)

Upvotes: 1

Related Questions