NetWorker: Så här gör du kommandorads-REST API JSON-svar läsbart för människor
Summary: Kommandorads-REST API-svar (Application Programming Interface) är i oformaterad JSON, vilket kan vara svårt att parsa. Den här kunskapsbasartikeln innehåller metoder för att formatera REST API-svaret till utdata som kan läsas av människor. ...
Instructions
NetWorker Representational State Transfer (REST) API-anrop kan utföras från kommandoraden på en Linux NetWorker-server med hjälp av curl befallning. Till exempel:
curl -k -u USERNAME:'PASSWORD' https://localhost:9090/nwrestapi/v3/global/RESTAPI-ENDPOINT
Svarsnyttolasten för en GET-åtgärd finns i JSON. Standardsvaret kan vara svårt att parsa eftersom det vanligtvis är en gång kontinuerlig linje. Till exempel:
nve:~ # curl -k -u Administrator:'!Password1' https://localhost:9090/nwrestapi/v3/global
{"links":[{"href":"https://localhost:9090/nwrestapi/v3/global/alerts","title":"List of alert messages"},{"href":"https://localhost:9090/nwrestapi/v3/global/auditlogconfig","title":"Audit log configuration"},{"href":"https://localhost:9090/nwrestapi/v3/global/auditlogconfigs","title":"Audit log configurations"},{"href":"https://localhost:9090/nwrestapi/v3/global/backups","title":"List of backups"},{"href":"https://localhost:9090/nwrestapi/v3/global/clients","title":"List of clients"},{"href":"https://localhost:9090/nwrestapi/v3/global/cloudboostappliances","title":"List of cloudboost appliances"},{"href":"https://localhost:9090/nwrestapi/v3/global/datadomainsystems","title":"List of data domain systems"},{"href":"https://localhost:9090/nwrestapi/v3/global/dddevicereplication","title":"DD device replication"},{"href":"https://localhost:9090/nwrestapi/v3/global/devices","title":"List of storage devices"},{"href":"https://localhost:9090/nwrestapi/v3/global/directives","title":"List of backup directives"},{"href":"https://localhost:9090/nwrestapi/v3/global/inspect","title":"Inspect remote/local server"},{"href":"https://localhost:9090/nwrestapi/v3/global/jobgroups","title":"List of job groups"},{"href":"https://localhost:9090/nwrestapi/v3/global/jobindications","title":"List of job indications"},{"href":"https://localhost:9090/nwrestapi/v3/global/jobs","title":"List of jobs"},{"href":"https://localhost:9090/nwrestapi/v3/global/jukeboxes","title":"List of jukeboxes"},{"href":"https://localhost:9090/nwrestapi/v3/global/labels","title":"List of volume label templates"},{"href":"https://localhost:9090/nwrestapi/v3/global/licenseconfig","title":"Server license configuration"},{"href":"https://localhost:9090/nwrestapi/v3/global/licenses","title":"List of license templates"},{"href":"https://localhost:9090/nwrestapi/v3/global/lockbox","title":"Lockbox resource"},{"href":"https://localhost:9090/nwrestapi/v3/global/mediaconfig","title":"Server media configuration"},{"href":"https://localhost:9090/nwrestapi/v3/global/mobilestorageunits","title":"Mobile storage units"},{"href":"https://localhost:9090/nwrestapi/v3/global/nasdevices","title":"List of NAS devices"},{"href":"https://localhost:9090/nwrestapi/v3/global/notifications","title":"List of notification settings"},{"href":"https://localhost:9090/nwrestapi/v3/global/nsrcloneconfig","title":"NSR Clone Configuration"},{"href":"https://localhost:9090/nwrestapi/v3/global/pools","title":"List of pools"},{"href":"https://localhost:9090/nwrestapi/v3/global/probes","title":"List of probes"},{"href":"https://localhost:9090/nwrestapi/v3/global/protectiongroups","title":"List of protection groups"},{"href":"https://localhost:9090/nwrestapi/v3/global/protectionpolicies","title":"List of protection policies"},{"href":"https://localhost:9090/nwrestapi/v3/global/recoverapps","title":"List of recovery applications"},{"href":"https://localhost:9090/nwrestapi/v3/global/recovers","title":"List of recover resources"},{"href":"https://localhost:9090/nwrestapi/v3/global/rules","title":"List of rules"},{"href":"https://localhost:9090/nwrestapi/v3/global/schedules","title":"List of schedules"},{"href":"https://localhost:9090/nwrestapi/v3/global/securityconfig","title":"Server security configuration"},{"href":"https://localhost:9090/nwrestapi/v3/global/serverconfig","title":"Server configuration"},{"href":"https://localhost:9090/nwrestapi/v3/global/servermessages","title":"List of server messages"},{"href":"https://localhost:9090/nwrestapi/v3/global/serverstatistics","title":"Server statistics"},{"href":"https://localhost:9090/nwrestapi/v3/global/sessions","title":"List of save/recover sessions"},{"href":"https://localhost:9090/nwrestapi/v3/global/storagenodes","title":"List of storage nodes"},{"href":"https://localhost:9090/nwrestapi/v3/global/tenants","title":"Restricted data zone protection"},{"href":"https://localhost:9090/nwrestapi/v3/global/timepolicies","title":"List of Time Policies"},{"href":"https://localhost:9090/nwrestapi/v3/global/unconfiguredlibraries","title":"List of unconfigured libraries"},{"href":"https://localhost:9090/nwrestapi/v3/global/usergroups","title":"List of user groups"},{"href":"https://localhost:9090/nwrestapi/v3/global/vmware","title":"View of VMware objects"},{"href":"https://localhost:9090/nwrestapi/v3/global/volumes","title":"List of volumes"}]}
JSON-utdata är oformaterade och kan vara svåra att parsa. Utdata kan dock formateras till ett mer lättläst "pretty print"-format.
För NetWorker Virtual Edition-system (NVE) kan du lägga till python -m json.tool till curl befallning. Till exempel:
nve:~ # curl -k -u Administrator:'!Password1' https://localhost:9090/nwrestapi/v3/global | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4374 0 4374 0 0 9751 0 --:--:-- --:--:-- --:--:-- 9763
{
"links": [
{
"href": "https://localhost:9090/nwrestapi/v3/global/alerts",
"title": "List of alert messages"
},
{
"href": "https://localhost:9090/nwrestapi/v3/global/auditlogconfig",
"title": "Audit log configuration"
},
{
"href": "https://localhost:9090/nwrestapi/v3/global/auditlogconfigs",
"title": "Audit log configurations"
},
{
"href": "https://localhost:9090/nwrestapi/v3/global/backups",
"title": "List of backups"
},
{
"href": "https://localhost:9090/nwrestapi/v3/global/clients",
"title": "List of clients"
},
******* Removed for brevity *******
]
}
För andra Linux-system kan detta uppnås genom att lägga till jq till curl befallning:
[root@nsr ~]# curl -k -u Administrator:'!Password1' https://localhost:9090/nwrestapi/v3/global | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4258 0 4258 0 0 7253 0 --:--:-- --:--:-- --:--:-- 7241
{
"links": [
{
"href": "https://localhost:9090/nwrestapi/v3/global/alerts",
"title": "List of alert messages"
},
{
"href": "https://localhost:9090/nwrestapi/v3/global/auditlogconfig",
"title": "Audit log configuration"
},
{
"href": "https://localhost:9090/nwrestapi/v3/global/auditlogconfigs",
"title": "Audit log configurations"
},
{
"href": "https://localhost:9090/nwrestapi/v3/global/backups",
"title": "List of backups"
},
{
"href": "https://localhost:9090/nwrestapi/v3/global/clients",
"title": "List of clients"
},
******* Removed for brevity *******
]
}
jq ingår inte i NetWorker, detta är ett tredjepartsverktyg som kan installeras på systemet. Rådgör med systemadministratören för att installera jq eller andra JSON-formateringsverktyg efter behov.
För Windows-värdar är det osannolikt att kommandoraden används för att uppnå detta. Detta görs vanligtvis via PowerShell som kräver ytterligare funktioner, ofta med skript. De flesta Windows-baserade system använder ett användargränssnitt, till exempel Post-Man, för att formatera REST API GET-begäranden.