From a2de44dcde2b5e4e57479fb1b3ed01b090403bfe Mon Sep 17 00:00:00 2001 From: Matt Cotter Date: Thu, 2 Jan 2025 12:24:28 -0600 Subject: [PATCH] feat: add exclude config option for excluding host log files --- internal/config/configschema.go | 1 + .../connections/host_monitoring/logs.yaml | 6 ++++++ .../connections/host_monitoring/logs.yaml | 6 ++++++ .../macos/connections/host_monitoring/logs.yaml | 15 ++++++++++++++- scripts/install_mac.sh | 17 +++++++++++------ 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/internal/config/configschema.go b/internal/config/configschema.go index 15abd0e7..54fb033a 100644 --- a/internal/config/configschema.go +++ b/internal/config/configschema.go @@ -12,6 +12,7 @@ import ( type HostMonitoringLogsConfig struct { Enabled bool `yaml:"enabled" mapstructure:"enabled"` Include []string `yaml:"include,omitempty" mapstructure:"include"` + Exclude []string `yaml:"exclude,omitempty" mapstructure:"exclude"` } type HostMonitoringHostMetricsConfig struct { diff --git a/packaging/docker/observe-agent/connections/host_monitoring/logs.yaml b/packaging/docker/observe-agent/connections/host_monitoring/logs.yaml index d9b89d94..88b11bc3 100644 --- a/packaging/docker/observe-agent/connections/host_monitoring/logs.yaml +++ b/packaging/docker/observe-agent/connections/host_monitoring/logs.yaml @@ -9,6 +9,12 @@ receivers: - /hostfs/var/log/**/*.log - /hostfs/var/log/syslog {{- end }} + {{- if .Logs.Exclude }} + exclude: + {{- range .Logs.Exclude }} + - {{ . }} + {{- end }} + {{- end }} include_file_path: true storage: file_storage retry_on_failure: diff --git a/packaging/linux/etc/observe-agent/connections/host_monitoring/logs.yaml b/packaging/linux/etc/observe-agent/connections/host_monitoring/logs.yaml index 891cfd42..0f203036 100644 --- a/packaging/linux/etc/observe-agent/connections/host_monitoring/logs.yaml +++ b/packaging/linux/etc/observe-agent/connections/host_monitoring/logs.yaml @@ -9,6 +9,12 @@ receivers: - /var/log/**/*.log - /var/log/syslog {{- end }} + {{- if .Logs.Exclude }} + exclude: + {{- range .Logs.Exclude }} + - {{ . }} + {{- end }} + {{- end }} include_file_path: true storage: file_storage retry_on_failure: diff --git a/packaging/macos/connections/host_monitoring/logs.yaml b/packaging/macos/connections/host_monitoring/logs.yaml index 77df7a4d..917c47a1 100644 --- a/packaging/macos/connections/host_monitoring/logs.yaml +++ b/packaging/macos/connections/host_monitoring/logs.yaml @@ -1,6 +1,19 @@ receivers: filelog/host_monitoring: - include: [/var/log/**/*.log] + include: + {{- if .Logs.Include }} + {{- range .Logs.Include }} + - {{ . }} + {{- end }} + {{- else }} + - /var/log/**/*.log + {{- end }} + {{- if .Logs.Exclude }} + exclude: + {{- range .Logs.Exclude }} + - {{ . }} + {{- end }} + {{- end }} include_file_path: true storage: file_storage retry_on_failure: diff --git a/scripts/install_mac.sh b/scripts/install_mac.sh index a2d7fdb4..b8857a61 100644 --- a/scripts/install_mac.sh +++ b/scripts/install_mac.sh @@ -31,6 +31,9 @@ while [ $# -gt 0 ]; do --metrics_enabled) METRICS_ENABLED="$arg" ;; + --setup_launch_daemon) + SETUP_LAUNCH_DAEMON="$arg" + ;; *) echo "Unknown option: $opt" exit 1 @@ -114,12 +117,14 @@ sudo ln -sf $observeagent_install_dir/observe-agent /usr/local/bin echo "Observe agent successfully installed to $observeagent_install_dir" -# Install the launchd agent -echo "Installing $service_name as a LaunchDaemon. This may ask for your password..." -sudo cp -f $tmp_dir/observe-agent.plist /Library/LaunchDaemons/$service_name.plist -sudo chown root:wheel /Library/LaunchDaemons/$service_name.plist -sudo launchctl load -w /Library/LaunchDaemons/$service_name.plist -sudo launchctl kickstart "system/$service_name" +# Install the launchd agent unless the variable is specified to false +if [ -z "$SETUP_LAUNCH_DAEMON" ] || [[ "$(echo "$SETUP_LAUNCH_DAEMON" | tr '[:upper:]' '[:lower:]')" == "true" ]]; then + echo "Installing $service_name as a LaunchDaemon. This may ask for your password..." + sudo cp -f $tmp_dir/observe-agent.plist /Library/LaunchDaemons/$service_name.plist + sudo chown root:wheel /Library/LaunchDaemons/$service_name.plist + sudo launchctl load -w /Library/LaunchDaemons/$service_name.plist + sudo launchctl kickstart "system/$service_name" +fi echo echo "---"