Skip to content

Commit 912c3c5

Browse files
committed
up
1 parent cc2dc07 commit 912c3c5

File tree

5 files changed

+327
-138
lines changed

5 files changed

+327
-138
lines changed

crowdsec-docs/docs/log_processor/service-discovery-setup/detect-yaml.md

Lines changed: 70 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ title: detect.yaml file format
44
sidebar_position: 1
55
---
66

7-
# File layout: `detect.yaml`
8-
A minimal detection file is a YAML map with a top‐level `detect:` key. Under it, each entry describes one service plan:
7+
# `detect.yaml` syntax
8+
9+
A minimal detection file is a YAML map with a top‐level `detect:` key.
10+
11+
Under it, each entry describes one service plan:
912

1013
```yaml
1114
# detect.yaml
@@ -27,19 +30,58 @@ detect:
2730
type: apache2
2831
```
2932
30-
Fields
33+
## Fields
34+
35+
### `when`
36+
37+
A list of expression that must return a boolean.
38+
39+
If multiple expressions are provided, they must all return `true` for the service to be included.
40+
41+
```yaml
42+
when:
43+
- Host.OS == "linux"
44+
- Systemd.UnitInstalled("<unit>")
45+
```
46+
47+
You can use any of the helper referenced [here](/log_processor/service-discovery-setup/expr.md).
48+
)
49+
50+
### `hub_spec`
51+
52+
A map of hub items to install.
53+
54+
Specifying an invalid item type or item will log an error but will not prevent the detection to continue.
55+
56+
```yaml
57+
hub_spec:
58+
collections:
59+
- crowdsecurity/linux
60+
parsers:
61+
- crowdsecurity/nginx-logs
62+
scenarios:
63+
- crowdsecurity/http-bf
64+
```
65+
66+
### `acquisition_spec`
67+
68+
This item defines the acquisition that will be written to disk
69+
70+
```yaml
71+
acquisition_spec:
72+
filename: foobar.yaml
73+
datasource:
74+
source: docker
75+
container_name: foo
76+
labels:
77+
type: bar
78+
```
79+
80+
The `filename` attribute will be used to generate the name of file in the form of `acquis.d/setup.<filename>.yaml`.
3181

32-
- `when`: a list of boolean expressions evaluated on the host. Examples include:
33-
- `Systemd.UnitInstalled("<unit>")`, `Windows.ServiceEnabled("<name>")`
34-
- `Host.OS == "linux"`, `Host.OS == "windows"`
35-
- `Path.Exists("/path/file")`, `len(Path.Glob("/path/*.log")) > 0`
36-
- `System.ProcessRunning("<binary>")`
37-
- `hub_spec`: which Hub items to install (collections/parsers/scenarios, etc.). Unknown item types are preserved and passed through.
38-
- `acquisition_spec`: how to generate a per‐service acquisition file:
39-
- `filename`: base name (no slashes). The actual path will be `acquis.d/setup.<filename>.yaml`.
40-
- `datasource`: a map validated against the selected `source` (e.g., `file`, `journalctl`, `docker`, `wineventlog`, `cloudwatch`, `kinesis`, …). Required fields vary per source; the CLI validates them for you.
82+
The content of `datasource` will be validated (syntax, required fields depending on the datasource configured) and be written as-is to the file.
4183

42-
Examples
84+
## Examples
4385

4486
Basic OS / Hub only:
4587

@@ -49,7 +91,8 @@ detect:
4991
when:
5092
- Host.OS == "linux"
5193
hub_spec:
52-
collections: [crowdsecurity/linux]
94+
collections:
95+
- crowdsecurity/linux
5396
```
5497

5598
`journalctl` source with a filter:
@@ -61,12 +104,14 @@ detect:
61104
- Systemd.UnitInstalled("caddy.service")
62105
- len(Path.Glob("/var/log/caddy/*.log")) == 0
63106
hub_spec:
64-
collections: [crowdsecurity/caddy]
107+
collections:
108+
- crowdsecurity/caddy
65109
acquisition_spec:
66110
filename: caddy.yaml
67111
datasource:
68112
source: journalctl
69-
labels: {type: caddy}
113+
labels:
114+
type: caddy
70115
journalctl_filter:
71116
- "_SYSTEMD_UNIT=caddy.service"
72117
```
@@ -76,45 +121,22 @@ Windows event log:
76121
```yaml
77122
detect:
78123
windows_auth:
79-
when: [ Host.OS == "windows" ]
124+
when:
125+
- Host.OS == "windows"
80126
hub_spec:
81-
collections: [crowdsecurity/windows]
127+
collections:
128+
- crowdsecurity/windows
82129
acquisition_spec:
83130
filename: windows_auth.yaml
84131
datasource:
85132
source: wineventlog
86133
event_channel: Security
87-
event_ids: [4625, 4623]
134+
event_ids:
135+
- 4625
136+
- 4623
88137
event_level: information
89-
labels: {type: eventlog}
138+
labels:
139+
type: eventlog
90140
```
91141

