From 7eaf72a069483dac74713f243e4eeceb6fec3be7 Mon Sep 17 00:00:00 2001 From: Giacomo Sanchietti Date: Thu, 22 Feb 2024 18:01:34 +0100 Subject: [PATCH] ns-api: notify, replace priority with level --- packages/ns-api/README.md | 20 +++++++++++++++----- packages/ns-api/files/ns.notify | 4 ++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/ns-api/README.md b/packages/ns-api/README.md index 37e084db0..bcb4cf33f 100644 --- a/packages/ns-api/README.md +++ b/packages/ns-api/README.md @@ -6057,7 +6057,7 @@ Response example: "notifications": [ { "id": 3, - "priority": "low", + "level": 2, "title": "mytest", "payload": {}, "timestamp": 1708523000, @@ -6065,7 +6065,7 @@ Response example: }, { "id": 1, - "priority": "high", + "level": 3, "title": "os_update", "payload": { "new_relase": "1.2.3" @@ -6090,7 +6090,7 @@ Response example: "notifications": [ { "id": 2, - "priority": "low", + "level": 2, "title": "new_host", "payload": { "host": "7.7.7.7" @@ -6102,11 +6102,21 @@ Response example: } ``` +Valid values for level are are: +- `0`: DEBUG +- `1`: INFO +- `2`: NOTICE +- `3`: WARNING +- `4`: ERR +- `5`: CRIT +- `6`: ALERT +- `7`: EMERG + ### add-notification Add a new notification: ``` -api-cli ns.notify add-notification --data '{"priority": "high", "title": "os_update", "payload": {"new_relase": "1.2.3"}}' +api-cli ns.notify add-notification --data '{"level": 2, "title": "os_update", "payload": {"new_relase": "1.2.3"}}' ``` Response example: @@ -6137,7 +6147,7 @@ Response example: ```json { "id": 1, - "priority": "high", + "level": 2, "title": "os_update", "payload": { "new_relase": "1.2.3" diff --git a/packages/ns-api/files/ns.notify b/packages/ns-api/files/ns.notify index 0afb373b2..b55fb3a0e 100755 --- a/packages/ns-api/files/ns.notify +++ b/packages/ns-api/files/ns.notify @@ -17,7 +17,7 @@ if cmd == 'list': print(json.dumps({ "list-read-notifications": {}, "list-unread-notifications": {}, - "add-notification": {"title": "string", "priority": "string", "payload": "object"}, + "add-notification": {"title": "string", "level": 2, "payload": "object"}, "get-notification": {"id": "int"}, "mark-as-read": {"id": "int"}, "mark-as-unread": {"id": "int"}, @@ -34,7 +34,7 @@ else: args = json.loads(sys.stdin.read()) if action == "add-notification": - ret = notify.add_notification(args.get("title"), args.get("priority"), args.get("payload")) + ret = notify.add_notification(args.get("title"), args.get("level"), args.get("payload")) elif action == "get-notification": ret = notify.get_notification(args.get("id")) elif action == "mark-as-read":