def post(self): payload = json.loads(self.request.body) org = Organization.get_by_id(int(payload['organization'])) inv = Invitation(parent=org) inv.email = payload['email'] inv.put() inv.send()
def put(self): payload = json.loads(self.request.body) id = int(self.request.url.rsplit('/', 1)[1]) org = Organization.get_by_id(id) org.title = str(payload['title']) org.alert_email = str(payload['alert_email']) org.put()
def get(self): id = int(self.request.url.rsplit('/', 3)[1]) org = Organization.get_by_id(id) key = self.request.url.rsplit('/', 1)[1] heart = Heart.get_by_key_name(key, parent=org) flatlines = Flatline.all().ancestor(heart).order("-start").fetch(10) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps({'title': heart.title or heart.key().id_or_name(), 'time_zone': heart.time_zone, 'cron': heart.cron, 'threshold': heart.threshold, 'last_pulse': str(heart.last_pulse), 'flatlines': map(lambda f: {'start': str(f.start), 'end': str(f.end), 'active': str(f.active)}, flatlines)}))
def delete(self): id = int(self.request.url.rsplit('/', 3)[1]) org = Organization.get_by_id(id) key = self.request.url.rsplit('/', 1)[1] heart = Heart.get_by_key_name(key, parent=org) flatlines = Flatline.all(keys_only=True).ancestor(heart).order("-start") heart.delete() for f in flatlines: db.delete(f)
def get(self): id = int(self.request.url.rsplit('/', 2)[1]) org = Organization.get_by_id(id) hearts = Heart.all().ancestor(org.key()).order("-created").fetch(2000) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps({ 'title': org.title, 'hearts': map(indextransform, hearts) }))
def get(self): id = int(self.request.url.rsplit('/', 1)[1]) org = Organization.get_by_id(id) newhearts = Heart.all().ancestor(org.key()).filter('title =', '').fetch(2000) flatlines = Flatline.all().filter("active =", True).fetch(2000) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps({ 'newhearts': map(indextransform, newhearts), 'flatlines': map(flatlinetransform, flatlines), }))
def get(self): id = int(self.request.url.rsplit('/', 2)[1]) org = Organization.get_by_id(id) hearts = Heart.all().ancestor(org.key()).order("-created").fetch(2000) # Activate hearts before deactivated onces hearts.sort( cmp=lambda x,y: -1 if x.threshold > 0 else 1 ) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps({ 'organization': indextransform( org ), 'hearts': map(heartlisttransform, hearts) }))
def get(self): id = self.request.get_all('id')[0] org = int(self.request.get_all('org')[0]) if id.find('\\') > 0: self.response.write('key must not contain backslash') return h = Organization.get_by_id(org).get_heart(id) h.registerPulse() self.response.write('ok')
def get(self): id = self.request.get_all('id')[0] org = int(self.request.get_all('org')[0]) if id.find('\\') > 0: self.response.write('key must not contain backslash') return h = Organization.get_by_id(org).get_heart(id) h.register_pulse() self.response.write('ok')
def put(self): payload = json.loads(self.request.body) id = int(self.request.url.rsplit('/', 3)[1]) org = Organization.get_by_id(id) key = self.request.url.rsplit('/', 1)[1] heart = Heart.get_by_key_name(key, parent=org) heart.title = str(payload['title']) heart.threshold = int(payload['threshold']) heart.cron = str(payload['cron']) heart.time_zone = str(payload['time_zone']) croniter(heart.cron) heart.put()
def get(self): id = int(self.request.url.rsplit('/', 1)[1]) org = Organization.get_by_id(id) newhearts = Heart.all().ancestor(org.key()).filter('title =', '').fetch(2000) flatlines = Flatline.all().filter("active =", True).fetch(2000) self.response.headers['Content-Type'] = 'application/json' self.response.out.write( json.dumps({ 'newhearts': map(indextransform, newhearts), 'flatlines': map(flatlinetransform, flatlines), }))
def post(self): id = self.request.get_all('id')[0] org = int(self.request.get_all('org')[0]) if id.find('\\') > 0: self.response.write('key must not contain backslash') return pulse_time = datetime.datetime.strptime(self.request.get('pulse_time'),"%Y-%m-%d %H:%M:%S.%f") h = Organization.get_by_id(org).get_heart(id) h.register_pulse(pulse_time) self.response.write('ok')
def put(self): payload = json.loads(self.request.body) id = int(self.request.url.rsplit('/', 3)[1]) org = Organization.get_by_id(id) key = self.request.url.rsplit('/', 1)[1] heart = Heart.get_by_key_name(key, parent=org) heart.title = str(payload['title']) heart.check_deactivation(int(payload['threshold'])) heart.threshold = int(payload['threshold']) heart.maintenance_day = datetime.strptime(payload['maintenance_day'], '%Y-%m-%d').date() if len( payload['maintenance_day'] ) > 0 else None heart.cron = str(payload['cron']) heart.time_zone = str(payload['time_zone']) croniter(heart.cron) heart.check_maintenance() heart.put()
def get(self): id = int(self.request.url.rsplit('/', 2)[1]) org = Organization.get_by_id(id) rangestart = datetime.utcnow() - timedelta(days=7) hearts = Heart.all().ancestor(org.key()).filter('title !=', '').count() oldflatlines = Flatline.all().filter("start >", rangestart).order("-start").fetch(2000) oldflatlinesactive = Flatline.all().filter("end >", rangestart).order("-end").fetch(2000) oldflatlines = list(set(oldflatlines) | set(oldflatlinesactive)) alltime = hearts*24*60*60*7 if hearts > 0 else 1 downtime = sum(map(lambda x: x.seconds, map(lambda x: (x.end if x.end is not None else datetime.utcnow()) - (x.start if x.start < rangestart else rangestart),oldflatlines))) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps({ 'organization': indextransform( org ), 'flatlines': map(flatlinetransform, oldflatlines), 'availablility' : 1 - float(downtime)/alltime, 'downtime' : downtime, 'hearts': hearts }))
def get(self): org_id = self.request.url.rsplit('/', 1)[1] if not org_id.isdigit(): self.abort(404) org = Organization.get_by_id(int(org_id)) if org is None: self.abort(404) newhearts = Heart.all().ancestor(org.key()).filter('title =', '').fetch(2000) maintenancehearts = Heart.all().ancestor(org.key()).filter('maintenance_day !=', None).order('-maintenance_day').fetch(2000) flatlines = Flatline.all().filter("active =", True).fetch(2000) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps({ 'title': org.title, 'newhearts': map(indextransform, newhearts), 'flatlines': map(flatlinetransform, flatlines), 'maintenancehearts': map(heartlisttransform, maintenancehearts), 'users': org.users, 'alert_email' : org.alert_email, }))
def get(self): id = int(self.request.url.rsplit('/', 3)[1]) org = Organization.get_by_id(id) key = self.request.url.rsplit('/', 1)[1] heart = Heart.get_by_key_name(key, parent=org) flatlines = Flatline.all().ancestor(heart).order("-active").order("-start").order("-end").fetch(10) response = {'organization': indextransform(org), 'title': heart.title or heart.key().id_or_name(), 'time_zone': heart.time_zone, 'cron': heart.cron, 'threshold': heart.threshold, 'last_pulse': str(heart.last_pulse or ''), 'maintenance_day': str(heart.maintenance_day or ''), 'flatlines': map(flatlinetransform, flatlines), 'calculated_flatline': str(heart.calculate_next_flatline() or '') } self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(response))