Skip to content

Instantly share code, notes, and snippets.

@jameshy
Last active December 21, 2023 07:00
Show Gist options
  • Save jameshy/d3fdbf645e224ac1df9678cbf77afc09 to your computer and use it in GitHub Desktop.
Save jameshy/d3fdbf645e224ac1df9678cbf77afc09 to your computer and use it in GitHub Desktop.
Remove all systems from papertrail
curl -s -H "X-Papertrail-Token: API-TOKEN-HERE" https://papertrailapp.com/api/v1/systems.json | jq '.[] .name' | xargs -I {} -d '\n' sh -c 'papertrail-remove-system -s {}; echo deleted {}'
@sickdyd
Copy link

sickdyd commented Dec 21, 2023

I installed fluentd/papertrail on a cluster that had hundreds of pods running. Each pod created a system on papertrail, however my intention was to log only a specific namespace. Manually deleting each one of the systems on papertrail is an absolute pain. I took the above script and edited to make it work with DELETE requests to papertrail. I am using FLUENT_HOSTNAME as a key to get which specific logs I want to delete (we had some other logs that we want to keep). Leaving this here in case someone else stumbles upon the same kind of issue:

curl -s -H "X-Papertrail-Token: API-TOKEN-HERE" https://papertrailapp.com/api/v1/systems.json | \
jq -r '.[] | select(.name | contains("add fluent hostname")) | ._links.self.href' | \
xargs -I {} curl -v -X DELETE -H "X-Papertrail-Token: API-TOKEN-HERE" {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment