How to pass a filter to the Alerts API call with a post

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Please sign in to see details of an important advisory in our Customer Advisories area.

How to pass a filter to the Alerts API call with a post

L0 Member

I am attempting to get back a list of alerts with a status of resolved, but the filter is not working for me.  Any ideas?   I get back items, but they don't always have a status of resolved.  Sometimes they do, sometimes the status is open, etc.  See code below.

 

 

api_key="my token goes here"
json_body='{
  "limit": "3",
  "filters": [
    {
      "status": "resolved"
    }
  ]
}'
curl -X POST $url2 -H "Content-Type: application/json" -H "Accept: */*" -H "x-redlock-auth: $api_key" -d "$json_body"
 
1 accepted solution

Accepted Solutions

L1 Bithead

Hi CBarichello,

 

You are on the right path. You are missing a filter that would inform the API as to how far back to query for alerts. Here I am querying for resolved alerts from the last 3 hours via v2 POST:

# Get a 10 minute token
token=$(curl -X POST https://api2.prismacloud.io/login -H 'Content-Type: application/json' -d '{"username":"'$PRISMA_ACCESS_KEY_ID'","password":"'$PRISMA_SECRET_KEY'"}' | jq -r '.token')
# Body of the POST
body='{"detailed":"true","timeRange":{"type":"relative","value":{"amount":3,"unit":"hour"}},"filters":[{"name":"alert.status","operator":"=","value":"resolved"}]}'

curl -L -X POST 'https://api2.prismacloud.io/v2/alert?detailed=true' -H 'Content-Type: application/json; charset=UTF-8' -H 'Accept: */*' -H 'x-redlock-auth: '$token --data-raw "$body"

# Same thing via v2 GET
curl -L -X GET 'https://api2.prismacloud.io/v2/alert?timeType=relative&timeAmount=3&timeUnit=hour&detailed=true&alert.status=resolved' -H 'Accept: */*' -H 'x-redlock-auth: '$token

 

All info can be found the developer documentation https://pan.dev/prisma-cloud/api/cspm/post-alerts-v-2/
Hope this helps.
Helping protect our customers' digital way of life.

View solution in original post

2 REPLIES 2

L1 Bithead

Hi CBarichello,

 

You are on the right path. You are missing a filter that would inform the API as to how far back to query for alerts. Here I am querying for resolved alerts from the last 3 hours via v2 POST:

# Get a 10 minute token
token=$(curl -X POST https://api2.prismacloud.io/login -H 'Content-Type: application/json' -d '{"username":"'$PRISMA_ACCESS_KEY_ID'","password":"'$PRISMA_SECRET_KEY'"}' | jq -r '.token')
# Body of the POST
body='{"detailed":"true","timeRange":{"type":"relative","value":{"amount":3,"unit":"hour"}},"filters":[{"name":"alert.status","operator":"=","value":"resolved"}]}'

curl -L -X POST 'https://api2.prismacloud.io/v2/alert?detailed=true' -H 'Content-Type: application/json; charset=UTF-8' -H 'Accept: */*' -H 'x-redlock-auth: '$token --data-raw "$body"

# Same thing via v2 GET
curl -L -X GET 'https://api2.prismacloud.io/v2/alert?timeType=relative&timeAmount=3&timeUnit=hour&detailed=true&alert.status=resolved' -H 'Accept: */*' -H 'x-redlock-auth: '$token

 

All info can be found the developer documentation https://pan.dev/prisma-cloud/api/cspm/post-alerts-v-2/
Hope this helps.
Helping protect our customers' digital way of life.

L0 Member

Thanks for the detailed information.   After reading your post, I changed my code from

-d '{"limit":"3","filters":[{"status":"resolved"}]}'

to

d '{"limit":"3","filters":[{"name":"alert.status","operator":"=","value":"resolved"}]}'

It works great now.  

  • 1 accepted solution
  • 1054 Views
  • 2 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!