Skip to content

Instantly share code, notes, and snippets.

@alces
alces / get_java_rpm_version.py
Created December 31, 2019 14:00
Print Java RPM version (tested on RedHat 7)
import rpm
for pkg in rpm.TransactionSet().dbMatch('provides', 'java'):
print '%s:%s:%s:%s' % (pkg['name'], pkg['version'], pkg['release'], pkg['epoch'])
@alces
alces / md5_pass_encrypt.py
Created November 19, 2019 10:53
MD5 UN*X password encryption in Python
import crypt
crypt.crypt('my-secret-word', '$1$someSalt$')
@alces
alces / summarize_by_day.prometheus
Created November 6, 2019 05:13
Prometheus expression summarizing message count for a given Kafka topic by day
sum(increase(kafka_producer_topic_metrics_record_send_total{topic = "$my_topic_name"}[1d]))
@alces
alces / kafka_topics_delete.sh
Created October 30, 2019 05:56
Delete Kafka topics with matching names
TOPIC_NAME_REGEX='(CI|TST|IT)[0-9]'
ZOOKEEPER_ADDR=127.0.0.1:2181
for topic in $(kafka-topics --zookeeper $ZOOKEEPER_ADDR --list | egrep $TOPIC_NAME_REGEX)
do
kafka-topics --zookeeper $ZOOKEEPER_ADDR --delete --topic $topic
done
@alces
alces / Jenkinsfile
Created October 7, 2019 06:16
Ask for password in Jenkins pipeline
pipeline {
agent {
label 'Linux'
}
stages {
stage('ask') {
steps {
script {
def askpass = input(
message: 'Please enter the password',
@alces
alces / delete_old_schemas.py
Created September 19, 2019 07:51
Remove old schemes from Confluent Schema Registry
#!/usr/bin/env python
# Cleanup old schemas from schema registry
import httplib
import json
import re
DELETE_REGEX = 'IT6[0-6][0-9]-'
con = httplib.HTTPConnection('127.0.0.1', 8081)
@alces
alces / get_compressed_url.py
Created September 10, 2019 09:17
Fetch compressed content from an URL (e.g., usable with Lenses REST API)
#!/usr/bin/env python
# Get compressed URL content
import gzip
import StringIO
import urllib2
req = urllib2.Request('http://my.lenses.url/api/alerts',
headers = {
'Accept-encoding': 'gzip',
@alces
alces / check_srv.py
Created September 9, 2019 07:18
Check service availability from Python script
!/usr/bin/env python
# Check service availability
# Usage: $0 hostname port
import socket
import sys
if len(sys.argv) != 3:
sys.stderr.write("Usage: %s hostname port\n" % sys.argv[0])
sys.exit(2)
@alces
alces / pause_connectors.py
Created August 14, 2019 04:35
Pause or resume all connectors on a Kafka Connect cluster
#!/usr/bin/env python
CONNECT_ENDPOINT = 'http://10.0.0.24:8083'
import httplib
import json
import os
import sys
action = 'pause' if os.path.basename(sys.argv[0]).startswith('pause') else 'resume'
@alces
alces / curl_with_client_auth.sh
Created April 1, 2019 09:36
Provide SSL client authentication via curl command line
curl --cacert /path/to/ca-root.crt \
--cert /path/to/client.crt \
--key /path/to/client.key \
https://service.with.client.auth