<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Python: panos opstate in General Topics</title>
    <link>https://live.paloaltonetworks.com/t5/general-topics/python-panos-opstate/m-p/1230402#M124444</link>
    <description>&lt;P&gt;I'm having tremendous success automating security policy updates with the panos Python library, but I'm currently stuck on obtaining the hit counts of rules programmatically.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm able to access all attributes of the SecurityRule objects, but the opstate hit_count attributes all come back as None.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Relevant code;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;if type(rule) is SecurityRule:
	print(f'\t{rule.name}')
	print(rule.opstate.hit_count.hit_count)
	print(rule.opstate.hit_count.latest)
	print(rule.opstate.hit_count.last_hit_timestamp)
	print(rule.opstate.hit_count.last_reset_timestamp)&lt;/LI-CODE&gt;
&lt;P&gt;output&lt;/P&gt;
&lt;PRE&gt;    Rule Name&lt;BR /&gt;None&lt;BR /&gt;None&lt;BR /&gt;None&lt;BR /&gt;None&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've attempted to use the refresh method a number of different ways, but None is always what is returned.&amp;nbsp;I have to be missing something silly, and I can't find what I need in the documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://pan-os-python.readthedocs.io/en/latest/module-policies.html#panos.policies.HitCount" target="_blank"&gt;https://pan-os-python.readthedocs.io/en/latest/module-policies.html#panos.policies.HitCount&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Panorama is running 11.1.6-h3&lt;/P&gt;</description>
    <pubDate>Fri, 30 May 2025 00:01:40 GMT</pubDate>
    <dc:creator>dawonk</dc:creator>
    <dc:date>2025-05-30T00:01:40Z</dc:date>
    <item>
      <title>Python: panos opstate</title>
      <link>https://live.paloaltonetworks.com/t5/general-topics/python-panos-opstate/m-p/1230402#M124444</link>
      <description>&lt;P&gt;I'm having tremendous success automating security policy updates with the panos Python library, but I'm currently stuck on obtaining the hit counts of rules programmatically.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm able to access all attributes of the SecurityRule objects, but the opstate hit_count attributes all come back as None.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Relevant code;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;if type(rule) is SecurityRule:
	print(f'\t{rule.name}')
	print(rule.opstate.hit_count.hit_count)
	print(rule.opstate.hit_count.latest)
	print(rule.opstate.hit_count.last_hit_timestamp)
	print(rule.opstate.hit_count.last_reset_timestamp)&lt;/LI-CODE&gt;
&lt;P&gt;output&lt;/P&gt;
&lt;PRE&gt;    Rule Name&lt;BR /&gt;None&lt;BR /&gt;None&lt;BR /&gt;None&lt;BR /&gt;None&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've attempted to use the refresh method a number of different ways, but None is always what is returned.&amp;nbsp;I have to be missing something silly, and I can't find what I need in the documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://pan-os-python.readthedocs.io/en/latest/module-policies.html#panos.policies.HitCount" target="_blank"&gt;https://pan-os-python.readthedocs.io/en/latest/module-policies.html#panos.policies.HitCount&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Panorama is running 11.1.6-h3&lt;/P&gt;</description>
      <pubDate>Fri, 30 May 2025 00:01:40 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/general-topics/python-panos-opstate/m-p/1230402#M124444</guid>
      <dc:creator>dawonk</dc:creator>
      <dc:date>2025-05-30T00:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: Python: panos opstate</title>
      <link>https://live.paloaltonetworks.com/t5/general-topics/python-panos-opstate/m-p/1230538#M124451</link>
      <description>&lt;P&gt;Making progress thanks to some of the comments here;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/PaloAltoNetworks/pan-os-python/issues/388" target="_blank"&gt;https://github.com/PaloAltoNetworks/pan-os-python/issues/388&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Expanding the relevant code to show that running the refresh method on the the rulebase successfully populates the rule_creation_timestamp and rule_modification_timestamp.&amp;nbsp; These both will also return None without the refresh method.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;for rulebase in theserulebases:
	print('...absoutely need to refresh the rulebase to get create/modify counts')
	rulebase.opstate.hit_count.refresh("security", all_rules=True)
	
	for rule in rulebase.children:
		if type(rule) is SecurityRule:
			print(f'\t{rule.name}')
						print(rule.opstate.hit_count.hit_count)
			print(rule.opstate.hit_count.latest)
			print(rule.opstate.hit_count.last_hit_timestamp)
			print(rule.opstate.hit_count.last_reset_timestamp)
			#- only these work after 
			print(datetime.fromtimestamp(rule.opstate.hit_count.rule_creation_timestamp))
			print(datetime.fromtimestamp(rule.opstate.hit_count.rule_modification_timestamp))
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My next action is to retrieve Firewall objects and see what I can get from them.&lt;/P&gt;</description>
      <pubDate>Fri, 30 May 2025 14:02:40 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/general-topics/python-panos-opstate/m-p/1230538#M124451</guid>
      <dc:creator>dawonk</dc:creator>
      <dc:date>2025-05-30T14:02:40Z</dc:date>
    </item>
  </channel>
</rss>

