Skip to content

Instantly share code, notes, and snippets.

@dgulinobw
dgulinobw / nginx_accesslog2csv.py
Last active February 14, 2023 10:15
Convert Nginx combinded access log to CSV format, splitting path and parameters into columns, in a memory-efficient manner.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# nginx_accesslog2csv: Convert nginx default, combined access log to CSV format
import os
import csv
import re
import sys
import datetime
@dgulinobw
dgulinobw / getopenPRs.5m.sh
Last active February 8, 2022 16:49
argos/bitbar plugin to check bitbucket PR requests
#!/bin/bash
# shellcheck disable=SC2034
# shellcheck disable=SC2154
# shellcheck source=/dev/null
# <bitbar.title>Bitbucket Pull Requests</bitbar.title>
# <bitbar.version>1.0</bitbar.version>
# <bitbar.author>Mikey Beck</bitbar.author>
# <bitbar.author.github>mikeybeck</bitbar.author.github>
# <bitbar.desc>Shows Bitbucket open pull request information</bitbar.desc>
@dgulinobw
dgulinobw / gerrit_incoming_crs.5m+.py
Last active January 27, 2022 17:35
bitbar/argos gerrit open and unapproved change reviews
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# <bitbar.title>Gerrit Incoming Code Reviews</bitbar.title>
# <bitbar.version>v1.1</bitbar.version>
# <bitbar.author>Ryan Sydnor</bitbar.author>
# <bitbar.author>Drew Gulino</bitbar.author>
# <bitbar.author.github>ryansydnor</bitbar.author.github>
# <bitbar.desc>Displays your incoming code reviews.</bitbar.desc>
# <bitbar.dependencies>python</bitbar.dependencies>
@dgulinobw
dgulinobw / ec2_tagging.py
Last active November 12, 2021 18:09
EC2: set tags on resources to match the tags of the instances they are attached to.
#!/usr/bin/env python
import boto3
import collections
import datetime
import time
ec = boto3.client('ec2',region_name="us-east-1")
reservations = ec.describe_instances().get('Reservations',[])
instances = [
@dgulinobw
dgulinobw / show_limits.sh
Last active August 13, 2021 12:05
Show percentage used of 1) per-process ulimit open files, and 2) system-wide open files limit.
#!/bin/bash
printf "%-20s %10s %10s %14s\n" "Process" "Ulimit" "Used" "% Ulimit Used"
length=62
printf -v line '%*s' "$length"
echo ${line// /-}
# gather proceses to list from all of /var/run/
for f in $(find /var/run/ -type f -name "*.pid" | sort)
# gather processes to list from monit
#for f in $(grep pidfile /etc/monit.d/* | awk '{print $6}' | sort)
@dgulinobw
dgulinobw / iam_scan.py
Last active July 22, 2021 20:57
List out all AWS IAM policies of user, group, role, and s3 buckets
#!/usr/bin/env python
from __future__ import print_function
import boto3
import sys
from pygments import highlight, lexers, formatters
from botocore.exceptions import ClientError
iam = boto3.resource('iam')
s3 = boto3.client('s3')
@dgulinobw
dgulinobw / iam_key_scan.py
Created July 22, 2021 18:46
List all users and their active access keys
#!/usr/bin/env python
from __future__ import print_function
import boto3
iam = boto3.resource('iam')
for user in iam.users.all():
for key in user.access_keys.all():
if key.status == "Active":
print("user: {}, key: {}".format(user.name, key.id))
@dgulinobw
dgulinobw / replace_ec2_sg_ip.py
Created July 22, 2021 18:12
Search and replace an IP/CIDR in all AWS EC2 security groups
#!/usr/bin/env python
from __future__ import print_function
import json
import boto3
from botocore.exceptions import ClientError
ip="50.56.24.206/32"
new_ip="192.237.176.126/32"
for region in ["us-east-1","us-west-1", "us-west-2"]:
@dgulinobw
dgulinobw / ec2_sg_scan.py
Created July 22, 2021 18:06
Searches through AWS EC2 security groups for entries. Example: ./ec2_sg_scan.py 1.2.3.4
#!/usr/bin/env python
from __future__ import print_function
import sys
import json
import boto3
from pprint import pprint
from termcolor import colored
from botocore.exceptions import ClientError
@dgulinobw
dgulinobw / gerrit_incoming_crs.5m+.py
Created June 10, 2021 16:13
Gerrit Incoming Code Reviews for bitbar/argos
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# <bitbar.title>Gerrit Incoming Code Reviews</bitbar.title>
# <bitbar.version>v1.0</bitbar.version>
# <bitbar.author>Ryan Sydnor</bitbar.author>
# <bitbar.author.github>ryansydnor</bitbar.author.github>
# <bitbar.desc>Displays your incoming code reviews.</bitbar.desc>
# <bitbar.dependencies>python</bitbar.dependencies>