sensu / sensu-flow

Github Action for Sensu flow resource management pattern.
MIT License
7 stars 6 forks source link

Enhancement: State Management for Entities #27

Open nheimlich opened 3 years ago

nheimlich commented 3 years ago

Hi, I am currently using the entity API to mass update entity labels and subscriptions. I believe it would be highly beneficial to have entities state-managed integrated through sensu flow as well. I've attached code snippets of my basic script to update such components. Currently, it requires the API_Key and namespace as inputs.

curl -X GET \ https://demo.sensu.io:8080/api/core/v2/namespaces/$namespace/entities \ -H "Authorization: Key $API_KEY" | jq -r '.[].metadata.name' >> test.txt

input="test.txt" while IFS= read -r host; do curl -X PATCH \ -H "Authorization: Key $API_KEY" \ -H 'Content-Type: application/merge-patch+json' \ -d '{ "metadata": { "labels": { "proc_name": "cron" } } }' \ https://demo.sensu.io:8080/api/core/v2/namespaces/$namespace/entities/$host

input="test.txt" while IFS= read -r host; do curl -X PATCH \ -H "Authorization: Key $API_KEY" \ -H 'Content-Type: application/merge-patch+json' \ -d '{ "subscriptions": ["system/linux/","ping"] }' \ https://demo.sensu.io:8080/api/core/v2/namespaces/$namespace/entities/$host done <"$input" rm test.txt

A way to support this would to generate a file within cluster that has all of the entities states. Attached is a purposed image of what this file would look like. This is a file that ansible would use to ensure hosts can use custom fields.

image

jspaleta commented 2 years ago

Hmm this is a little different functionality than originally envisioned. This introduces a yaml file that isn't a sensu resource.

I get why this is desired, to coerse entities into compliance, but this might be better a distinct script separate from sensu-flow that can be run a separate ci or cron job on a different cadence.