本文整理汇总了Python中opserver_util.OpServerUtils.convert_to_utc_timestamp_usec方法的典型用法代码示例。如果您正苦于以下问题:Python OpServerUtils.convert_to_utc_timestamp_usec方法的具体用法?Python OpServerUtils.convert_to_utc_timestamp_usec怎么用?Python OpServerUtils.convert_to_utc_timestamp_usec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opserver_util.OpServerUtils
的用法示例。
在下文中一共展示了OpServerUtils.convert_to_utc_timestamp_usec方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import convert_to_utc_timestamp_usec [as 别名]
def __init__(self, query_json, analytics_api_ip,
analytics_api_port, user, password, logger):
self.query_json = query_json
self._analytics_api_ip = analytics_api_ip
self._analytics_api_port = analytics_api_port
self._user = user
self._password = password
self._logger = logger
if self.query_json is not None:
self._start_time = self.query_json['start_time']
self._end_time = self.query_json['end_time']
# If the start_time/end_time in the query is specified as
# relative time, then the actual start_time/end_time for the
# FlowRecordTable query and UFlowData query would be different.
# Since the FlowRecordTable is queried first and the result of
# which is used to query the UFlowData table, the result may
# not be correct if the start_time/end_time is different for
# FlowRecord and UFlowData queries. Therefore, convert the
# relative start/end time to absolute time.
if not str(self._start_time).isdigit():
self._start_time = \
OpServerUtils.convert_to_utc_timestamp_usec(self._start_time)
if not str(self._end_time).isdigit():
self._end_time = \
OpServerUtils.convert_to_utc_timestamp_usec(self._end_time)
示例2: parse_args
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import convert_to_utc_timestamp_usec [as 别名]
def parse_args(self):
"""
Eg. python log.py --opserver-ip 127.0.0.1
--opserver-port 8081
--source 127.0.0.1
--node-type Control
--module bgp | cfgm | vnswad
--instance-id 0
--message-type UveVirtualMachineConfigTrace
--category xmpp
--level SYS_INFO | SYS_ERROR
--object vn | vm
--object-id name
--object-select-field ObjectLog | SystemLog
--reverse
--verbose
--raw
--trace BgpPeerTraceBuf
[--start-time now-10m --end-time now] | --last 10m
--send-syslog
--syslog-server 127.0.0.1
--syslog-port 514
"""
defaults = {
'opserver_ip': '127.0.0.1',
'opserver_port': '8081',
'start_time': 'now-10m',
'end_time': 'now',
}
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.set_defaults(**defaults)
parser.add_argument("--opserver-ip", help="IP address of OpServer")
parser.add_argument("--opserver-port", help="Port of OpServer")
parser.add_argument(
"--start-time", help="Logs start time (format now-10m, now-1h)")
parser.add_argument("--end-time", help="Logs end time")
parser.add_argument(
"--last", help="Logs from last time period (format 10m, 1d)")
parser.add_argument("--source", help="Logs from source address")
parser.add_argument("--node-type", help="Logs from node type",
choices=NodeTypeNames.values())
parser.add_argument(
"--module", help="Logs from module", choices=ModuleNames.values())
parser.add_argument("--instance-id", help="Logs from module instance")
parser.add_argument("--category", help="Logs of category")
parser.add_argument("--level", help="Logs of level")
parser.add_argument("--message-type", help="Logs of message type")
parser.add_argument("--reverse", action="store_true",
help="Show logs in reverse chronological order")
parser.add_argument(
"--verbose", action="store_true", help="Show internal information")
parser.add_argument(
"--all", action="store_true", help="Show all logs")
parser.add_argument(
"--raw", action="store_true", help="Show raw XML messages")
parser.add_argument(
"--object", help="Logs of object type", choices=OBJECT_TABLE_LIST)
parser.add_argument("--object-id", help="Logs of object name")
parser.add_argument(
"--object-select-field", help="Select field to filter the log",
choices=[VizConstants.OBJECT_LOG, VizConstants.SYSTEM_LOG])
parser.add_argument("--trace", help="Dump trace buffer")
parser.add_argument("--limit", help="Limit the number of messages")
parser.add_argument("--send-syslog", action="store_true",
help="Send syslog to specified server and port")
parser.add_argument("--syslog-server",
help="IP address of syslog server", default='localhost')
parser.add_argument("--syslog-port", help="Port to send syslog to",
type=int, default=514)
self._args = parser.parse_args()
if self._args.last is not None:
self._args.last = '-' + self._args.last
self._start_time = OpServerUtils.convert_to_utc_timestamp_usec(
self._args.last)
self._end_time = OpServerUtils.convert_to_utc_timestamp_usec('now')
else:
try:
if (self._args.start_time.isdigit() and
self._args.end_time.isdigit()):
self._start_time = int(self._args.start_time)
self._end_time = int(self._args.end_time)
else:
self._start_time =\
OpServerUtils.convert_to_utc_timestamp_usec(
self._args.start_time)
self._end_time =\
OpServerUtils.convert_to_utc_timestamp_usec(
self._args.end_time)
except:
print 'Incorrect start-time (%s) or end-time (%s) format' %\
(self._args.start_time, self._args.end_time)
return -1
return 0
示例3: parse_args
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import convert_to_utc_timestamp_usec [as 别名]
def parse_args(self):
"""
Eg. python flow.py --opserver-ip 127.0.0.1
--opserver-port 8081
--vrouter a6s23
--source-vn default-domain:default-project:vn1
--destination-vn default-domain:default-project:vn2
--source-ip 1.1.1.1
--destination-ip 2.2.2.2
--protocol TCP
--source-port 32678
--destination-port 80
--action drop
--direction ingress
[--start-time now-10m --end-time now] | --last 10m
"""
defaults = {
'opserver_ip': '127.0.0.1',
'opserver_port': '8081',
'start_time': 'now-10m',
'end_time': 'now',
'direction' : 'ingress',
}
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.set_defaults(**defaults)
parser.add_argument("--opserver-ip", help="IP address of OpServer")
parser.add_argument("--opserver-port", help="Port of OpServer")
parser.add_argument(
"--start-time", help="Flow record start time (format now-10m, now-1h)")
parser.add_argument("--end-time", help="Flow record end time")
parser.add_argument(
"--last", help="Flow records from last time period (format 10m, 1d)")
parser.add_argument("--vrouter", help="Flow records from vrouter")
parser.add_argument("--source-vn",
help="Flow records with source virtual network")
parser.add_argument("--destination-vn",
help="Flow records with destination virtual network")
parser.add_argument("--source-ip",
help="Flow records with source IP address")
parser.add_argument("--destination-ip",
help="Flow records with destination IP address")
parser.add_argument("--protocol", help="Flow records with protocol")
parser.add_argument("--source-port",
help="Flow records with source port", type=int)
parser.add_argument("--destination-port",
help="Flow records with destination port", type=int)
parser.add_argument("--action", help="Flow records with action")
parser.add_argument("--direction", help="Flow direction",
choices=['ingress', 'egress'])
parser.add_argument(
"--verbose", action="store_true", help="Show internal information")
self._args = parser.parse_args()
# Validate start-time and end-time
if self._args.last is not None:
self._args.last = '-' + self._args.last
self._start_time = OpServerUtils.convert_to_utc_timestamp_usec(
self._args.last)
self._end_time = OpServerUtils.convert_to_utc_timestamp_usec('now')
else:
try:
if (self._args.start_time.isdigit() and
self._args.end_time.isdigit()):
self._start_time = int(self._args.start_time)
self._end_time = int(self._args.end_time)
else:
self._start_time =\
OpServerUtils.convert_to_utc_timestamp_usec(
self._args.start_time)
self._end_time =\
OpServerUtils.convert_to_utc_timestamp_usec(
self._args.end_time)
except:
print 'Incorrect start-time (%s) or end-time (%s) format' %\
(self._args.start_time, self._args.end_time)
return -1
# Validate flow arguments
if self._args.source_ip is not None and self._args.source_vn is None:
print 'Please provide source virtual network in addtion to '\
'source IP address'
return -1
if self._args.destination_ip is not None and \
self._args.destination_vn is None:
print 'Please provide destination virtual network in addtion to '\
'destination IP address'
return -1
if self._args.source_port is not None and self._args.protocol is None:
print 'Please provide protocol in addtion to source port'
return -1
if self._args.destination_port is not None and \
self._args.protocol is None:
print 'Please provide protocol in addtion to '\
'destination port'
return -1
# Convert direction
if self._args.direction.lower() == "ingress":
#.........这里部分代码省略.........
示例4: parse_args
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import convert_to_utc_timestamp_usec [as 别名]
def parse_args(self):
"""
Eg. python stats.py --opserver-ip 127.0.0.1
--opserver-port 8081
--table AnalyticsCpuState.cpu_info
--where name=a6s40 cpu_info.module_id=Collector
--select "T=60 SUM(cpu_info.cpu_share)"
--sort "SUM(cpu_info.cpu_share)"
[--start-time now-10m --end-time now] | --last 10m
python stats.py --table AnalyticsCpuState.cpu_info
"""
defaults = {
'opserver_ip': '127.0.0.1',
'opserver_port': '8081',
'start_time': 'now-10m',
'end_time': 'now',
'select' : [],
'where' : [],
'sort': []
}
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.set_defaults(**defaults)
parser.add_argument("--opserver-ip", help="IP address of OpServer")
parser.add_argument("--opserver-port", help="Port of OpServer")
parser.add_argument(
"--start-time", help="Logs start time (format now-10m, now-1h)")
parser.add_argument("--end-time", help="Logs end time")
parser.add_argument(
"--last", help="Logs from last time period (format 10m, 1d)")
parser.add_argument(
"--table", help="StatTable to query", choices=STAT_TABLE_LIST)
parser.add_argument(
"--dtable", help="Dynamic StatTable to query")
parser.add_argument(
"--select", help="List of Select Terms", nargs='+')
parser.add_argument(
"--where", help="List of Where Terms to be ANDed", nargs='+')
parser.add_argument(
"--sort", help="List of Sort Terms", nargs='+')
self._args = parser.parse_args()
if self._args.table is None and self._args.dtable is None:
return -1
if self._args.last is not None:
self._args.last = '-' + self._args.last
self._start_time = OpServerUtils.convert_to_utc_timestamp_usec(
self._args.last)
self._end_time = OpServerUtils.convert_to_utc_timestamp_usec('now')
else:
try:
if (self._args.start_time.isdigit() and
self._args.end_time.isdigit()):
self._start_time = int(self._args.start_time)
self._end_time = int(self._args.end_time)
else:
self._start_time =\
OpServerUtils.convert_to_utc_timestamp_usec(
self._args.start_time)
self._end_time =\
OpServerUtils.convert_to_utc_timestamp_usec(
self._args.end_time)
except:
print 'Incorrect start-time (%s) or end-time (%s) format' %\
(self._args.start_time, self._args.end_time)
return -1
return 0