本文整理汇总了Python中splunklib.searchcommands.dispatch函数的典型用法代码示例。如果您正苦于以下问题:Python dispatch函数的具体用法?Python dispatch怎么用?Python dispatch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dispatch函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_generating_command_as_unit
def test_generating_command_as_unit(self):
simulate_path = get_searchcommand_example("simulate.py")
self.assertTrue(os.path.isfile(simulate_path))
# Copy population.csv to the $SPLUNK_HOME/var/run/splunk/ directory
population_file = os.path.join(os.path.dirname(simulate_path),
"population.csv")
shutil.copy(population_file, validators.File._var_run_splunk)
# load the SimulateCommand class from simulate.py
simulate = imp.load_source('searchcommands_app', simulate_path)
instream = StringIO()
outstream = StringIO()
cli_args = [
"simulate.py",
"__GETINFO__",
"duration=00:00:10",
"csv=population.csv",
"rate=1",
"interval=00:00:01"]
# Run the process
dispatch(simulate.SimulateCommand, cli_args, instream, outstream,
"__main__")
expected_info_path = os.path.join(os.path.dirname(__file__), 'data/_expected_results/test_generating_command_in_isolation.getinfo.csv')
self.assertEqual(io.open(os.path.abspath(expected_info_path), newline='').read(), outstream.getvalue())
instream = StringIO()
outstream = StringIO()
cli_args = [
"simulate.py",
"__EXECUTE__",
"duration=00:00:10",
"csv=population.csv",
"rate=1",
"interval=00:00:01"]
# Run the process
dispatch(simulate.SimulateCommand, cli_args, instream, outstream,
"__main__")
rows = outstream.getvalue().split("\r\n")[1:-1]
found_fields = rows[0].split(",")
expected_fields = [
'_time',
'_serial',
'text',
'__mv__time',
'__mv__serial',
'__mv_text',
]
self.assertEqual(len(expected_fields), len(found_fields))
self.assertEqual(expected_fields, found_fields)
# did we get the field names and at least 2 events?
self.assertTrue(3 < len(rows))
return
开发者ID:kalpsfeb28,项目名称:splunk-sdk-python,代码行数:58,代码来源:test_examples.py
示例2: test_helloworld_generating_command_as_unit
def test_helloworld_generating_command_as_unit(self):
helloworld_path = get_searchcommand_example("generatehello.py")
self.assertTrue(os.path.isfile(helloworld_path))
helloworld = imp.load_source('searchcommands_app', helloworld_path)
instream = StringIO()
outstream = StringIO()
cli_args = [
"generatehello.py",
"__GETINFO__",
"count=5",
]
# Run the process
dispatch(helloworld.GenerateHelloCommand, cli_args, instream, outstream,
"__main__")
expected_info_path = os.path.join(os.path.dirname(__file__), 'data/_expected_results/test_generating_command_in_isolation.getinfo.csv')
self.assertEqual(io.open(os.path.abspath(expected_info_path), newline='').read(), outstream.getvalue())
# Overwrite the existing StringIO objects
instream = StringIO()
outstream = StringIO()
cli_args = [
"generatehello.py",
"__EXECUTE__",
"count=5",
]
# Run the process
dispatch(helloworld.GenerateHelloCommand, cli_args, instream, outstream,
"__main__")
# Trim the blank lines at either end of the list
rows = outstream.getvalue().split("\r\n")[1:-1]
found_fields = rows[0].split(",")
expected_fields = [
'_time',
'event_no',
'_raw',
'__mv__time',
'__mv_event_no',
'__mv__raw',
]
self.assertEqual(len(expected_fields), len(found_fields))
self.assertEqual(expected_fields, found_fields)
# Trim the field names
events = rows[1:]
self.assertEqual(5, len(events))
for i in range(1, len(events)):
event = events[i].split(",")
self.assertEqual(i + 1, int(event[1]))
self.assertEqual(i + 1, int(event[2][-1]))
return
开发者ID:kalpsfeb28,项目名称:splunk-sdk-python,代码行数:55,代码来源:test_examples.py
示例3: len
event_id = hashlib.md5(incident[0]['incident_id'] + now).hexdigest()
event = 'time="%s" severity=INFO origin="ModifyIncidentsCommand" event_id="%s" user="%s" action="change" incident_id="%s" %s="%s" previous_%s="%s"' % (now, event_id, user, incident[0]['incident_id'], key, attrs[key], key, incident[0][key])
input.submit(event, hostname = socket.gethostname(), sourcetype = 'incident_change', source = 'modifyincidents.py', index = self.config['index'])
incident[0][key] = attrs[key]
if len(changed_keys) > 0:
uri = '/servicesNS/nobody/alert_manager/storage/collections/data/incidents/' + incident[0]['_key']
del incident[0]['_key']
contentsStr = json.dumps(incident[0])
serverResponse, serverContent = rest.simpleRequest(uri, sessionKey=sessionKey, jsonargs=contentsStr)
if self.comment:
self.comment = self.comment.replace('\n', '<br />').replace('\r', '')
event_id = hashlib.md5(incident[0]['incident_id'] + now).hexdigest()
event = 'time="%s" severity=INFO origin="ModifyIncidentsCommand" event_id="%s" user="%s" action="comment" incident_id="%s" comment="%s"' % (now, event_id, user, incident[0]['incident_id'], self.comment)
event = event.encode('utf8')
input.submit(event, hostname = socket.gethostname(), sourcetype = 'incident_change', source = 'modifyincidents.py', index = self.config['index'])
else:
self.logger.warn("No attributes to modify found, aborting.")
else:
self.logger.warn("No incident_id field found in event, aborting.")
yield record
dispatch(ModifyIncidentsCommand, sys.argv, sys.stdin, sys.stdout, __name__)
开发者ID:simcen,项目名称:alert_manager,代码行数:30,代码来源:modifyincidents.py
示例4: __dir__
textmodel.save(args['model'].replace(".pkl",".%s" % args['textmodel']))
elif args['textmodel'] == 'hashing':
model['text'] = args['textmodel']
joblib.dump(model, args['model'])
print >> sys.stderr, "END"
channel.send({
'model': args['model'],
'score': score.item() if score else None,
'training_size': X_train.shape[0],
'test_size': X_test.shape[0]
})
"""
def __dir__(self):
return ["reset", "model", "textmodel", "test_size", "target", "_C"]
@Configuration(clear_required_fields=True)
def map(self, records):
try:
for record in records:
yield record
except:
yield {}
dispatch(MCTrain, sys.argv, sys.stdin, sys.stdout, __name__)
开发者ID:nlproc,项目名称:splunkml,代码行数:30,代码来源:mctrain.py
示例5: Option
doc=''' Temp Field ''', default='SLP')
field = Option(
doc=''' field to put value in ''',
default='psi')
def stream(self, events):
"""
:param events:
:return:
"""
for event in events:
self.logger.debug("start")
try:
p = float(event[self.SLP])
event[self.field] = round( 0.491154 * p ,2)
except:
event[self.field] = "N/A"
yield event
dispatch(Psi, sys.argv, sys.stdin, sys.stdout, __name__)
开发者ID:dakiri,项目名称:weather_station,代码行数:30,代码来源:psi.py
示例6: Option
doc=''' Temp Field ''', default='SLP')
field = Option(
doc=''' field to put value in ''',
default='kilopascals')
def stream(self, events):
"""
:param events:
:return:
"""
for event in events:
self.logger.debug("start")
try:
p = float(event[self.SLP])
event[self.field] = round( 33.8639 * ( p /10) ,2)
except:
event[self.field] = "N/A"
yield event
dispatch(Kilopascals, sys.argv, sys.stdin, sys.stdout, __name__)
开发者ID:dakiri,项目名称:weather_station,代码行数:30,代码来源:kilopascals.py
示例7: processDate
def processDate(self, event, field):
try:
timestamp = float(event[field])
value = repr(datetime.date.fromtimestamp(timestamp))
return eval("humanize." + self.command + "(" + value + ")")
except ValueError:
pass
def processTime(self, event, field):
try:
timestamp = float(event[field])
value = repr(datetime.datetime.fromtimestamp(timestamp))
return eval("humanize." + self.command + "(" + value + ")")
except ValueError:
pass
def stream(self, events):
self.logger.debug('HumanizeCommand: {}\n {}'.format(self, self.command)) # logs command line
for event in events:
for field in self.fieldnames:
if self.command in ['naturalday', 'naturaldate'] and field in event and len(event[field]) > 0:
event[field] = self.processDate(event, field)
elif self.command == 'naturaltime' and field in event and len(event[field]) > 0:
event[field] = self.processTime(event, field)
elif field in event and len(event[field]) > 0:
event[field] = eval("humanize." + self.command + "(" + event[field] + ")")
yield event
dispatch(HumanizeCommand, sys.argv, sys.stdin, sys.stdout, __name__)
开发者ID:northben,项目名称:splunk_humanize,代码行数:30,代码来源:humanize.py
示例8: stream
default='new_wind_chill')
def stream(self, events):
"""
:param events:
:return:
"""
for event in events:
self.logger.debug("start")
try:
temp = float(event[self.Temp])
RH = float(event[self.Relh])
wind = float(event[self.Winds])
old_chil = round((0.0817*(3.71*(pow(wind, 0.5)) + 5.81-0.25*wind)*(temp-91.4)+91.4),2)
new_chil = round(((35.74+0.6215*temp-35.75*pow(wind,0.16)+0.4275*temp*pow(wind,0.16))),2)
event[self.field] = round(old_chil,2)
event[self.field2] = round(new_chil,2)
except:
event[self.field] = "N/A"
event[self.field2] = "N/A"
yield event
dispatch(WindChill, sys.argv, sys.stdin, sys.stdout, __name__)
开发者ID:dakiri,项目名称:weather_station,代码行数:30,代码来源:wind_chill.py
示例9: vincenty
current[relative_distance] = vincenty(last_pos, current_pos, miles=bool(self.miles))
position_tracker[current[self.group_by]] = current_pos
yield current
else:
last_pos = None
for event in events:
current = event
if not (current[latitude] or current[longitude]):
current[relative_distance] = 0.0
self.logger.debug(
"[%s] - Using distance=0 for private IPs or unknown coordinates. Exclude if undesired." % str(
self.metadata.searchinfo.sid))
else:
current_pos = (float(current[latitude]), float(current[longitude]))
if last_pos is None:
current[relative_distance] = 0.0
self.logger.debug("[%s] - Initializing the first location with distance=0" % str(
self.metadata.searchinfo.sid))
else:
if use_haversine:
current[relative_distance] = haversine(last_pos, current_pos, miles=bool(self.miles))
else:
current[relative_distance] = vincenty(last_pos, current_pos, miles=bool(self.miles))
last_pos = current_pos
self.logger.debug(current)
yield current
self.logger.info("[%s] - Completed successfully." % str(self.metadata.searchinfo.sid))
dispatch(GeoDistanceCommand, sys.argv, sys.stdin, sys.stdout, __name__)
开发者ID:seunomosowon,项目名称:SA-geodistance,代码行数:30,代码来源:geodistance.py
示例10: enumerate
X = X.toarray()
y_pred = None
mah = None
clf = classifiers.get(classifier)
if clf:
try:
clf.fit(X)
y = clf.decision_function(X).ravel()
threshold = stats.scoreatpercentile(y, 100 * fraction)
y_pred = y > threshold
if classifier == 'covariance_estimator' and args['showmah']:
mah = clf.mahalanobis(X)
except ValueError:
y_pred = np.zeros((X.shape[0]))
for i, y in enumerate(y_pred):
if y:
record = records[i]
if mah is not None:
record['mahalanobis'] = mah[i].item()
channel.send(record)
else:
channel.send({ "error": "Incorrect classifier specified %s" % classifier })
"""
def __dir__(self):
return ['threshold','kernel','degree','gamma','coef0','support_fraction','showmah','classifier']
dispatch(Outliers, sys.argv, sys.stdin, sys.stdout, __name__)
开发者ID:nlproc,项目名称:splunkml,代码行数:30,代码来源:outliers.py
示例11: SearchTableCommand
import logging, os, splunk
from splunklib.searchcommands import \
dispatch, StreamingCommand, Configuration, Option, validators
@Configuration()
class SearchTableCommand(StreamingCommand):
pattern = Option(
doc='''
**Syntax:** **pattern=***<regular-expression>*
**Description:** Regular expression pattern to match''',
require=False, validate=validators.RegularExpression())
def stream(self, records):
#pydevd.settrace()
self.logger.setLevel(logging.DEBUG)
self.logger.debug('SearchTableCommand: %s' % self) # logs command line
for record in records:
found = "false"
for field in record:
matches = len(list(self.pattern.finditer(str(record[field]))))
if matches > 0:
found = "true"
if found == "true":
yield record
self.logger.debug('SearchTableCommand: Done')
dispatch(SearchTableCommand, sys.argv, sys.stdin, sys.stdout, __name__)
开发者ID:bshuler,项目名称:pstools,代码行数:29,代码来源:search_table.py
示例12: str
#print 'Row:', curr_row
curr_cell = -1
_raw = ""
line = {}
while curr_cell < num_cells:
if curr_row > 0:
curr_cell += 1
# Cell Types: 0=Empty, 1=Text, 2=Number, 3=Date, 4=Boolean, 5=Error, 6=Blank
cell_type = worksheet.cell_type(curr_row, curr_cell)
cell_value = worksheet.cell_value(curr_row, curr_cell)
head_value = worksheet.cell_value(0, curr_cell)
#print ' ', cell_type, ':', cell_value
_raw = _raw + '"' + str(head_value) + '"="' + str(cell_value) +'" '
line[str(head_value)] = str(cell_value)
else:
curr_cell += 1
if curr_row > 1:
line["_time"] = time.time()
line["line_number"] = i
line["_raw"] = _raw
line["worksheet_name"] = worksheet_name
yield line
i=i+1
dispatch(WGetxlsCommand, sys.argv, sys.stdin, sys.stdout, __name__)
开发者ID:bshuler,项目名称:pstools,代码行数:26,代码来源:wgetxls.py
示例13: dict
asset['_raw'] = util.tojson(asset)
yield asset
else:
try:
# If not 200 status_code showing error message in Splunk UI
record = util.dictexpand(response)
record['url'] = url
record['_raw'] = util.tojson(response)
except Exception as e:
record = dict()
record['url'] = url
record['error'] = e
record['_raw'] = util.tojson(response)
yield record
else:
try:
# If not 200 status_code showing error message in Splunk UI
record = util.dictexpand(response)
record['url'] = url
record['_raw'] = util.tojson(response)
except Exception as e:
record = dict()
record['url'] = url
record['error'] = e
record['_raw'] = util.tojson(response)
yield record
dispatch(getUserCommand, sys.argv, sys.stdin, sys.stdout, __name__)
开发者ID:Brainfold,项目名称:getsnow,代码行数:30,代码来源:getuser.py
示例14: Option
outputfield = Option(
doc='''
**Syntax:** **outputfield=***<fieldname>*
**Description:** Name of the field that will hold the found time''',
require=True, validate=validators.Fieldname())
def stream(self, records):
self.logger.debug('StrptimeFindCommand: %s', self) # logs command line
pattern = self.pattern
for record in records:
count = 0
datetime_str_orig = record[self.fieldname]
valid_strptime_string = record[self.pattern]
datetime_object = 0
limit=len(valid_strptime_string)
while len(datetime_str_orig) > limit:
datetime_str=datetime_str_orig
while len(datetime_str) > limit:
try:
datetime_object = datetime.strptime(datetime_str, valid_strptime_string)
break
except:
datetime_str = datetime_str[:-1]
datetime_str_orig = datetime_str_orig[1:]
if datetime_object:
record[self.outputfield] = time.mktime(datetime_object.timetuple())
yield record
dispatch(StrptimeFindCommand, sys.argv, sys.stdin, sys.stdout, __name__)
开发者ID:bshuler,项目名称:pstools,代码行数:29,代码来源:strptime_find.py
示例15: PasGetUserInfoCommand
#!/usr/bin/env python
import requests
import json
import sys, time
from splunklib.searchcommands import \
dispatch, GeneratingCommand, Configuration, Option, validators
@Configuration()
class PasGetUserInfoCommand(GeneratingCommand):
user = Option(require=True)
def generate(self):
url = 'http://localhost:5000/user_list/api/v1.0/users/' + self.user
data = requests.get(url).json()
if 'user' in data:
# Known user.
row = {}
for k, v in data['user'].iteritems():
row[str(k)] = str(v)
yield row
else:
# Unknown user. Return no data.
pass
dispatch(PasGetUserInfoCommand, sys.argv, sys.stdin, sys.stdout, __name__)
开发者ID:Sonalikhodake,项目名称:splunk-ref-pas-test,代码行数:25,代码来源:pasgetuserinfo.py
示例16: process_records
target = model['target']
fields = model['fields']
if model.get('text'):
if model['text'] == 'lsi':
textmodel = LsiModel.load(args['model'].replace(".pkl",".%s" % model['text']))
elif model['text'] == 'tfidf':
textmodel = TfidfModel.load(args['model'].replace(".pkl",".%s" % model['text']))
else:
textmodel = model['text']
except Exception as e:
print >> sys.stderr, "ERROR", e
channel.send({ 'error': "Couldn't find model %s" % args['model']})
else:
X, y_labels, textmodel = process_records(records, fields, target, textmodel=textmodel)
print >> sys.stderr, X.shape
y = est.predict(X)
y_labels = encoder.inverse_transform(y)
for i, record in enumerate(records):
record['%s_predicted' % target] = y_labels.item(i)
channel.send(record)
"""
def __dir__(self):
return ["model"]
dispatch(MCPredict, sys.argv, sys.stdin, sys.stdout, __name__)
开发者ID:nlproc,项目名称:splunkml,代码行数:30,代码来源:mcpredict.py
示例17: Option
Count the number of words in the `text` of each tweet in tweets.csv and store the result in `word_count`.
.. code-block::
| inputlookup tweets | countmatches fieldname=word_count pattern="\\w+" text
"""
fieldname = Option(
doc='''
**Syntax:** **fieldname=***<fieldname>*
**Description:** Name of the field that will hold the match count''',
require=True, validate=validators.Fieldname())
pattern = Option(
doc='''
**Syntax:** **pattern=***<regular-expression>*
**Description:** Regular expression pattern to match''',
require=True, validate=validators.RegularExpression())
def stream(self, records):
self.logger.debug('CountMatchesCommand: %s', self) # logs command line
pattern = self.pattern
for record in records:
count = 0
for fieldname in self.fieldnames:
matches = pattern.findall(six.text_type(record[fieldname].decode("utf-8")))
count += len(matches)
record[self.fieldname] = count
yield record
dispatch(CountMatchesCommand, sys.argv, sys.stdin, sys.stdout, __name__)
开发者ID:larrys,项目名称:splunk-sdk-python,代码行数:30,代码来源:countmatches.py
示例18: float
"NE",
"ENE",
"E",
"ESE",
"SE",
"SSE",
"S",
"SSW",
"SW",
"WSW",
"W",
"WNW",
"NW",
"NNW",
"N",
]
for event in events:
self.logger.debug("start")
try:
wd = float(event[self.Windd])
event[self.field] = dirs[int(1 + abs(round(wd / 22.5, 0)))]
except:
event[self.field] = "N/A"
yield event
dispatch(WindDir, sys.argv, sys.stdin, sys.stdout, __name__)
开发者ID:dakiri,项目名称:weather_station,代码行数:30,代码来源:wind_dir.py
示例19: stream
doc=''' field to put value in ''',
default='heatIndex')
def stream(self, events):
"""
:param events:
:return:
"""
for event in events:
self.logger.debug("start")
try:
T = float(event[self.Temp])
RH = float(event[self.Relh])
HI =(0.5 * (T + 61.0 + (T-68.0)*1.2 + (RH*0.094)))
event[self.field] = round(HI,2)
except:
event[self.field] = "N/A"
yield event
dispatch(HeatIndex, sys.argv, sys.stdin, sys.stdout, __name__)
开发者ID:dakiri,项目名称:weather_station,代码行数:30,代码来源:heat_index.py
示例20: Option
"""
SLP = Option(
doc=''' Temp Field ''', default='SLP')
field = Option(
doc=''' field to put value in ''',
default='Pressure_mmHg')
def stream(self, events):
"""
:param events:
:return:
"""
for event in events:
self.logger.debug("start")
try:
p = float(event[self.SLP])
event[self.field] = round(25.4 * p, 2)
except:
event[self.field] = "N/A"
yield event
dispatch(PmmHg, sys.argv, sys.stdin, sys.stdout, __name__)
开发者ID:dakiri,项目名称:weather_station,代码行数:29,代码来源:pmmHg.py
注:本文中的splunklib.searchcommands.dispatch函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论