Export and import the whole configuration

One document holds a server's whole configuration: flows, alerts, code snippets and libraries, global scripts and settings, and, when you ask for it, the config map. Use it to back up a server or to copy its setup to another one. Users and passwords are never included; create them again on the other server.

Export

curl -s -u 'admin:PASSWORD' -H 'X-Weavster-CSRF: 1' \
  'http://127.0.0.1:8080/api/v1/config/export?includeConfigMap=true' > config.json
{"format":"weavster-config-v1",
 "flows":[{"id":"adt","enabled":true,"destinations":[{"name":"ehr","type":"http","url":"https://ehr.example.com/in"}]}],
 "alerts":[],"snippets":[],"snippetLibraries":[],
 "scripts":{"deploy":"log('deployed')"},"settings":{"retention":{"days":30}},
 "configmap":{"region":"eu"}}

Flows are exported without their runtime state. The config map is left out unless you add includeConfigMap=true, because it usually holds values for one environment (hostnames, for example). An empty config map is exported as {}, so importing it with overwriteConfigMap empties the target's.

Import

curl -s -u 'admin:PASSWORD' -H 'X-Weavster-CSRF: 1' -X POST \
  'http://127.0.0.1:8080/api/v1/config/import' --data-binary @config.json
{"flows":{"created":["adt"],"updated":[]},"alerts":0,"snippets":0,"snippetLibraries":0,
 "scripts":1,"settings":1,"configMapReplaced":false,"deployed":["adt"]}
Parameter What it does
force=true Replaces flows, alerts, snippets, and libraries that already exist. Without it, any that exist stop the import with 409 naming them, and nothing is written.
nodeploy=true Leaves the imported flows undeployed. Without it, every imported flow that is enabled and undeployed is deployed afterwards. Deploying a flow also deploys the flows it depends on (even disabled ones, as POST /api/v1/flows/{id}/deploy does); deployed lists every imported flow that was deployed.
overwriteConfigMap=true Replaces the config map with the document's, which must be there (export with includeConfigMap=true; {} empties the config map). A document without one returns 400. Without this parameter, the server keeps its own config map and the document's is ignored (not even checked).
  • Everything is checked before anything is written: the format, every flow, alert, snippet, and value, and that each snippet's library is in the document or already on the server. Problems return 400 naming the item.
  • Global scripts and settings in the document are created or replaced; others on the server are kept.
  • If someone creates a flow, alert, snippet, or library with an id from the document while the import runs (without force), the import stops with 409 rather than replacing it.
  • If writing fails part-way (for example, the database is unavailable), the reply is 500. Fix the cause and import again with force=true.
  • If a flow does not deploy, the reply is 500 and names it; the configuration is imported. Deploy the flow yourself with POST /api/v1/flows/{id}/deploy.

Permissions

Export needs flows:view, alerts:edit, snippets:edit, scripts:edit, and settings:edit, plus configmap:edit with includeConfigMap=true. Import needs flows:edit and the same …:edit permissions, plus flows:deploy unless nodeploy=true, and configmap:edit with overwriteConfigMap=true. The admin permission includes them all.

Command-line client

Command What it does
exportcfg "path" Writes the configuration without the config map to a file.
exportcfg "path" overwriteconfigmap Also includes the config map, so importing with overwriteconfigmap replaces the target's config map.
importcfg "path" [nodeploy] [overwriteconfigmap] [force] Imports a file written by exportcfg. The options match the parameters above and can come in any order.
weavster> exportcfg "config.json" overwriteconfigmap
exported 2 flows, 1 alerts, 1 snippets, 1 snippet libraries, 1 scripts, 1 settings, 1 config map entries to config.json
weavster> importcfg "config.json" overwriteconfigmap
imported 2 flows (2 new, 0 replaced), 1 alerts, 1 snippets, 1 snippet libraries, 1 scripts, 1 settings from config.json
replaced the config map
deployed adt

A file that does not exist is reported (Error: open config.json: no such file or directory) and nothing is sent to the server.