As an operator, I would like an easy way to dump my Sensu check, filter, mutator, handler, and asset definitions to a yaml file that could be reimported should I need to blow away etcd.
There isn't an operator-centric way of exporting an existing config. I'd have to write up a script to iterate through the various API endpoints, or use sensuctl. This is fairly onerous and makes restoring my Sensu configuration a less-than-fun process. Even if I'm using something like config management, or have a repo of files, I'd still have to add those back one-by-one.
sensuctl dump --help
sensuctl dump {checks,filters,handlers,assets,mutators,all} --file FILE --namespace
sensuctl dump all -F /etc/sensu/site-config.yaml
Could also do an API call
curl -H "Authorization: Bearer TOKEN" \
http://127.0.0.1:8080/api/core/v2/namespaces/default/settings/{checks,filters,mutators,handlers,assets}
or
curl -H "Authorization: Bearer TOKEN" \
http://127.0.0.1:8080/api/core/v2/settings
The idea here being that I could either as the deployment owner dump the ENTIRE config, or I could say as a team member dump the config for my namespace.
Another use case here is for use in troubleshooting. Sensu Classic provides means to dump the entire configuration so support can look at everything as a whole easily. Users could also use this to get the entire picture in a single output/file.
I second this, I want a simple way to backup my configs as JSON
https://docs.sensu.io/sensu-core/1.7/reference/configuration
Storing check, filter, mutator, handler, and asset config files in /etc/sensu/ directory would be helpful.
Would also like the ability to dump other API resources, e.g. Events.
Here's a simple script I whipped up to tackle this for myself. I'm not sure how easily I can re-import it, but it's better than nothing.
Edit: Switched to wrapped-json format (except sensuctl config) so it can be used for sensuctl create -- note that this means each file is not actually a valid json array, but rather multiple json configs concatenated.
print-all-resources.sh
#!/bin/bash
get_date_safe_for_filenames() {
date +"%Y%m%d-%H%M%S"
}
# use -h or --help to get usage info
if [[ "$*" =~ -h ]]; then
echo "Outputs all sensu resources to specified directory using \`sensuctl\`.
Default output folder is \"./sensu_backup_[CURRENT_DATE_TIME]/\".
usage: $0 <output_dir, default: \"./sensu_backup_$(get_date_safe_for_filenames)/\">
"
exit
fi
_outputDir=${1:-"./sensu_backup_$(get_date_safe_for_filenames)/"}
mkdir -p "${_outputDir}"
_typesWithNamespaces=(
asset
check
entity
event
filter
handler
hook
mutator
role
role-binding
silenced
)
for _type in "${_typesWithNamespaces[@]}"; do
sensuctl "${_type}" list --all-namespaces --format wrapped-json >> "${_outputDir}/${_type}.json" || echo "Issue with type: ${_type}"
done
_typesWithoutNamespaces=(
cluster-role
cluster-role-binding
namespace
user
)
for _type in "${_typesWithoutNamespaces[@]}"; do
sensuctl "${_type}" list --format wrapped-json >> "${_outputDir}/${_type}.json" || echo "Issue with type: ${_type}"
done
sensuctl cluster member-list --format wrapped-json >> "${_outputDir}/cluster-member-list.json" || echo "Issue with type: cluster-member-list"
sensuctl config view --format json >> "${_outputDir}/sensuctl-config.json" || echo "Issue with type: sensuctl-config"
I just saw that this was closed and wanted to say 鉂わ笍鉂わ笍 鉂わ笍 鉂わ笍 鉂わ笍
Most helpful comment
Here's a simple script I whipped up to tackle this for myself.
I'm not sure how easily I can re-import it, but it's better than nothing.Edit: Switched to
wrapped-jsonformat (except sensuctl config) so it can be used forsensuctl create-- note that this means each file is not actually a valid json array, but rather multiple json configs concatenated.print-all-resources.sh