diff --git a/delete-occurrences-of-item/README.md b/delete-occurrences-of-item/README.md new file mode 100644 index 0000000..573d05a --- /dev/null +++ b/delete-occurrences-of-item/README.md @@ -0,0 +1,23 @@ +# Delete all occurrences of an item + +A simple bash script that deletes all occurrences of a Rollbar item via the API. +Be careful with running this script; there is no way to recover the occurrences you delete! + +## Usage +``` +bash delete_item.sh +``` + +- `` The number you see in the url of the item page: https://rollbar.com///item/ +- `` A project access token with *read* scope +- `` A project access token with *write* scope + +## Dependencies + +This script uses [`jq`](https://stedolan.github.io/jq/) and [`curl`](https://curl.haxx.se/). + +## Notes + +The script loops over the occurrences of the item until it finds any, but sometimes some occurrences are still remain. +If you want to make sure that all occurrences are deleted, just check the UI if there are any occurrences left and run +the script again. diff --git a/delete-occurrences-of-item/delete_item.sh b/delete-occurrences-of-item/delete_item.sh new file mode 100644 index 0000000..b06808b --- /dev/null +++ b/delete-occurrences-of-item/delete_item.sh @@ -0,0 +1,35 @@ +#!/bin/bash +### Delete all occurrences of a Rollbar item + +### Parameters +# The item counter from the item url: https://rollbar.com///item// +ITEM_COUNTER="$1" +# A project access token with 'read' scope +READ_TOKEN="$2" +# A project access token with 'write' scope +WRITE_TOKEN="$3" + + +HOST='https://api.rollbar.com' +API="$HOST/api/1" + +item_id=$(curl -s -k "$API/item_by_counter/$ITEM_COUNTER?access_token=$READ_TOKEN" | jq .result.itemId) +page=1 +tmp_file=$(mktemp /tmp/rollbar.XXX) + +while : +do + printf "\n\nDeleting occurrences of https://rollbar.com/item/$item_id from page $page\n\n" + + curl -s -k "$API/item/$item_id/instances?page=$page&access_token=$READ_TOKEN" | \ + jq .result.instances[].id > "$tmp_file" + + < "$tmp_file" xargs -P20 -I instance_id curl -s -k -XDELETE "$API/instance/instance_id?access_token=$WRITE_TOKEN" + + if [ $(wc -l < $tmp_file) -eq 0 ] + then break + else ((page++)) + fi +done + +rm -rf "$tmp_file"