Skip to content

Instantly share code, notes, and snippets.

View ruanbekker's full-sized avatar
🇿🇦

Ruan Bekker ruanbekker

🇿🇦
View GitHub Profile
@ruanbekker
ruanbekker / loki_nginx_regex_access_logs.md
Last active November 5, 2024 13:45
Loki Regex LogQL Query for Nginx Access Logs

Access Log:

172.16.4.86 - - [04/Jun/2022:07:58:38 +0000] "GET / HTTP/2.0" 301 280 "-" "curl"

Query in Grafana / Loki:

{job="prod/nginx"} |= "GET / " 
@ruanbekker
ruanbekker / prometheus_relabel_configs.md
Created May 28, 2022 12:19
Prometheus Relabel Config Example

Prometheus Relabling

Using a standard prometheus config to scrape two targets:

  • ip-192-168-64-29.multipass:9100
  • ip-192-168-64-30.multipass:9100
global:
  scrape_interval:     15s
 evaluation_interval: 15s
@ruanbekker
ruanbekker / ship_logs_to_loki.py
Created May 27, 2022 14:34
Python Requests to ship logs to Loki API
#!/usr/bin/env python3
# docs: https://grafana.com/docs/loki/latest/api/#post-lokiapiv1push
import requests
import time
# variables
LOKI_USERNAME="x"
LOKI_PASSWORD="x"
LOKI_ENDPOINT="https://loki-api.example.com/loki/api/v1/push"
@ruanbekker
ruanbekker / mysqldump_anonamize_column_values.md
Last active May 28, 2022 14:00
Very basic bash script to sanitize a mysql table column from a database dump

This is a basic example with a dirty bash script on how to create a copy of a production database and update the column values of the new (test / staged) database, which might be sensitive or which is not suitable for test environments.

This test is intentional for small datasets.

The flow:

  • mysqldump of the production database to a sql file
  • create the staging database
  • import the production data from the sql file into the staging database
  • run the bash script which loops through each record and updates the selected column value (creditcard_num)
@ruanbekker
ruanbekker / install_geth_ropsten_fast.sh
Last active March 15, 2022 04:57
Boostrap Geth Ropsten Installation
#!/usr/bin/env bash
export GOVERSION="1.17.2"
export GETHVERSION="1.10.9"
apt update
apt install wget tar locales-all -y
touch /var/lib/cloud/instance/locale-check.skip
mkdir -p /blockchain/ethereum/data
mkdir -p /usr/local/geth/${GETHVERSION}/bin
@ruanbekker
ruanbekker / aws_sns_sms_python.md
Created October 6, 2021 13:38
Send SMS with AWS SNS using Python

Sending SMS's with AWS SNS:

import boto3
sms_number='+27000000000'

sns = boto3.Session(profile_name='default', region_name='eu-west-1').client('sns')

response = sns.publish(
 PhoneNumber=sms_number, 
@ruanbekker
ruanbekker / python_datetime_gmtplus2.md
Last active October 1, 2021 07:51
Python use Datetime to get time in SAST or custom timezone

Install pytz:

pip install pytz

Python example to get time in GMT+2 or Africa/Johannesburg:

>>> import pytz
@ruanbekker
ruanbekker / Dockerfile
Created July 9, 2021 09:42
Liquibase Migrations in CI/CD CodeBuild Pipeline with Docker
FROM maven:3.6.1-amazoncorretto-11 as builder
ARG DB_USER
ARG DB_PASSWORD
ARG DB_URL
ENV DB_USER=${DB_USER}
ENV DB_PASSWORD=${DB_PASSWORD}
ENV DB_URL=${DB_URL}
RUN curl -LJO https://github.com/liquibase/liquibase/releases/download/v4.2.0/liquibase-4.2.0.tar.gz && \
@ruanbekker
ruanbekker / install_bitcoin_core_testnet.sh
Created June 23, 2021 14:10
Install Bitcoin Core Testnet on Linux Script
#!/usr/bin/env bash
# Note:
# I use this script to bootstrap testnet nodes, if you are using the mainnet,
# I STRONGLY recommend to set rpcallowip to localhost
# environment variables
export ARCH=x86_64
export BITCOIN_VERSION=0.21.1
export BITCOIN_URL=https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/bitcoin-${BITCOIN_VERSION}-${ARCH}-linux-gnu.tar.gz
@ruanbekker
ruanbekker / awscli_v2_ubuntu.md
Created February 23, 2021 12:29
Install AWS CLI Version 2 on Ubuntu 20
$ apt update
$ apt search awscli
$ apt install curl wget unzip -y
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
$ unzip awscliv2.zip
$ ./aws/install
$ aws --version
aws-cli/2.1.28 Python/3.8.8 Linux/4.19.121-linuxkit exe/x86_64.ubuntu.20 prompt/off