NXQL language definition (classic)
While the NXQL tutorial guides you through your first steps with NXQL, this document gives a more formal definition of the query capabilities of NXQL.
Selecting plain objects
To select objects from an object table, use this form of the select statement:
Example:
Selecting plain events
To select events from an event table, use this form of the select statement:
Example:
This query returns the start time and the incoming and outgoing traffic of the last 100 connections whose status is not equal to established or closed. That is, those connection with a status equal to rejected, no host or no service.
Selecting events with decoration
To select events and their linked objects from a given event table, use the following form of the select statement. Note that there is no limit on the number of object tables that you can specify, as long as the object table is really linked to the events.
Example:
The query returns the start time as well as the name of the user who initiated the last 100 connections whose status is not equal to established or closed, that is, with a status equal to rejected, no host or no service.
Another example:
This last query is identical to the previous one, except that it does not return the start time of the connection. Since these kinds of queries return one tuple per event, you may see a tuple with the same user name and device name appearing more than once in the results. These tuples are not really duplicated results, they actually belong to different connections although you may not see the difference due to the selected fields.
Selecting objects with activity
To select objects linked to an activity (event), use the following select statement. The difference with the previous family of queries is that in the former you get one result tuple per event, while in this latter you get one result tuple per object.
Example:
This query returns those devices which executed a binary whose threat level is intermediate or high yesterday. In addition, for each device, the query computes the number of distinct binaries matching the condition.
Selecting two objects
To select unique pairs of objects linked to a given type of events, use the following select statement. Note that you can select no more than two object tables and that you cannot use any logic operator.
Example:
This query returns the unique pairs of devices and packages, where the name of the package contains the term Office.
Updating objects
The update statement modifies categories or custom fields of an object table:
To reset the value of a category or custom field, use the following update statement:
Examples:
This query updates the Location category of every device whose name begins with PA to Paris.
This query resets the Location category to nil. If an auto-tagging rule for the Location of devices is in force, the system will reset the value to the keyword of the matching auto-tagging rule.
Filter
A filter is a condition on a field value. It has the following format:
Where [comparer] may have one of the following values:
eq
: equal. If the type of the field is an array of [type],eq
is true if at least one element of the array is equal to the value.ne
: not equal. If the type of the field is an array of [type],ne
is true if no element of the array is equal to the value.lt
: less than.le
: less or equal.gt
: greater than.ge
: greater or equal.
Where [type] may have one of the following values:
boolean
: A true or false value. Use keywords true and false, yes and no, or 1 and 0 as boolean literals.string
: A string, If the string contains a space or a double-quote, it must be double-quoted and the quote duplicated, for example,"Softy ""Visual"""
.integer
: An integer number, for example10
.real
: A floating-point number, for example12.56
.enum
: A list of distinct values. As in the case of strings, if the value contains a space or a double-quote, it must be double-quoted.second
: A natural number representing seconds, for example60 seconds
.millisecond
: A natural number representing milliseconds, for example60000 milliseconds
.microsecond
: A natural number representing microseconds, for example60000000 microseconds
.byte
: A natural number representing bytes, for example1048576 bytes
.ip_address
: An IP address, for example172.16.10.5
.ip_network
: An IP network, for example172.16.0.0/16
.mac_address
: A MAC address, for example48:5b:39:18:70:bb
.mhz
: A natural number representing mega hertz, for example1600 mhz
.sid
: A Windows security token, for exampleS-1-5-21-3623811015-3361044348-30300820-1013
.md5
: A MD5 hash code in hexadecimal format, for exampled41d8cd98f00b204e9800998ecf8427e
.port
: A port type (udp/tcp) followed by a port number, for exampletcp/8080
.version
: Four integers separated by a '.', for example5.1.0.34
.datetime
: A date and time in ISO 8601 format, for example2014-06-12T13:54:51
.time
: A time in ISO 8601 format, for example13:54:51
.date
: A date in ISO 8601 format, for example2014-06-12
.day
: A natural number representing days, for example7 days
.percent
: A fraction of 1 represented with 2 decimal places, for example0.75
, or75%
when displaying formatted output.permill
: A fraction of 1 represented with 3 decimal places, for example0.752
, or75.2%
when displaying formatted output.
Use the special type pattern
to match a string against a star pattern expression. Note that only the eq
and ne
operators are available for the type pattern
, for example:
(eq name (pattern "NY*"))
Filters belonging to the same where
clause are composed with a logic AND
. For instance, the following where
clause selects only devices whose name begins with NY and whose manufacturer is Dell:
Between
Date and time in a between
clause is composed of a date time in ISO 8601 format or one of the following keywords:
now
: query time.midnight
: last midnight.sunday
: last Sunday at 00:00:00.monday
: last Monday at 00:00:00.tuesday
: last Tuesday at 00:00:00.wednesday
: last Wednesday at 00:00:00.thursday
: last Thursday at 00:00:00.friday
: last Friday at 00:00:00.saturday
: last Saturday at 00:00:00.
Optionally followed by a positive or negative integer and one of the following units:
w
: week, for example 7 days.d
: day for example 24 hours.h
: 1 hour.m
: 1 minute.s
: 1 second.
Examples:
(between midnight now): today.
(between midnight-1d midnight): yesterday.
(between monday monday+24h): last monday.
(between 2014-7-16@14:00:00 2014-7-16@15:00:00): on 2014-7-16 between 2 and 3 PM.
Last updated