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": self._args.direction = 1 elif self._args.direction.lower() == "egress": self._args.direction = 0 else: print 'Direction should be ingress or egress' return -1 # Protocol if self._args.protocol is not None: if self._args.protocol.isalpha(): protocol = OpServerUtils.str_to_ip_protocol( self._args.protocol) if protocol == -1: print 'Please provide valid protocol' return -1 self._args.protocol = protocol return 0
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( "--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: 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
def parse_args(self): """ Eg. python log.py --opserver-ip 127.0.0.1 --opserver-port 8081 --source 127.0.0.1 --module bgp | cfgm | vnswad --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 """ 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( "--module", help="Logs from module", choices=ModuleNames.values()) 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") 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
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("--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: 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
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 """ 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") 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
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": self._args.direction = 1 elif self._args.direction.lower() == "egress": self._args.direction = 0 else: print 'Direction should be ingress or egress' return -1 # Protocol if self._args.protocol is not None: if self._args.protocol.isalpha(): protocol = OpServerUtils.str_to_ip_protocol( self._args.protocol) if protocol == -1: print 'Please provide valid protocol' return -1 self._args.protocol = protocol return 0