Skip to content

Instantly share code, notes, and snippets.

View thepacketgeek's full-sized avatar

Mat Wood thepacketgeek

View GitHub Profile
@thepacketgeek
thepacketgeek / .zshrc
Created January 6, 2022 18:20
Git checkout branch w/ fzf
gch() {
git checkout $(git for-each-ref refs/heads/ --format='%(refname:short)' | fzf)
}
gchr() {
git checkout --track $(git branch --remotes | fzf)
}
@thepacketgeek
thepacketgeek / host-cargo-docs.sh
Created January 4, 2022 22:00
Host `cargo doc` in HTTP server
#!/bin/bash
set -o errexit
pushd `BROWSER=echo cargo doc --open | sed "s/\/doc\/.*/\/doc\//"` && python -m http.server; popd
@thepacketgeek
thepacketgeek / gist:6f00c7d2e2d9e4ba8df20b9adf214067
Created June 25, 2021 17:59
Telegraf Syslog with "source" tag
./telegraf --test --config /etc/telegraf/telegraf.conf --input-filter syslog --test-wait 15
2021-06-25T17:55:06Z I! Starting Telegraf
> syslog,appname=docker-compose,facility=daemon,host=bb8,hostname=droplet,location=home,severity=info,source=10.0.0.12 facility_code=3i,message="<redacted>",severity_code=6i,timestamp=1624643706396113000i,version=1i 1624643706400667198
> syslog,appname=tailscaled,facility=daemon,host=bb8,hostname=dev,location=home,severity=info,source=10.0.0.15 facility_code=3i,message="<redacted>",severity_code=6i,timestamp=1624643706403394000i,version=1i 1624643706407850408
> syslog,appname=docker-compose,facility=daemon,host=bb8,hostname=droplet,location=home,severity=info,source=10.0.0.12 facility_code=3i,message="<redacted>",severity_code=6i,timestamp=1624643706675853000i,version=1i 1624643706679251683
> syslog,appname=multipathd,facility=daemon,host=bb8,hostname=droplet,location=home,severity=info,source=10.0.0.12 facility_code=3i,message="<redacted>",severity_code=6i,timestamp=162464370
@thepacketgeek
thepacketgeek / gist:24dc4665cc4045d730ca032ed4b8aaa1
Created November 24, 2020 14:28
Influx Query for showing delta of cumulative iface counts
SELECT
non_negative_derivative(mean("ifHCInOctets"), 1s) * 8 AS "Rx",
non_negative_derivative(mean("ifHCOutOctets"), 1s) * 8 AS "Tx"
FROM "interface"
WHERE ("ifAlias" = 'Some if here')
AND $timeFilter GROUP BY time($__interval) fill(null)

Diving into Rust

If you're wanting to get involved with Rust projects and see what the magic is all about, here are some great starting points!

Read

  • A Gentle Introduction
    • A little more focused on the main concepts, only takes an hour or so
  • The Book
    • This is the first and foremost (albiet most time consuming) way to get familiar
  • Py2Rs
extern crate pcarp;
use std::fs::File;
use std::io::{Cursor, Read};
use std::net::IpAddr;
use std::path::Path;
use std::result::Result;
use bgp_rs::{Header, Message, Reader};
use byteorder::{NetworkEndian, ReadBytesExt};
Update {
withdrawn_routes: [],
attributes: [
ORIGIN(
IGP
),
AS_PATH(
ASPath {
segments: []
}
@thepacketgeek
thepacketgeek / calc_mask_length.py
Created July 24, 2015 15:19
Convert Subnet Mask to CIDR length
def calc_mask_length(mask):
""" Convert subnet mask (255.255.255.0) to CIDR mask length (/24) """
return sum([bin(int(x)).count('1') for x in mask.split('.')])
print calc_mask_length('255.255.255.0')
# 24
#!/usr/bin/env python
## Tiny Syslog Server in Python.
##
## This is a tiny syslog server that is able to receive UDP based syslog
## entries on a specified port and save them to a file.
## That's it... it does nothing else...
## There are a few configuration parameters.
LOG_FILE = 'youlogfile.log'
import paramiko
import re
from time import sleep
# Router connection details (could be read in from file or argparse)
peer = '172.16.2.10'
username = 'admin'
password = 'admin'
def collect_output(shell, command):