Skip to content

Instantly share code, notes, and snippets.

@alces
alces / signalflow_metrics.go
Created Nov 16, 2022
Getting metrics from SignalFX
View signalflow_metrics.go
package main
import (
"fmt"
"log"
. "github.com/signalfx/signalfx-go/signalflow"
)
const (
@alces
alces / gcloud_function_call.sh
Created Mar 26, 2021
Call Google Cloud function from command line
View gcloud_function_call.sh
gcloud --project my-project-id \
functions call hello-world \
--data '{}' \
--region us-east1
@alces
alces / ec2_instance_creation_time.py
Created Nov 27, 2020
Print out "creation time" for EC2 instances (in reality, it's the first network interface attachement time)
View ec2_instance_creation_time.py
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 Oct 1, 2020
Passing a list as a value of an external Ansible variable
View ansible_pass_list.sh
ansible-playbook our_playbook.yml -e '{"our_var": ["one", "two", "three",]}'
@alces
alces / lenses-cli-groups.sh
Created Jul 6, 2020
Manipulating groups with lenses-cli
View lenses-cli-groups.sh
# 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 Jul 3, 2020
Getting list of subset of the commits in a git branch in a reverse order with a custom format
View git_log.sh
# See git log --help for details
git log --reverse --after='Jan 19' --format='format:%h %an'
@alces
alces / check_keytabs.sh
Created Jan 7, 2020
Check all Kerberos keytabs in the current directory
View check_keytabs.sh
#!/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
@alces
alces / get_java_rpm_version.py
Created Dec 31, 2019
Print Java RPM version (tested on RedHat 7)
View get_java_rpm_version.py
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 Nov 19, 2019
MD5 UN*X password encryption in Python
View md5_pass_encrypt.py
import crypt
crypt.crypt('my-secret-word', '$1$someSalt$')
@alces
alces / summarize_by_day.prometheus
Created Nov 6, 2019
Prometheus expression summarizing message count for a given Kafka topic by day
View summarize_by_day.prometheus
sum(increase(kafka_producer_topic_metrics_record_send_total{topic = "$my_topic_name"}[1d]))