Skip to content

Instantly share code, notes, and snippets.

View ruanbekker's full-sized avatar
🇿🇦

Ruan Bekker ruanbekker

🇿🇦
View GitHub Profile
@ruanbekker
ruanbekker / python_github_discussions_graphql.py
Created March 10, 2024 15:54
How to Create Github Discussions via GraphQL API using Python Requests
"""
This script uses the GraphQL API to create discussions programatically using Python and Requests.
"""
import os
import time
import json
import requests
def url_builder(path):
@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 / k3s-demo-with-cluster.md
Created September 27, 2019 15:29
kubernetes demo with cluster mode on k3s

Install k3s on master node:

curl -sfL https://get.k3s.io | sh -
# get token
cat /var/lib/rancher/k3s/server/node-token

Install k3s on worker nodes as agents:

@ruanbekker
ruanbekker / flask_prometheus.md
Created January 11, 2021 13:30
Python Flask with Prometheus Basic Example
$ curl http://localhost:5000/metrics
# HELP python_gc_objects_collected_total Objects collected during gc
# TYPE python_gc_objects_collected_total counter
python_gc_objects_collected_total{generation="0"} 317.0
python_gc_objects_collected_total{generation="1"} 71.0
python_gc_objects_collected_total{generation="2"} 0.0
# HELP python_gc_objects_uncollectable_total Uncollectable object found during GC
# TYPE python_gc_objects_uncollectable_total counter
python_gc_objects_uncollectable_total{generation="0"} 0.0
@ruanbekker
ruanbekker / elasticsearch_in_lxd.md
Created December 27, 2019 17:24
Fix Elasticsearch issues in LXD/LXC containers

Errors like this appear when you start elasticsearch in a container:

$ journalctl -xe
Dec 27 16:50:17 elasticsearch-03 mount[62]: mount: /sys/kernel/config: cannot mount configfs read-only.
Dec 27 16:50:17 elasticsearch-03 systemd-sysctl[63]: Couldn't write '262144' to 'vm/max_map_count', ignoring: Read-only file system
Dec 27 16:50:17 elasticsearch-03 systemd-sysctl[63]: Couldn't write '1' to 'fs/protected_hardlinks', ignoring: Read-only file system
Dec 27 16:50:17 elasticsearch-03 systemd-sysctl[63]: Couldn't write '1' to 'fs/protected_symlinks', ignoring: Read-only file system

$ /etc/init.d/elasticsearch status
@ruanbekker
ruanbekker / traefik_portainer.md
Last active January 30, 2024 20:15
Traefik with SSL + Portainer on Docker Swarm Repro

Traefik and Portainer on Docker Swarm with Letsencrypt

Reproducing a Traefik with SSL and Portainer setup on a 2 Node Docker Swarm

Install Docker:

Install Docker on both nodes with a Bootstrap Script:

$ curl https://gitlab.com/rbekker87/scripts/raw/master/setup-docker-ubuntu.sh | bash
@ruanbekker
ruanbekker / docker-nfs-volumes.md
Created December 10, 2017 10:43
NFS Volumes with Docker Swarm

Create NFS Volumes:

Creating the NFS Volume:

$ docker volume create --driver local \
  --opt type=nfs \
  --opt o=addr=192.168.1.115,uid=1000,gid=1000,rw \
  --opt device=:/mnt/volumes/mysql-test \
  mysql-test-1
@ruanbekker
ruanbekker / encryption_tool.py
Last active January 22, 2024 07:54
Encryption / Decryption with Python and Simple-Crypt
# https://github.com/andrewcooke/simple-crypt
import base64
import argparse
from flata import Flata, Query, where
from flata.storages import JSONStorage
from simplecrypt import encrypt, decrypt
from getpass import getpass
db_init = Flata('mydb.json', storage=JSONStorage)
@ruanbekker
ruanbekker / decrypt.py
Created April 6, 2019 20:37
Python Encryption / Decryption tool using NACL and SimpleCrypt
import argparse
import simplecrypt
import nacl.secret
import nacl.utils
import nacl.pwhash
import base64
import random
import uuid
import sys
@ruanbekker
ruanbekker / vault_api_app_users.md
Last active January 22, 2024 07:53
Vault API Usage: Provision App Keys to Create KV pairs