本文整理汇总了Python中opserver_introspect_utils.VerificationOpsSrv.post_query方法的典型用法代码示例。如果您正苦于以下问题:Python VerificationOpsSrv.post_query方法的具体用法?Python VerificationOpsSrv.post_query怎么用?Python VerificationOpsSrv.post_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opserver_introspect_utils.VerificationOpsSrv
的用法示例。
在下文中一共展示了VerificationOpsSrv.post_query方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: verify_message_table_filter
# 需要导入模块: from opserver_introspect_utils import VerificationOpsSrv [as 别名]
# 或者: from opserver_introspect_utils.VerificationOpsSrv import post_query [as 别名]
def verify_message_table_filter(self):
self.logger.info("verify_message_table_where_filter");
vns = VerificationOpsSrv('127.0.0.1', self.opserver_port)
where_clause1 = "ModuleId = QueryEngine"
where_clause2 = str("Source =" + socket.gethostname())
res = vns.post_query('MessageTable',
start_time = '-10m', end_time = 'now',
select_fields = ["ModuleId"],
where_clause = str(where_clause1 + " OR " + where_clause2),
filter = "ModuleId = QueryEngine")
if res == []:
return False
else:
assert(len(res) > 0)
moduleids = list(set(x['ModuleId'] for x in res))
self.logger.info(str(moduleids))
if len(moduleids) != 1: # 1 moduleid: Collector
return False
res1 = vns.post_query('MessageTable',
start_time = '-10m', end_time = 'now',
select_fields = ["ModuleId"],
where_clause = str(where_clause1 + " AND " + where_clause2),
filter = "ModuleId = Collector")
self.logger.info(str(res1))
if res1 != []:
return False
return True
示例2: verify_test_stat
# 需要导入模块: from opserver_introspect_utils import VerificationOpsSrv [as 别名]
# 或者: from opserver_introspect_utils.VerificationOpsSrv import post_query [as 别名]
def verify_test_stat(self, table, stime, select_fields, where_clause, num,
check_rows = None, sort_fields=None, filt=None):
self._logger.info("verify_test_stat")
vns = VerificationOpsSrv('127.0.0.1', self._opserver_port)
res = vns.post_query(table, start_time=stime, end_time='now',
select_fields=select_fields,
where_clause=where_clause,
sort_fields=sort_fields,
filter=filt)
self._logger.info(str(res))
if (len(res) != num):
self._logger.info("Found %d rows, expected %d" % (len(res),num))
return False
if check_rows is None:
return True
for crow in check_rows:
match = False
for row in res:
for k in crow.keys():
if k in row:
if (crow[k] != row[k]):
break
else:
break
else:
match = True
break
if match is False:
self._logger.info("Could not match %s" % str(crow))
return False
return True
示例3: verify_test_stat
# 需要导入模块: from opserver_introspect_utils import VerificationOpsSrv [as 别名]
# 或者: from opserver_introspect_utils.VerificationOpsSrv import post_query [as 别名]
def verify_test_stat(
self,
table,
stime,
select_fields,
where_clause,
num,
check_rows=None,
check_uniq=None,
sort_fields=None,
filt=None,
):
self._logger.info("verify_test_stat")
vns = VerificationOpsSrv("127.0.0.1", self._opserver_port)
res = vns.post_query(
table,
start_time=stime,
end_time="now",
select_fields=select_fields,
where_clause=where_clause,
sort_fields=sort_fields,
filter=filt,
)
self._logger.info("Recieved %s" % str(res))
self._logger.info("Found %d rows, expected %d" % (len(res), num))
if len(res) != num:
return False
if check_uniq is not None:
for k, v in check_uniq.iteritems():
vs = set()
for row in res:
if k in row:
vs.add(row[k])
self._logger.info("Expected %d uniq values of %s, found %s" % (v, k, str(vs)))
if len(vs) != v:
return False
if check_rows is None:
return True
self._logger.info("Checking against %s" % str(check_rows))
for crow in check_rows:
match = False
for row in res:
for k in crow.keys():
if k in row:
if crow[k] != row[k]:
self._logger.error(
"Expected %s : %s got %s : %s" % (str(k), str(crow[k]), str(k), str(row[k]))
)
break
else:
break
else:
match = True
break
if match is False:
self._logger.info("Could not match %s" % str(crow))
return False
return True
示例4: verify_message_table_moduleid
# 需要导入模块: from opserver_introspect_utils import VerificationOpsSrv [as 别名]
# 或者: from opserver_introspect_utils.VerificationOpsSrv import post_query [as 别名]
def verify_message_table_moduleid(self):
self.logger.info("verify_message_table_moduleid");
vns = VerificationOpsSrv('127.0.0.1', self.opserver_port)
# query for QueryEngine logs
res_qe = vns.post_query('MessageTable',
start_time = '-10m', end_time = 'now',
select_fields = ["Type", "Messagetype" ],
where_clause = "ModuleId = QueryEngine")
# query for Collector logs
res_c = vns.post_query('MessageTable',
start_time = '-10m', end_time = 'now',
select_fields = ["Type", "Messagetype" ],
where_clause = "ModuleId = Collector")
if (res_qe == []) or (res_c == []):
return False
assert(len(res_qe) > 0)
assert(len(res_c) > 0)
return True
示例5: verify_flow_samples
# 需要导入模块: from opserver_introspect_utils import VerificationOpsSrv [as 别名]
# 或者: from opserver_introspect_utils.VerificationOpsSrv import post_query [as 别名]
def verify_flow_samples(self, generator_obj):
self.logger.info("verify_flow_samples")
vns = VerificationOpsSrv('127.0.0.1', self.opserver_port)
res = vns.post_query('FlowSeriesTable',
start_time=str(generator_obj.flow_start_time),
end_time=str(generator_obj.flow_end_time),
select_fields=['T'], where_clause='')
self.logger.info(str(res))
if len(res) == generator_obj.num_flow_samples:
return True
return False
示例6: verify_intervn_sum
# 需要导入模块: from opserver_introspect_utils import VerificationOpsSrv [as 别名]
# 或者: from opserver_introspect_utils.VerificationOpsSrv import post_query [as 别名]
def verify_intervn_sum(self, gen_obj):
self.logger.info("verify_intervn_sum")
vns = VerificationOpsSrv('127.0.0.1', self.opserver_port)
res = vns.post_query('StatTable.UveVirtualNetworkAgent.vn_stats',
start_time='-10m',
end_time='now',
select_fields=gen_obj.vn_sum_rows['select'],
where_clause=gen_obj.vn_sum_rows['whereclause'])
self.logger.info(str(res))
if len(res) == gen_obj.vn_sum_rows['rows']:
return True
return False
示例7: verify_collector_obj_count
# 需要导入模块: from opserver_introspect_utils import VerificationOpsSrv [as 别名]
# 或者: from opserver_introspect_utils.VerificationOpsSrv import post_query [as 别名]
def verify_collector_obj_count(self):
vns = VerificationOpsSrv('127.0.0.1', self.opserver_port)
res = vns.post_query('ObjectCollectorInfo',
start_time = '-10m', end_time = 'now',
select_fields = ["ObjectLog"],
where_clause = str('ObjectId=' + socket.gethostname()),
sync = False)
if res == []:
return False
else:
assert(len(res) > 0)
self.logger.info(str(res))
return True
示例8: verify_message_table_messagetype
# 需要导入模块: from opserver_introspect_utils import VerificationOpsSrv [as 别名]
# 或者: from opserver_introspect_utils.VerificationOpsSrv import post_query [as 别名]
def verify_message_table_messagetype(self):
self.logger.info("verify_message_table_messagetype");
vns = VerificationOpsSrv('127.0.0.1', self.opserver_port)
# query for CollectorInfo logs
res = vns.post_query('MessageTable',
start_time = '-10m', end_time = 'now',
select_fields = ["ModuleId" ],
where_clause = "Messagetype = CollectorInfo")
if (res == []):
return False
assert(len(res) > 0)
# verify if the result returned is ok
moduleids = list(set(x['ModuleId'] for x in res))
self.logger.info("Modules: %s " % str(moduleids))
# only one moduleid: Collector
if (not((len(moduleids) == 1))):
return False
if (not ("Collector" in moduleids)):
return False
return True
示例9: verify_flow_series_aggregation_binning
# 需要导入模块: from opserver_introspect_utils import VerificationOpsSrv [as 别名]
# 或者: from opserver_introspect_utils.VerificationOpsSrv import post_query [as 别名]
def verify_flow_series_aggregation_binning(self, generator_obj):
self.logger.info('verify_flow_series_aggregation_binning')
vns = VerificationOpsSrv('127.0.0.1', self.opserver_port)
# 1. stats
self.logger.info('Flowseries: [sum(bytes),sum(packets)]')
res = vns.post_query('FlowSeriesTable',
start_time=str(generator_obj.flow_start_time),
end_time=str(generator_obj.flow_end_time),
select_fields=['sum(bytes)', 'sum(packets)'], where_clause='')
self.logger.info(str(res))
assert(len(res) == 1)
exp_sum_pkts = exp_sum_bytes = 0
for f in generator_obj.flows:
exp_sum_pkts += f.packets
exp_sum_bytes += f.bytes
assert(res[0]['sum(packets)'] == exp_sum_pkts)
assert(res[0]['sum(bytes)'] == exp_sum_bytes)
# 2. flow tuple + stats
self.logger.info('Flowseries: [sport, dport, sum(bytes), sum(packets)]')
# Each flow has unique (sport, dport). Therefore, the following query
# should return # records equal to the # flows.
res = vns.post_query('FlowSeriesTable',
start_time=str(generator_obj.flow_start_time),
end_time=str(generator_obj.flow_end_time),
select_fields=['sport', 'dport', 'sum(bytes)', 'sum(packets)'],
where_clause='')
self.logger.info(str(res))
assert(len(res) == generator_obj.flow_cnt)
for r in res:
cnt = 0
for f in generator_obj.flows:
if r['sport'] == f.sport and r['dport'] == f.dport:
assert(r['sum(packets)'] == f.packets)
assert(r['sum(bytes)'] == f.bytes)
break
cnt += 1
assert(cnt < generator_obj.flow_cnt)
# All flows has the same (sourcevn, destvn). Therefore, the following
# query should return one record.
res = vns.post_query('FlowSeriesTable',
start_time=str(generator_obj.flow_start_time),
end_time=str(generator_obj.flow_end_time),
select_fields=['sourcevn', 'destvn', 'sum(bytes)', 'sum(packets)'],
where_clause='')
self.logger.info(str(res))
assert(len(res) == 1)
exp_sum_pkts = exp_sum_bytes = 0
for f in generator_obj.flows:
exp_sum_pkts += f.packets
exp_sum_bytes += f.bytes
assert(res[0]['sum(packets)'] == exp_sum_pkts)
assert(res[0]['sum(bytes)'] == exp_sum_bytes)
# top 3 flows
res = vns.post_query('FlowSeriesTable',
start_time=str(generator_obj.flow_start_time),
end_time=str(generator_obj.flow_end_time),
select_fields=['sport', 'dport', 'sum(bytes)'],
where_clause='',
sort_fields=['sum(bytes)'], sort=2, limit=3)
self.logger.info(str(res))
assert(len(res) == 3)
exp_res = sorted(generator_obj.flows, key=lambda flow: flow.bytes, reverse=True)
cnt = 0
for r in res:
assert(r['sport'] == exp_res[cnt].sport)
assert(r['dport'] == exp_res[cnt].dport)
assert(r['sum(bytes)'] == exp_res[cnt].bytes)
cnt += 1
# 3. T=<granularity> + stats
self.logger.info('Flowseries: [T=<x>, sum(bytes), sum(packets)]')
st = str(generator_obj.flow_start_time)
et = str(generator_obj.flow_start_time+(30*1000*1000))
granularity = 10
res = vns.post_query('FlowSeriesTable', start_time=st, end_time=et,
select_fields=['T=%s' % (granularity), 'sum(bytes)', 'sum(packets)'],
where_clause='sourcevn=domain1:admin:vn1 AND destvn=domain1:admin:vn2')
self.logger.info(str(res))
num_records = (int(et)-int(st))/(granularity*1000*1000)
assert(len(res) == num_records)
ts = [generator_obj.flow_start_time+((x+1)*granularity*1000*1000) for x in range(num_records)]
exp_result = {
ts[0]:{'sum(bytes)':5500, 'sum(packets)': 65},
ts[1]:{'sum(bytes)':725, 'sum(packets)': 15},
ts[2]:{'sum(bytes)':700, 'sum(packets)': 8}
}
assert(len(exp_result) == num_records)
for r in res:
try:
stats = exp_result[r['T']]
except KeyError:
assert(False)
assert(r['sum(bytes)'] == stats['sum(bytes)'])
assert(r['sum(packets)'] == stats['sum(packets)'])
# 4. T=<granularity> + tuples + stats
#.........这里部分代码省略.........
示例10: verify_flow_table
# 需要导入模块: from opserver_introspect_utils import VerificationOpsSrv [as 别名]
# 或者: from opserver_introspect_utils.VerificationOpsSrv import post_query [as 别名]
def verify_flow_table(self, generator_obj):
# query flow records
self.logger.info('verify_flow_table')
vns = VerificationOpsSrv('127.0.0.1', self.opserver_port)
res = vns.post_query('FlowRecordTable',
start_time=str(generator_obj.flow_start_time),
end_time=str(generator_obj.flow_end_time),
select_fields=['UuidKey', 'agg-packets', 'agg-bytes'],
where_clause='')
self.logger.info("FlowRecordTable result:%s" % str(res))
assert(len(res) == generator_obj.flow_cnt)
# query based on various WHERE parameters
# sourcevn and sourceip
res = vns.post_query('FlowRecordTable',
start_time=str(generator_obj.flow_start_time),
end_time=str(generator_obj.flow_end_time),
select_fields=['UuidKey', 'sourcevn', 'sourceip'],
where_clause='sourceip=10.10.10.1 AND sourcevn=domain1:admin:vn1')
self.logger.info(str(res))
assert(len(res) == generator_obj.flow_cnt)
res = vns.post_query('FlowSeriesTable',
start_time=str(generator_obj.flow_start_time),
end_time=str(generator_obj.flow_end_time),
select_fields=['sourcevn', 'sourceip'],
where_clause='sourceip=10.10.10.1 AND sourcevn=domain1:admin:vn1')
self.logger.info(str(res))
assert(len(res) == generator_obj.num_flow_samples)
# give non-existent values in the where clause
res = vns.post_query('FlowRecordTable',
start_time=str(generator_obj.flow_start_time),
end_time=str(generator_obj.flow_end_time),
select_fields=['UuidKey', 'sourcevn', 'sourceip'],
where_clause='sourceip=20.1.1.10')
self.logger.info(str(res))
assert(len(res) == 0)
res = vns.post_query('FlowSeriesTable',
start_time=str(generator_obj.flow_start_time),
end_time=str(generator_obj.flow_end_time),
select_fields=['sourcevn', 'sourceip'],
where_clause='sourceip=20.1.1.10 AND sourcevn=domain1:admin:vn1')
self.logger.info(str(res))
assert(len(res) == 0)
# destvn and destip
res = vns.post_query('FlowRecordTable',
start_time=str(generator_obj.flow_start_time),
end_time=str(generator_obj.flow_end_time),
select_fields=['UuidKey', 'destvn', 'destip'],
where_clause='destip=10.10.10.2 AND destvn=domain1:admin:vn2')
self.logger.info(str(res))
assert(len(res) == generator_obj.flow_cnt)
res = vns.post_query('FlowSeriesTable',
start_time=str(generator_obj.flow_start_time),
end_time=str(generator_obj.flow_end_time),
select_fields=['destvn', 'destip'],
where_clause='destip=10.10.10.2 AND destvn=domain1:admin:vn2')
self.logger.info(str(res))
assert(len(res) == generator_obj.num_flow_samples)
# give non-existent values in the where clause
res = vns.post_query('FlowRecordTable',
start_time=str(generator_obj.flow_start_time),
end_time=str(generator_obj.flow_end_time),
select_fields=['UuidKey', 'destvn', 'destip'],
where_clause='destip=10.10.10.2 AND destvn=default-domain:default-project:default-virtual-network')
self.logger.info(str(res))
assert(len(res) == 0)
res = vns.post_query('FlowSeriesTable',
start_time=str(generator_obj.flow_start_time),
end_time=str(generator_obj.flow_end_time),
select_fields=['destvn', 'destip'],
where_clause='destip=20.1.1.10 AND destvn=domain1:admin:vn2')
self.logger.info(str(res))
assert(len(res) == 0)
# sport and protocol
res = vns.post_query('FlowRecordTable',
start_time=str(generator_obj.flow_start_time),
end_time=str(generator_obj.flow_end_time),
select_fields=['UuidKey', 'sport', 'protocol'],
where_clause='sport=13 AND protocol=1')
self.logger.info(str(res))
assert(len(res) == 1)
res = vns.post_query('FlowSeriesTable',
start_time=str(generator_obj.flow_start_time),
end_time=str(generator_obj.flow_end_time),
select_fields=['sport', 'protocol'],
where_clause = 'sport=13 AND protocol=1')
self.logger.info(str(res))
assert(len(res) == 5)
# give no-existent values in the where clause
res = vns.post_query('FlowRecordTable',
start_time=str(generator_obj.flow_start_time),
end_time=str(generator_obj.flow_end_time),
select_fields=['UuidKey', 'sport', 'protocol'],
where_clause='sport=20 AND protocol=17')
self.logger.info(str(res))
assert(len(res) == 0)
res = vns.post_query('FlowSeriesTable',
#.........这里部分代码省略.........
示例11: verify_message_table_sort
# 需要导入模块: from opserver_introspect_utils import VerificationOpsSrv [as 别名]
# 或者: from opserver_introspect_utils.VerificationOpsSrv import post_query [as 别名]
def verify_message_table_sort(self):
self.logger.info("verify_message_table_sort:Ascending Sort")
vns = VerificationOpsSrv('127.0.0.1', self.opserver_port)
where_clause1 = "ModuleId = QueryEngine"
where_clause2 = str("Source =" + socket.gethostname())
exp_moduleids = ['Collector', 'OpServer', 'QueryEngine']
# Ascending sort
res = vns.post_query('MessageTable',
start_time = '-10m', end_time = 'now',
select_fields = ["ModuleId"],
where_clause = str(where_clause1 + " OR " + where_clause2),
sort_fields = ["ModuleId"], sort = 1)
if res == []:
return False
else:
assert(len(res) > 0)
moduleids = []
for x in res:
if x['ModuleId'] not in moduleids:
moduleids.append(x['ModuleId'])
self.logger.info(str(moduleids))
for module in exp_moduleids:
if module not in moduleids:
return False
expected_res = sorted(res, key=itemgetter('ModuleId'))
if res != expected_res:
return False
# Descending sort
self.logger.info("verify_message_table_sort:Descending Sort");
res = vns.post_query('MessageTable',
start_time = '-10m', end_time = 'now',
select_fields = ["ModuleId"],
where_clause = str(where_clause1 + " OR " + where_clause2),
sort_fields = ["ModuleId"], sort = 2)
if res == []:
return False
else:
assert(len(res) > 0)
moduleids = []
for x in res:
if x['ModuleId'] not in moduleids:
moduleids.append(x['ModuleId'])
self.logger.info(str(moduleids))
for module in exp_moduleids:
if module not in moduleids:
return False
expected_res = sorted(res, key=itemgetter('ModuleId'), reverse=True)
if res != expected_res:
return False
# Limit
res = vns.post_query('MessageTable',
start_time = '-10m', end_time = 'now',
select_fields = ["ModuleId"],
where_clause = str(where_clause1 + " OR " + where_clause2),
sort_fields = ["ModuleId"], sort = 1, limit=1)
if res == []:
return False
else:
assert(len(res) > 0)
moduleids = []
for x in res:
if x['ModuleId'] not in moduleids:
moduleids.append(x['ModuleId'])
self.logger.info(str(moduleids))
if len(moduleids) == 1: # 2 moduleids: Collector/QueryEngine
if moduleids[0] != 'Collector':
return False
return True
else:
return False