Using the API to get unused and used rules

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements

Using the API to get unused and used rules

L1 Bithead

Hi all,

I am trying to use the API to get a list of unused and another of used rules.  Via the API I only get the following error

<response status="error"><msg><line>An error occured. See dagger.log for information.</line></msg></response>

I have also tried with the following

https://hostname/api/?type=op&action=show&key=PaloaltoKey&xpath=/show/running/rule-use/rule-base=sec...

I then get a list of all policies.  This does not change even if I change from used to unused, or from security to nat or pbf.

Does anyone know how to get an api command that will simply list the unused security rules as on e would get from a normal command line query?

Hope so,

thanks

Stefan

1 accepted solution

Accepted Solutions

L3 Networker


You need send the following over the API,

<show><running><rule-use><vsys>vsys1</vsys><type>unused</type><rule-base>security</rule-base></rule-use></running></show>

The resultant URL would look look like this,

https://MYFIREWALL/api/?cmd=%3Cshow%3E%3Crunning%3E%3Crule-use%3E%3Cvsys%3Evsys1%3C%2Fvsys%3E%3Ctype...

View solution in original post

7 REPLIES 7

L7 Applicator

Have you seen the option on the GUI?

Policy tab and on the bottom of the screen is the check box to highlight unused policies.

Steve Puluka BSEET - IP Architect - DQE Communications (Metro Ethernet/ISP)
ACE PanOS 6; ACE PanOS 7; ASE 3.0; PSE 7.0 Foundations & Associate in Platform; Cyber Security; Data Center

L3 Networker


You need send the following over the API,

<show><running><rule-use><vsys>vsys1</vsys><type>unused</type><rule-base>security</rule-base></rule-use></running></show>

The resultant URL would look look like this,

https://MYFIREWALL/api/?cmd=%3Cshow%3E%3Crunning%3E%3Crule-use%3E%3Cvsys%3Evsys1%3C%2Fvsys%3E%3Ctype...

L5 Sessionator

Thanks everyone for the responses.  All of them works Smiley Happy

L2 Linker

I wanted to provide an example if using Panorama. 

 

This is a snippet from Postman where i have variables for Panorama and the associated api key {{prod-panorama}} and whatever device-group I want to review {{device-group}}.  To retrieve pre-rules with no hits:no hits.JPG

 

Hi thank you for sharing the API for using panorama, one more question if i may

Do you know if there is any API using Panorama that i can get all used rules with timestamp of last used.

from the API above i can get only the timestamp of last modify and timestamp of creation.

 

@jasonrakers your help will be much appreciated 

 

Hi @Serhan,


At Panorama level, this command will get stats for all rules at summary level:

https://{{host}}/api?key={{key}}&type=op&cmd=<show><rule-hit-count><device-group><entry name='{{device-group-name}}'><pre-rulebase><entry name='security'><rules><all/></rules></entry></pre-rulebase></entry></device-group></rule-hit-count></show>


If you use a similar command for a specific rule, you can detailed stats including last-hit-timestamp:

https://{{host}}/api?key={{key}}&type=op&cmd=<show><rule-hit-count><device-group><entry name='{{device-group-name}}'><pre-rulebase><entry name='security'><rules><rule-name><entry name='{{rule-name}}'/></rule-name></rules></entry></pre-rulebase></entry></device-group></rule-hit-count></show>


 Hope that helps.

Help the community: "Like" helpful comments, and click "Accept as Solution" if you found your answer 🙂
  • 1 accepted solution
  • 11470 Views
  • 7 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!