def get(self):
if not self.dev.connected:
logger.error("{0}: Firewall timed out or incorrect device credentials.".format(self.firewall_config['name']))
return {'error' : 'Could not connect to device.'}, 504
else:
logger.info("{0}: Connected successfully.".format(self.firewall_config['name']))
try:
rpc = etree.tostring(str(jns.rpc.get_security_policies_hit_count()), encoding='unicode')
except Exception as e:
logger.error("Error parsing rpc: {0}".format(str(e)))
return {'error' : 'Error parsing soup.'}, 500
finally:
self.dev.close()
soup = BS(rpc,'xml')
entries = list()
for hitcount in soup.find('policy-hit-count').children:
if type(hitcount) != Tag or hitcount.name != 'policy-hit-count-entry':
continue
aux = {
'count' : int(hitcount.find('policy-hit-count-count').text),
'from' : hitcount.find('policy-hit-count-from-zone').text,
'to' : hitcount.find('policy-hit-count-to-zone').text,
'policy' : hitcount.find('policy-hit-count-policy-name').text
}
entries.append(aux)
return {'len' : len(entries), 'hitcount' : entries}
评论列表
文章目录