Export and import of the tree as files
Probeward can write its monitoring configuration as plain files and read such files back. That lets you keep the configuration in a Git repository, review a change as a diff, apply it, and rebuild or copy a site from the files. The files and two commands are the whole interface: Probeward does not talk to Git or to any other service for you.
The format has a JSON Schema, export-import.schema.json. A test checks real exports against it, and checks that it lists the same settings the product has.
Quick start: keeping the configuration in Git
# 1. Export the whole tree into a repository checkout, and commit it.
cd ~/monitoring-config
probeward admin export .
git add -A && git commit -m "Export of the monitoring configuration"
# 2. Edit a limit in a file. For example, raise the warning limit of a ping sensor.
$EDITOR sites/head-office/servers/web-1.device.yaml
git diff # one changed line
# 3. Plan. Nothing is changed.
probeward admin import . --plan
# ~ sensor Head office / Servers / web-1 / Ping
# limits.rtt_ms.warn_max: 100 -> 250
# Plan 3f2a... (against configuration revision 412)
# Nothing was changed. To apply exactly this plan: --apply --plan-id 3f2a...
# 4. Apply exactly that plan, as an administrator, and commit.
probeward admin import . --apply --plan-id 3f2a... --as olga
git commit -am "Raise the ping warning limit on web-1"probeward admin commands read the same environment as the server (PROBEWARD_DATABASE_URL and PROBEWARD_VAULT_KEY_FILE) and work whether or not the server is running. The server picks up the change like any other configuration change: sensors are polled with the new settings from their next poll.
Exporting again later rewrites the same files. Files an earlier export wrote and the new export does not (a device you deleted) are removed, so that git status shows the deletion. Other files in the directory, such as a README.md or .git, are left alone.
The format
Layouts
There are two, chosen at export time with --layout (command line) or layout= (API). Both hold exactly the same information and both can be imported.
directory (the default) | single | |
|---|---|---|
| Files | one for the top level, one per site, one per group, one per device | one, probeward.yaml |
| A change to one sensor | changes one line in one small file | changes one line in a very large file |
| Merging two people's edits | rarely conflicts, since people edit different devices | conflicts whenever two edits are near each other |
| Passing it around | a directory (or the tar archive the API gives you) | one file |
| A site with thousands of sensors | hundreds of small files | one file of several megabytes |
The directory layout is the default because large installations are where this matters: a diff, a review and a merge all work per device, and a pull request that touches three devices shows three small files. The single file is for passing a configuration around, for small installations and for sending one group to a colleague.
probeward.yaml format, layout, scope, credentials, destinations, schedules
sites/head-office/site.yaml a site (a probe): its settings and maintenance windows
sites/head-office/servers/group.yaml a group, nested as deeply as the tree is
sites/head-office/servers/web-1.device.yaml a device with its sensorsThe names of directories and files are made from the names of the objects, to be readable. They are not the identity of anything (see below): the nesting of the directories is what places an object in the tree. Moving a .device.yaml file to another group's directory moves the device. Two siblings whose names make the same file name both get a short piece of their id added, so the names do not depend on which was exported first.
A group or device export (--scope group --id ...) uses groups/<name>/group.yaml or devices/<name>.device.yaml at the top and says in probeward.yaml where it came from.
Determinism
The same configuration always produces the same bytes. Keys come in a fixed order, children are sorted by name and then by id, quoting follows one rule, lines are never folded, and nothing volatile is written: no timestamps, versions, health or counters. Export twice and the files are identical; change one setting and one line changes. Every file starts with the same one-line comment.
What a file looks like
# Probeward configuration, format 1. See docs/export-import.md.
id: 01a220ef-5ef7-757c-9afc-4128b02add8b
name: web-1
address: 192.0.2.10
hostname: web-1.example.org
settings:
interval_secs: 30
depends_on:
- id: 01a220ef-5f03-774e-873e-54713042255f
path:
- Head office
- Network
- core-sw1
- Ping
sensors:
- id: 01a220ef-5f41-7630-a620-354c6e46887e
name: Ping
kind: ping
master: true
params:
count: 3
limits:
rtt_ms:
warn_max: 100Only what an operator set is written.
- Settings are written where they are set and nowhere else. A child does not repeat what it inherits. A key that is absent inherits; a key that is present is an override, even when its value equals the built-in default.
notify: []means "notify nobody below here" and is different from nonotifykey. Clearing an override means deleting its line. - Everything that is not inherited (
enabled,position, a sensor'sparams) is written when it differs from the default and left out when it is the default. - Settings are exported as the product stores them, not from a list in the exporter, so a setting added in a later release is exported without a change to the exporter. A test fails when the product has a setting or an attribute that the exporter has neither handled nor listed as "not configuration".
- Names, not ids, for the things that are shared: credentials, notification destinations and schedules are written by name wherever they are used (
snmp_credential: lab-snmp). Their definitions are at the top of the export: destinations and schedules in full, credentials as name, kind and the settings that are not secret (for an SNMPv3 credential the security level and protocols, for a Windows credential the authentication method and domain, and for any credential itsallowed_ranges), and never a value. - Dependencies are written on the object that depends:
depends_onon a device suppresses the whole device, on a sensor just that sensor. The sensor depended on is given byidand by thepathof names. It may be anywhere in the tree, including outside what you exported. - The Windows transport of a device is
windows_transport: wmiwhen its Windows sensors use native WMI through a Windows probe. WinRM is the default and is left out. An import does not check what the probe runs on: under a Linux probe the Windows sensors of such a device report the problem when they are polled. - The master check of a device is
master: trueon one of its sensors. - Templates a device or sensor was created from are kept as
template: {id, version}. They are references: the template itself lives in the product. - Maintenance windows that recur (weekly and monthly) are written under the site, group, device or sensor they belong to.
Identity, renames and history
History (scans, rollups, incidents) belongs to a sensor id. An import must never create a new sensor for something that only moved or was renamed, because that would leave its history behind. So:
- An object with an
idis that object, wherever the files now put it and whatever they now call it. Rename a sensor in a file, move a device to another group's directory, or move a group to another site: the plan says "renamed" or "moved", and the history stays attached. This is the normal case, because every export carries ids. - An object without an
id, as in a file you wrote by hand, is matched by place and name: among the children of the matched parent, the one object with that name. A unique match keeps the object and its history. No match creates a new object. More than one match is an error that asks for anid. A sensor is also matched by itsdiscovery_keywhen the file has one. - So a rename without an id is a new object. The old one is not touched (and keeps its history) unless you import with
--prune, which then removes it, history included. Keep the ids in the files. - A kind of sensor cannot change. If a file says an existing sensor is another kind, the import refuses and says to give the new sensor another name.
- An id that belongs to something outside the part of the tree the files cover is an error, not a silent move. Import the whole tree to move things between sites.
- An id that does not exist here creates an object with that id. That is how a site is rebuilt from its files on an empty installation, with the same ids as before.
A sensor's discovery_key is what discovery matches by, so that discovering again adds no duplicate. It is kept as it is, and a file without one does not take it away.
Commands
Export
probeward admin export DIR # the whole tree, directory layout
probeward admin export DIR --layout single # one file
probeward admin export DIR --scope group --id 01a2... # a group, or: site, deviceGET /api/v1/config/export?scope=tree|probe|group|device&id=...&layout=directory|single&format=tar|yaml|json does the same over the API. tar (the default for the directory layout) is an archive you unpack with tar -x; yaml is the single file; json is {"layout": ..., "files": {"path": "text"}}. In the UI, Export is in the menu of every site, group and device in the tree. Each export is audited.
Import
probeward admin import DIR # plan: show what would change (the default)
probeward admin import DIR --apply --plan-id ID --as USER
probeward admin import DIR --apply --yes --as USER # plan and apply in one go, no question
probeward admin import DIR --prune # also plan the removal of what the files omit
probeward admin import DIR --clone --under "Branch/Servers"Without --plan-id or --yes, --apply shows the plan and asks. --as names the administrator the changes are attributed to in the audit record; it is required to apply.
Over the API:
| Call | Does |
|---|---|
POST /api/v1/config/import/plan | Reads and checks the files and returns the plan. Changes nothing. |
POST /api/v1/config/import/apply | Applies the plan named by plan_id, or refuses. |
Both take {"files": {"path": "text", ...}, "prune": false, "clone": false, "under": {...}}, and apply also takes plan_id. In the UI, Import in the tree's menu takes the files (or a folder), shows the plan as a diff and asks for confirmation.
Only root administrators can use these routes and the commands (see limits). An import also follows the permissions of the person importing: attaching or changing a sensor that runs programs on the probe host (a script or Nagios plugin sensor) needs an administrator, as do creating a site and changing a schedule or a notification destination. An import is not a way round any of these.
Plan and apply
An import never changes anything before it has shown what it will do.
Plan reads every file and reports every problem it finds, not just the first, each with the file, the line and the path inside it. Unknown fields are errors. Sensor parameters are checked by the same code the API uses, as are settings, limits, destinations, schedules and windows, and the finished tree is checked as a whole (a dependency cycle is refused). Then it compares the files with the installation and lists, object by object:
- created, changed (field by field, old and new), moved (from where), renamed (from what), removed;
- how many objects are unchanged;
- what cannot be applied and why, for example a credential that does not exist here;
- what the files do not mention and the import leaves alone.
Apply applies exactly the plan that was shown. The plan has an id that covers the configuration revision it was computed against, the files and the options. Applying recomputes the plan and refuses (HTTP 409, plan_stale) if it is no longer the same plan, because somebody changed the tree or the files in between; plan again and read what it now says. The writes happen in one database transaction, locked against other configuration changes: all of it or none of it. Every change is in the audit record under the usual action (sensor.update, device.move, group.create ...), attributed to the user who applied it and marked with the same import_id, and one config.import entry summarises the import. The engine picks the changes up as it picks up any other.
Removal is the dangerous part. By default an import deletes nothing: objects below the imported root that the files do not mention are left as they are, and the plan counts them. With --prune ("prune": true) it removes them, only below the root that was imported (the sites of a whole-tree import, the group of a group export, and so on). The plan lists exactly what goes, and the history of every removed sensor goes with it: the plan says how many sensors, scans and incidents. This is the same rule as a template update that removes a sensor. Prune never removes a site, a credential, a destination or a schedule, and never removes a one-off maintenance window.
Files replace the state of the objects they describe. If a file for a device no longer has a setting that is set in the installation, applying clears it back to inherit. A pause is never touched.
The round trip is exact: export, import into an empty installation, export again gives identical files, and importing an installation's own export into itself gives an empty plan.
Copying a site
To make a second site that looks like the first: export a group, change what differs, import it under another site.
probeward admin export clone/ --scope group --id 01a2... # "Head office / Servers"
sed -i 's/192\.0\.2\./198.51.100./' clone/groups/servers/*.device.yaml # new addresses
probeward admin import clone/ --clone --under "Branch" --plan
probeward admin import clone/ --clone --under "Branch" --apply --yes --as olga--clone ignores every id in the files and creates everything new, so the copy has no history and the original is untouched. References inside the files (a dependency between two copied sensors) point at the copies; references to things outside them (a switch's ping in another group) keep pointing where they did. --under is the id of a site or group, or its names from the site down separated by / (use the id when a name contains a /). Without it, a group or device export goes under the parent it came from, and when that does not exist in this installation the import asks for --under. Credentials, destinations and schedules are shared, not copied.
Importing the same files again without --clone updates the objects the first import created; it does not copy them again.
What is not exported, and how to supply it
Secrets, never. Credential values, webhook URLs and signing keys, Telegram and Discord tokens, SMTP passwords, API tokens, push tokens, probe pairing material, TOTP secrets, recovery codes, password hashes and session tokens are in no file and in no plan. A test plants a marker in every one of them, exports and plans in every way the product allows, and fails if the marker appears anywhere. Account names of credentials are treated as secret too.
A credential is exported as its name, kind and non-secret settings. The import looks it up by name. If it does not exist, the plan says so, lists every credential that is needed with its kind, and cannot be applied. Create the credentials (Settings, Credentials, or POST /api/v1/credentials) with the names the plan gives, then plan again. Nothing is created with an empty secret, because that would poll with a wrong credential.
A credential's allowed address ranges are exported among its settings, because they are part of what the credential may do and are not secret. The plan lists them for each credential it needs, so the credential can be created with them. The import never changes a credential, so it does not apply them: an existing credential keeps the ranges it has, and a new one gets them only when you create it with them. See credentials stay on their targets for what the ranges do.
Also not exported, because they are not configuration:
| What | Why |
|---|---|
| Users, roles, grants, API tokens, sessions | Accounts and access, not monitoring configuration |
| Audit record, timeline, incidents, history, rollups | Records of what happened |
| Pauses | Operational state; a pause expires or is lifted by a person |
| One-off maintenance windows, and adjustments to a recurring one | Operational state. A one-off window that has passed is history. Only recurring windows are configuration |
| Probe pairing and certificates, connection state | A site is exported by name; pair the probe again with a token from the UI |
| Push tokens | Secrets. Issue one for a push sensor after importing it |
| Global settings (SMTP server, heartbeat, retention) | Installation settings, not the tree |
| Sensor health, freshness and acknowledgements | State |
Pauses and one-off windows already in the installation are left as they are by an import, also with --prune, unless the object they are on is removed, which removes them with it.
Messages you will meet
| Message | What to do |
|---|---|
probeward.yaml: this file is missing | The directory is not an export, or you named the wrong one. |
format version 2 is newer than this Probeward understands | Upgrade Probeward before importing. |
site.yaml:12:5: sensors[1].params.port: ... | The file, line and path of the problem, then what is wrong with the value. |
"surprise" is not a recognised field | A typo, or a field from a newer format. Unknown fields are never ignored. |
YAML anchors are not supported (also aliases, tags, merge keys, duplicate keys, more than one document) | Write the value out. The files are plain data. |
more than one existing object matches device "twin"; add the id | Two siblings have that name. Put the id from an export in the file. |
... exists in this installation outside the part of the tree these files cover | The id is of something elsewhere. Import the whole tree, or use --clone. |
a sensor's kind cannot change | Give the new sensor another name; remove the old one with --prune. |
one-off windows are operational state | Only weekly and monthly windows are in the files. |
"pause" is not part of the files | Remove the key. Pause from the UI or the API. |
create these credentials first ... and plan again | See above. |
... only administrators ... (blocked) | Ask an administrator to apply it. |
plan_stale (HTTP 409) | The tree or the files changed since the plan. Plan again and read it. |
the dependencies would form a cycle: a -> b -> a | Remove one of the dependencies in the files. |
two destinations are named "x" (on export) | The files refer to destinations by name, so rename one first. |
Limits
Export and import need a root administrator. A branch admin cannot export their branch, even though they can see all of it: the files name the credentials, destinations and schedules a branch uses, and the import compares against the whole tree, and neither has been limited to a grant's scope yet.
An import is bounded so that a hostile or mistaken file cannot use unlimited resources: 96 MiB per API request, 50,000 files, 64 MiB in all, 32 MiB per file, 64 levels of nesting, two million YAML nodes in a file, 400,000 objects, and groups nested at most 32 deep. Paths must be relative and stay inside the directory; symbolic links are not followed by the command line. Tens of thousands of sensors are fine: ten thousand sensors export in about a second and plan in a few seconds on a development machine.