def disable(self, user): if self.role >= ROLE_ADMIN: user.disabled = 1 db_session.merge(user) db_session.commit() return True return False
def makeApprover(self, user): if self.role >= ROLE_ADMIN: user.role = ROLE_APPROVER db_session.merge(user) db_session.commit() return True return False
def makeAdmin(self, user): if self.role >= ROLE_ADMIN: user.role = ROLE_ADMIN db_session.merge(user) db_session.commit() return True return False
def confirm(self, token): s = Serializer(current_app.config['SECRET_KEY']) try: data = s.loads(token) print "Token data = %s" % data except: traceback.print_tb(exc_traceback, limit=1, file=sys.stderr) return False if data.get('confirm') != self.id: print "ERROR: data.get confirm != self.id" return False self.confirmed = 1 db_session.merge(self) db_session.commit() db_session.flush() return True
def insert(self, date, hour, direction, address, count, percent): print "%s, %s, %s, %s, %s, %s" % (date, hour, direction, address, count, percent) self.tdstamp = "%s %s:00.00" % (date, hour) self.direction = direction self.address = ip2int(address) self.flows = count self.percentTraffic = percent try: db_session.merge(self) db_session.flush() #db_session.commit() except AttributeError: traceback.print_exc(file=sys.stderr) except: traceback.print_exc(file=sys.stderr) db_session.rollback()
def insert(self, ip, domain, rank=0): self.ip = ip self.domain = domain self.updated = datetime.utcnow() self.rank = rank try: db_session.merge(self) db_session.commit() except AttributeError: # traceback.print_exc(file=sys.stderr) pass except IntegrityError: pass except InvalidRequestError: db_session.rollback() except OperationalError: traceback.print_exc(file=sys.stderr)
def add(): # https://developer.cisco.com/site/cmx-mobility-services/learn/tutorials/node-js-listener/ # https://msesandbox.cisco.com:8081/manage/#notifications output = { 'error': True, 'error_message': 'Unknown error', 'message': None, } try: if request.json: request_json = request.json notifications = request_json["notifications"] for notification in notifications: mac_address = notification["deviceId"] notification_type = notification["notificationType"] last_seen = notification["lastSeen"] subscription_name = notification["subscriptionName"] floor_id = notification["floorId"] event_id = notification["eventId"] timestamp = notification["timestamp"] location_map_hierarchy = notification['locationMapHierarchy'] location_x = notification['locationCoordinate']['x'] location_y = notification['locationCoordinate']['y'] location_z = notification['locationCoordinate']['z'] location_unit = notification['locationCoordinate']['unit'] # Not every notification has all fields entity = get_value_or_default(notification, 'entity') band = get_value_or_default(notification, "band") ap_mac_address = get_value_or_default(notification, "apMacAddress") ssid = get_value_or_default(notification, "ssid") confidence_factor = get_value_or_default( notification, "confidence_factor") absence_duration_minutes = get_value_or_default( notification, "absenceDurationInMinutes") db_object = CMXNotification( mac_address, notification_type, subscription_name, timestamp, confidence_factor, last_seen, event_id, floor_id, band, entity, location_map_hierarchy, location_x, location_y, location_z, location_unit, ssid, ap_mac_address, absence_duration_minutes) db_session.merge(db_object) output['error'] = False output['message'] = "{} notification for {}".format( notification_type, mac_address) output['error_message'] = None else: output['error'] = True output['error_message'] = 'JSON data not provided on request' except Exception as e: db_session.rollback() print("Error handling CMX Notification!") traceback.print_exc() output['error_message'] = str(e) output['error'] = True finally: return Response(json.dumps(output), mimetype='application/json')
def update(self): db_session.merge(self) db_session.flush() db_session.commit()