This procedure summarizes how to configure Office 365 to permit syslog-ng Premium Edition (syslog-ng PE) to fetch log messages using the Office 365 Management Activity API.
A valid Office 365 account (for example: Azure Active Directory Premium P2).
Administrator permissions to the Office 365 account.
Content subscription must be enabled for the content types you want to fetch logs from.
syslog-ng Premium Edition version 7.0.15 or later.
The syslog-ng PE application communicates with the Management Activity API through a service app registered in Azure. Complete the following steps to register a service app. For details on registering an app, see the Office 365 documentation.
Login to https://portal.azure.com.
Register a new web application (for example, syslog-service-app).
Grant all application permissions and delegated permissions to the created app.
Create secret (password) for the app. Record the password somewhere, as you will need it later to configure syslog-ng PE. If you set an expiration to the password, make sure to renew the password and update it in your syslog-ng PE configuration file before it expires.
In the authentication settings of the new app, enable Access Tokens.
Enabling audit logging in Office 365. Note that your user must have an administrator permissions to enable audit logging. For details on enabling audit logging, see the Office 365 documentation. If you have problems enabling audit logging, see Troubleshooting audit logging in Office 365
Start content subscriptions for the content types you want to fetch logs from using the following command. The office365subscriptiontool utility is automatically installed with syslog-ng PE version 7.0.15 and newer.
%syslog-ng-installation-directory%/bin/office365subscriptiontool start --tenant-id=[your tenant-id] --client-id=[your client-id] --client-secret=[your client-secret in escaped format] --content-type=[content-type-to-fetch-logs-from]
Note that special characters (for example, ?/*+!$) in the client secret must be escaped (according to the rules of escaping in bash/shell) when starting the content subscription.
In your syslog-ng PE configuration, you will have to use the source driver matching the content type of the content subscription. For example, use the office365-azure-active-directory() driver for the Audit.AzureActiveDirectory content type.
Repeat this step for every content type you want to fetch logs from.
NOTE: When a subscription is created, it can take up to 12 hours for the first content blobs to become available for that subscription.
The office365() drivers have the following options. The tenant-id(), client-id(), and client-secret() option is required, the others are optional.
Type: | string |
Default: |
Description: The ID of the service app. For details, see Configuring Office 365 to permit fetching logs.
Type: | string |
Default: |
Description: The password of the service app. For details, see Configuring Office 365 to permit fetching logs.
If you set an expiration to the password, make sure to renew the password and update it in your syslog-ng PE configuration file before it expires.
Type: | real number [seconds] |
Default: |
The value of time-reopen() |
Description: When there are no messages available in a poll event, the Office 365 Management Activity API waits fetch-no-data-delay() seconds before the next poll.
NOTE: You can set the fetch-no-data-delay() value to fractions, for example:
fetch-no-data-delay(0.5)
Type: | string |
Default: |
None |
Description:If you receive the following error message during syslog-ng PE startup, set the persist-name() option of the duplicate drivers:
Error checking the uniqueness of the persist names, please override it with persist-name option. Shutting down.
This error occurs if you use identical drivers in multiple sources, for example, if you configure two file sources to read from the same file. In this case, set the persist-name() of the drivers to a custom string, for example, persist-name("example-persist-name1").
Type: | string |
Default: |
Description: The ID of the Tenant that the Office 365 account belongs to.
Accepted values: | number [seconds] |
Default: | 60 |
Description: The time to wait in seconds before a dead connection is reestablished.
By default, this option uses the value set in the time-reopen() global option.
If you have trouble with enabling audit logging in Office 365, complete the following steps.
Login to https://protection.office.com/.
Verify that the Search > Audit log search context is active. If it is not, execute the following commands from PowerShell:
$ $UserCredential = Get-Credential # use your Azure account $ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection $ Import-PSSession $Session -DisableNameChecking $ Enable-OrganizationCustomization # Wait 4 hours $ Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $true # Wait 1 hour $ Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $false # Wait 1 hour $ Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $true # Wait 1 hour
Login to https://protection.office.com/ and check if there are audit logs under Search > Audit log search. Note that in some cases, the logs will appear only after 24-48 hours.
The osquery application allows you to ask questions about your machine using an SQL-like language. For example, you can query running processes, logged in users, installed packages and syslog messages as well. You can make queries on demand, and also schedule them to run regularly.
The osquery() source of syslog-ng PE allows you read the results of periodical osquery queries (from the /var/log/osquery/osqueryd.results.log file) and automatically parse the messages (if you want to use syslog-ng PE to send log messages to osquery, read this blogpost). For example, you can:
Create filters from the fields of the messages.
Limit which fields to store, or create additional fields (combine multiple fields into one filed, and so on).
Send the messages to a central location, for example, to Elasticsearch, directly from syslog-ng PE.
The syslog-ng PE application automatically adds the .osquery. prefix to the name of the fields the extracted from the message.
The osquery() source is available in syslog-ng PE version
To use the osquery() driver, the scl.conf file must be included in your syslog-ng PE configuration:
@include "scl.conf"
The osquery() driver is actually a reusable configuration snippet configured to read the osquery log file using the file() driver, and process its JSON contents. For details on using or writing such configuration snippets, see Reusing configuration blocks. You can find the source of this configuration snippet on GitHub.
The following syslog-ng PE configuration sample uses the default settings of the driver, reading osquery result logs from the /var/log/osquery/osqueryd.results.log file, and writes the log messages generated from the traps into a file.
@version: 7.0 @include "scl.conf" source s_osquery { osquery(); }; log { source(s_osquery); destination { file("/var/log/example.log"); }; };
Filter for messages related to loading Linux kernel modules:
@version: 7.0 @include "scl.conf" source s_osquery { osquery(); }; log { source(s_osquery); filter f_modules { "${.osquery.name}" eq "pack_incident-response_kernel_modules" }; destination { file("/var/log/example.log"); }; };
The following syslog-ng PE configuration sample reads osquery result logs from the /tmp/osquery_input.log file, and writes the log messages generated from the traps into a file. Using the format-json template, the outgoing message will be a well-formed JSON message.
{"name":"pack_osquery-monitoring_osquery_info","hostIdentifier":"testhost","calendarTime":"Fri Jul 21 10:04:41 2017 UTC","unixTime":"1500631481","decorations":{"host_uuid":"4C4C4544-004D-3610-8043-C2C04F4D3332","username":"myuser"},"columns":{"build_distro":"xenial","build_platform":"ubuntu","config_hash":"43cd1c6a7d0c283e21e026a53e619b2e582e94ee","config_valid":"1","counter":"4","extensions":"active","instance_id":"d0c3eb0d-f8e0-4bea-868b-18a2c61b438d","pid":"19764","resident_size":"26416000","start_time":"1500629552","system_time":"223","user_time":"476","uuid":"4C4C4544-004D-3610-8043-C2C04F4D3332","version":"2.5.0","watcher":"19762"},"action":"added"}
@version: 7.0 @include "scl.conf" source s_osquery { osquery( file(/tmp/osquery_input.log) prefix(.osquery.) ); }; destination d_file { file("/tmp/output.txt" template("$(format_json --key .osquery.*)\n") ); }; log { source(s_osquery); destination(d_file); flags(flow-control); };
Outgoing message; message='{"_osquery":{"unixTime":"1500631481","name":"pack_osquery-monitoring_osquery_info","hostIdentifier":"testhost","decorations":{"username":"myuser","host_uuid":"4C4C4544-004D-3610-8043-C2C04F4D3332"},"columns":{"watcher":"19762","version":"2.5.0","uuid":"4C4C4544-004D-3610-8043-C2C04F4D3332","user_time":"476","system_time":"223","start_time":"1500629552","resident_size":"26416000","pid":"19764","instance_id":"d0c3eb0d-f8e0-4bea-868b-18a2c61b438d","extensions":"active","counter":"4","config_valid":"1","config_hash":"43cd1c6a7d0c283e21e026a53e619b2e582e94ee","build_platform":"ubuntu","build_distro":"xenial"},"calendarTime":"Fri Jul 21 10:04:41 2017 UTC","action":"added"}}\x0a'
To configure a destination to send the log messages to Elasticsearch, see elasticsearch2: Sending messages directly to Elasticsearch version 2.0 or higher (DEPRECATED). For other destinations, see Sending and storing log messages — destinations and destination drivers.
© 2023 One Identity LLC. ALL RIGHTS RESERVED. Feedback Terms of Use Privacy