def save_neighbor_data(self, neighbors_data): device_controller = DeviceController(self.db, self.logger) for neighbor in neighbors_data["neighbors"]: device = device_controller.check_device(neighbor["device_id"]) if not device: neighbors_data["neighbors"].remove(neighbor) self.db.device_neighbor.insert_one(neighbors_data)
def post(self): device = request.json app.logger.info(device) device_controller = DeviceController(mongo_db, app.logger) result = device_controller.add_single_device(device) if result: return make_response(dumps(True), 200) else: return make_response(jsonify(False), 500)
def get(self, id): device_controller = DeviceController(mongo_db, app.logger) print("Detail device") device = device_controller.get_device_detail(id) if device: return make_response(dumps(device)) else: app.logger.warning("Device not found") return make_response(dumps(False))
def get(self): tg = TopologyGeneratorAPI(mongo_db, app.logger) device_controller = DeviceController(mongo_db, app.logger) topology = tg.generate_topology(id_device=None) packet_loss = list() for edge in topology["edges"]: data = device_controller.get_packet_loss(edge["src"]["host"], edge["src"]["interface"], edge["dst"]["host"], edge["dst"]["interface"]) packet_loss.append(data) packet_loss_dict = {"data": packet_loss} return make_response(dumps(packet_loss_dict))
def post(self, id): parms = request.json if "location" in parms.keys(): device_controller = DeviceController(mongo_db, app.logger) location_id = device_controller.get_location_id(parms["location"]) parms["location_id"] = location_id del parms["location"] if "hostname" in parms.keys(): del parms["hostname"] try: mongo_db.list_devices.update_one({"_id": ObjectId(id)}, {"$set": parms}) return make_response(jsonify(True), 200) except errors.PyMongoError as e: raise
def get(self, id): device_controller = DeviceController(mongo_db, app.logger) packet_loss = device_controller.get_device_packetloss(id) return make_response(dumps(packet_loss))
def get(self, id): device_controller = DeviceController(mongo_db, app.logger) response_time = device_controller.get_device_response_time(id) return make_response(dumps(response_time))
def get(self): device_controller = DeviceController(mongo_db, app.logger) ret_dict = device_controller.device_health_summary() return make_response(dumps(ret_dict))
def get(self, id): device_controller = DeviceController(mongo_db, app.logger) device_util = device_controller.device_utilization(id) return make_response(dumps(device_util))
def post(self): parms = request.json device_controller = DeviceController(mongo_db, app.logger) interface_stat = device_controller.get_device_interface_detail(parms) return make_response(dumps(interface_stat))
def get(self): device_controller = DeviceController(mongo_db, app.logger) list_all_interface = device_controller.all_interface_util() return make_response(dumps(list_all_interface))
def get(self, group_by=None): device_controller = DeviceController(mongo_db, app.logger) get_all_device = device_controller.get_all_device(group_by=group_by) return make_response(dumps(get_all_device))
def get(self): device_controller = DeviceController(mongo_db, app.logger) device_status = device_controller.get_device_status_summary() return make_response(dumps(device_status))
def post(self): parms = request.json device_controller = DeviceController(mongo_db, app.logger) device_controller.save_device_list(parms["device_list"]) return make_response(jsonify(True), 200)
def post(self): location = request.json device_controller = DeviceController(mongo_db, app.logger) result = device_controller.add_new_location(location) return make_response(jsonify(result))