本文整理汇总了Python中splunk.Intersplunk.readResults方法的典型用法代码示例。如果您正苦于以下问题:Python Intersplunk.readResults方法的具体用法?Python Intersplunk.readResults怎么用?Python Intersplunk.readResults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类splunk.Intersplunk
的用法示例。
在下文中一共展示了Intersplunk.readResults方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from splunk import Intersplunk [as 别名]
# 或者: from splunk.Intersplunk import readResults [as 别名]
def main():
# get config from config file
config = ConfigParser.ConfigParser()
if os.path.exists(os.path.join('..', 'local', 'slack.conf')):
config.readfp(open(os.path.join('..', 'local', 'slack.conf')))
else:
config.readfp(open(os.path.join('..', 'default', 'slack.conf')))
# username and icon can only be set by conf
username = config.get('config', 'username')
icon = config.get('config', 'icon')
# update args if user speicify them in search
channel = kwargs.get('channel', config.get('config', 'channel'))
if not channel.startswith('#'): channel = '#' + channel
if config.get('config', 'allow_user_set_slack_url').lower() in TRUE_VALUES:
url = kwargs.get('url', config.get('config', 'url'))
else:
url = config.get('config', 'url')
# no url specified, dont procceed.
if not url:
raise Exception("Not slack url specified!")
# read search results
results = sis.readResults(None, None, True)
https_proxy = config.get('config', 'proxy')
proxyDict = {
"https" : https_proxy
}
# prepare data to be sent to slack
data = {
'text': get_pretty_table(results),
'username': username,
'channel': channel,
'icon_url': icon,
'mrkdwn': True,
}
if https_proxy != "":
# send data to slack.
r = requests.post(url, data=json.dumps(data), proxies=proxyDict)
else:
r = requests.post(url, data=json.dumps(data))
if r.status_code == 200:
sis.outputResults(results)
else:
err_msg = ("Error sending results to slack, reason: {r}, {t}".format(
r=r.reason, t=r.text))
sis.generateErrorResults(err_msg)
示例2: main
# 需要导入模块: from splunk import Intersplunk [as 别名]
# 或者: from splunk.Intersplunk import readResults [as 别名]
def main():
# get config from config file
config = ConfigParser.ConfigParser()
config.readfp(open(os.path.join('..', 'default', 'hipchat.conf')))
# update args if user speicify them in search
room = kwargs.get('room', config.get('default', 'room'))
color = kwargs.get('color', config.get('default', 'color'))
notify = kwargs.get('notify', config.get('default', 'notify'))
msg_fmt = kwargs.get('message_format',
config.get('default', 'message_format'))
if config.get('default', 'allow_users_set_base_url').lower() in TRUE_VALUES:
base_url = kwargs.get('base_url', config.get('default', 'base_url'))
else:
base_url = config.get('default', 'base_url')
# check if auth token is set properly
try:
auth_token = {"auth_token": config.get(room, 'auth_token')}
except ConfigParser.NoSectionError as e:
raise Exception("Room not set, please set the room stanza")
except ConfigParser.NoOptionError as e:
raise Exception("Auth token not set, please set auth token for room")
# construct url
url = base_url + "{s}{r}/notification".format(
s='' if base_url.endswith('/') else '/', r=room)
# read search results
results = sis.readResults(None, None, True)
# prepare data to be sent
data = {
'message': get_pretty_table(results, msg_fmt),
'message_format': msg_fmt,
'color': color,
'notify': notify.lower() in TRUE_VALUES
}
# send data
headers = {'Content-type': 'application/json'}
r = requests.post(url,
data=json.dumps(data),
params=auth_token,
headers=headers)
if r.status_code == 204:
sis.outputResults(results)
else:
err_msg = ("Error sending results to slack, reason: {r}, {t}".format(
r=r.reason, t=r.text))
sis.generateErrorResults(err_msg)
示例3: run
# 需要导入模块: from splunk import Intersplunk [as 别名]
# 或者: from splunk.Intersplunk import readResults [as 别名]
def run(messages, count, mapping):
results = si.readResults(None, None, True)
ORS = []
seenValues = set() # dedup rows
for i, result in enumerate(results):
if count > 0 and i >= count:
break
ANDS = []
for j, (renamed, attr) in enumerate(mapping):
val = str(result.get(attr,''))
if renamed == None or renamed == '':
if val != '':
ANDS.append(val)
else:
ANDS.append('%s="%s"' % (renamed, val))
andstr = str(ANDS)
if len(ANDS) > 0 and andstr not in seenValues:
ORS.append(ANDS)
seenValues.add(andstr)
output = ""
if len(ORS) > 1:
output += "("
for i, OR in enumerate(ORS):
if i > 0:
output += ") OR ("
for j, AND in enumerate(OR):
if j > 0:
output += " " #" AND "
output += AND
if len(ORS) > 1:
output += ")"
si.outputResults([{'search': output}], messages)
示例4: str
# 需要导入模块: from splunk import Intersplunk [as 别名]
# 或者: from splunk.Intersplunk import readResults [as 别名]
"""
out = None
err = None
if self.locateProcess(proc_name=the_proc_name):
p = subprocess.Popen(self._proc_cmds['kill_proc_name'][self.getPlatform()] + [str(the_proc_name)],
stdout=subprocess.PIPE)
out, err = p.communicate()
else:
logger.error("Process Name: " + str(the_proc_name) + " not found " +
" running on the system!")
return [out,err]
if __name__ == '__main__':
try:
results = si.readResults()
keywords, options = si.getKeywordsAndOptions()
for entry in results:
## PID
if "pid" in entry:
pid = entry["pid"]
else:
pid = options.get('pid', None)
## Process Name
if 'proc_name' in entry:
proc_name = entry['proc_name']
else:
proc_name = options.get('proc_name', None)
示例5: len
# 需要导入模块: from splunk import Intersplunk [as 别名]
# 或者: from splunk.Intersplunk import readResults [as 别名]
########################
key = '_raw'
tableName = ''
if len(sys.argv) >= 3:
tableName = sys.argv[1]
key = sys.argv[2]
########################
#results,dummyresults,settings = isp.getOrganizedResults()
results = isp.readResults(None, None, True)
rowkey = []
for field in results:
if field.get(key, None):
rowkey.append(field.get(key))
#############################
#
#f = open('/root/input','w')
#
#f.write(str(rowkey))
#
#f.close()
#
示例6: arg_on_and_enabled
# 需要导入模块: from splunk import Intersplunk [as 别名]
# 或者: from splunk.Intersplunk import readResults [as 别名]
def arg_on_and_enabled(argvals, arg, rex=None, is_bool=False):
result = False
if is_bool:
rex = "^(?:t|true|1|yes)$"
if (rex is None and arg in argvals) or (arg in argvals and re.match(rex, argvals[arg])):
result = True
return result
if __name__ == '__main__':
logger = setup_logging()
logger.info('starting..')
eStart = time.time()
try:
results = si.readResults(None, None, False)
keywords, argvals = si.getKeywordsAndOptions()
validate_args(keywords, argvals)
if arg_on_and_enabled(argvals, "debug", is_bool=True):
logger.setLevel(logging.DEBUG)
logger.debug("detecting debug argument passed, setting command log_level=DEBUG")
output_column_name = "mvmath"
if arg_on_and_enabled(argvals, "labelfield"):
output_column_name = argvals['labelfield']
if arg_on_and_enabled(argvals, "prefix"):
output_column_name = argvals['prefix'] + output_column_name
for row in results:
示例7: dict
# 需要导入模块: from splunk import Intersplunk [as 别名]
# 或者: from splunk.Intersplunk import readResults [as 别名]
recs.append([rec[n] for rec in records])
elif t=='numeric':
recs.append(float(n))
elif t=='string':
recs.append(n.lstrip('"').rstrip('"'))
return recs
if __name__ == '__main__':
stdin = None
if not os.isatty(0):
stdin = sys.stdin
settings = dict()
records = si.readResults(settings = settings, has_header = True)
sessionKey = settings['sessionKey']
logger.debug("sessionKey = %s" % sessionKey)
ret = collections.OrderedDict()
for i in range(1, len(sys.argv)):
func = py.parse_func(sys.argv[i])
logger.debug("func = %s" % func)
recs = get_inputs(records, func.arguments)
logger.debug("get_inputs = %s" % recs)
f = py.find_func(func)
f._sessionKey_ = sessionKey
try:
if len(func.arguments)==0:
示例8: setup_logging
# 需要导入模块: from splunk import Intersplunk [as 别名]
# 或者: from splunk.Intersplunk import readResults [as 别名]
if __name__ == '__main__':
logger = setup_logging()
# Set this when debugging
logger.setLevel(logging.DEBUG)
logger.debug("entered __main__")
search=''
try:
if len(sys.argv) > 1:
search = sys.argv[2]
logger.debug("search: '" + search + "'")
else:
raise Exception("Usage: strace <search>")
(isgetinfo, sys.argv) = si.isGetInfo(sys.argv)
if isgetinfo:
reqsop = True
preop = "prestrace " + search +""
logger.debug("passed to prestrace: '" + preop + "'")
si.outputInfo(False, False, False, reqsop, preop) # calls sys.exit()
results = si.readResults(None, None, True)
si.outputResults(results)
logger.debug("exited __main__")
except Exception, e:
si.generateErrorResults(e)