def key_filter(objects, notification=False, notifier=send_notification.send_mail): notify_list = [] watched_keys = queries.query_key_list() conn = connect.connect() cur = conn.cursor() if watched_keys: for key in watched_keys: for item_id, item in objects.iteritems(): for item_key in item['tags']: if fnmatch.fnmatch(item_key,key['key']) and fnmatch.fnmatch(item['tags'][item_key],key['value']): if item['create'] == 1: item['action'] = 1 elif item['modify'] == 1: item['action'] = 2 elif item['delete'] == 1: item['action'] = 4 inserts.insert_key_event(item, item_key, key['id']) notify_list.append([(item['timestamp'], item['changeset'], item['username'].encode('utf8'), item['action'], item_key, item['tags'][item_key])]) if notify_list and notification: send_notification.send_notification(notify_list, 'key', notifier=notifier)
def compare_stats(rdb,rname,high_prio,fpc): key = join(('fabric_drop_high:',rname,':fpc:',str(fpc)),'') previous_stat = rdb.get(key) if previous_stat: if previous_stat != high_prio: send_notification(rname) rdb.set(key,high_prio) else: rdb.set(key,high_prio)
def compare_stats(rdb, rname, high_prio, fpc): key = join(('fabric_drop_high:', rname, ':fpc:', str(fpc)), '') previous_stat = rdb.get(key) if previous_stat: if previous_stat != high_prio: send_notification(rname) rdb.set(key, high_prio) else: rdb.set(key, high_prio)
def post(self): eventid = self.request.get('eventid') event = self.load_event_with_eventid_cached(eventid) if event == None: self.http_error_message('Event id %s not found' % (eventid)) return # don't try sending notification to every owner, but one. send_notification.send_notification( '*****@*****.**', self.request.get('to'), event.owner.email(), self.request.get('mail_title'), self.request.get('mail_message'))
def post(self): eventid = self.request.get('eventid') event = self.event_cache.get_cached(eventid) if event == None: self.http_error_message('Event id %s not found' % (eventid)) return # TODO: expand owners # don't try sending notification to every owner, but one. send_notification.send_notification( self.request.get('to'), event.owner.email(), self.request.get('mail_title'), self.request.get('mail_message'))
def user_filter(changesets, notification=False, notifier=send_notification.send_mail): notify_list = [] watched_users = queries.query_user_list() conn = connect.connect() cur = conn.cursor() if watched_users: for changesetid, changeset in changesets.iteritems(): for user in watched_users: if fnmatch.fnmatch(changeset['username'].encode('utf-8'), user['username']): inserts.insert_user_event(changeset, user['id']) notify_list.append([(changeset['timestamp'], changesetid, changeset['username'].encode('utf8'), changeset['create'], changeset['modify'], changeset['delete'])] + user) if notify_list and notification: send_notification.send_notification(notify_list, 'user', notifier=notifier)
def object_filter(objects, notification=False, notifier=send_notification.send_mail): notify_list = [] watched_objects = queries.query_object_list() conn = connect.connect() cur = conn.cursor() if watched_objects: for obj in watched_objects: for item_id, item in objects.iteritems(): if item_id == obj['element']: if item['create'] == 1: item['action'] = 1 elif item['modify'] == 1: item['action'] = 2 elif item['delete'] == 1: item['action'] = 4 inserts.insert_object_event(item, obj['id']) notify_list.append({ 'timestamp': item['timestamp'], 'changesetid': item['changeset'], 'username': item['username'].encode('utf8'), 'action': item['action'], 'element': item_id, 'author': obj['author'], 'address': obj['email'], 'reason': obj['reason'] }) if notify_list and notification: send_notification.send_notification(notify_list, 'object', notifier=notifier)
def sign_up(): if request.method == 'POST': _first_name = request.form['fname'] _last_name = request.form['lname'] _email = request.form['email'] _password = request.form['psw'] _password_repeat = request.form['psw-repeat'] _gender = request.form['gender'] _dob = request.form['dob'] _address1 = request.form['address1'] _address2 = request.form['address2'] _city = request.form['city'] _state = request.form['state'] _zip = request.form['zipcode'] if _password != _password_repeat: return json.dumps( {'html': '<span>Passwords should match!!</span>'}) else: sql = "INSERT INTO patient_details (patient_id, p_f_name, p_gender, p_l_name, p_dob, p_address, p_city," \ " p_state, p_zip, p_email, p_password) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" temp_dob = _dob.replace('-', '') patient_id = str(temp_dob) + str(_zip) address = _address1 + " " + _address2 val = (patient_id, _first_name, _gender, _last_name, _dob, address, _city, _state, _zip, _email, _password) mycursor.execute(sql, val) mydb.commit() # inserting dummy glucose values in to glucose_readings tables once patient is registered g_sql = "INSERT INTO glucose_readings(glucose_value, patient_id, updated_time) VALUES(%s, %s, %s)" g_val = (0, patient_id, datetime.datetime.now()) mycursor.execute(g_sql, g_val) mydb.commit() # inserting dummy glucose values in to glucose_readings tables once patient is registered send_notification(_first_name, _email) return render_template('login.html') else: flash('Registration Unsuccessful!') print('check you input data.') return render_template('sign-up.html')
def analyze_stats(rdb, ddos_records, other_records, vips_flags, vips_pps, vips_baseline, vips_multiplier, vips_map): gevent.sleep(60) if ddos_records: rdb.publish('ddos_reports', pickle.dumps(ddos_records)) for key in vips_flags: if vips_flags[key] == 1: vips_flags[key] = 0 del ddos_records[:] if other_records: rdb.publish('internal_traffic', pickle.dumps(other_records)) del other_records[:] for key in vips_pps: if vips_pps[key] != 0: #nfmon_gauge.send('pps_'+vips_map[key].replace('.','-'),vips_pps[key]) if vips_baseline[key] != 0: # we dont care about services with pps < 10kpps if(vips_pps[key] > 60000 and vips_pps[key] > vips_baseline[key]*vips_multiplier[key]): ratio = vips_pps[key]//vips_baseline[key] vips_flags[key] = 1 send_notification(vips_map[key],ratio) vips_baseline[key] = vips_pps[key] clear_pps(vips_pps)
def object_filter(objects, notification=False, notifier=send_notification.send_mail): notify_list = [] watched_objects = queries.query_object_list() conn = connect.connect() cur = conn.cursor() if watched_objects: for obj in watched_objects: for item_id, item in objects.iteritems(): if item_id == obj['element']: if item['create'] == 1: item['action'] = 1 elif item['modify'] == 1: item['action'] = 2 elif item['delete'] == 1: item['action'] = 4 inserts.insert_object_event(item, obj['id']) notify_list.append([(item['timestamp'], item['changeset'], item['username'].encode('utf8'), item['action'], item_id)] + obj) if notify_list and notification: send_notification.send_notification(notify_list, 'object', notifier=notifier)
def send_notification(): yesterday_pls = notification.get_yesterday_pls() notification.send_notification(yesterday_pls)