To find Intrusion Prevention (IPS/IDS) rules that can be recommended by a Recommendation Scan, you need to search on the recommendationsMode field of the IPS rules (IPS rules do not have a recommendable field).
The API field names and values are not necessarily the same as you see in the UI. To see the field names in the API Reference:
- Go to the API Reference:
https://automation.deepsecurity.trendmicro.com/article/12_0/api-reference?platform=on-premise
- List item Scroll down to the Intrusion Prevention area and click
Describe an Intrusion Prevention Rule
- In the center panel, click 200 successful operation
- In the Response Schema, look for
recommendationsMode
:
Indicates whether recommendation scans consider the rule. To avoid
errors on existing rules, only change the value between enabled (rule
is included in recommendations scan) and ignored (rule is ignored by
recommendations scan). Other values (disabled or ignored) indicate
that the rule is not supported by recommendation scans. Searchable as
Choice.
So, you want to perform a Choice search for rules that have recommendationsMode
equals ignored
.
def find_rules_for_recommendable(api, configuration, api_version, api_exception):
rule_id_s = []
# Set search criteria
search_criteria = api.SearchCriteria()
search_criteria.field_name = "recommendationsMode"
search_criteria.choice_value = "ignored"
search_criteria.choice_test = "equal"
# Create a search filter
search_filter = api.SearchFilter()
search_filter.search_criteria = [search_criteria]
try:
# Search for all intrusion prevention rules for the CVE
ip_rules_api = api.IntrusionPreventionRulesApi(api.ApiClient(configuration))
ip_rules_search_results = ip_rules_api.search_intrusion_prevention_rules(api_version,
search_filter=search_filter)
print(ip_rules_search_results)
for rule in ip_rules_search_results.intrusion_prevention_rules:
rule_id_s.append(rule.id)
return rule_id_s
except api_exception as e:
return "Exception: " + str(e)`
As a bonus, and anticipating where you are going next, here is how you would assign a list of rules to a policy:
def apply_intrusion_prevention_recommendations(api, configuration, api_version, api_exception, policy_id, rule_ids):
rule_ids_obj = api.models.RuleIDs(rule_ids)
ips_recommendations_api = api.PolicyIntrusionPreventionRuleAssignmentsRecommendationsApi(api.ApiClient(configuration))
try:
ip_assignments = ips_recommendations_api.add_intrusion_prevention_rule_ids_to_policy(policy_id, api_version, intrusion_prevention_rule_ids=rule_ids_obj, overrides=False)
return ip_assignments
except api_exception as e:
return "Exception: " + str(e)
Hope that helps! (BTW I'm a DS content developer)