Dashboards & Visualizations

How to list & query macros for definitions using the Splunk Javascript SDK?

afgibson84
New Member

Does anyone know how to query macros using the Javascript SDK? I would like to essentially have the app list and/or query the macros.conf files so that I can dynamically pull in macro names and definitions.

0 Karma
1 Solution

renjith_nair
Legend

Hi @afgibson84,

try below,

var service = new splunkjs.Service({username: "admin", password: "yourpassword"});
var definition= service.get('properties/macros/"your macro name" /definition')["body"]
---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

woodcock
Esteemed Legend

It often helps to see how Splunk itself does this. You can logon to your Search Head and run this command (and you can snoop on other aspects with debug tools of your browser):

|rest/servicesNS/-/-/configs/conf-macros splunk_server=local | dedup id | table eai:acl.owner eai:acl.sharing disabled title definition validation errormsg | rename eai:acl.* AS * | sort 0 title
0 Karma

renjith_nair
Legend

Hi @afgibson84,

try below,

var service = new splunkjs.Service({username: "admin", password: "yourpassword"});
var definition= service.get('properties/macros/"your macro name" /definition')["body"]
---
What goes around comes around. If it helps, hit it with Karma 🙂

felipesewaybric
Contributor

The answer above works for me.

0 Karma

vidhyaArumalla
Path Finder

This works

0 Karma

renjith_nair
Legend

@felipesewaybricker , @vidhyaArumalla . Glad to hear 🙂 you could upvote and accept it as an answer

---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

Anam
Community Manager
Community Manager

Hi @afgibson84

Please go ahead and accept the answer if the solution worked for you. If not, can you post more information on your query?

Thanks

0 Karma

afgibson84
New Member

Thank you - the answer above helped get me started but service.get() returned a promise. Here is what worked for me (using an already authenticated session):

var http = new splunkjs.SplunkWebHttp();
var service = new splunkjs.Service(http);
service.get('propertiec/macros/<name>/definition')
    .then((definition) => {
        console.log('here is the definition:',definition);
    });
0 Karma
Get Updates on the Splunk Community!

Enter the Dashboard Challenge and Watch the .conf24 Global Broadcast!

The Splunk Community Dashboard Challenge is still happening, and it's not too late to enter for the week of ...

Join Us at the Builder Bar at .conf24 – Empowering Innovation and Collaboration

What is the Builder Bar? The Builder Bar is more than just a place; it's a hub of creativity, collaboration, ...

Combine Multiline Logs into a Single Event with SOCK - a Guide for Advanced Users

This article is the continuation of the “Combine multiline logs into a single event with SOCK - a step-by-step ...