Demos¶
Samconf comes with a set of demo applications to show certain aspects of samconf.
samprobe – test and query config files¶
The tool was primarily developed to test the samconf library. It is also useful to check and query config files.
To verify a config file :
$ samprobe test/smoketest/config.json
PATH VALUE TYPE
/root None SAMCONF_CONFIG_VALUE_OBJECT
root/elos None SAMCONF_CONFIG_VALUE_OBJECT
elos/UseEnv FALSE SAMCONF_CONFIG_VALUE_BOOLEAN
elos/Port 54321 SAMCONF_CONFIG_VALUE_INT
elos/Temperature 31.680000 SAMCONF_CONFIG_VALUE_REAL
elos/ip 127.0.0.0 SAMCONF_CONFIG_VALUE_STRING
elos/Scanner None SAMCONF_CONFIG_VALUE_OBJECT
Scanner/SyslogScanner None SAMCONF_CONFIG_VALUE_OBJECT
SyslogScanner/SyslogPath /dev/log SAMCONF_CONFIG_VALUE_STRING
SyslogScanner/InputFilter None SAMCONF_CONFIG_VALUE_OBJECT
InputFilter/sshd None SAMCONF_CONFIG_VALUE_OBJECT
sshd/4000 event.source.appname SAMCONF_CONFIG_VALUE_STRING
elos/Logger SAMCONF_CONFIG_VALUE_STRING
env_example – test and query configs created from environment variables¶
This is an example application to check configurations created from environment variables. In this example some environment variables are set with a prefix SAMCONF. A string is passed with env://SAMCONF as location for the samconfLoad function. The env:// indicates that the config shall be loaded from environment variables and not a file. The prefix .i.e SAMCONF indicates that not all environment variables are to be loaded into a configuration but only those with the given prefix are to be loaded.
To use this demo :
$ env_example
PATH KEY VALUE TYPE
SAMCONF/VARIABLE/STRING STRING utest string 1
SAMCONF/VARIABLE/INT INT 42 2
SAMCONF/VARIABLE/REAL REAL 1.986500 3
SAMCONF/VARIABLE/BOOL BOOL 1 4
SAMCONF/SAMCONF/VARIABLE/INT INT 42 2
dump_merged_config - merge multiple configs and dump the result¶
This is an example application to dump the result of merging multiple configurations. The result can be dumped as JSON, a tree view or both.
To use this demo:
$ dump_merged_config --help
Merge all the configurations in the provided directories or files and dump them as JSON or a tree
Usage: dump_merged_config [OPTIONS] <DIRECTORIES|CONFIGS>
Options:
-j, --json Dump the merged config as JSON
-t, --tree Dump the merged config tree
-s, --enforceSignature Enforce the signature for all configs after this option
-u, --allowUnsigned Don't enforce the signature for any configs following this option
-h, --help Print this help message
$ dump_merged_config --tree --json test/smoketest/
{
"root": {
"elos": {
"UseEnv": false,
"Port": 54321,
"Temperature": 31.68,
"ip": "127.0.0.0",
"Scanner": {
"SyslogScanner": {
"SyslogPath": "\/dev\/log",
"InputFilter": {
"sshd": {
"4000": "event.source.appname"
}
}
}
},
"Logger": ""
}
}
}
❌ / ((null))
└── ❌ root
└── ❌ elos
├── ❌ UseEnv: false
├── ❌ Port: 54321
├── ❌ Temperature: 31.680000
├── ❌ ip: "127.0.0.0"
├── ❌ Scanner
│ └── ❌ SyslogScanner
│ ├── ❌ SyslogPath: "/dev/log"
│ └── ❌ InputFilter
│ └── ❌ sshd
│ └── ❌ 4000: "event.source.appname"
└── ❌ Logger: ""
dump_config - load a single config and dump it to stdout¶
This is an example application to load and dump a configurations. The output can be as JSON, a tree view or both.
To use this demo:
$ dump_config --help
Load a config files and dump and it as JSON or a tree
Usage: dump_config [OPTIONS] <CONFIG>
Options:
-j, --json Dump the config as JSON
-t, --tree Dump the config tree
-s, --enforceSignature Enforce the signature for the config
-h, --help Print this help message
$ dump_config --tree --json test/smoketest/config.json
ERROR reading config
ERROR freeing the config object
null