GET status of all system folders

Use api_config_status.py to retrieve status information for all system folders with a combination of /config and /status requests. This

Figure 1. api_config_status.py
#!/usr/bin/env python
#
# Copyright 2017 Voci Technologies  All rights reserved.
# Unsupported example code - Not for production use.
#
# Reads company, org, and folder data from a specified host,
# uses it to call the /status endpoint for each folder,
# and saves output as JSON or CSV as specified. 

import requests
import json

def usage(argv):
    print "Usage:", argv[0], "<sparkhost:port> <root token> <csv || json>"
    exit(1)

def main(argv): 
    if len(argv) != 4: usage(argv) 
    host, token, output_format = argv[1:]
    tokens = gettokens(host,token)
    folderinfo = getfolderinfo(host,token)
    getfolders(host, folderinfo, tokens, output_format)

def gettokens(host, token): 
    url = "http://%s/config?token=%s" % (host,token)
    cfg = requests.get(url).json()
    return dict([(comp,d['uuid']) for comp,d in cfg.iteritems()])

def getfolderinfo(host, token): 
    url = "http://%s/config/folders?token=%s" % (host,token)
    return requests.get(url).json()

def findfolders(host, folder_info, tokens, output_format): 
    for comp, comp_data in folder_info.iteritems():
        print comp+" (Token: "+tokens[comp]+")"
        for org, org_data in comp_data.iteritems():
            for folder, folder_data in org_data.iteritems():
                writefolderstatus(host, tokens[comp], comp, org, folder, output_format)

def writefolderstatus(host, token, comp, org, folder, output_format):  
    url = "http://%s/status/%s/%s/%s?token=%s&format=%s" % (host, comp, org, folder, token, output_format)
    print "  URL is "+url
    OUTPUT_FILE = comp+"-"+org+"-"+folder+"-status."+output_format
    print "    Writing JSON to "+OUTPUT_FILE
    target = open(OUTPUT_FILE, 'w')
    if output_format == "json":
        target.write(json.dumps(requests.get(url).json(), indent=4, sort_keys=True))
    if output_format == "csv":
        response = requests.get(url)
        target.write(response.content)
        target.write('\n')
    target.close()

if __name__ == '__main__': 
    from sys import argv
    main(argv)

api_config_status.py uses the root API token to retrieve the processing status for all system folders.

Use this script with the following command and arguments:

python api_config_status.py $host:$port $root_token $format
$host
Hostname or URL for the system running V‑Spark.
$port
Port configured for the host system. Default 3000.
$root_token
V‑Spark's root authorization token. Only available to system administrators.
$format
Specify json or csv to be used for the output file generated by the script.

api_config_status.py saves output to a file named with this format: $co_short-$org_short-$folder-status.$format

$co_short

Company short name used to filter the request.

$org_short

Organization short name used to filter the request.

$folder
Folder used to filter the request.
$format
The output format specified with the initial command-line argument.