Skip to content

Instantly share code, notes, and snippets.

@david-bc
Last active April 4, 2019 15:00
Show Gist options
  • Save david-bc/29427e8039eeaf7aa74bd7d4d21bf217 to your computer and use it in GitHub Desktop.
Save david-bc/29427e8039eeaf7aa74bd7d4d21bf217 to your computer and use it in GitHub Desktop.
Kadmin Utilities
// https://devhints.io/js-fetch
// Delete All Producers
fetch('/kadmin/api/manager/producers')
.then(res => res.json())
.then(data => {
Promise.all(
data.content.map(p => fetch(`/kadmin/api/manager/producers/${p.id}`, { method: 'DELETE' }))
).then(() => alert(`Deleted ${data.content.length} producers`))
})
javascript:(function(){fetch("/kadmin/api/manager/producers").then(e=>e.json()).then(e=>{Promise.all(e.content.map(e=>fetch(`/kadmin/api/manager/producers/${e.id}`,{method:"DELETE"}))).then(()=>alert(`Deleted ${e.content.length} producers`))});})();
// Delete Old or Inactive Consumers
fetch('/kadmin/api/manager/consumers')
.then(res => res.json())
.then(data => {
const oldDate = new Date().getTime() - 10800000; // 3 hours ago
const oldConsumers = data.content.filter(c => c.lastUsedTime < oldDate || c.total <= 0)
Promise.all(
oldConsumers.map(p => fetch(`/kadmin/api/manager/consumers/${p.consumerGroupId}`, { method: 'DELETE' }))
).then(() => alert(`Deleted ${oldConsumers.length} old or in active consumers`))
})
javascript:(function(){fetch("/kadmin/api/manager/consumers").then(e=>e.json()).then(e=>{const t=(new Date).getTime()-108e5,n=e.content.filter(e=>e.lastUsedTime<t||e.total<=0);Promise.all(n.map(e=>fetch(`/kadmin/api/manager/consumers/${e.consumerGroupId}`,{method:"DELETE"}))).then(()=>alert(`Deleted ${n.length} old or in active consumers`))});})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment