Skip to content

Instantly share code, notes, and snippets.

View cupracer's full-sized avatar

Thomas Schulte cupracer

  • NRW, Germany
  • 23:32 (UTC +02:00)
View GitHub Profile
@cupracer
cupracer / varnishlog-examples.sh
Last active May 12, 2024 17:50
varnishlog examples (version 4.x)
# filter by request host header
varnishlog -q 'ReqHeader ~ "Host: example.com"'
# filter by request url
varnishlog -q 'ReqURL ~ "^/some/path/"'
# filter by client ip (behind reverse proxy)
varnishlog -q 'ReqHeader ~ "X-Real-IP: .*123.123.123.123"'
# filter by request host header and show request url and referrer header
@cupracer
cupracer / window-open-notify-homematic.yaml
Last active October 22, 2023 12:25 — forked from sotatech/window-open-notify-homematic.yaml
Notify HomeMatic when a window is open.
blueprint:
name: Heizkoerpertemperatur bei geoeffnetem Verschluss absenken
description:
An automation blueprint that reduces the set temperature of your climate
device or group if a contact sensor is open for more than the preset wait time.
It uses the Homematic window sensor channel to set the temperature to the "Open-window
temperature" set in the device configuration. You should set the "Mode for temperature
fall detection" to Inactive to avoid conflicts. It waits until the contact is closed
again in order to restore the climate entity temperature. It has an optional blocking
entity to prevent the automation running unnecessarily, for example during the
@cupracer
cupracer / simple_image_walk.sh
Created August 23, 2022 08:49
Get all steps used during container image building (aka Dockerfile instructions)
#!/bin/bash
IMAGE=$1
PARENT=$IMAGE
declare -a RESULTS REV_RESULTS
while [ -n "${PARENT}" ]; do
JSON=$(docker inspect $PARENT |jq .)
RESULTS+=("$(echo $JSON | jq '.[0]'.ContainerConfig.Cmd)")
@cupracer
cupracer / read-udev-multipath-events.py
Last active June 13, 2022 09:27
Read specific multipath events from systemd-udevd.service via systemd-journal
#!/usr/bin/env python3
#
# use with:
# udevadm control --log-level=debug
#
# example output:
#
# ACTIVE: 0, STARTED: 142, SUCCEEDED: 142, BURSTS: 0, LONGEST: 0.366994 secs (device: dm-18, start: 11:22:09.099568, end: 11:22:09.466562)
# Burst detected. Resetting.
@cupracer
cupracer / monitor-logfile-and-react-on-hits.sh
Last active June 10, 2022 08:28
Simple logfile monitor which counts occurrences of a string and reacts after n hits
#!/bin/bash
USE_SYSTEMD_JOURNAL=0
LOGFILE=/var/log/snapper.log
WAIT_FOR_HITS=3
SEARCH_TERM="test 123"
################
if [ ${USE_SYSTEMD_JOURNAL} -lt 1 ] && ! [ -r ${LOGFILE} ]; then
@cupracer
cupracer / haproxy.cfg
Last active March 13, 2022 10:06
HAproxy HTTP + HTTPS passthrough (roughly created, but works for me)
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
log-send-hostname
maxconn 4096
pidfile /var/run/haproxy.pid
user haproxy
group haproxy
daemon
stats socket /var/run/haproxy.stats level admin
@cupracer
cupracer / test.php
Created August 24, 2021 20:49
Don't compare float values in PHP!
<?php
$a = 0.20;
// Test 1:
$b = 1 - 0.80; // 0.20
if ($a == $b) {
echo "true";
@cupracer
cupracer / dates.sh
Created July 26, 2021 18:34
Generate dates in Bash
#!/bin/bash
# Simple one-liner to increase and print dates. To be used in scripts.
# Current command starts today and prints next 100 dates.
#
# Output:
# 2021-07-26
# 2021-07-27
# 2021-07-28
# ...
@cupracer
cupracer / timestamp.py
Last active April 20, 2021 09:13
Calculate timestamps by adding or subtracting seconds
#!/usr/bin/python3
import sys
import re
from datetime import datetime, timedelta
if not len(sys.argv) == 4:
print('\n * usage: ' + sys.argv[0] + ' %Y-%m-%d-%H:%M[:%S] add|sub #seconds\n')
exit(1)
@cupracer
cupracer / nfs.stp
Last active February 10, 2021 17:54
Systemtap script to trace various NFS calls
#! /usr/bin/env stap
global log_nfs_file_open = 1;
global log_nfs_file_read = 1;
global log_nfs_file_write = 1;
global log_nfs_getattr = 1;
global log_nfs_permission = 1;
global log_nfs_opendir = 1;
global log_nfs_lookup = 1;