- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
02-19-2020 09:41 AM - edited 02-19-2020 09:42 AM
Hi,
I have the following code to check the vpn status, this code execute op "show vpn flow'
I'm ussing pandevice library in my imports
def check_vpn_status(fw): #check vpn status
vpn_ike = fw.op(cmd= "show vpn flow", xml=True)
with open('vpn_status.xml', 'wb') as file:
file.write(vpn_ike)
print(type(vpn_ike))
. and generate an xml file like this. Exist one method how to read the file to search into file the ie state and show in the print the following tunnels are up ?. I'm stuck how to manipulate that file generated by fw.op
<response status="success"><result>
<total>1</total>
<num_ipsec>1</num_ipsec>
<IPSec>
<entry>
<peerip>12.12.12.12</peerip>
<name>Bluecoat_IPSEC:ID-1</name>
<outer-if>ethernet1/1</outer-if>
<gwid>1</gwid>
<localip>172.16.10.1</localip>
<state>init</state>
<inner-if>tunnel.10</inner-if>
<mon>off</mon>
<owner>1</owner>
<id>1</id>
</entry>
</IPSec>
<dp>dp0</dp>
<num_sslvpn>0</num_sslvpn>
</result></response>
Any advise I really appreciate.
best Regards
Andres
02-19-2020 09:58 AM
I would skip the file part of this. If your true goal is just to see the states of things, I would take advantage of the fact that fw.op()
returns an xml.etree.ElementTree
object and use the python functions available to iterate over the results:
result = fw.op('show vpn flow')
for entry in result.findall('./result/IPSec/entry'):
name = entry.find('./name')
state = entry.find('./state')
if name is None or state is None:
# This should never happen, but just to code defensively...
continue
print('{0} has state {1}'.format(name.text, state.text))
02-19-2020 09:58 AM
I would skip the file part of this. If your true goal is just to see the states of things, I would take advantage of the fact that fw.op()
returns an xml.etree.ElementTree
object and use the python functions available to iterate over the results:
result = fw.op('show vpn flow')
for entry in result.findall('./result/IPSec/entry'):
name = entry.find('./name')
state = entry.find('./state')
if name is None or state is None:
# This should never happen, but just to code defensively...
continue
print('{0} has state {1}'.format(name.text, state.text))
02-19-2020 10:24 AM
Thanks a lot !!!!!!!!! you rocks!!!
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!