Skip to content

Instantly share code, notes, and snippets.

View ulexxander's full-sized avatar
💪
Workin hard

Alexander Ustyugov ulexxander

💪
Workin hard
View GitHub Profile
@ulexxander
ulexxander / grafana-discord-notification-template.tpl
Created November 17, 2023 14:12
Grafana better Discord notification template than default one (ugly).
{{ define "__discord_subject" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ if gt (.Alerts.Resolved | len) 0 }}, RESOLVED:{{ .Alerts.Resolved | len }}{{ end }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }} {{ if gt (len .CommonLabels) (len .GroupLabels) }}({{ with .CommonLabels.Remove .GroupLabels.Names }}{{ .Values | join " " }}{{ end }}){{ end }}{{ end }}
{{ define "__discord_values_list" }}{{ if len .Values }}{{ $first := true }}{{ range $refID, $value := .Values -}}
{{ if $first }}{{ $first = false }}{{ else }}, {{ end }}{{ $refID }}={{ $value }}{{ end -}}
{{ else }}[no value]{{ end }}{{ end }}
{{ define "__discord_alert_list" }}
{{ range . -}}
Value: {{ template "__discord_values_list" . }}
{{ if len .Labels -}}
@ulexxander
ulexxander / docker-friendly-iptables.sh
Created April 24, 2024 18:06
Docker friendly iptables rules when cloud firewall rules can't be used, e.g. on baremetal hosts. Can protect both regular services as well as Docker containers forwarded ports.
# 1. Set IPTABLES_RESTORE_NOFLUSH=yes in /etc/default/netfilter-persistent
# 2. Put contents of that file in /etc/iptables/rules.v4
# 3. Apply this file now and after each reboot by running: systemctl enable --now iptables.service
# 4. You can also apply this file directlry using: iptables-restore --noflush < /etc/iptables/rules.v4
*filter
#################################################
############# INPUT chain #############
#################################################
@ulexxander
ulexxander / docker-layers-diff.sh
Created May 17, 2024 10:04
Simple shell script to diff Docker image layers, see which layers was changed between two images.
#!/bin/sh
# Usage:
# docker-layers-diff image-1 image-2
set -e
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Missing 1 / 2 args"
exit 1
@ulexxander
ulexxander / Dockerfile
Created May 27, 2024 09:03
Cache and secret mounts in Dockerfile for Go projects
FROM golang:1.20-bookworm AS builder
WORKDIR /build
ENV \
GOOS=linux \
GOARCH=amd64 \
CGO_ENABLED=0 \
GOCACHE=/go-build-cache \
GOMODCACHE=/go-mod-cache
COPY . .
ARG VERSION