Splunk Dev

Python SDK Visualization

leordimalanta
Explorer

Hi to all,

How to produce a visualization in splunk sdk python? For example pie charts, line graph, and etc.

Thanks in advance!

Tags (3)
0 Karma

maurelio79
Communicator

Hi, i'm just learning t as well, anyway you can put your result in xml file, parse the xml and use (for example flotchart) to represent the result. For example:

def get_data(self):


        DATA = []

        params = {"earliest_time" : "-30d", "latest_time" : "now", "exec_mode" : "blocking", "auto_cancel" : 600 }
        search = 'search index=main sourcetype=syslog | search *ERROR* | stats count by process' 
        job = service.jobs.create(search, **params)
        #job = service.jobs.create(search)

        while True: 
          if job.isDone: 
            break 
        content = str(job.results(output_mode='xml'))
        #print "Output: %s" % content

        with open('result.xml', 'w') as f:
            f.write(content)

        tree = ET.parse('result.xml')
        root = tree.getroot()

        for child in root:
            if child[0].tag != "fieldOrder":
                #print child[0][0][0].text, child[1][0][0].text
                DATA.append([child[0][0][0].text, child[1][0][0].text])

        return DATA

Then you have to put the return DATA in flotchart. To know how to use flotchart:
search flotchart on web (it seems i can not insert link)

0 Karma

leordimalanta
Explorer

Thank you! I will try this to my next project!

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...