Skip to content

Instantly share code, notes, and snippets.

View adrianlzt's full-sized avatar

Adrián López adrianlzt

View GitHub Profile
@adrianlzt
adrianlzt / docker_clean_ask.py
Last active January 23, 2025 07:44
Delete all none images and then ask the user, for each image:tag, if he wants to delete it
#!/usr/bin/env python3
import subprocess
def remove_image(image_id):
"""Safely remove a docker image."""
try:
subprocess.run(["docker", "rmi", image_id], check=True, capture_output=True)
print(f" ✓ Removed: {image_id}")
except subprocess.CalledProcessError:
#!/bin/bash
# Check if two arguments (cgroup paths) are provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <cgroup1_path> <cgroup2_path>"
exit 1
fi
cgroup1_path="$1"
cgroup2_path="$2"
@adrianlzt
adrianlzt / README.md
Last active January 16, 2025 15:12
Connect to the PostgreSQL where AWX stores its data, Get the credentials stored and select which one you want to decode. You need to pass the AWX secret_key.
❯ uv run https://gist.githubusercontent.com/adrianlzt/b2c2c9581757ad359216eef0f05beb1a/raw/5a0f29c2496a98e9aef0eef8ad1469d1cbdd09e8/awx_secrets.py --host 10.1.1.10 --user awx --password SECRETPASSWORD --secret-key SECRETKEY

Reading inline script metadata from `./awx_secrets.py`
Available secrets:
1. Name: Demo Credential, Type: Machine
Select the secret to decrypt: 7
username: admin
#!/bin/bash
#
# Aplicación para editar un KV secret version 2 en Vault
#
path=$1
tmpfile=$(mktemp)
# Fetch the secret and write it to a temporary file
vault kv get -format=json $path | jq -er .data.data > $tmpfile
# Creamos una CA self-signed para generar los certificados de los clientes VPN
resource "tls_private_key" "foo-vpn-ca-key" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "tls_self_signed_cert" "foo-vpn-ca" {
private_key_pem = tls_private_key.foo-vpn-ca-key.private_key_pem
subject {
@adrianlzt
adrianlzt / revprox.go
Created January 16, 2024 16:05
Simple reverse proxy in Go (forked to adapt to Azure functions use-case)
package main
import (
"crypto/tls"
"log"
"net/http"
"net/http/httputil"
"net/url"
"os"
)
#!/usr/bin/env python
"""
Script to handle keepalived notifications.
This script will be called by keepalived with three arguments:
- "GROUP" or "INSTANCE"
- name of the group or instance
- target state of the transition: "MASTER", "BACKUP", "FAULT"
The script should return 1 if the number of parameters is not 3, if the
target state is not "MASTER", "BACKUP" or "FAULT", or if the first parameter
@adrianlzt
adrianlzt / query.sql
Created February 9, 2023 08:11
Zabbix: PostgreSQL query to migrate the old item prototype macros ($1) to its discovery macro
WITH macro AS (
SELECT
itemid,
(regexp_matches(key_, '(\{#[^\}]*\})'))[1] AS m
FROM
items)
UPDATE
items
SET
name = regexp_replace(name, '(\$1)', macro.m)
@adrianlzt
adrianlzt / gitlab-automatic-upgrade.py
Created October 28, 2022 11:31
Script to upgrade gitlab from one version to the latest, using a backup and docker
#!/usr/bin/env python
# -*- coding: utf-8 -*
# vim:fenc=utf-8
#
# Script to upgrade gitlab from one version to the latest, using a backup and docker.
#
import os
import sys
import argparse
@adrianlzt
adrianlzt / pushbullet.py
Last active September 14, 2022 16:04
Pushbullet notifications for m/monit
#!/usr/bin/env python3
# Copyright (c) 2022 Adrian Lopez
#
# Based on https://github.com/PinGwynn/mmonit-mattermost
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell