Skip to content

Instantly share code, notes, and snippets.

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]'
# 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

@ollyg
ollyg / gist:16680dba03c7a3d06646481c601f7502
Last active September 2, 2019 21:11
search and fix unescaped TT variables
# find files
g grep -cP "% [a-z][a-z._\(\/\)']+ %" share/views/
# vim command
.,$s:\(% \l[a-z._('/)]\+\) %:\1 | hmtl_entity %:cgI
Device
GET /device??q={search}&{params} # Lists ALL devices OR filters by search and/or params, if present
# params: vendor, dns, name, location, ip, description
# these can hopefully be autogenerated/parsed
POST /device # Creates a device.
GET /device/{ip} # Gets Device Generic Info
GET /device/{ip}/{query}
# query is one of:
# Details
@ollyg
ollyg / gist:611b3cb119e890e1e48e9285429d15fa
Created March 17, 2019 20:27
API implementation notes
Search
Device
Port
VLAN
Node
Device
Details
Ports
Modules