I am going with a different approach now. Created a custom search command called dynrange and calling it like below
index=order_activation sourcetype=order_trans ProductName="$DEVICE1$-$STORAGE1$-$COLOR1$" | dedup OrderId | stats sum(SKUQuantity) as TotalDevices | gauge TotalDevices [dynrange __EXECUTE__ None None $DEVICE1$-$STORAGE1$-$COLOR1$]
The search works and does not return any errors, but it is still not rendering the dynamic range on the Radial Gauge. How do I troubleshoot the custom search command, to see if it is returning the right values.
[root@ip-172-31-26-130 bin]# cat dynrange.py
# Version 4.0
import sys
import splunk.Intersplunk
import csv
import re
(isgetinfo, sys.argv) = splunk.Intersplunk.isGetInfo(sys.argv)
if len(sys.argv) < 3:
splunk.Intersplunk.parseError("3 Arguments are required")
if isgetinfo:
splunk.Intersplunk.outputInfo(False, False, False, False, None)
results = splunk.Intersplunk.readResults(None, None, True)
file2 = '/opt/splunk/etc/apps/search/lookups/inventory.csv'
def searchText(search_text):
#print "search_text:", search_text
with open(file2) as fp1:
root = csv.reader(fp1)
result = [i for i in root if re.findall(search_text, i[0])]
return result
newresult = {}
offset = 0
header = []
#countDev = 0
x = 0
y1 = 0
y2 = 0
y3 = 0
totVolume = 0
search_text = ''
if len(results) > 0:
search_text = str(sys.argv[4]).strip()
#countDev = int(sys.argv[2])
try:
#tmp1, tmp2, tmp3 = search_text.split("-")
search_text = search_text.replace("*", "[^-]*")
result = searchText(search_text)
#pprint.pprint(result)
for line in result:
totVolume = totVolume + int(line[1])
#print line
#print line[1]
except:
print "wrong search text. *-*-*"
if totVolume == 0:
totVolume = 40000
y1 = ((totVolume * 50)/100)
y2 = ((totVolume * 80)/100)
y3 = totVolume
print "Device = %s, X = %d, Y1 = %d, Y2 = %d, Y3 = %d" % (search_text, x, y1, y2, y3)
newresult['x'] = 0
header.append('x')
newresult['y1'] = y1
header.append('y1')
newresult['y2'] = y2
header.append('y2')
newresult['y3'] = y3
header.append('y3')
newresults = []
if len(newresult) > 0:
newresults.append(newresult)
splunk.Intersplunk.outputResults(newresults, None, header)
... View more