diff --git a/EXAMPLES.md b/EXAMPLES.md index fae1185..0a71809 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -55,6 +55,12 @@ The following examples are Linux. ./getfolderid.py -f /gelcontent ``` +**getruleid.py** + +```bash +getruleid.py -u /SASVisualAnalytics/** -p "authenticatedUsers" +``` + **deletefolder.py** ```bash @@ -238,4 +244,12 @@ importpackages.py -d /tmp/mypackage -q ```bash # read log files from job execution and add archive them to an os directory ./archivefiles.py -n log -d 6 -p /job -fp /tmp -``` \ No newline at end of file +``` +**archivefiles.py** + +```bash +#his tool will export all the reports in your viya system to there own +# individual json file in a directory + +./snapshotreports.py -c 10 -d ~/snapshot +``` diff --git a/__pycache__/sharedfunctions.cpython-36.pyc b/__pycache__/sharedfunctions.cpython-36.pyc index 6a17302..ded7975 100644 Binary files a/__pycache__/sharedfunctions.cpython-36.pyc and b/__pycache__/sharedfunctions.cpython-36.pyc differ diff --git a/getauditrecords.py b/getauditrecords.py index 991c7d9..73f111c 100644 --- a/getauditrecords.py +++ b/getauditrecords.py @@ -44,7 +44,7 @@ parser.add_argument("-u","--user", help="Filter by Username",default=None) parser.add_argument("-A","--after", help="Filter entries that are created after the specified timestamp. For example: 2020-01-03 or 2020-01-03T18:15Z",default=None) parser.add_argument("-B","--before", help="Filter entries that are created before the specified timestamp. For example: 2020-01-03 or 2020-01-03T18:15Z",default=None) parser.add_argument("-S","--sortby", help="Sort the output ascending by this field",default='timeStamp') -parser.add_argument("-o","--output", help="Output Style", choices=['csv','json','simple'],default='csv') +parser.add_argument("-o","--output", help="Output Style", choices=['csv','json','simple','simplejson'],default='csv') args = parser.parse_args() appname=args.application diff --git a/getconfigurationproperties.py b/getconfigurationproperties.py index fbd8770..6921dd4 100755 --- a/getconfigurationproperties.py +++ b/getconfigurationproperties.py @@ -38,7 +38,7 @@ from sharedfunctions import callrestapi, printresult parser = argparse.ArgumentParser(description="Return a set of configuration properties") parser.add_argument("-c","--configuration", help="Enter the configuration definition.",required='True') -parser.add_argument("-o","--output", help="Output Style", choices=['csv','json','simple'],default='json') +parser.add_argument("-o","--output", help="Output Style", choices=['csv','json','simple','simplejson'],default='json') args = parser.parse_args() configurationdef=args.configuration diff --git a/getfolderid.py b/getfolderid.py index 67b82a6..af6789a 100755 --- a/getfolderid.py +++ b/getfolderid.py @@ -35,7 +35,7 @@ from sharedfunctions import getfolderid, printresult # setup command-line arguements parser = argparse.ArgumentParser() parser.add_argument("-f","--folderpath", help="Enter the path to the viya folder.",required='True') -parser.add_argument("-o","--output", help="Output Style", choices=['csv','json','simple'],default='simple') +parser.add_argument("-o","--output", help="Output Style", choices=['csv','json','simple','simplejson'],default='csv') args = parser.parse_args() path_to_folder=args.folderpath diff --git a/getruleid.py b/getruleid.py index a973fe2..c30f194 100755 --- a/getruleid.py +++ b/getruleid.py @@ -5,11 +5,14 @@ # December 2017 # # getruleid pass in a uri and identity and return the rule id +# for example +# getruleid.py -u /SASVisualAnalytics/** -p "authenticatedUsers" # # Change History # # 27JAN2017 Comments added # 18JUN2018 Output JSON +# 20Feb2020 make identity a required parameter # # Copyright © 2018, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. # @@ -34,8 +37,8 @@ from sharedfunctions import callrestapi, printresult parser = argparse.ArgumentParser() parser.add_argument("-u","--objecturi", help="Enter the objecturi.",required='True') -parser.add_argument("-p","--principal", help="Enter the identity name or authenticatedUsers, everyone or guest") -parser.add_argument("-o","--output", help="Output Style", choices=['csv','json','simple'],default='json') +parser.add_argument("-p","--principal", help="Enter the identity name or authenticatedUsers, everyone or guest",required='True') +parser.add_argument("-o","--output", help="Output Style", choices=['csv','json','simple','simplejson'],default='json') args = parser.parse_args() objuri=args.objecturi @@ -53,7 +56,5 @@ reqtype='get' result=callrestapi(reqval,reqtype) -#print("ruleid= "+result['items'][0]['id']) - # print rest call results printresult(result,output_style) diff --git a/listcaslibs_example.py b/listcaslibs_example.py index 704decc..e1cb11b 100644 --- a/listcaslibs_example.py +++ b/listcaslibs_example.py @@ -32,7 +32,7 @@ from sharedfunctions import callrestapi,printresult parser = argparse.ArgumentParser() parser.add_argument("-s","--server", help="The CAS SERVER.",required='True',default="cas-shared-default") -parser.add_argument("-o","--output", help="Output Style", choices=['csv','json','simple'],default='json') +parser.add_argument("-o","--output", help="Output Style", choices=['csv','json','simple','simplejson'],default='csv') args = parser.parse_args() casserver=args.server output_style=args.output @@ -41,7 +41,7 @@ output_style=args.output reqtype='get' # set the endpoint to call -reqval='/dataSources/providers/cas/sources/'+casserver+'/children' +reqval='/dataSources/providers/cas/sources/'+casserver+'/children?&limit=100000' #make the rest call using the callrestapi function. You can have one or many calls caslib_result_json=callrestapi(reqval,reqtype) diff --git a/listfiles.py b/listfiles.py index 66ebf49..127942f 100755 --- a/listfiles.py +++ b/listfiles.py @@ -37,7 +37,7 @@ parser.add_argument("-pf","--parentfolder", help="Parent Folder Name.",default=N parser.add_argument("-d","--days", help="List files older than this number of days",default='-1') parser.add_argument("-m","--modifiedby", help="Last modified id equals",default=None) parser.add_argument("-s","--sortby", help="Sort the output descending by this field",default='modifiedTimeStamp') -parser.add_argument("-o","--output", help="Output Style", choices=['csv','json','simple'],default='json') +parser.add_argument("-o","--output", help="Output Style", choices=['csv','json','simple','simplejson'],default='json') args = parser.parse_args() output_style=args.output diff --git a/listrules.py b/listrules.py index 758abb0..28a757a 100755 --- a/listrules.py +++ b/listrules.py @@ -4,7 +4,7 @@ # listrules.py # August 2018 # -# listrulesforidentity +# listrules # # Change History # December 2018 - Added custom CSV output code, which writes out consistent columns in a specific order for the result rules JSON @@ -34,7 +34,7 @@ parser = argparse.ArgumentParser(description="List rules for a principal and/or parser.add_argument("-u","--uri", help="Enter a string that the objecturi contains.",default="none") parser.add_argument("-p","--principal", help="Enter the identity name or authenticatedUsers, everyone or guest",default='none') -parser.add_argument("-o","--output", help="Output Style", choices=['csv','json','simple'],default='json') +parser.add_argument("-o","--output", help="Output Style", choices=['csv','json','simple','simplejson'],default='json') args = parser.parse_args() objuri=args.uri diff --git a/sharedfunctions.py b/sharedfunctions.py index 5cc85a6..4d8b050 100755 --- a/sharedfunctions.py +++ b/sharedfunctions.py @@ -475,6 +475,7 @@ def file_accessible(filepath, mode): # change history # 28oct2018 initial development # 22dec2018 add csv columns only relevent for csv output, defaults provided but can be overriden when called +# 20feb2020 add simplejson output style def printresult(result,output_style,colsforcsv=["id","name","type","description","creationTimeStamp","modifiedTimeStamp"]): @@ -484,6 +485,8 @@ def printresult(result,output_style,colsforcsv=["id","name","type","description" if output_style=='simple': simpleresults(result) + elif output_style=='simplejson': + simplejsonresults(result) elif output_style=='csv': csvresults(result,columns=colsforcsv) else: @@ -630,4 +633,37 @@ def getidsanduris(resultdata): resultdict['ids'].append(resultdata['items'][i]['id']) resultdict['uris'].append(resultdata['items'][i]['uri']) - return resultdict \ No newline at end of file + return resultdict + + +# simplejsonresults +# given a result json structure, remove all the "links" items +# this will return a more readable json output +# change history +# 20feb2020 initial development + +def simplejsonresults(resultdata): + + + if 'items' in resultdata: # list of items returned by rest call + + for key in list(resultdata): + if key == 'links': del resultdata[key] + + total_items=resultdata['count'] + returned_items=len(resultdata['items']) + + if total_items == 0: print("Note: No items returned.") + + for i in range(0,returned_items): + + for key in list(resultdata['items'][i]): + if key=='links': + del resultdata['items'][i][key] + + print(json.dumps(resultdata,indent=2)) + + elif 'id' in resultdata: #one item returned by rest call + + del resultdata['links'] + print(json.dumps(resultdata,indent=2)) diff --git a/snapshotreports.py b/snapshotreports.py index 3dc9869..2e4e266 100755 --- a/snapshotreports.py +++ b/snapshotreports.py @@ -4,6 +4,18 @@ # snapshotreports.py # April 2019 # +# this tool will export all the reports in your viya system to there own +# individual json file in a directory. +# +# The purpose of the tools is to be able to have a granular backup of reports +# so that you could restore an individual report to a system. Something that +# is not currently supported by Viya backup or promotion +# +# example +# +# save each to their own package all reports that have changed in the last 10 days +# snapshotreports.py -c 10 -d ~/snapshot +# # Change History # # @@ -119,8 +131,7 @@ if areyousure.upper() =='Y': json_name=resultdata['items'][i]["name"].replace(" ","")+'_'+str(i) json_name=json_name.replace("(","_") - json_name=json_name.replace(")","_") - + json_name=json_name.replace(")","_") command=clidir+'sas-admin transfer export -u /reports/reports/'+id+' --name "'+package_name+'"' print(command)