Browse Source

Make json dns data pretty with jq

Ask Bjørn Hansen 7 years ago
parent
commit
30b1cf41a7
6 changed files with 331 additions and 87 deletions
  1. 15 7
      dns/1.168.192.in-addr.arpa.json
  2. 2 0
      dns/Makefile
  3. 91 21
      dns/example.com.json
  4. 53 18
      dns/hc.example.com.json
  5. 152 30
      dns/test.example.com.json
  6. 18 11
      dns/test.example.org.json

+ 15 - 7
dns/1.168.192.in-addr.arpa.json

@@ -1,5 +1,6 @@
-{ "serial": 3,
-  "ttl":    600,
+{
+  "serial": 3,
+  "ttl": 600,
   "max_hosts": 2,
   "origin": "1.168.192.IN-ADDR.ARPA.",
   "logging": {
@@ -8,13 +9,20 @@
   },
   "targeting": "country continent @ regiongroup region ip asn",
   "contact": "support.bitnames.com",
-  "data" : {
-    "":  {
-      "ns": { "ns1.example.net.": null, "ns2.example.net.": null }
+  "data": {
+    "": {
+      "ns": {
+        "ns1.example.net.": null,
+        "ns2.example.net.": null
+      }
     },
     "2": {
-        "ptr": [ [ "bar.example.com." ] ],
-        "ttl": "601"
+      "ptr": [
+        [
+          "bar.example.com."
+        ]
+      ],
+      "ttl": "601"
     }
   }
 }

+ 2 - 0
dns/Makefile

@@ -0,0 +1,2 @@
+pretty:
+	bash -c 'for f in *.json; do echo $$f; jq . < $$f > $$f.tmp && mv $$f.tmp $$f; done'

+ 91 - 21
dns/example.com.json

@@ -1,29 +1,99 @@
-{ "serial": 3,
-  "ttl":    600,
+{
+  "serial": 3,
+  "ttl": 600,
   "max_hosts": 2,
-  "data" : {
-    "":  {
-      "ns": { "ns1.example.net.": null, "ns2.example.net.": null },
-      "mx": [ { "preference": 20, "mx": "mx2.example.net", "weight": 0 },
-              { "preference": 10, "mx": "mx.example.net.", "weight": 1 }
-            ]
-    },
-    "europe": { "mx": [ { "mx": "mx-eu.example.net" }]},
-    "foo": { 
-      "a": [ [ "192.168.1.2", 10 ], [ "192.168.1.3", 10 ], [ "192.168.1.4", 10 ] ],
-      "aaaa": [ ["fd06:c1d3:e902::2", 10], ["fd06:c1d3:e902:202:a5ff:fecd:13a6:a", 10], ["fd06:c1d3:e902::4", 10] ]
-    },
-    "weight": { 
-      "a": [ [ "192.168.1.2", 100 ], [ "192.168.1.3", 50 ], [ "192.168.1.4", 25 ] ],
+  "data": {
+    "": {
+      "ns": {
+        "ns1.example.net.": null,
+        "ns2.example.net.": null
+      },
+      "mx": [
+        {
+          "preference": 20,
+          "mx": "mx2.example.net",
+          "weight": 0
+        },
+        {
+          "preference": 10,
+          "mx": "mx.example.net.",
+          "weight": 1
+        }
+      ]
+    },
+    "europe": {
+      "mx": [
+        {
+          "mx": "mx-eu.example.net"
+        }
+      ]
+    },
+    "foo": {
+      "a": [
+        [
+          "192.168.1.2",
+          10
+        ],
+        [
+          "192.168.1.3",
+          10
+        ],
+        [
+          "192.168.1.4",
+          10
+        ]
+      ],
+      "aaaa": [
+        [
+          "fd06:c1d3:e902::2",
+          10
+        ],
+        [
+          "fd06:c1d3:e902:202:a5ff:fecd:13a6:a",
+          10
+        ],
+        [
+          "fd06:c1d3:e902::4",
+          10
+        ]
+      ]
+    },
+    "weight": {
+      "a": [
+        [
+          "192.168.1.2",
+          100
+        ],
+        [
+          "192.168.1.3",
+          50
+        ],
+        [
+          "192.168.1.4",
+          25
+        ]
+      ],
       "max_hosts": "1"
     },
-    "bar": { 
-      "a": [ [ "192.168.1.2", 10 ] ],
+    "bar": {
+      "a": [
+        [
+          "192.168.1.2",
+          10
+        ]
+      ],
       "ttl": "601"
     },
-    "bar.no": { "a": [] },
+    "bar.no": {
+      "a": []
+    },
     "0": {
-      "a": [ [ "192.168.0.1", 10 ] ]
+      "a": [
+        [
+          "192.168.0.1",
+          10
+        ]
+      ]
     },
     "0-alias": {
       "alias": "0"
@@ -42,7 +112,7 @@
       "ttl": 86400
     },
     "cname-internal-referal": {
-      "cname": "bar"      
+      "cname": "bar"
     }
   }
 }

+ 53 - 18
dns/hc.example.com.json

@@ -1,28 +1,63 @@
-{ "serial": 3,
-  "ttl":    600,
+{
+  "serial": 3,
+  "ttl": 600,
   "max_hosts": 2,
   "targeting": "country continent @ regiongroup region",
-  "data" : {
-    "":  {
-      "ns": { "ns1.example.net.": null, "ns2.example.net.": null },
-      "mx": [ { "preference": 20, "mx": "mx2.example.net", "weight": 0 },
-              { "preference": 10, "mx": "mx.example.net.", "weight": 1 }
-            ]
+  "data": {
+    "": {
+      "ns": {
+        "ns1.example.net.": null,
+        "ns2.example.net.": null
+      },
+      "mx": [
+        {
+          "preference": 20,
+          "mx": "mx2.example.net",
+          "weight": 0
+        },
+        {
+          "preference": 10,
+          "mx": "mx.example.net.",
+          "weight": 1
+        }
+      ]
     },
     "tucs": {
-      "a": [ [ "194.106.223.155", 100 ], [ "199.15.176.188", 100 ],
-             [ "207.171.7.49", 100 ], [ "207.171.7.59", 100 ],
-             [ "207.171.7.64", 100 ], [ "207.171.7.65", 100 ]
-           ],
+      "a": [
+        [
+          "194.106.223.155",
+          100
+        ],
+        [
+          "199.15.176.188",
+          100
+        ],
+        [
+          "207.171.7.49",
+          100
+        ],
+        [
+          "207.171.7.59",
+          100
+        ],
+        [
+          "207.171.7.64",
+          100
+        ],
+        [
+          "207.171.7.65",
+          100
+        ]
+      ],
       "max_hosts": "1",
       "closest": true,
       "health": {
-         "type": "tcp",
-         "frequency": 15,
-         "retry_time": 5,
-         "retries": 2,
-         "timeout": 3,
-         "port": 80
+        "type": "tcp",
+        "frequency": 15,
+        "retry_time": 5,
+        "retries": 2,
+        "timeout": 3,
+        "port": 80
       }
     }
   }

+ 152 - 30
dns/test.example.com.json

@@ -1,53 +1,166 @@
-{ "serial": 3,
-  "ttl":    600,
+{
+  "serial": 3,
+  "ttl": 600,
   "max_hosts": 2,
-  "logging": {
-  },
+  "logging": {},
   "targeting": "country continent @ regiongroup region ip asn",
   "contact": "support.bitnames.com",
-  "data" : {
-    "":  {
-      "ns": { "ns1.example.net.": null, "ns2.example.net.": null },
-      "spf": [ { "spf": "v=spf1 ~all", "weight": 1000 } ],
-      "mx": [ { "preference": 20, "mx": "mx2.example.net", "weight": 0 },
-              { "preference": 10, "mx": "mx.example.net.", "weight": 1 }
-            ]
-    },
-    "europe": { "mx": [ { "mx": "mx-eu.example.net" }]},
+  "data": {
+    "0": {
+      "a": [
+        [
+          "192.168.0.1",
+          10
+        ]
+      ]
+    },
+    "": {
+      "ns": {
+        "ns1.example.net.": null,
+        "ns2.example.net.": null
+      },
+      "spf": [
+        {
+          "spf": "v=spf1 ~all",
+          "weight": 1000
+        }
+      ],
+      "mx": [
+        {
+          "preference": 20,
+          "mx": "mx2.example.net",
+          "weight": 0
+        },
+        {
+          "preference": 10,
+          "mx": "mx.example.net.",
+          "weight": 1
+        }
+      ]
+    },
+    "europe": {
+      "mx": [
+        {
+          "mx": "mx-eu.example.net"
+        }
+      ]
+    },
     "foo": {
-      "a": [ [ "192.168.1.2", 10 ], [ "192.168.1.3", 10 ], [ "192.168.1.4", 10 ] ],
-      "aaaa": [ ["fd06:c1d3:e902::2", 10], ["fd06:c1d3:e902:202:a5ff:fecd:13a6:a", 10], ["fd06:c1d3:e902::4", 10] ],
+      "a": [
+        [
+          "192.168.1.2",
+          10
+        ],
+        [
+          "192.168.1.3",
+          10
+        ],
+        [
+          "192.168.1.4",
+          10
+        ]
+      ],
+      "aaaa": [
+        [
+          "fd06:c1d3:e902::2",
+          10
+        ],
+        [
+          "fd06:c1d3:e902:202:a5ff:fecd:13a6:a",
+          10
+        ],
+        [
+          "fd06:c1d3:e902::4",
+          10
+        ]
+      ],
       "txt": "this is foo"
     },
     "weight": {
-      "a": [ [ "192.168.1.2", 100 ], [ "192.168.1.3", 50 ], [ "192.168.1.4", 25 ] ],
-      "txt": [ { "txt": "w10000", "weight": 10000 },
-               { "txt": "w1",   "weight": 1 }
-             ],
+      "a": [
+        [
+          "192.168.1.2",
+          100
+        ],
+        [
+          "192.168.1.3",
+          50
+        ],
+        [
+          "192.168.1.4",
+          25
+        ]
+      ],
+      "txt": [
+        {
+          "txt": "w10000",
+          "weight": 10000
+        },
+        {
+          "txt": "w1",
+          "weight": 1
+        }
+      ],
       "max_hosts": "1"
     },
-   "_sip._tcp": { "srv": [ { "port": 5060, "srv_weight": 100, "priority": 10, "target": "sipserver.example.com."}] },
+    "_sip._tcp": {
+      "srv": [
+        {
+          "port": 5060,
+          "srv_weight": 100,
+          "priority": 10,
+          "target": "sipserver.example.com."
+        }
+      ]
+    },
     "bar": {
-      "a": [ [ "192.168.1.2" ] ],
+      "a": [
+        [
+          "192.168.1.2"
+        ]
+      ],
       "ttl": "601"
     },
     "three.two.one": {
-      "a": [ [ "192.168.1.5" ] ],
+      "a": [
+        [
+          "192.168.1.5"
+        ]
+      ],
       "ttl": "601"
     },
     "one": {
-      "a": [ [ "192.168.1.6" ] ],
+      "a": [
+        [
+          "192.168.1.6"
+        ]
+      ],
       "ttl": "601"
     },
     "a.b.c": {
-      "a": [ [ "192.168.1.7" ] ],
+      "a": [
+        [
+          "192.168.1.7"
+        ]
+      ],
       "ttl": "601"
     },
-    "bar.no": { "a": [] },
-    "bar.as15169": { "a": [ ["192.168.1.4" ] ] },
-    "bar.[1.0.0.255]": { "a": [ ["192.168.1.3" ] ] },
-    "0": {
-      "a": [ [ "192.168.0.1", 10 ] ]
+    "bar.no": {
+      "a": []
+    },
+    "bar.as15169": {
+      "a": [
+        [
+          "192.168.1.4"
+        ]
+      ]
+    },
+    "bar.[1.0.0.255]": {
+      "a": [
+        [
+          "192.168.1.3"
+        ]
+      ]
     },
     "0-alias": {
       "alias": "0"
@@ -66,7 +179,16 @@
       "cname": "geo-europe.bitnames.com."
     },
     "www.se": {
-      "cname": [ [ "geo-europe", 10 ], [ "geo-dk", 10 ] ]
+      "cname": [
+        [
+          "geo-europe",
+          10
+        ],
+        [
+          "geo-dk",
+          10
+        ]
+      ]
     },
     "www-cname": {
       "cname": "bar"

+ 18 - 11
dns/test.example.org.json

@@ -1,14 +1,21 @@
 {
-    "data" : {
-        "bad-example-there-really-should-be-an-ns-record-at-the-apex-here": {},
-        "bar": {
-            "a": [ [ "192.168.1.2" ] ]
-        },
-        "sub-alias": {
-        	"alias": "sub"
-        },
-        "sub": {
-        	"ns": [ "ns1.example.com", "ns2.example.com" ]
-        }
+  "data": {
+    "bad-example-there-really-should-be-an-ns-record-at-the-apex-here": {},
+    "bar": {
+      "a": [
+        [
+          "192.168.1.2"
+        ]
+      ]
+    },
+    "sub-alias": {
+      "alias": "sub"
+    },
+    "sub": {
+      "ns": [
+        "ns1.example.com",
+        "ns2.example.com"
+      ]
     }
+  }
 }