-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Adding macOS unified logging source to collectors #26542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kroepke
wants to merge
26
commits into
master
Choose a base branch
from
feat/macos-unified-logging-receiver
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
1450a37
feat(collectors): add macOS unified logging receiver config
kroepke ba4b65f
feat(collectors): add macOS unified logging source config
kroepke 315e969
feat(collectors): map macOS unified logging records to GIM fields
kroepke f5f6397
feat(collectors): add macOS unified logging source form
kroepke 4d3a7b0
fix(collectors): write macOS process_id/user_id as String for shared-…
kroepke 66a5e03
Merge branch 'master' into feat/macos-unified-logging-receiver
kroepke d5313e1
Merge branch 'master' into feat/macos-unified-logging-receiver
kroepke 2a2e8a0
Merge branch 'master' into feat/macos-unified-logging-receiver
kroepke bfc4f29
update macos_unified_logging configuration
kroepke 113058d
we now have 4 sources instead of 3
kroepke d7d2c99
give us a bit more space for longer titles in the fleet grid
kroepke 15c737c
give macOS Unified Logging badge enough space in the column
kroepke c3f274c
add changelog
kroepke 47b4572
Merge branch 'master' into feat/macos-unified-logging-receiver
kroepke abe3d78
Merge branch 'master' into feat/macos-unified-logging-receiver
thll 6bdce49
Merge branch 'master' into feat/macos-unified-logging-receiver
bernd 36b5f20
Update changelog/unreleased/pr-26542.toml
kroepke a7cfb2c
Update changelog/unreleased/pr-26542.toml
kroepke efab43b
remove start_date from config, max_poll_interval, max_log_age are now…
kroepke 6f558a1
prefer library functions over local reimplementations
kroepke 1f271b3
need to restate defaults for onboarding
kroepke db0e77d
update comment
kroepke 9e13a3e
add license header
kroepke fd81271
address linter error
kroepke 79acb89
adjusted tests since we no longer use start_time
kroepke 9c13c85
missed a test with new macos source config defaults
kroepke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| type = "a" | ||
| message = "Add macOS Unified Logging Collector source" | ||
|
|
||
| pulls = ["26542"] | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...c/main/java/org/graylog/collectors/config/receiver/MacOSUnifiedLoggingReceiverConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * Copyright (C) 2020 Graylog, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the Server Side Public License, version 1, | ||
| * as published by MongoDB, Inc. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * Server Side Public License for more details. | ||
| * | ||
| * You should have received a copy of the Server Side Public License | ||
| * along with this program. If not, see | ||
| * <http://www.mongodb.com/licensing/server-side-public-license>. | ||
| */ | ||
| package org.graylog.collectors.config.receiver; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
| import com.google.auto.value.AutoValue; | ||
| import jakarta.annotation.Nullable; | ||
| import org.graylog.collectors.CollectorOSType; | ||
| import org.graylog.collectors.config.GoDurationSerializer; | ||
| import org.graylog.collectors.config.extension.FileStorageExtensionConfig; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.EnumSet; | ||
|
|
||
| import static org.graylog2.shared.utilities.StringUtils.f; | ||
|
|
||
| /** | ||
| * OTel collector macOS Unified Logging Receiver configuration. | ||
| * <p> | ||
| * Graylog only models the live-collection subset of the upstream receiver's options. The upstream | ||
| * {@code archive_path} (one-shot collection from a static {@code .logarchive}) and {@code end_time} | ||
| * (a bounded, finite collection window) options are intentionally omitted: the collector is meant | ||
| * for continuous live tailing, so those would only ever produce one-shot behavior. | ||
| * | ||
| * @see <a href="https://github.com/Graylog2/collector/tree/main/receiver/macosunifiedloggingreceiver">macOS Unified Logging Receiver</a> | ||
| */ | ||
| @AutoValue | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| public abstract class MacOSUnifiedLoggingReceiverConfig implements CollectorReceiverConfig { | ||
| public static final String RECEIVER_TYPE = "macos_unified_logging"; | ||
|
|
||
| public String type() { | ||
| return RECEIVER_TYPE; | ||
| } | ||
|
|
||
| @Override | ||
| public EnumSet<CollectorOSType> osSupport() { | ||
| return EnumSet.of(CollectorOSType.MACOS); | ||
| } | ||
|
|
||
| @Nullable | ||
| @JsonProperty("predicate") | ||
| public abstract String predicate(); | ||
|
|
||
| @JsonProperty("max_poll_interval") | ||
| @JsonSerialize(using = GoDurationSerializer.class) | ||
| public abstract Duration maxPollInterval(); | ||
|
|
||
| @JsonProperty("max_log_age") | ||
| @JsonSerialize(using = GoDurationSerializer.class) | ||
| public abstract Duration maxLogAge(); | ||
|
|
||
| @JsonProperty("format") | ||
| public String format() { | ||
| return "ndjson"; | ||
| } | ||
|
|
||
| // Persists the live-mode forward cursor; required for cursor tracking and de-duplication. | ||
| @JsonProperty("storage") | ||
| public abstract String storage(); | ||
|
|
||
|
|
||
| public static Builder builder(String id) { | ||
| return new AutoValue_MacOSUnifiedLoggingReceiverConfig.Builder() | ||
| .name(f("macos_unified_logging/%s", id)) | ||
| .maxPollInterval(Duration.ofSeconds(30)) | ||
| .maxLogAge(Duration.ofHours(24)) | ||
| .storage(FileStorageExtensionConfig.defaultInstance().name()); | ||
| } | ||
|
|
||
| @AutoValue.Builder | ||
| public abstract static class Builder { | ||
| public abstract Builder name(String name); | ||
|
|
||
| public abstract Builder predicate(@Nullable String predicate); | ||
|
|
||
| public abstract Builder maxPollInterval(Duration maxPollInterval); | ||
|
|
||
| public abstract Builder maxLogAge(Duration maxLogAge); | ||
|
|
||
| public abstract Builder storage(String storage); | ||
|
|
||
| public abstract MacOSUnifiedLoggingReceiverConfig build(); | ||
| } | ||
| } |
100 changes: 100 additions & 0 deletions
100
graylog2-server/src/main/java/org/graylog/collectors/db/MacOSUnifiedLoggingSourceConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * Copyright (C) 2020 Graylog, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the Server Side Public License, version 1, | ||
| * as published by MongoDB, Inc. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * Server Side Public License for more details. | ||
| * | ||
| * You should have received a copy of the Server Side Public License | ||
| * along with this program. If not, see | ||
| * <http://www.mongodb.com/licensing/server-side-public-license>. | ||
| */ | ||
| package org.graylog.collectors.db; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.fasterxml.jackson.annotation.JsonTypeName; | ||
| import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
| import com.google.auto.value.AutoValue; | ||
| import com.google.common.base.Strings; | ||
| import jakarta.annotation.Nullable; | ||
| import org.graylog.collectors.config.receiver.CollectorReceiverConfig; | ||
| import org.graylog.collectors.config.receiver.MacOSUnifiedLoggingReceiverConfig; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.Optional; | ||
|
|
||
| @AutoValue | ||
| @JsonTypeName(MacOSUnifiedLoggingSourceConfig.TYPE_NAME) | ||
| @JsonDeserialize(builder = MacOSUnifiedLoggingSourceConfig.Builder.class) | ||
| public abstract class MacOSUnifiedLoggingSourceConfig implements SourceConfig { | ||
| public static final String TYPE_NAME = "macos_unified_logging"; | ||
|
|
||
| @Override | ||
| @JsonProperty(TYPE_FIELD) | ||
| public abstract String type(); | ||
|
|
||
| @Nullable | ||
| @JsonProperty("predicate") | ||
| public abstract String predicate(); | ||
|
|
||
| @JsonProperty("max_poll_interval") | ||
| public abstract Duration maxPollInterval(); | ||
|
|
||
| @JsonProperty("max_log_age") | ||
| public abstract Duration maxLogAge(); | ||
|
|
||
| public static Builder builder() { | ||
| return Builder.create(); | ||
| } | ||
|
|
||
| @Override | ||
| public void validate() { | ||
| // empty predicates are valid | ||
| if (maxPollInterval().isZero() || maxPollInterval().isNegative()) { | ||
| throw new IllegalArgumentException("max_poll_interval must be positive"); | ||
| } | ||
| if (maxLogAge().isNegative()) { | ||
| throw new IllegalArgumentException("max_log_age must be zero or positive"); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<CollectorReceiverConfig> toReceiverConfig(String id) { | ||
| final var builder = MacOSUnifiedLoggingReceiverConfig.builder(id) | ||
| .maxLogAge(maxLogAge()) | ||
| .maxPollInterval(maxPollInterval()); | ||
| if (predicate() != null) { | ||
| builder.predicate(Strings.emptyToNull(predicate())); | ||
| } | ||
| return Optional.of(builder.build()); | ||
| } | ||
|
|
||
| @AutoValue.Builder | ||
| public abstract static class Builder { | ||
| @JsonCreator | ||
| public static Builder create() { | ||
| return new AutoValue_MacOSUnifiedLoggingSourceConfig.Builder() | ||
| .type(TYPE_NAME); | ||
| } | ||
|
|
||
| @JsonProperty(TYPE_FIELD) | ||
| public abstract Builder type(String type); | ||
|
|
||
| @JsonProperty("predicate") | ||
| public abstract Builder predicate(@Nullable String predicate); | ||
|
|
||
| @JsonProperty("max_poll_interval") | ||
| public abstract Builder maxPollInterval(Duration maxPollInterval); | ||
|
|
||
| @JsonProperty("max_log_age") | ||
| public abstract Builder maxLogAge(Duration maxLogAge); | ||
|
|
||
| public abstract MacOSUnifiedLoggingSourceConfig build(); | ||
| } | ||
| } |
102 changes: 102 additions & 0 deletions
102
.../main/java/org/graylog/collectors/input/processor/MacOSUnifiedLoggingRecordProcessor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /* | ||
| * Copyright (C) 2020 Graylog, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the Server Side Public License, version 1, | ||
| * as published by MongoDB, Inc. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * Server Side Public License for more details. | ||
| * | ||
| * You should have received a copy of the Server Side Public License | ||
| * along with this program. If not, see | ||
| * <http://www.mongodb.com/licensing/server-side-public-license>. | ||
| */ | ||
| package org.graylog.collectors.input.processor; | ||
|
|
||
| import com.google.common.base.Strings; | ||
| import org.apache.commons.lang.StringUtils; | ||
| import org.graylog.inputs.otel.OTelJournal; | ||
| import org.graylog.schema.EventFields; | ||
| import org.graylog.schema.ProcessFields; | ||
| import org.graylog.schema.UserFields; | ||
| import org.graylog.schema.VendorFields; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Processes macOS unified logging records into GIM fields. | ||
| * <p> | ||
| * The fixed receiver emits a plain-text body (the human-readable message), native OTel severity | ||
| * and timestamp — all handled by {@link org.graylog.collectors.input.CollectorIngestCodec} — plus | ||
| * structured {@code macos.*} attributes. This processor maps only those attributes: well-fitting | ||
| * ones to GIM fields, and macOS-specific identifiers (boot session, activity/trace IDs, sender | ||
| * image) preserved under a {@code macos_*} prefix. | ||
| * | ||
| * @see <a href="https://developer.apple.com/documentation/os/logging">Apple Unified Logging</a> | ||
| */ | ||
| public class MacOSUnifiedLoggingRecordProcessor implements LogRecordProcessor { | ||
|
|
||
| @Override | ||
| public Map<String, Object> process(OTelJournal.Log log) { | ||
| final Map<String, Object> result = new HashMap<>(); | ||
| String processImagePath = null; | ||
|
|
||
| for (final var attr : log.getLogRecord().getAttributesList()) { | ||
| final var value = attr.getValue(); | ||
| switch (attr.getKey()) { | ||
| // Mapped to GIM fields. | ||
| case "macos.subsystem" -> putStr(result, EventFields.EVENT_SOURCE, value.getStringValue()); | ||
| case "macos.category" -> putStr(result, VendorFields.VENDOR_SUBTYPE, value.getStringValue()); | ||
| case "macos.eventType" -> putStr(result, VendorFields.VENDOR_EVENT_TYPE, value.getStringValue()); | ||
| case "macos.formatString" -> putStr(result, VendorFields.VENDOR_EVENT_DESCRIPTION, value.getStringValue()); | ||
| case "macos.processImagePath" -> { | ||
| final var path = Strings.emptyToNull(value.getStringValue()); | ||
| if (path != null) { | ||
| processImagePath = path; | ||
| result.put(ProcessFields.PROCESS_PATH, path); | ||
| } | ||
| } | ||
| case "macos.processID" -> result.put(ProcessFields.PROCESS_ID, Long.toString(value.getIntValue())); | ||
| case "macos.userID" -> result.put(UserFields.USER_ID, Long.toString(value.getIntValue())); | ||
| // macOS-specific identifiers preserved under a macos_* prefix. | ||
| case "macos.threadID" -> result.put("macos_thread_id", value.getIntValue()); | ||
| case "macos.bootUUID" -> putStr(result, "macos_boot_uuid", value.getStringValue()); | ||
| case "macos.machTimestamp" -> result.put("macos_mach_timestamp", value.getIntValue()); | ||
| case "macos.traceID" -> result.put("macos_trace_id", value.getIntValue()); | ||
| case "macos.activityIdentifier" -> result.put("macos_activity_id", value.getIntValue()); | ||
| case "macos.parentActivityIdentifier" -> result.put("macos_parent_activity_id", value.getIntValue()); | ||
| case "macos.creatorActivityID" -> result.put("macos_creator_activity_id", value.getIntValue()); | ||
| case "macos.processImageUUID" -> putStr(result, "macos_process_image_uuid", value.getStringValue()); | ||
| case "macos.senderImagePath" -> putStr(result, "macos_sender_image_path", value.getStringValue()); | ||
| case "macos.senderImageUUID" -> putStr(result, "macos_sender_image_uuid", value.getStringValue()); | ||
| case "macos.senderProgramCounter" -> result.put("macos_sender_program_counter", value.getIntValue()); | ||
| default -> { | ||
| // Ignore non-macos attributes. | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Derive the process name from the executable path. | ||
| if (processImagePath != null) { | ||
| Path path = Paths.get(processImagePath); | ||
| final var fileName = path.getFileName(); | ||
| if (fileName != null) { | ||
| result.put(ProcessFields.PROCESS_NAME, fileName.toString()); | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| private static void putStr(Map<String, Object> target, String field, String value) { | ||
| if (StringUtils.isNotBlank(value)) { | ||
| target.put(field, value); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.