Skip to content

Instantly share code, notes, and snippets.

@alces
alces / k8s_nifi_grep.sh
Created June 30, 2023 14:01
Looking for a pattern inside NiFi flowfiles on multiple clusters deployed atop of k8s
#!/bin/bash
PATTERN='for-example-a-kafka-topic-name-to-look-for'
for ns in $(kubectl get ns | awk '{if ($1 !~ /^NAME|kube-/) {print $1}}')
do
echo "Looking into $ns"
kubectl exec -n "$ns" -c nifi nifi-0 -- zgrep "$PATTERN" permanent_configs/flow.xml.gz 2>/dev/null
done
@alces
alces / fieldalignment_fix.sh
Created December 30, 2022 14:12
Fixing fieldalignment issues reported by govet
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment
fieldalignment -fix a_problematic_file.go
@alces
alces / install_terraform_provider.sh
Created December 7, 2022 13:21
Install a Terraform provider to a cache (tested on alpine Docker image)
#!/bin/sh -e
# Install a Terraform provider
OS=linux
ARCH=amd64
OPTS=`getopt -l dont-unzip,full-url:,group:,provider:,site:,url:,version: -- df:g:p:u:s:v: "$@"` || exit 1
eval set -- "$OPTS"
@alces
alces / signalflow_metrics.go
Created November 16, 2022 11:32
Getting metrics from SignalFX
package main
import (
"fmt"
"log"
. "github.com/signalfx/signalfx-go/signalflow"
)
const (
@alces
alces / gcloud_function_call.sh
Created March 26, 2021 12:20
Call Google Cloud function from command line
gcloud --project my-project-id \
functions call hello-world \
--data '{}' \
--region us-east1
@alces
alces / ec2_instance_creation_time.py
Created November 27, 2020 13:45
Print out "creation time" for EC2 instances (in reality, it's the first network interface attachement time)
import boto3
import datetime
# iterator over EC2 instances for region
def ec2_instances(region):
client = boto3.client('ec2', region_name = region)
for reservation in client.describe_instances().get('Reservations', []):
for instance in reservation.get('Instances', []):
yield instance
@alces
alces / ansible_pass_list.sh
Created October 1, 2020 09:18
Passing a list as a value of an external Ansible variable
ansible-playbook our_playbook.yml -e '{"our_var": ["one", "two", "three",]}'
@alces
alces / lenses-cli-groups.sh
Created July 6, 2020 12:45
Manipulating groups with lenses-cli
# Nice doc is here: https://docs.lenses.io/dev/lenses-cli/index.html
LENSES_CLI_CMD="lenses-cli --host https://10.0.17.20:9991/ --user admin --pass admin --insecure groups"
# Get the list
$LENSES_CLI_CMD get --output JSON
# Group config file
cat > config.yaml << EOF
name: windows_admins
description: "Admins from AD"
@alces
alces / git_log.sh
Last active July 3, 2020 11:58
Getting list of subset of the commits in a git branch in a reverse order with a custom format
# See git log --help for details
git log --reverse --after='Jan 19' --format='format:%h %an'
@alces
alces / check_keytabs.sh
Created January 7, 2020 12:36
Check all Kerberos keytabs in the current directory
#!/bin/bash
# Check all keytabs in the current directory
for kt in *.keytab
do
pr=$(klist -k $kt | tail -1 | awk '{print $2}')
echo -n "${kt}: "
kinit -kt $kt $pr > /dev/null 2>&1 && echo OK || echo FAILED
done