def callback(self, ch, method, properties, body): jsonrpclib_history.clear() self.check() sys.stdout.flush() record = json.loads(body) record = self.mgr.modify_record(record) try: self.mgr.add_acl(**record) ch.basic_ack(delivery_tag=method.delivery_tag) except InvalidRequest as e: self.mgr.logger.exception("Invalid request") ch.basic_ack(delivery_tag=method.delivery_tag)
def run(self): self.mgr.logger.info("Ready..") while True: jsonrpclib_history.clear() self.check() sys.stdout.flush() try: data, addr = self.sock.recvfrom(1024) except socket.timeout: continue record = json.loads(data) record = self.mgr.modify_record(record) self.mgr.add_acl(**record) self.sock.sendto("ok", addr)
def run(self): self.mgr.logger.info("Ready..") while True: jsonrpclib_history.clear() self.check() sys.stdout.flush() try : data, addr = self.sock.recvfrom(1024) except socket.timeout: continue record = json.loads(data) record = self.mgr.modify_record(record) self.mgr.add_acl(**record) self.sock.sendto("ok", addr)
def stats_loop(self, interval=5): l_ibytes, l_ebytes = self.get_stats() gig = 1024**3 self.logger.info("total gigs: in=%d out=%d filtered=%d", l_ibytes/gig, l_ebytes/gig, (l_ibytes-l_ebytes)/gig) while True: last = time.time() time.sleep(interval) ibytes, ebytes = self.get_stats() now = time.time() actual_interval = (now - last) ibw = (ibytes - l_ibytes) *8 / actual_interval / 1024 / 1024 ebw = (ebytes - l_ebytes) *8 / actual_interval / 1024 / 1024 self.logger.info("mbps: in=%d out=%d filtered=%d", ibw, ebw, ibw-ebw) l_ibytes, l_ebytes = ibytes, ebytes jsonrpclib_history.clear()
def stats_loop(self, interval=5): l_ibytes, l_ebytes = self.get_stats() gig = 1024**3 self.logger.info("total gigs: in=%d out=%d filtered=%d", l_ibytes / gig, l_ebytes / gig, (l_ibytes - l_ebytes) / gig) while True: last = time.time() time.sleep(interval) ibytes, ebytes = self.get_stats() now = time.time() actual_interval = (now - last) ibw = (ibytes - l_ibytes) * 8 / actual_interval / 1024 / 1024 ebw = (ebytes - l_ebytes) * 8 / actual_interval / 1024 / 1024 self.logger.info("mbps: in=%d out=%d filtered=%d", ibw, ebw, ibw - ebw) l_ibytes, l_ebytes = ibytes, ebytes jsonrpclib_history.clear()
def main(): ''' main execution routine for devops command. Parse the command line options, build the RESTful request, send it to stdlib, and then process the response. ''' global SNMP_SETTINGS global DEBUG args = parse_cmd_line() DEBUG = args['debug'] log("Entering {0}.".format(sys._getframe().f_code.co_name), level='DEBUG') config = read_config(args['config']) SNMP_SETTINGS = config['snmp'] if args['test'] == 'parse_only': print "\nargs:" pprint(args) print "\nconfig:" pprint(config) return 0 elif args['test'] == 'trap': send_trap('', test='trap') return 0 elif args['test'] == 'get': print "Connecting to eAPI at {0}".format(config['switches'][0]['url']) switch = Server(config['switches'][0]['url']) (interface, counters) = get_intf_counters(switch, interface="Management1") print "\nTest=get: received the following counters from Management 1:" pprint(counters) print "Test=get: --------------------------\n" return 0 log("Started up successfully. Entering main loop...") reference = {} while True: history.clear() for device in config['switches']: log("Polling {0} with eAPI".format(device['name'])) current = {} # Create the Server object on the first round if device.get('eapi_obj', None) is None: device['eapi_obj'] = Server(device['url']) try: current = get_device_counters(device) except EapiException: log("Connection error with eAPI. Will retry device next pass", error=True) # Remove stale data reference.pop(device['hostname'], None) continue if reference.get(device['hostname'], None) is None: # Have not contacted this device since startup or # this is the first contact. Continue to next device/itter. log("Established contact with {0}".format(device['name'])) reference[device['hostname']] = dict(current) continue get_device_status(device) changes = compare_counters(device, reference[device['hostname']], current, test=args['test']) do_actions(device, changes, int(config['counters']['poll'])) # Copy current stats-->reference to reset the "deltas" for the # next run. reference[device['hostname']] = dict(current) log("---sleeping for {0} seconds.".format(config['counters']['poll']), level='DEBUG') time.sleep(int(config['counters']['poll']))