Skip to content

Instantly share code, notes, and snippets.

@ollyg
ollyg / gist:5782078
Last active December 19, 2023 19:09
Setting X-REMOTE_USER in Apache proxied request
RequestHeader unset X-REMOTE_USER
RequestHeader set X-REMOTE_USER "%{REMOTE_USER}e" env=REMOTE_USER
# see http://httpd.apache.org/docs/current/mod/mod_headers.html#header
SELECT ips[1] AS left_ip,
ports[1] AS left_port,
(SELECT array_agg(a) FROM jsonb_array_elements_text(vlans->0) AS a) AS left_vlans,
(SELECT array_agg(a)
FROM jsonb_array_elements_text(vlans->0) AS a
WHERE a NOT IN
(SELECT b FROM jsonb_array_elements_text(vlans->1) AS b)) as only_left_vlans,
ips[2] AS right_ip,
PUT http://localhost:5000/api/v1/object/device/192.0.2.1/nodes
# GET/DELETE methods take query string params to filter:
# device, port, action, status, username, userip, backend
# list of jobs in the queue
# accepts LIMIT option
GET http://localhost:5000/api/v1/queue/jobs
# submit one or more new jobs
SELECT ip
FROM device
LEFT OUTER JOIN admin ON (device.ip = admin.device
AND admin.status = 'queued'
AND admin.action = 'macsuck')
FULL OUTER JOIN device_skip ON (device_skip.device = device.ip
AND (device_skip.actionset @> string_to_array('macsuck', '')
OR (device_skip.deferrals >= '10'
AND device_skip.last_defer > (LOCALTIMESTAMP - '7 days' ::interval))))
WHERE admin.device IS NULL
@ollyg
ollyg / gist:02f3e7d3fbad5e8af7b92f4fe3a13645
Last active November 10, 2022 22:18
macsuck submit API
PUT http://localhost:5000/api/v1/action/macsuck/192.0.2.1?enqueue=true&timestamp=now
port
mac
vlan?
params - "not part of the resource itself" so OK for query string
cannot use macsuck_no because then job refuses to run
but will rows be removed by snmp job exec?
skip is_macsuckable_now in check phase
use early phase to gather data or skip if in `extra` or `port` (mnemonic: path), use store to store.
@ollyg
ollyg / config.yaml
Last active August 22, 2022 08:03
netdisco ignore interfaces revision
ignore_deviceports:
'group:__ANY__':
- 'port:EOBC'
- 'port:unrouted VLAN(?: \d+)?'
# etc...
'vendor:juniper':
- '128.0.0.0/2'
- 'port:.+\.1638[3456]'
- 'port:.+\.3276[789]'
@ollyg
ollyg / netdisco-import-unifi.pl
Created July 21, 2017 07:05
Collection script for UniFi AP controller
#!/usr/bin/env perl
use strict;
use warnings;
our $home;
BEGIN {
use FindBin;
FindBin::again();
@ollyg
ollyg / logstash.conf
Created June 20, 2012 13:29
logstash config and filter to fully parse a syslog message (PRI, timestamp, host)
filter {
# strip the syslog PRI part and create facility and severity fields.
# the original syslog message is saved in field %{syslog_raw_message}.
# the extracted PRI is available in the %{syslog_pri} field.
#
# You get %{syslog_facility_code} and %{syslog_severity_code} fields.
# You also get %{syslog_facility} and %{syslog_severity} fields if the
# use_labels option is set True (the default) on syslog_pri filter.
grok {
type => "syslog-relay"
# curl -f >> onto authorized_keys
# grep a_k for certs
# if more than two lines
# sed out the first N of them
curl -sf https://my-cert.pub >> ~/.ssh/authorized_keys &&
sed -i '' '1!G;h;$!d' ~/.ssh/authorized_keys &&
awk '!/^cert-authority / || ++n < 3' ~/.ssh/authorized_keys > ~/.ssh/authorized_keys.tmp &&
sed '1!G;h;$!d' ~/.ssh/authorized_keys.tmp > ~/.ssh/authorized_keys &&
rm ~/.ssh/authorized_keys.tmp &&
@ollyg
ollyg / netdisco3-ideas.md
Last active November 21, 2019 18:33
netdisco3 ideas

Selected Technologies

  • FastAPI
  • TaskTiger
  • Redis
  • PostgreSQL
  • peewee
  • structlog

Interesting Software