Getting Data In

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


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,

Tags (2)
0 Karma

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
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):
        service = client.connect(host=HOST,
        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('.//{}key[@name="label"]')
        quotas = tree.findall('.//{}key[@name="quota"]')
        types = tree.findall('.//{}key[@name="type"]')

        print '%-45s     %-16s     %-50s' % ("License Label Name",
                                             "Quota (Bytes)",
                                             "License Type")
        for j in labels:
            print '%-45s ==> %-16s ==> %-50s' % (labels[x].text,
            x += 1
        # error handling code here
        print "Main loop: We failed."
        return 1 # exit on error
        #print "Main loop: Perfect execution."
        return 0 # exit errorlessly

if __name__ == '__main__':
0 Karma

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

Admin Your Splunk Cloud, Your Way

Join us to maximize different techniques to best tune Splunk Cloud. In this Tech Enablement, you will get ...

Cloud Platform | Discontinuing support for TLS version 1.0 and 1.1

Overview Transport Layer Security (TLS) is a security communications protocol that lets two computers, ...

New Customer Testimonials

Enterprises of all sizes and across different industries are accelerating cloud adoption by migrating ...