Skip to content

Instantly share code, notes, and snippets.

View kchristensen's full-sized avatar

Kyle Christensen kchristensen

View GitHub Profile
@kchristensen
kchristensen / wireguard.j2
Last active April 28, 2023 12:12
Turn UnifiOS Wireguard configs into MacOS device profiles
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PayloadDisplayName</key>
<string>WireGuard</string>
<key>PayloadType</key>
<string>Configuration</string>
<key>PayloadDescription</key>
<string>Configures WireGuard VPN profiles</string>
@kchristensen
kchristensen / check_haproxy_health.py
Last active August 31, 2021 23:07
Nagios Haproxy Health Check
#!/usr/bin/env python
import sys
import urllib2
if len(sys.argv) != 2:
print('USAGE: {0} <hostname>').format(sys.argv[0])
sys.exit(2)
try:
@kchristensen
kchristensen / fancontrol.sh
Created January 10, 2020 17:19
Dell R720 Fan Control
#!/usr/bin/env bash
CWD=$(dirname "$0")
# This file should contain: IDRAC_PASSWORD="YOUR_PASSWORD"
. ${CWD}/fancontrol.env
IDRAC_HOST="idrac.yourdomain.com"
IDRAC_USER="root"
IPMI_CMD="ipmitool -I lanplus -H ${IDRAC_HOST} -U ${IDRAC_USER} -P ${IDRAC_PASSWORD}"
@kchristensen
kchristensen / letsencrypt.sh
Last active January 2, 2017 15:51
Automatically renew SSL certificates issued by letsencrypt
#!/bin/env bash
function help() {
echo "Usage: $0 -d <DOMAIN> -e <EMAIL> -s <KEYSIZE>"
exit 1
}
DAYS_TO_RENEW=35
EMAIL="kyle@junglist.org"
KEY_SIZE=2048
@kchristensen
kchristensen / php_watch.php
Last active April 18, 2016 20:45
Inotify example
<?php
$fd = inotify_init();
$watch_dir = '/tmp/';
$watch_email = 'kyle@crowdgather.com';
$new_files = array();
$last_event = time();
$interval = 10;
stream_set_blocking($fd, 0);
@kchristensen
kchristensen / check_dns_resolution.py
Last active January 3, 2016 07:28
Nagios DNS resolution health check
#!/usr/bin/env python
"""
Nagios check to test DNS resolution data pulled from Graphite
"""
import optparse
import logging
import requests
import sys
#!/bin/sh
# Edit in the commands you want to run
COMMAND="uptime"
unset CHAR PASS CONFIRM
echo -n "Enter webserver root password: "
while IFS= read -r -s -n1 CHAR
do
@kchristensen
kchristensen / docker-watch.sh
Created December 17, 2015 14:00
Watches docker to see if any of your containers have exited abnormally and notifies slack
#!/bin/bash
INSTANCE=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
SLACK_CHANNEL='#ops-notifications'
SLACK_URL='<%= node['base']['slack']['hook'] %>'
SLACK_USERNAME='DockerBot'
for CONTAINER in $(docker ps -a|grep -v CONTAINER|awk '{print $1}')
do
STATE=$(docker inspect -f '{{.State.Running}}' ${CONTAINER})
@kchristensen
kchristensen / gist:eb4bd6aa3200dafbe52d
Last active December 12, 2015 07:49
PHP Globals micro optimization
/*
foreach ($GLOBALS as $field => $value)
{
if (!in_array($field, array('_ENV', '_POST', '_GET', '_SERVER', '_FILES', '_REQUEST', 'GLOBALS', '_COOKIE')))
{
$data[$field] = $value;
}
}
*/
@kchristensen
kchristensen / ec2-instance-slack-watch.py
Last active December 10, 2015 15:28
Notify Slack if people leave EC2 test instances running
#!/usr/bin/env python
import boto3
import json
import requests
from datetime import datetime
filter = [{'Name': 'tag:Name', 'Values': ['test-kitchen', 'Packer']}]
boto3.setup_default_session(profile_name='prod')
ec2 = boto3.resource('ec2')