|
| 1 | +--- |
| 2 | +id: intro |
| 3 | +title: Service Discovery & Setup |
| 4 | +sidebar_position: 1 |
| 5 | +--- |
| 6 | + |
| 7 | + |
| 8 | +> Implementation notes & validation |
| 9 | +> |
| 10 | +> - The CLI can list supported services from your file (`--list-supported-services`). It also validates each datasource by type and errors out on unknown/misplaced fields (e.g., `source` missing; wrong keys for `journalctl`/`docker`; filename with slashes). |
| 11 | +> |
| 12 | +
|
| 13 | +--- |
| 14 | + |
| 15 | +# Use your custom `detect.yaml` |
| 16 | +You can provide your file in two ways: |
| 17 | + |
| 18 | +```bash |
| 19 | +# Path flag (recommended) |
| 20 | +cscli setup detect --detect-config /path/to/detect.yaml |
| 21 | + |
| 22 | +# Or via environment variable |
| 23 | +CROWDSEC_SETUP_DETECT_CONFIG=/path/to/detect.yaml cscli setup detect |
| 24 | +``` |
| 25 | + |
| 26 | +Helpful flags: |
| 27 | +- `--yaml` – render the setup plan as YAML (easy to review/edit); default output is JSON. |
| 28 | +- `--force <svc>` – pretend detection matched for `<svc>` (repeatable). |
| 29 | +- `--ignore <svc>` – drop `<svc>` from the plan even if matched (repeatable). |
| 30 | +- `--skip-systemd` – disable systemd‐based detection (useful in containers/chroots). |
| 31 | +- `--list-supported-services` – print the service keys present in your file and exit. |
| 32 | + |
| 33 | +**End‑to‑end flow (typical)** |
| 34 | +```bash |
| 35 | +# 1) build a plan from your rules |
| 36 | +cscli setup detect --detect-config ./detect.yaml --yaml > setup.yaml |
| 37 | + |
| 38 | +# 2) validate that plan (optional but recommended) |
| 39 | +cscli setup validate ./setup.yaml |
| 40 | + |
| 41 | +# 3) install Hub items + write acquis files |
| 42 | +cscli setup install-hub ./setup.yaml |
| 43 | +cscli setup install-acquisition ./setup.yaml --acquis-dir /etc/crowdsec/acquis.d |
| 44 | +``` |
| 45 | + |
| 46 | +# Examples: override defaults (nginx path, etc.) |
| 47 | +If your logs live in non‑standard locations, just encode that in `acquisition_spec`. |
| 48 | + |
| 49 | +```yaml |
| 50 | +# detect.yaml |
| 51 | +--- |
| 52 | +detect: |
| 53 | + nginx-custom: |
| 54 | + when: |
| 55 | + - Systemd.UnitInstalled("nginx.service") or len(Path.Glob("/srv/logs/nginx/*.log")) > 0 |
| 56 | + hub_spec: |
| 57 | + collections: [crowdsecurity/nginx] |
| 58 | + acquisition_spec: |
| 59 | + filename: nginx.yaml |
| 60 | + datasource: |
| 61 | + source: file |
| 62 | + filenames: |
| 63 | + - /srv/logs/nginx/*.log # <- your path here |
| 64 | + labels: {type: nginx} |
| 65 | +``` |
| 66 | +
|
| 67 | +You can also define detection purely by process name when systemd isn’t a good signal: |
| 68 | +```yaml |
| 69 | + app-by-process: |
| 70 | + when: [ System.ProcessRunning("myappd") ] |
| 71 | + acquisition_spec: |
| 72 | + filename: myappd.yaml |
| 73 | + datasource: |
| 74 | + source: file |
| 75 | + filenames: [ /var/log/myappd/*.log ] |
| 76 | + labels: {type: myappd} |
| 77 | +``` |
| 78 | +
|
| 79 | +--- |
| 80 | +
|
| 81 | +# Generated acquisition files & coexistence with your own files |
| 82 | +When you install acquisition from a setup plan, the CLI writes one file per service as `setup.<name>.yaml` in the acquisition directory (typically `/etc/crowdsec/acquis.d`). The content is **prefixed with a header** that includes a truncated `cscli-checksum` and a comment stating it was generated by `cscli setup`. |
| 83 | + |
| 84 | +- Files carrying a valid `cscli-checksum` are considered **generated** and may be overwritten by future runs. |
| 85 | +- Files **without** a valid checksum are treated as **manually edited**; in interactive flows, the CLI shows a colorized diff and asks before overwriting. In unattended flows, the command refuses to proceed if manual files are detected. |
| 86 | +- Either way, the safest practice is: **don’t edit generated files**. If you need changes, delete the generated `setup.<name>.yaml` and create your own hand‑managed file instead. |
| 87 | + |
| 88 | +> Tips |
| 89 | +> - The actual on‑disk path is computed as `acquis.d/setup.<filename>` where `<filename>` comes from `acquisition_spec.filename`. |
| 90 | +> - Use `--acquis-dir` to target a different directory. |
| 91 | +> - `--dry-run` prints what would be created without writing files. |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +# Unattended installs with a custom detect file |
| 96 | +Package installers often call: |
| 97 | + |
| 98 | +```bash |
| 99 | +cscli setup unattended |
| 100 | +``` |
| 101 | + |
| 102 | +This mode: |
| 103 | +- uses the same `--detect-config` and `--acquis-dir` flags; |
| 104 | +- never prompts for confirmation; |
| 105 | +- will skip itself entirely if `CROWDSEC_SETUP_UNATTENDED_DISABLE` is non‑empty (handy for Ansible/automation); |
| 106 | +- installs Hub items and writes `setup.*.yaml` files if and only if there are no conflicting manual acquisitions. |
| 107 | + |
| 108 | +--- |
| 109 | + |
| 110 | +# Validation & troubleshooting |
| 111 | +- **Validate your setup plan** before writing files: |
| 112 | + ```bash |
| 113 | + cscli setup validate ./setup.yaml |
| 114 | + ``` |
| 115 | +- Common validation errors (examples): |
| 116 | + - missing `datasource.source` |
| 117 | + - wrong keys for a source type (e.g., `filename` under `journalctl`) |
| 118 | + - missing mandatory fields (e.g., `journalctl_filter` for `journalctl`, `containers/services` for `docker`) |
| 119 | + - `acquisition_spec.filename` contains slashes/backslashes |
| 120 | + |
| 121 | +--- |
| 122 | + |
| 123 | +# Reference snippets |
| 124 | +- Linux collection detection: |
| 125 | + ```yaml |
| 126 | + detect: |
| 127 | + linux: |
| 128 | + when: [ Host.OS == "linux" ] |
| 129 | + hub_spec: |
| 130 | + collections: [crowdsecurity/linux] |
| 131 | + ``` |
| 132 | +- MariaDB/MySQL file detection with distro fallbacks: |
| 133 | + ```yaml |
| 134 | + detect: |
| 135 | + mariadb: |
| 136 | + when: |
| 137 | + - Systemd.UnitInstalled("mariadb.service") or Path.Exists("/var/log/mariadb/mariadb.log") |
| 138 | + hub_spec: { collections: [crowdsecurity/mariadb] } |
| 139 | + acquisition_spec: |
| 140 | + filename: mariadb.yaml |
| 141 | + datasource: |
| 142 | + source: file |
| 143 | + labels: {type: mysql} |
| 144 | + filenames: |
| 145 | + - /var/log/mysql/error.log |
| 146 | + - /var/log/mariadb/mariadb.log |
| 147 | + ``` |
| 148 | + |
0 commit comments