# Asset filter

### Overview

For Eliona apps with Continuous Asset Creation (CAC), it is useful to have the ability to choose which assets are created in Eliona. This can prevent the Infravolt budget from being exceeded.

Most apps with CAC therefore offer an asset filter as a configuration option. If the app supports this option, follow this document for configuration.

Note that the asset filter is empty by default and imports all available assets. Defining an asset filter is therefore completely optional.

### Structure

The `assetFilter` is a two-dimensional array, where:

* The **outer array** rules combined by logical **OR** (disjunction).
* Each **inner array** rules combined by logical **AND** (conjunction).
* Each rule is an object with the following properties:
  * `parameter`: The asset attribute to be checked.
  * `regex`: A regular expression for checking whether the attribute matches.

### Logical evaluation

The filter logic follows these rules:

* An asset **matches**if at least one inner array (AND rule group) is evaluated as `true` .
* An inner array is evaluated as **`true`** if all of its rules match.
* A rule **matches**, if the asset attribute defined in `parameter` matches the regular expression in `regex` .
* If `assetFilter` empty or `null` is, all assets pass the filter.

### Available parameters

While there are general parameters such as "name", each app has its own set of parameters. More information about the possible filter parameters can be found in the documentation of the respective app.

### Regular expressions

The `regex`-field enables advanced filtering with regular expressions. Here are some commonly used patterns:

* `.*` – Matches everything
* `^Main.*` – Matches strings that begin with "Main"
* `192\\.168\\..*` – Matches IP addresses in the 192.168 range.*.*
* `(A|B|C)` – Matches "A", "B", or "C"

### Example scenarios

#### 0. Import everything

```json
[]
```

#### 1. Filter devices with the name "Main" and type "Router"

```json
[
  [{ "parameter": "deviceName", "regex": "Main.*" },
   { "parameter": "deviceType", "regex": "Router" }]
]
```

#### 2. Filter devices with specific MAC addresses

```json
[
  [{ "parameter": "macAddress", "regex": "(70:82:0e:12:28:cc|70:56:06:12:.*)" }]
]
```

#### 3. Filter every asset with an IP address in the range 192.168.x.x

```json
[
  [{ "parameter": "ipAddress", "regex": "192\\.168\\..*" }]
]
```

#### 4. Complex filtering with multiple conditions

```json
[
  [
    { "parameter": "deviceName", "regex": "Main.*" },
    { "parameter": "deviceType", "regex": "Router" }
  ],
  [
    { "parameter": "macAddress", "regex": "(70:82:0e:12:28:cc|70:56:06:12:.*)" }
  ],
  [
    { "parameter": "ipAddress", "regex": "192\\.168\\..*" }
  ]
]
```

**How it works:**

* If an asset **fulfills at least one of the three groups**, it passes the filter.
* The first group requires that **both conditions** (`deviceName` and `deviceType`) are met.
* The second and third groups contain **only one condition each**, so an asset passes the filter if it has a matching `macAddress` or `ipAddress` .

**Example asset evaluation:**

| deviceName | deviceType | macAddress        | ipAddress    | Matches?         |
| ---------- | ---------- | ----------------- | ------------ | ---------------- |
| MainRouter | Router     | 00:11:22:33:44:55 | 10.0.0.1     | ✅ (First group)  |
| Printer    | Printer    | 70:82:0e:12:28:cc | 10.0.0.1     | ✅ (Second group) |
| Server     | Server     | 00:11:22:33:44:55 | 192.168.5.10 | ✅ (Third group)  |
| MainSwitch | Switch     | 00:11:22:33:44:55 | 10.0.0.1     | ❌ (No match)     |

### Error handling

If a regular expression is invalid, an error is returned describing the problem. Make sure that:

* The regular expression follows correct syntax.
* Escape sequences (e.g. `\\.` for a dot) are used correctly.

### Conclusion

The `assetFilter` enables flexible filtering of assets with logical conditions and regular expressions. By combining multiple conditions with AND and OR rules, users can create powerful filter logic tailored precisely to their needs.
