14 Reference: Custom Audit Rule Context Object Methods
Use this reference to obtain details about functionality that you can access through an instance of a rule pack manager, rule issue, and rule reporter that you create in custom audit rules.
Audit Rule Classes | Description |
---|---|
The rule pack manager instance you create provides methods to access rule pack data. |
|
The rule issue instance you create provides methods to set properties of the reported issue. |
|
The rule reporter instance you create provides methods to handle reported issues. |
RulePack Class Methods
The rule pack manager instance provides methods to access rule pack data.
The Oracle JAF rule pack manager provides the following methods that you can call on an instance of a RulePack
object that you obtain from the Rule
context object.
Method | Description |
---|---|
getPackInfo() |
Returns an object that contains a read-only copy of the rule pack summary information. Properties include path, prefix, title, version, enabled, status. |
getRuleCustomOptions(string ruleName, string packPrefix) |
Returns an object that contains read-only copy of the custom options for a rule. That is, those specified by the user, and not JAF system rule options. Both arguments are optional: if packPrefix is omitted, the current rulepack is assumed. If ruleName is omitted the calling rule's options are returned. |
getRuleCustomOption(string property, string ruleName, string packPrefix) |
Returns the specified custom option property value for the rule, or null if not found. The ruleName and packPrefix arguments are optional. If packPrefix is omitted, the current rulepack is assumed. If ruleName is omitted the calling rule's option property is returned. |
getRuleOptions(string ruleName, string prefix) |
Returns an object that contains a read-only copy of the options for a rule. Both arguments are optional: if prefix is omitted, the current rule pack is assumed. If ruleName is omitted the calling rule's options are returned. |
getRuleOption(string property, string name, string prefix) |
Returns the specified rule option property for the rule. Arguments name and prefix are optional: if prefix is omitted, the current rule pack is assumed. If ruleName is omitted the calling rule's option property is returned. |
getPrefix() | Returns a string that is the rule pack prefix. |
setRuleOptions(string ruleName, Object options) |
Sets the options for the rule in the caller's rule pack. The rulename argument is optional - if omitted, the calling rule's options are updated. options is an object containing the property/values to apply. Returns |
isRuleEnabled(string ruleName, string prefix) |
Returns The prefix argument is optional, and if omitted, the rule is assumed to be in the caller's rule pack. |
isRuleDisabled(string ruleName, string prefix) |
Returns The prefix is optional, and if omitted, the rule is assumed to be in the caller's rule pack. |
disableRule(string ruleName) |
Disables the specified rule in the caller's rule pack. Returns |
enableRule(string ruleName) |
Enables the specified rule in the caller's rule pack. Returns Note: In the current release, only a previously loaded rule (at startup) can be re-enabled. That is, |
getRuleCount() | Returns the number of rules defined in the calling rule's rule pack. |
getEnabledRuleCount() | Returns the number of rules currently enabled in the calling rule's rule pack. |
getRuleList() | Returns a list of the rule names in the calling rule's rule pack. |
getEnabledRuleList() | Returns an array list of the names of the currently enabled rules in the calling rule's rule pack. |
getRule() | Returns the instance of a rule in the caller's rule pack to allow its exported methods to be called. |
getExtension() | Returns the rule pack specific data supplied by setExtension() .
|
setExtension(* data) |
Sets rule pack specific data that can be retrieved via data can be any data type, and can be used to refer to any data, libraries, and son on that is useful to the rule. |
sendMsg(string ruleName, ...data) |
Sends a data message to the data represents any number of arguments - these arguments are presented to onMsg(Object sender, *[] data); where sender is an object of the following format:
Returns the value returned by Note that a rule cannot send a data message to itself (to mitigate race conditions). |
broadcastMsg(string[] ruleNames, ...data) |
Send a data message to the If ruleNames is null, the data is broadcast to all currently enabled rules with an exported Returns the number of rules whose Refer to |
getInfo() |
Returns miscellaneous information about the JAF instance as an object that has the following properties as strings.
|
Rule Issue Class Methods
You can create an Issue
object and use the provided methods of the Oracle JAF Issue
class to set properties of the reported issue.
The Oracle JAF Issue
class provides the following constructor and setter methods that you can use to set the properties of the Issue
object that you create within the registered event listener function of your audit rule.
Issue
class is to call the constructor method to create an Issue
instance with details like the issue description and optional message ID:var myIssue = new context.Issue(msg [, messageID]);
The severity for the rule is obtained from the rule definition, but this may be overridden within a rule using Issue.setSeverity()
.
Method | Description |
---|---|
constructor(string msg [, string id]) |
msg—(optional) a string that is the issue description. id—(optional) a string that is an optional message ID. This will appear in the audit output as |
setId(string id) |
Sets the id portion of a message id. id—a string that is the trailing ID in a message number. For example, if the id is |
setPosition(number line, number column, number startIndex, number endIndex) or setPosition(Object pos) |
Overrides the line/column numbers in the audited file that appear in the reported message or JSON. line—the line number in the audited data. column—the column number in the audited data. startIndex—(optional) the starting position in the audited data. endIndex—(optional) the ending position in the audited data. Note that line/column may be specified as null, in which case the line and column will be computed by JAF from startIndex. May also be specified as an object, for example:
where pos is an object with the following format: line—the line number. column—the column number. startIndex or start—the start index. endIndex or end—the end index. The pos object may either be constructed by a rule or can be the return value from |
setSeverity(string severity) | Sets the severity of the issue (overriding the rule severity defined in the rules.json file, or the modified severity in configuration property ruleMods. May be info, minor, major, critical, or blocker.
|
setMsgKey(string id) | Sets the message ID for the issue. This overrides the message key obtained from the rule pack's msgid.json file if it exists.
|
setReportedFilePath(string filepath) |
Sets the specified file path as the reported file path for the issue. This is designed for use where an issue is being reported by a rulepack lifecycle listener (e.g., Note: This is not required for normal audit cycle rules. |
Rule Reporter Class Methods
You can create an Reporter
object and use the provided methods of the Oracle JAF Reporter
class to handle reported issues.
The Oracle JAF Reporter
class provides the following methods that you can use to handle reporting of the Issue
object that you pass to the Reporter
instance in the registered event listener function of your audit rule.
Reporter
instance is to call the addIssue()
method:context.reporter.addIssue(myIssue, context);
Method | Description |
---|---|
addIssue(Object issue, Object context [, string severity]) |
Adds an issue—an context—the context object passed to the rule. severity—(optional) allows a rule to override the rule severity. May be infor, minor, major, critical, or blocker. |
clearIssues() |
Removes all issues added to the |
getCount() | Returns the current number of issues added to the Reporter instance for the current file.
|
getFormat() | Returns the current output format: prose or json .
|