92142

93-
## Expression Helpers Reference
94-
95-
Expressions run against an environment that exposes helpers and facts via these names:
96-
97-
- Host — host facts from gopsutil/host.InfoStat. See https://pkg.go.dev/github.com/shirou/gopsutil/host#InfoStat
98-
Example: Host.OS == "linux".
99-
100-
- Path — filesystem helpers:
101-
- Path.Exists(path) -> bool
102-
- Path.Glob(pattern) -> []string
103-
Example: len(Path.Glob("/var/log/nginx/*.log")) > 0.
104-
105-
- System — process helpers:
106-
- System.ProcessRunning(name) -> bool (by process name)
107-
108-
- Systemd (Linux) — systemd unit helpers:
109-
- Systemd.UnitInstalled(unit) -> bool
110-
- Systemd.UnitConfig(unit, key) -> string (empty string if unit missing; error if key missing)
111-
- Systemd.UnitLogsToJournal(unit) -> bool (true if stdout/stderr go to journal or journal+console)
112-
113-
- Windows (Windows builds only):
114-
- Windows.ServiceEnabled(service) -> bool (true if the service exists and is Automatic start; returns false on non-Windows builds)
115-
116-
- Version — semantic version checks (can be used with Host.PlatformVersion):
117-
- Version.Check(version, constraint) -> bool
118-
- Supports operators like =, !=, <, <=, >, >=, ranges (1.1.1 - 1.3.4), AND with commas (>1, <3), and ~ compatible ranges.
119-
120-
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
---
2+
id: setup-expr-helpers
3+
title: Expr Helpers
4+
sidebar_position: 1
5+
---
6+
7+
# Expression Helpers Reference
8+
9+
Various helpers are available for use in the `detect.yaml` file to determine how crowdsec should be configured.
10+
11+
## Host
12+
13+
This object gives access to various information about the current state of the operating system
14+
15+
### `Host.Hostname`
16+
17+
&nbsp;&nbsp;&nbsp;&nbsp;Returns the hostname of the machine
18+
19+
> `Host.Hostname == "mymachine"`
20+
21+
### `Host.Uptime`
22+
23+
&nbsp;&nbsp;&nbsp;&nbsp;Returns the uptime of the machine in seconds.
24+
25+
### `Host.Boottime`
26+
27+
&nbsp;&nbsp;&nbsp;&nbsp;Returns the unix timestamp of the time the machine booted.
28+
29+
### `Host.Procs`
30+
31+
&nbsp;&nbsp;&nbsp;&nbsp;Returns the number of processes on the machine.
32+
33+
### `Host.OS`
34+
35+
&nbsp;&nbsp;&nbsp;&nbsp;Returns the name of the OS (`linux`, `freebsd`, `windows`, ...)
36+
37+
> `Host.OS == "linux"`
38+
39+
### `Host.Platform`
40+
41+
&nbsp;&nbsp;&nbsp;&nbsp;Returns the variant of the OS (`ubuntu`, `linuxmint`, ....)
42+
43+
> `Host.Platform == "ubuntu"`
44+
45+
### `Host.PlatformFamily`
46+
47+
&nbsp;&nbsp;&nbsp;&nbsp;Returns the family of the OS (`debian`, `rhel`, ...)
48+
49+
> `Host.Platform == "debian"`
50+
51+
### `Host.KernelVersion`
52+
53+
&nbsp;&nbsp;&nbsp;&nbsp;Returns the current kernel version as returned by `uname -r`
54+
55+
> `Host.KernelVersion == "6.16.2"
56+
57+
### `Host.KernelArch`
58+
59+
&nbsp;&nbsp;&nbsp;&nbsp;Returns the native architecture of the system (`x86_64`, ...)
60+
61+
> `Host.KernelArch == "x86_64"`
62+
63+
### `Host.VirtualizationSystem`
64+
65+
&nbsp;&nbsp;&nbsp;&nbsp;Returns the name of the virtualization system in use if any.
66+
67+
> `Host.VirtualizationSystem == "kvm"`
68+
69+
### `Host.VirtualizationRole`
70+
71+
&nbsp;&nbsp;&nbsp;&nbsp;Returns the virtualization role of the system if any (`guest`, `host`)
72+
73+
> `Host.VirtualizationRole == "host"`
74+
75+
### `Host.HostID`
76+
77+
&nbsp;&nbsp;&nbsp;&nbsp;Returns a unique ID specific to the system.
78+
79+
## Path
80+
81+
This object exposes helpers functions for the filesystem
82+
83+
### `Exists(path) bool`
84+
85+
&nbsp;&nbsp;&nbsp;&nbsp;Returns `true` if the specified path exists.
86+
87+
> `Path.Exists("/var/log/nginx/access.log") == true`
88+
89+
### `Glob(pattern) []string`
90+
91+
&nbsp;&nbsp;&nbsp;&nbsp;Returns a list of files matching the provided pattern.
92+
93+
&nbsp;&nbsp;&nbsp;&nbsp;Returns an empty list if the glob pattern is invalid
94+
95+
> `len(Path.Glob("/var/log/nginx/*.log")) > 0`
96+
97+
## System
98+
99+
### `ProcessRunning(name) bool`
100+
101+
&nbsp;&nbsp;&nbsp;&nbsp;Returns `true` if there's any with the specified name running
102+
103+
> `System.ProcessRunning("nginx") == true`
104+
105+
## Systemd
106+
107+
&nbsp;&nbsp;&nbsp;&nbsp;This object exposes helpers to get informations about systemd units.
108+
109+
&nbsp;&nbsp;&nbsp;&nbsp;Only available on Linux.
110+
111+
### `UnitInstalled(unitName) bool`
112+
113+
&nbsp;&nbsp;&nbsp;&nbsp;Returns `true` if the provided unit is installed.
114+
115+
> `Systemd.UnitInstalled("nginx") == true`
116+
117+
### `UnitConfig(unitName, key) string`
118+
119+
&nbsp;&nbsp;&nbsp;&nbsp;Returns the value of the specified key from the specified unit.
120+
121+
&nbsp;&nbsp;&nbsp;&nbsp;Returns an empty value if the unit if not installed and an error if the key does not exist.
122+
123+
> `Systemd.UnitConfig("nginx", "StandardOutput") == "journal"`
124+
125+
### `UnitLogsToJournal(unitName) bool`
126+
127+
&nbsp;&nbsp;&nbsp;&nbsp;Returns `true` if unit stdout/stderr are redirect to journal or journal+console.
128+
129+
> `Systemd.UnitLogsToJournal("nginx") == true`
130+
131+
## Windows
132+
133+
&nbsp;&nbsp;&nbsp;&nbsp;This object exposes helpers to get informations about Windows services.
134+
135+
&nbsp;&nbsp;&nbsp;&nbsp;Only available on Windows.
136+
137+
### `ServiceEnabled(serviceName) bool`
138+
139+
&nbsp;&nbsp;&nbsp;&nbsp;Returns `true` if the specified service exists and is configured to start automatically on boot.
140+
141+
> `Windows.ServiceEnabled("MSSSQLSERVER") == true`
142+
143+
## Version
144+
145+
### `Check(version, constraint) bool`
146+
147+
&nbsp;&nbsp;&nbsp;&nbsp;Performs a semantic version check.
148+
149+
&nbsp;&nbsp;&nbsp;&nbsp;Constraint supports operators like `=`, `!=`, `<`, `<=`, `>`, `>=`, ranges (1.1.1 - 1.3.4), AND with commas (`>1`, `<3`), and ~ compatible ranges.
150+
151+
> `Version.Check(Host.KernelVersion, ">=6.24.0")`

0 commit comments

Comments
 (0)