Source code for suricata_check.checkers.mandatory

 1"""`MandatoryChecker`."""
 2
 3import logging
 4
 5from suricata_check.checkers.interface import CheckerInterface
 6from suricata_check.utils.checker import is_rule_option_set
 7from suricata_check.utils.checker_typing import ISSUES_TYPE, Issue, Rule
 8
 9
[docs] 10class MandatoryChecker(CheckerInterface): 11 """The `MandatoryChecker` contains several checks based on the Suricata syntax that are critical. 12 13 Codes M000-M009 report on missing mandatory rule options. 14 """ 15 16 codes = { 17 "M000": {"severity": logging.ERROR}, 18 "M001": {"severity": logging.ERROR}, 19 } 20 21 def _check_rule( 22 self: "MandatoryChecker", 23 rule: Rule, 24 ) -> ISSUES_TYPE: 25 issues: ISSUES_TYPE = [] 26 27 if not is_rule_option_set(rule, "msg"): 28 issues.append( 29 Issue( 30 code="M000", 31 message="The rule did not specify a msg, which is a mandatory field.", 32 ) 33 ) 34 35 if not is_rule_option_set(rule, "sid"): 36 issues.append( 37 Issue( 38 code="M001", 39 message="The rule did not specify a sid, which is a mandatory field.", 40 ) 41 ) 42 43 return issues