Skip to content

Instantly share code, notes, and snippets.

View mitchellrj's full-sized avatar

Richard Mitchell mitchellrj

View GitHub Profile
@mitchellrj
mitchellrj / jmx-config.yml
Created February 5, 2022 12:25
Unifi CloudKey Prometheus monitoring
# taken from https://github.com/jacobalberty/unifi-docker/issues/408
---
lowercaseOutputLabelNames: true
lowercaseOutputName: true
rules:
- pattern: 'Tomcat<type=GlobalRequestProcessor, name=\"(\w+-\w+)-(\d+)\"><>(\w+):'
name: tomcat_$3_total
labels:
port: "$2"
protocol: "$1"
@mitchellrj
mitchellrj / rpict_exporter.py
Last active September 2, 2023 08:53
Basic Prometheus exporter and REST API for a single sensor from the LeChacal RPICT hat.
#!env python3
#
# Usage: rpict_exporter.py DEVICE DEVICE_TYPE [HOST] [PORT] [SENSOR NAMES...]
# Example usage: rpict_exporter.py /dev/ttyAMA0 RPICT3T1 0.0.0.0 9999
#
# MIT License
#
# Copyright (c) 2021 Richard Mitchell
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
@mitchellrj
mitchellrj / readme.md
Last active April 22, 2021 19:22
Get snapshot from Unifi Protect

Any commands in this guide are to be run on the CloudKey over SSH.

1. Create a new read-only user

Do this through the web interface, create a local user with username & password (not email address). It doesn't matter what you set the password to, you'll never use it.

2. Set your user to have the right permissions

There's no option to set user permissions through the web interface for local users. We need to find out the ID of the View Only group...

psql -p 5433 -U unifi-protect unifi-protect -c "SELECT id from groups WHERE name='View Only';"
@mitchellrj
mitchellrj / Dockerfile
Last active April 2, 2020 16:37
Prometheus exporter for Netgear LTE modems. Rough and ready.
FROM arm32v7/python:stretch
ENV MODEM_HOST=127.0.0.1
ENV MODEM_PASSWORD=password
EXPOSE 8000
RUN sh -c 'apk add --no-cache python3; python3 -m pip install eternalegypt prometheus_client'
COPY netgear_prometheus.py /netgear_prometheus.py
USER nobody
@mitchellrj
mitchellrj / reader.py
Last active June 5, 2018 16:36
Cheap and cheerful image recovery from a corrupted SD card that keeps unmounting itself
# usage:
# sudo python reader.py /dev/disk2s2 path-to-my-image.img
#
# keep re-inserting the card and hitting enter as instructed
import os.path
import sys
@mitchellrj
mitchellrj / README.md
Last active June 4, 2018 16:52
RFC6225 value calculator

I have no idea if this is a correct implementation or not, as I have no reference implementation to compare it to. I swear there used to be an implementation as part of Android but I can't find it now.

@mitchellrj
mitchellrj / plex-auto-updater.sh
Created May 12, 2018 19:17
CentOS / Red Hat auto updater script for Plex media server
#!/bin/sh
plex_token="YOUR TOKEN HERE"
plex_rpm_url="https://plex.tv/downloads/latest/1?channel=8&build=linux-ubuntu-x86_64&distro=redhat&X-Plex-Token=$plex_token"
current_version="$(rpm -q --queryformat '%{VERSION}\n' plexmediaserver)"
latest_version="$(curl -I $plex_rpm_url 2>/dev/null | egrep '^Location:' | cut -d'/' -f 5 | cut -d'-' -f1)"
if [ "$current_version" != "$latest_version" ]; then
rpm -Uvh $plex_rpm_url >/dev/null 2>&1
success="$?"
@mitchellrj
mitchellrj / export_single_slack_channel.py
Last active January 4, 2019 10:44
Export history from a single Slack channel
#!/usr/bin/env python3
import csv
import datetime
import getpass
import os
import re
import sys
import time
@mitchellrj
mitchellrj / Dockerfile
Created January 2, 2018 21:01
home-assistant.io Docker
FROM alpine:latest
EXPOSE 8123
VOLUME ["/root/.homeassistant"]
RUN ["apk", "update"]
RUN ["apk", "add", "--no-cache", "g++", "python3-dev", "python3", "linux-headers"]
RUN ["python3", "-m", "pip", "install", "homeassistant", "netdisco", "sqlalchemy", "warrant", "xmltodict"]
# Trim the fat
@mitchellrj
mitchellrj / settings.py
Created May 17, 2016 11:35
Show all queries in console for Django
LOGGING = {
'handlers': {
'console': {
# ...
},
# ...
},
'loggers': {
'django.db.backends': {
'handlers': ['console'],