|
1 | 1 | #cloud-config |
| 2 | +{{- if and .AppCode .OtelAuthToken .OtelIndex}} |
| 3 | +write_files: |
| 4 | + - path: /etc/otelcol-contrib/config.yaml |
| 5 | + permissions: '0640' |
| 6 | + content: | |
| 7 | + receivers: |
| 8 | + filelog/syslog: |
| 9 | + include: |
| 10 | + - /var/log/messages |
| 11 | + start_at: end |
| 12 | + include_file_path: true |
| 13 | + include_file_name: true |
| 14 | + exclude_older_than: 24h |
| 15 | + operators: |
| 16 | + - type: move |
| 17 | + id: move_to_source_name |
| 18 | + from: attributes["log.file.path"] |
| 19 | + to: attributes["_sourceName"] |
| 20 | + - type: remove |
| 21 | + id: remove_file_name |
| 22 | + field: attributes["log.file.name"] |
| 23 | + - type: time_parser |
| 24 | + id: parse_timestamp |
| 25 | + layout: '%b %e %H:%M:%S' |
| 26 | + parse_from: body |
| 27 | + on_error: send |
| 28 | + attributes: |
| 29 | + index: "{{.OtelIndex}}" |
| 30 | + _sourceCategory: syslog |
| 31 | + _sourceHost: ${env:HOSTNAME} |
| 32 | + filelog/secure: |
| 33 | + include: |
| 34 | + - /var/log/secure |
| 35 | + start_at: end |
| 36 | + include_file_path: true |
| 37 | + include_file_name: true |
| 38 | + exclude_older_than: 24h |
| 39 | + operators: |
| 40 | + - type: move |
| 41 | + id: move_to_source_name |
| 42 | + from: attributes["log.file.path"] |
| 43 | + to: attributes["_sourceName"] |
| 44 | + - type: remove |
| 45 | + id: remove_file_name |
| 46 | + field: attributes["log.file.name"] |
| 47 | + - type: time_parser |
| 48 | + id: parse_timestamp |
| 49 | + layout: '%b %e %H:%M:%S' |
| 50 | + parse_from: body |
| 51 | + on_error: send |
| 52 | + attributes: |
| 53 | + index: "{{.OtelIndex}}" |
| 54 | + _sourceCategory: secure |
| 55 | + _sourceHost: ${env:HOSTNAME} |
| 56 | + filelog/audit: |
| 57 | + include: |
| 58 | + - /var/log/audit/audit.log |
| 59 | + start_at: end |
| 60 | + include_file_path: true |
| 61 | + include_file_name: true |
| 62 | + exclude_older_than: 24h |
| 63 | + operators: |
| 64 | + - type: move |
| 65 | + id: move_to_source_name |
| 66 | + from: attributes["log.file.path"] |
| 67 | + to: attributes["_sourceName"] |
| 68 | + - type: remove |
| 69 | + id: remove_file_name |
| 70 | + field: attributes["log.file.name"] |
| 71 | + attributes: |
| 72 | + index: "{{.OtelIndex}}" |
| 73 | + _sourceCategory: audit |
| 74 | + _sourceHost: ${env:HOSTNAME} |
| 75 | + processors: |
| 76 | + filter/drop_null_bytes: |
| 77 | + logs: |
| 78 | + log_record: |
| 79 | + - 'IsMatch(body, "^\x00+$")' |
| 80 | + batch: |
| 81 | + timeout: "1s" |
| 82 | + send_batch_size: 1024 |
| 83 | + resource: |
| 84 | + attributes: |
| 85 | + - key: appcode |
| 86 | + value: "{{.AppCode}}" |
| 87 | + action: upsert |
| 88 | + - key: com.redhat.otel.auth_token |
| 89 | + value: "${env:OTEL_AUTH_TOKEN}" |
| 90 | + action: upsert |
| 91 | + - key: arch |
| 92 | + value: "{{.OtelArch}}" |
| 93 | + action: upsert |
| 94 | +{{- range $k, $v := .OtelExtraAttrs}} |
| 95 | + - key: {{$k}} |
| 96 | + value: "{{$v}}" |
| 97 | + action: upsert |
| 98 | +{{- end}} |
| 99 | + exporters: |
| 100 | + otlphttp: |
| 101 | + endpoint: "{{.OtelEndpoint}}" |
| 102 | + tls: |
| 103 | + insecure_skip_verify: true |
| 104 | + service: |
| 105 | + telemetry: |
| 106 | + logs: |
| 107 | + level: "fatal" |
| 108 | + metrics: |
| 109 | + level: "basic" |
| 110 | + pipelines: |
| 111 | + logs: |
| 112 | + receivers: [filelog/syslog, filelog/secure, filelog/audit] |
| 113 | + processors: [filter/drop_null_bytes, resource, batch] |
| 114 | + exporters: [otlphttp] |
| 115 | + - path: /etc/otelcol-contrib/auth_token |
| 116 | + permissions: '0600' |
| 117 | + content: | |
| 118 | + OTEL_AUTH_TOKEN={{.OtelAuthToken}} |
| 119 | + - path: /etc/systemd/system/otelcol-contrib.service.d/capabilities.conf |
| 120 | + permissions: '0644' |
| 121 | + content: | |
| 122 | + [Service] |
| 123 | + AmbientCapabilities=CAP_DAC_READ_SEARCH |
| 124 | + Environment="HOSTNAME=%H" |
| 125 | + EnvironmentFile=/etc/otelcol-contrib/auth_token |
| 126 | +{{- end}} |
2 | 127 | runcmd: |
3 | 128 | - | |
4 | 129 | IFACE=$(ip route show default | awk '/default/ {print $5; exit}') |
5 | 130 | ip route add 10.0.0.0/8 via {{.Gateway}} dev "$IFACE" 2>/dev/null || true |
6 | 131 | echo "10.0.0.0/8 via {{.Gateway}}" > "/etc/sysconfig/network-scripts/route-$IFACE" |
| 132 | +{{- if and .AppCode .OtelAuthToken .OtelIndex}} |
| 133 | + - | |
| 134 | + PROXY_URL="" |
| 135 | + if ! curl -sf --connect-timeout 5 --head {{.OtelEndpoint}} > /dev/null 2>&1; then |
| 136 | + PROXY_URL="http://squid.corp.redhat.com:3128" |
| 137 | + fi |
| 138 | + RPM_URL="https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v{{.OtelColVersion}}/otelcol-contrib_{{.OtelColVersion}}_linux_ppc64le.rpm" |
| 139 | + HTTPS_PROXY="$PROXY_URL" curl -fsSL -o /tmp/otelcol-contrib.rpm "$RPM_URL" |
| 140 | + rpm -i /tmp/otelcol-contrib.rpm |
| 141 | + rm -f /tmp/otelcol-contrib.rpm |
| 142 | + chown -R otelcol-contrib:otelcol-contrib /etc/otelcol-contrib |
| 143 | + if [ -n "$PROXY_URL" ]; then |
| 144 | + printf '[Service]\nEnvironment="HTTPS_PROXY=%s/"\nEnvironment="NO_PROXY=10.*,192.168.*,localhost,127.0.0.1"\n' "$PROXY_URL" \ |
| 145 | + > /etc/systemd/system/otelcol-contrib.service.d/proxy.conf |
| 146 | + fi |
| 147 | + systemctl daemon-reload |
| 148 | + systemctl enable --now otelcol-contrib |
| 149 | +{{- end}} |
0 commit comments