---
description: How to use beforeAll to prepare shared data for monitor mappings.
date_published: 2026-08-13
date_modified: 2026-08-13
canonical_url: https://metricshub.org/community-connectors/develop/sources/before-all.html
---

# beforeAll (Section)

On this Page

- [When To Use](#when-to-use)
- [Syntax](#syntax)
- [Properties](#properties)
- [Recommended Pattern](#recommended-pattern)
- [Common Mistakes](#common-mistakes)
- [Community Examples](#community-examples)

## When To Use

Use `beforeAll` when several monitor sources need the same pre-fetched data.

Typical use cases:

- Login/session bootstrap for HTTP connectors.
- Shared discovery lists reused by multiple monitor tasks.
- Expensive command output collected once per cycle.

`beforeAll` sources still return tables and can be referenced anywhere with `${source::beforeAll.<name>}`.

## Syntax

```yaml
beforeAll:
  session:
    type: http
    method: post
    path: /rest/login-sessions
    body: '{"username":"%{esc(json)::USERNAME}","password":"%{esc(json)::PASSWORD}"}'
    resultContent: body
```

## Properties

| Property | Required | Default | Description |
| --- | --- | --- | --- |
| `beforeAll` | Yes | None | Object containing named sources executed before monitor tasks. |
| `<sourceName>` | Yes | None | Standard source definition (`http`, `commandLine`, `snmpTable`, etc.). |

## Recommended Pattern

- Keep `beforeAll` focused on reusable setup/data.
- Use explicit source names (`session`, `inventory`, `deviceList`) rather than `source(1)` for new connectors.
- Feed `executeForEachEntryOf.source` from a `beforeAll` table when fan-out is required.

## Common Mistakes

- Putting monitor-specific business logic in `beforeAll` instead of monitor sources.
- Fetching massive payloads and re-parsing them in every monitor.
- Returning unstable column layouts that break downstream mappings.

## Community Examples

- [Cassandra](https://github.com/metricshub/community-connectors/blob/main/src/main/connector/database/Cassandra/Cassandra.yaml)
- [LinuxFile](https://github.com/metricshub/community-connectors/blob/main/src/main/connector/system/LinuxFile/LinuxFile.yaml)
- [WindowsFile](https://github.com/metricshub/community-connectors/blob/main/src/main/connector/system/WindowsFile/WindowsFile.yaml)
