Skip to content

Instantly share code, notes, and snippets.

@hjacobs
hjacobs / zmon-kubernetes-pod-container-metrics.py
Created May 16, 2019 09:44
ZMON Kubernetes Pod Container Metrics
def check():
prometheus_url = "http://prometheus.kube-system.svc.cluster.local./api/v1/query"
metrics = {"_use_scheduled_time": True}
try:
container_selector = """{{container_name="{container_name}", pod_name="{pod_name}", namespace="{pod_namespace}"}}""".format(**entity)
def request_prometheus_metric(query):
params={"query": query.format(container_selector=container_selector)}
@lizthegrey
lizthegrey / attributes.rb
Last active February 24, 2024 14:11
Hardening SSH with 2fa
default['sshd']['sshd_config']['AuthenticationMethods'] = 'publickey,keyboard-interactive:pam'
default['sshd']['sshd_config']['ChallengeResponseAuthentication'] = 'yes'
default['sshd']['sshd_config']['PasswordAuthentication'] = 'no'
@jordansissel
jordansissel / 1-output.txt
Last active November 10, 2021 14:28
Convert curl|bash to an rpm with Docker and FPM
% docker build -t rust .
...
# Export the image to tarball, which itself contains tarballs and a manifest.json
% docker save -o rust.tar rust
# Extract the last layer
# tar's -O flag extracts a single entry from the tarball.
# The file we want is the last "Layer" in the manifest.json
% tar -xf rust.tar -O $(tar -xf rust.tar -O manifest.json | jq -r '.[].Layers[-1]') > curlbash.tar
@Baccata
Baccata / vpnconnect.sh
Last active March 25, 2020 00:35
Script to query pwd from lastpass and feed it to the vpn
#!/usr/bin/env bash
HOST="???" # address of the vpn
LASTPASS_ENTRY="???" # entry under which the password is saved in last pass
USERNAME=$(lpass show --sync=auto --username $LASTPASS_ENTRY)
PASSWORD=$(lpass show --sync=auto --password $LASTPASS_ENTRY)
# escaping the special chars in the password to allow sed-ing it
ESC_PWD=$(echo $PASSWORD | sed -e 's/[]\/$*.^[]/\\&/g')
@chmike
chmike / checkDomain.go
Last active December 1, 2023 19:21
Check domain name validity in Go
// Please use the package https://github.com/chmike/domain as is it maintained up to date with tests.
// checkDomain returns an error if the domain name is not valid.
// See https://tools.ietf.org/html/rfc1034#section-3.5 and
// https://tools.ietf.org/html/rfc1123#section-2.
func checkDomain(name string) error {
switch {
case len(name) == 0:
return nil // an empty domain name will result in a cookie without a domain restriction
case len(name) > 255:
@anguslees
anguslees / nodesh.sh
Last active December 2, 2020 01:05
"cloud-native" ssh replacement :P
#!/bin/sh
#
# The access this gives you is rather terrifing. Use sparingly.
#
set -e -x
node=$1
trap "kubectl delete pod nodesh-$node" EXIT
@savetheclocktower
savetheclocktower / laundry-spy.ino
Last active August 12, 2018 21:38
Laundry Spy firmware
// (see the blog post at https://andrewdupont.net/2018/04/27/laundry-spy-part-3-the-software/)
// GENERAL CONFIG
// ==============
// The baud rate of serial output for logging. If necessary, change the baud
// rate in your Serial Monitor to match this.
#define BAUD_RATE 115200
// The name by which this device will identify itself over mDNS (Bonjour).
@enricofoltran
enricofoltran / main.go
Last active April 1, 2024 00:17
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
@staaldraad
staaldraad / uid_awk.sh
Created December 12, 2017 14:06
Get the uid, gid and user groups without touching /etc/passwd or running the `id` command
awk -F: 'END {print "uid:"u" gid:"g" groups:"gg}{if($1=="Uid"){split($2,a," ");u=a[1]}if($1=="Gid"){split($2,a," ");g=a[1]}if($1=="Groups"){gg=$2}}' /proc/self/status
@staaldraad
staaldraad / awk_netstat.sh
Last active May 9, 2024 01:14
AWK to get details from /proc/net/tcp and /proc/net/udp when netstat and lsof are not available
# Gawk version
# Remote
grep -v "rem_address" /proc/net/tcp | awk '{x=strtonum("0x"substr($3,index($3,":")-2,2)); for (i=5; i>0; i-=2) x = x"."strtonum("0x"substr($3,i,2))}{print x":"strtonum("0x"substr($3,index($3,":")+1,4))}'
# Local
grep -v "rem_address" /proc/net/tcp | awk '{x=strtonum("0x"substr($2,index($2,":")-2,2)); for (i=5; i>0; i-=2) x = x"."strtonum("0x"substr($2,i,2))}{print x":"strtonum("0x"substr($2,index($2,":")+1,4))}'
# No Gawk
# Local
grep -v "rem_address" /proc/net/tcp | awk 'function hextodec(str,ret,n,i,k,c){