Collect from a database
This page explains how to collect events from a database. The appliance connects to the database on a schedule, reads the rows or documents added since its last poll, and stores each one as an event. Use it for audit tables and application logs that live in a database.
Role needed: a user with the Admin or Super Admin account type. A user with a custom role needs Settings access and, under Collection & Automation, Log Onboarding with Set.
Supported databases
| Log source type | Database | Default port |
|---|---|---|
mssql | Microsoft SQL Server | 1433 |
mysql | MySQL | 3306 |
oracle | Oracle Database | 1521 |
hanadb | SAP HANA | none; enter the port |
mongodb | MongoDB | none; enter the port |
Before you begin
- The database must accept connections from the appliance on its port.
- Create a read-only database account for the appliance, and store it under Credential Vault. See Onboard a data source.
- Decide which column or field marks new rows. It must increase for new data, such as an event time or a sequence number. The appliance remembers the last value it read for each source.
Add a SQL database source
This applies to mssql, mysql and oracle.
- Select Settings, then Log Onboarding under Collection & Automation, then select the + button.
- Choose the Log source type.
- Under Credential, choose the saved credential.
- Enter the Host and Port. For
mssqlyou can also enter an Instance Name and a Charset. Formysqlyou can enter a Database and Charset. Fororacle, enter the Service Name. - Enter the Query: a
SELECTstatement that returns the rows to collect. - Enter the Position Column: the column that increases for new rows.
- Under Position Column Type, choose
rowfor a numeric column ortimefor a date and time column. Fortime, enter the Position Column Format if the default of year-month-day hours:minutes:seconds does not match. - Set Poll Interval (seconds). The default is 300.
- Select Check connection. The appliance tests that it can open a connection to the host and port. It does not test the credential.
- Enter a Log source name, then select Save.
Write the query
The appliance adds its own filter and sort to your query. After the first poll it appends WHERE <position column> > <last value> ORDER BY <position column>, and on the first poll only ORDER BY <position column>. Your query therefore must not have its own WHERE or ORDER BY at the end. To filter, wrap the query:
SELECT * FROM (SELECT * FROM audit_log WHERE action <> 'HEARTBEAT') filtered
Every column of every row is kept on the event under its own name, and the row as text is kept in the event's message.
Add a SAP HANA source
- In the Add log source panel, choose
hanadb. - Enter the Host and Port, choose the Credential, and enter the Schema Name and Table Name.
- Enter the Position Column and Position Format. Position Column Type defaults to
time. - Set Poll Interval (seconds), select Check connection, enter a name and select Save.
There is no query field. The appliance reads the whole table in position-column order.
Add a MongoDB source
- In the Add log source panel, choose
mongodb. - Enter the Host and Port and choose the Credential.
- Enter the Authentication Database, and the Database and Collection to read.
- Enter the Position Field and choose its type under Position Field Type (
timeby default). Enter a Position Field Format if needed. - Set Poll Interval (seconds), select Check connection, enter a name and select Save.
The appliance reads documents in order of the position field and keeps each document's fields on the event.
Oracle audit records
For an Oracle source, a row that has an ACTION_NAME column is treated as an audit record and mapped to standard event fields. A row without it is stored unchanged. Name the columns in upper case, using aliases in your query if your audit view names them differently.
| Column | Becomes |
|---|---|
ACTION_NAME | The action, event category and event type. For example LOGON is an authentication start, SELECT is database access, and a CREATE USER or GRANT is an identity and access change. |
RETURN_CODE | The outcome. 0 is success and any other integer is failure. A failed LOGON is also marked as denied. |
DBUSERNAME | The user name. |
USERHOST | The source address. |
OBJECT_SCHEMA, OBJECT_NAME, GRANTEE, SYS_PRIVILEGE, OBJ_PRIVILEGE, ADMIN_OPTION | Oracle-specific context fields. ADMIN_OPTION of YES or NO becomes true or false. |
Only ACTION_NAME is required. Audit statement text can contain passwords. The appliance stores SQL_TEXT exactly as your query returns it and does not remove anything. Leave SQL_TEXT out of the query, or mask it there, if statements must not be kept.
Confirm that events arrive
After the first poll interval the source moves from Pending to Active in Log Onboarding. See Check that a source is sending. If it stays Pending, see Events are not arriving.