From 508437a6c0b140ef404eb8d5ba94a92515e45975 Mon Sep 17 00:00:00 2001 From: pettai Date: Sat, 19 Oct 2024 08:01:24 +0200 Subject: [PATCH 1/2] add more parsing functionality for transfering state --- jc/parsers/nsd_control.py | 16 +++++++++++++++- .../fixtures/generic/nsd_control-zonestatus.json | 2 +- .../fixtures/generic/nsd_control-zonestatus.out | 6 ++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/jc/parsers/nsd_control.py b/jc/parsers/nsd_control.py index fd80e9501..01f9dc887 100644 --- a/jc/parsers/nsd_control.py +++ b/jc/parsers/nsd_control.py @@ -89,7 +89,7 @@ def _process(proc_data): List of Dictionaries. Structured to conform to the schema. """ - int_list = {'verbosity', 'ratelimit', 'wait'} + int_list = {'verbosity', 'ratelimit', 'wait', 'transfer'} for entry in proc_data: for key in entry: @@ -229,6 +229,20 @@ def parse(data: str, raw: bool = False, quiet: bool = False): raw_output.append(zonename) continue + if line.startswith('notified-serial:'): + linedata = line.split(': ', maxsplit=1) + notified = linedata[1].strip('"').rstrip('"') + zstatus.update({'notified-serial': notified}) + continue + + if line.startswith('transfer:'): + linedata = line.split(': ', maxsplit=1) + transfer = linedata[1].strip('"').rstrip('"') + zstatus.update({'transfer': transfer}) + zonename.update({'status': zstatus}) + raw_output.append(zonename) + continue + # stats if line.startswith('server') or line.startswith('num.') or line.startswith('size.') or line.startswith('time.') or line.startswith('zone.'): itrparse = True diff --git a/tests/fixtures/generic/nsd_control-zonestatus.json b/tests/fixtures/generic/nsd_control-zonestatus.json index bf3b32437..6d2e06825 100644 --- a/tests/fixtures/generic/nsd_control-zonestatus.json +++ b/tests/fixtures/generic/nsd_control-zonestatus.json @@ -1 +1 @@ -[{"zone":"sunet.se","status":{"state":"ok","served-serial":"2023091302 since 2023-09-14T00:50:11","commit-serial":"2023091302 since 2023-09-14T07:04:05","wait":"27023 sec between attempts"}},{"zone":"catz.sunet.se","status":{"pattern":"example.catalog","catalog-member-id":"4b6f6ce2de5929e4.zones.example.catalog.","state":"ok","served-serial":"1705484863 since 2024-01-17T13:06:02","commit-serial":"1705484863 since 2024-01-17T13:06:02","wait":"21341 sec between attempts"}}] +[{"zone":"sunet.se","status":{"state":"ok","served-serial":"2023091302 since 2023-09-14T00:50:11","commit-serial":"2023091302 since 2023-09-14T07:04:05","wait":"27023 sec between attempts"}},{"zone":"sunet.dev","status":{"state":"refreshing","served-serial":"2023095893 since 2024-10-10T10:10:35","commit-serial":"2023095893 since 2024-10-18T10:00:45","notified-serial":"2023095880 since 2024-10-19T06:11:35","transfer":"TCP connected to 192.168.1.100"}},{"zone":"catz.sunet.se","status":{"pattern":"example.catalog","catalog-member-id":"4b6f6ce2de5929e4.zones.example.catalog.","state":"ok","served-serial":"1705484863 since 2024-01-17T13:06:02","commit-serial":"1705484863 since 2024-01-17T13:06:02","wait":"21341 sec between attempts"}}] diff --git a/tests/fixtures/generic/nsd_control-zonestatus.out b/tests/fixtures/generic/nsd_control-zonestatus.out index 4b57fcde9..cda4a4848 100644 --- a/tests/fixtures/generic/nsd_control-zonestatus.out +++ b/tests/fixtures/generic/nsd_control-zonestatus.out @@ -3,6 +3,12 @@ zone: sunet.se served-serial: "2023091302 since 2023-09-14T00:50:11" commit-serial: "2023091302 since 2023-09-14T07:04:05" wait: "27023 sec between attempts" +zone: sunet.dev + state: refreshing + served-serial: "2023095893 since 2024-10-10T10:10:35" + commit-serial: "2023095893 since 2024-10-18T10:00:45" + notified-serial: "2023095880 since 2024-10-19T06:11:35" + transfer: "TCP connected to 192.168.1.100" zone: catz.sunet.se pattern: example.catalog catalog-member-id: 4b6f6ce2de5929e4.zones.example.catalog. From 0c8d79fd429344b67e1c9036de06481b686d30b3 Mon Sep 17 00:00:00 2001 From: pettai Date: Mon, 21 Oct 2024 14:54:01 +0200 Subject: [PATCH 2/2] add additional/conditional fields into the schema --- jc/parsers/nsd_control.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jc/parsers/nsd_control.py b/jc/parsers/nsd_control.py index 01f9dc887..e2eed3048 100644 --- a/jc/parsers/nsd_control.py +++ b/jc/parsers/nsd_control.py @@ -28,9 +28,13 @@ "zone": string "status": { "state": string, + "pattern": string, # Additional + "catalog-member-id": string, # Additional "served-serial": string, "commit-serial": string, - "wait": string + "notified-serial": string, # Conditional + "wait": string, + "transfer": string # Conditional } } ]