Here's a little bit of python (2.x) code that uses the Splunk Python SDK to extract license values from the "licenser/stacks" RESTful endpoint that @mloven_splunk mentioned above. The output is equivalent to the output from splunk list licenser-stacks
. You'll have to have the Splunk Python SDK already installed on your system and you should probably add it to your PYTHONPATH. YMMV.
Here's what the output looks like on one of my forwarders:
$ python endpoint_license_stack.py
License Label Name Quota (Bytes) License Type
Splunk Forwarder ==> 1048576 ==> forwarder
Splunk Free ==> 524288000 ==> free
The code is really crappy because...well, just look at that for loop. Yuck.
Also, I always try to stick with libraries that are provided by most default Python installations, so I cannot use any of the cool output-formatting libraries that I've found and, frankly, I'm working with xml.etree...which is not a very friendly library...but I'll work with XML over JSON any day of the week so I cannot complain too much.
Don't forget to change the USERNAME and PASSWORD variables to something appropriate for your system.
import splunklib.client as client
import xml.etree.ElementTree as etree
import sys
HOST = "localhost"
PORT = 8089
USERNAME = "username" # this username requires the "license_edit" capability
PASSWORD = "password"
def main(args):
try:
service = client.connect(host=HOST,
port=PORT,
username=USERNAME,
password=PASSWORD)
htmlout = service.get('licenser/stacks') # Here's your REST endpoint
tree = etree.parse(htmlout.body) # "body" contains the XML output from the endpoint
labels = tree.findall('.//{http://dev.splunk.com/ns/rest}key[@name="label"]')
quotas = tree.findall('.//{http://dev.splunk.com/ns/rest}key[@name="quota"]')
types = tree.findall('.//{http://dev.splunk.com/ns/rest}key[@name="type"]')
print '%-45s %-16s %-50s' % ("License Label Name",
"Quota (Bytes)",
"License Type")
x=0
for j in labels:
print '%-45s ==> %-16s ==> %-50s' % (labels[x].text,
quotas[x].text,
types[x].text)
x += 1
service.logout()
except:
# error handling code here
print "Main loop: We failed."
return 1 # exit on error
else:
#print "Main loop: Perfect execution."
return 0 # exit errorlessly
if __name__ == '__main__':
sys.exit(main(sys.argv))