Getting Data In

How can I get the max volume per day for the license stack used using the REST API

SunDance
Explorer

Hello,
I can get information about the license stacks via the CLI:
splunk list licenser-stacks

I would like to get the same via a rest API call. Is this possible?

Thanks in advance,
Alex

Tags (2)
0 Karma

sspencer_splunk
Splunk Employee
Splunk Employee

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))
0 Karma

mloven_splunk
Splunk Employee
Splunk Employee
0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...