Skip to content

Instantly share code, notes, and snippets.

View slackpad's full-sized avatar

James Phillips slackpad

View GitHub Profile

Keybase proof

I hereby claim:

  • I am slackpad on github.
  • I am slackpad (https://keybase.io/slackpad) on keybase.
  • I have a public key whose fingerprint is 341A 925E B454 13DF AC9C A866 7718 3E68 2AC5 FC11

To claim this, I am signing this object:

@slackpad
slackpad / demo_checks.md
Last active December 8, 2015 08:01
Sample Consul check configurations from the Consul demo

disk.json

{
    "check": {
        "name": "Disk Util",
        "interval": "60s",
        "notes": "Critical 5%, warning 10% free",
        "script": "/usr/lib/nagios/plugins/check_disk -w 10% -c 5% -p /"
    }
}
{
"check": {
"name": "Disk Util",
"interval": "60s",
"notes": "Critical 5%, warning 10% free",
"script": "/usr/lib/nagios/plugins/check_disk -w 10% -c 5% -p /"
}
}
{
{
"Name": "My-Test-Token",
"Type": "client",
"Rules": "
key \"\" { policy = \"read\" }
key \"web/\" { policy = \"write\" }
key \"web/key1\" { policy = \"deny\" }
service \"\" { policy = \"write\" }
service \"secure-\" { policy = \"read\" }
event \"\" { policy = \"write\" }
dig @127.0.0.1 -p8600 nope.node.consul

; <<>> DiG 9.8.3-P1 <<>> @127.0.0.1 -p8600 nope.node.consul
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 14084
;; flags: qr aa rd; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; WARNING: recursion requested but not available
@slackpad
slackpad / dead_nodes.md
Last active March 23, 2016 17:53
A bare-bones dead node notification system for Consul

Here's a basic watch script that will look through the output for serfHealth checks in the critical state. The serfHealth check is a built-in check added by Consul that keeps track of the health of a node. When this watch handler fires, it will get the JSON body of the health endpoint passed to it over stdin.

#!/bin/sh
for node in $(jq '.[] | select(.CheckID=="serfHealth" and .Status=="critical") | .Node' -); do
 echo "$node is dead"
{
"Name": "",
"Template": {
"Type": "name_prefix_match"
},
"Service": {
"Service": "${name.full}",
"Failover": {
"NearestN": 3
}
{
"Config": {
"DevMode": true,
"Bootstrap": false,
"BootstrapExpect": 0,
"Server": true,
"Datacenter": "dc1",
"DataDir": "",
"DNSRecursor": "",
"DNSRecursors": [],
@slackpad
slackpad / consul-dns-log.patch
Created December 19, 2016 22:59
Simple patch to add extra TRACE level logging for failed requests
diff --git a/command/agent/dns.go b/command/agent/dns.go
index 7f373cd4..9fa78b66 100644
--- a/command/agent/dns.go
+++ b/command/agent/dns.go
@@ -270,6 +270,9 @@ func (d *DNSServer) handleQuery(resp dns.ResponseWriter, req *dns.Msg) {
if err := resp.WriteMsg(m); err != nil {
d.logger.Printf("[WARN] dns: failed to respond: %v", err)
}
+ if m.MsgHdr.Rcode != 0 {
+ d.logger.Printf("[TRACE] dns: request for %v failed: rcode=%s", q, dns.RcodeToString[m.MsgHdr.Rcode])
panic: in txn 802578 node leaf channel closed in 0
goroutine 52 [running]:
panic(0xee1140, 0xc454d24f40)
/usr/local/go/src/runtime/panic.go:500 +0x1a1
github.com/hashicorp/consul/vendor/github.com/hashicorp/go-immutable-radix.(*Txn).writeNode(0xc4533a4320, 0xc44eede460, 0xc42038d401, 0x1)
/root/go/src/github.com/hashicorp/consul/vendor/github.com/hashicorp/go-immutable-radix/iradix.go:164 +0x5cb
github.com/hashicorp/consul/vendor/github.com/hashicorp/go-immutable-radix.(*Txn).delete(0xc4533a4320, 0xc44eede4b0, 0xc44eede460, 0xc454d24ecf, 0x0, 0x1, 0x1, 0x1)
/root/go/src/github.com/hashicorp/consul/vendor/github.com/hashicorp/go-immutable-radix/iradix.go:302 +0x169
github.com/hashicorp/consul/vendor/github.com/hashicorp/go-immutable-radix.(*Txn).delete(0xc4533a4320, 0xc4533ddcc0, 0xc44eede4b0, 0xc454d24ecc, 0x3, 0x4, 0x1, 0x8)