Skip to content

Instantly share code, notes, and snippets.

View andreyev's full-sized avatar
💭
.

Andreyev Dias de Melo andreyev

💭
.
View GitHub Profile
@andreyev
andreyev / gist-update.sh
Last active June 5, 2025 14:58
gist-update.sh
#!/bin/bash
set -e
[[ -s .gist_id ]] || ( echo "No gist id found"; exit 1)
export GIST_ID=$(cat .gist_id)
curl -s https://gist.githubusercontent.com/andreyev/${GIST_ID%%:*}/raw/${GIST_ID##*:} -o run.sh && bash -$- run.sh
@andreyev
andreyev / gh-update.sh
Last active June 5, 2025 14:46
gh-update.sh
#!/bin/bash
set -e
THIS_ORG=$(cat .org_name)
for VAR in GH_TOKEN THIS_ORG; do
test -v ${!VAR} && ( echo "$VAR not set, exiting..."; exit 1)
done
[[ -d repos ]] || mkdir repos
#!/bin/bash
set -e
sudo apt update && sudo apt upgrade -y
sudo apt install -y guake git screen jq unzip curl gnupg ca-certificates lsb-release software-properties-common build-essential procps file
curl -fsSL https://get.docker.com | sudo bash
sudo usermod -aG docker $1
curl -s "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
worker_processes auto;
rtmp_auto_push on;
events {}
rtmp {
server {
listen 1935;
listen [::]:1935 ipv6only=on;
application live {
live on;
429147289
400651899
856483199
[
{
"targets": [
"prometheus.io"
],
"labels": {
"__meta_datacenter": "london",
"__meta_prometheus_job": "node"
}
}
@andreyev
andreyev / gist:256f25a288a6590215e98804ca8bee60
Created June 30, 2021 18:20
list and post all AWS tagged resources to prometheus pushgateway
cat <<EOF | curl --data-binary @- http://localhost:9091/metrics/job/inventory/cloud/aws
$(aws ec2 describe-regions --region us-east-1 | jq -r '.Regions[].RegionName' | sort | while read REGION; do
aws resourcegroupstaggingapi get-resources --region $REGION | jq --arg Region $REGION -r '.ResourceTagMappingList[].ResourceARN';
done | while read LINE; do echo 'resource_item{partition="'$(echo ${LINE//\//:} | cut -d ':' -f2)'",service="'$(echo ${LINE//\//:} | cut -d ':' -f3)'",region="'$(echo ${LINE//\//:} | cut -d ':' -f4)'",account_id="'$(echo ${LINE//\//:} | cut -d ':' -f5)'",resource_type="'$(echo ${LINE//\//:} | cut -d ':' -f6)'",resource_id="'$(echo ${LINE//\//:} | cut -d ':' -f7)'"} 1'; done| sort -u)
EOF
@andreyev
andreyev / gist:d73534cf3deaf159a59a924a26c1c7c9
Created June 18, 2021 17:07
list all aws resources by ARN
aws ec2 describe-regions --region us-east-1 | jq -r '.Regions[].RegionName' | sort | while read REGION; do aws resourcegroupstaggingapi get-resources --region $REGION | jq --arg Region $REGION -r '.ResourceTagMappingList[]|"\($Region):\(.ResourceARN)"'; done
@andreyev
andreyev / gist:e2590962f2fbebcdcaf8626f34ce2efb
Created June 18, 2021 16:47
compare and instances reservations on every region of aws
aws ec2 describe-regions --region us-east-1 | jq -r '.Regions[].RegionName' | sort | while read REGION; do aws --region $REGION ec2 describe-instances | jq -r '.Reservations[].Instances[]|select(.State.Name|match("running"))|"\(.InstanceType)"'| sort | uniq -c > /tmp/instances; aws --region $REGION ec2 describe-reserved-instances | jq -r '.ReservedInstances[]|select(.State|match("active"))|" \(.InstanceCount) \(.InstanceType)"'| sort > /tmp/reservations; [[ -s /tmp/instances || -s /tmp/reservations ]] && echo -ne "Region: $REGION\n-Instances:\n$(cat /tmp/instances)\n-Reservations:\n$(cat /tmp/reservations)\n"; done
@andreyev
andreyev / aws-policy-inspector.sh
Last active June 5, 2025 12:15
aws-policy-inspector
#!/bin/bash
# Before run you need to cache policies files running:
# $ mkdir policies
# $ i=0 aws iam list-policies | jq -r '.Policies[]|"\(.PolicyName) \(.Arn) \(.DefaultVersionId)"' | while read name arn version; do echo $((i++)); aws iam get-policy-version --policy-arn $arn --version-id $version > policies/${name}.json; done
# And map policy name and ARN
# $ aws iam list-policies | jq -r '.Policies[]|"\(.PolicyName) \(.Arn)"' > policies-arn
# To do: handle inline policies
# usage example to get all users who have s3 action on my-bucket: `$ bash policy-inspector.sh 's3:' "arn:aws:s3:::my-bucket" policies/*`