For the policies you can get the data with something similar to the following, written in python3.
Note: This does take a bit of time, generates a lot of output and you will need to increase the ASM Max response size under /etc/asm-config-rest.conf
from f5.bigip import ManagementRoot
import re
mgmt = ManagementRoot('155.121.lab.es.f5net.com', 'admin', 'admin')
_policies = mgmt.tm.asm.policies_s.get_collection()
_signature_sets = mgmt.tm.asm.signature_sets_s.get_collection()
_signatures = mgmt.tm.asm.signatures_s.get_collection()
_policy_IDs=[]
for _policyId in range(len(_policies)):
_policy_IDs.append(_policies[_policyId].id)
print('Policy Name: {}'.format(_policies[_policyId].name))
_policy_details = mgmt.tm.asm.policies_s.policy.load(id=_policies[_policyId].id)
_policy_signature_sets = _policy_details.signature_sets_s.get_collection()
for _set in range(len(_policy_signature_sets)):
_current_signature_ReferenceId=re.split('/|\?', _policy_signature_sets[_set].signatureSetReference.get("link"))[7]
for _id in range(len(_signature_sets)):
if _current_signature_ReferenceId in _signature_sets[_id].id:
_signature_set_name = _signature_sets[_id].name
print('\tSigSet Name: {}\tAlarm: {}\tLearn: {}\tBlock: {}'.format(_signature_set_name, _policy_signature_sets[_set].alarm, _policy_signature_sets[_set].learn, _policy_signature_sets[_set].block))
for _signature_set in range(len(_signature_sets)):
print('\n\nSignature Set: {}\n'.format(_signature_sets[_signature_set].name))
for _signature in range(len(_signature_sets[_signature_set].signatureReferences)):
_signature_ID = re.split('/|\?', _signature_sets[_signature_set].signatureReferences[_signature].get("link"))[7]
for _signature_id in range(len(_signatures)):
if _signature_ID in _signatures[_signature_id].id:
print('\tSignature Name: {}\tSignature ID: {}'.format(_signatures[_signature_id].name, _signatures[_signature_id].signatureId))
For the additional information from the virtual server you can get the securityLogProfiles from the virtual server objects. Not sure if your intention is to supply a virtual server and the discover the applied policy/policies and then iterate through the previous code to dump the data out.
vips=mgmt.tm.ltm.virtuals.get_collection()
for vip in range(len(vips)):
if hasattr(vips[vip], 'securityLogProfiles'):
print('VS Name: {}\tSecurity Log Profile: {}'.format(vips[vip].name, vips[vip].securityLogProfiles))
Let me know if this gets you on the path.