Logical and arithmetic expressions
Logical and arithmetic expressions can be used in SHOW
clauses and WHERE
clauses.
Truth
In WHERE
clauses, the following values are considered False:
Boolean False |
Number zero |
Empty string |
Empty list |
None (for example, missing attribute) |
All other values are considered True. This allows simple WHERE
clauses that choose only useful values. For example, to find all Software Instance nodes with a populated version:
SEARCH SoftwareInstance WHERE version SHOW type, version
Expressions
The following logical and arithmetic expressions are supported:
Equality |
|
Inequality |
|
Comparison |
|
Arithmetic |
|
Subwords |
For a single word search, the condition is true if For a multi-word search:
When used in a |
Substrings |
|
Regular expression match |
|
Containment |
|
Containment |
|
Definition |
|
Inverse |
|
And |
|
Or |
|
Precedence
Operator precedence works as you would expect. Parentheses (
and )
are used to explicitly group operations. Otherwise, in arithmetic expressions, *
and /
take precedence over +
and -
. In logical expressions, OR
has lowest precedence, followed by AND
, followed by NOT
, followed by all the other operators. i.e. this expression
NOT a > b OR c HAS SUBWORD d AND e = 10
is equivalent to
(((NOT (a > b)) OR ((c HAS SUBWORD d) AND (e = 10)))
Logical expressions in SHOW clauses
Logical expressions can be used in SHOW
clauses. To do so, they must be enclosed in parentheses, e.g.
SEARCH Host SHOW name, (ram > 1024)
The behavior of AND
and OR
in returning one of their input parameters can be useful in handling missing attributes, to avoid output of "None" when an attribute is not available, for example:
SEARCH Host SHOW name, (domain OR "Unknown domain")
SEARCH Host SHOW name, (virtual AND "Host identified as virtual" OR "Host not identified as virtual")
Logical expression name binding
Logical expressions can be bound to names. For example:
SEARCH Host WITH (virtual AND "yes" OR "no") AS is_virtual SHOW name, @is_virtual
Using a regular expression
The MATCHES condition enables you to search by matching against a regular expression (or regex), a pattern that matches various text strings. For example, A[0-9]+
matches any string that consists of the letter A followed by one or more digits.
Regular expressions have a defined syntax that enables you to define complex matching patterns. BMC Discovery uses the Python implementation; for full syntax and details of use, consult the Python documentation. For more information, see the
Python documentation
.
The following table lists a few of the matching characters that you can use when constructing regular expressions. An ordinary character, or a sequence of characters, matches that character or string.
Character | Details |
---|---|
. | A dot matches any single character. |
^ | A caret matches characters at the start of the string. |
$ | A dollar sign matches characters at the end of the string. |
* | An asterisk matches 0 or more repetitions of the preceding regex. For example, ab* matches "a," "ab," or "a" followed by any number of "b"s. |
+ | A plus sign matches one or more repetitions of the preceding regex. For example, ab+ matches "a" followed by any nonzero number of "b"s; it does not match just "a." |
? | A question mark matches 0 or 1 repetitions of the preceding regex. For example, ab? matches either "a" or "ab." |
[ ] | Square brackets indicate a set of characters that can be matched. For example, "asdf" matches any of the characters "a," "s," "d," "f." |
| | The vertical bar separates regular expressions, any or which can be matched. For example, A|B matches either A or B. |
\ | The backward slash followed by any special character matches the special character itself. |
Comments
Log in or register to comment.