def query(q_string): ''' Query the db with the given string and return with an array of alert objects. ''' try: _db = mysql.Database() _db._cursor.execute('''%s''' % (q_string)) logging.debug("Running mysql query: %s" % q_string) temp = _db._cursor.fetchall() alerts = [] for t in temp: t = mysql.alerts_convert_to_dict(t) a = Alert(t['id']) alerts.append(a) return alerts except Exception, e: logging.error(e.__str__())
def query(q_string): ''' Query the db with the given string and return with an array of alert objects. ''' try: _db = mysql.Database() _db._cursor.execute( '''%s''' % (q_string)) logging.debug("Running mysql query: %s" % q_string) temp = _db._cursor.fetchall() alerts = [] for t in temp: t = mysql.alerts_convert_to_dict(t) a = Alert(t['id']) alerts.append(a) return alerts except Exception, e: logging.error(e.__str__())
def load_alert(self, id): ''' Load an alert with a specific id. ''' logging.debug("Loading alert: %s" % id) try: self.db._cursor.execute( '''SELECT * FROM alerts WHERE id = %s LIMIT 1''', id) alert = self.db._cursor.fetchone() alert = mysql.alerts_convert_to_dict(alert) self.subject = alert['subject'] self.message = alert['message'] self.team = alert['team'] self.ack = alert['ack'] self.ackby = alert['ackby'] self.acktime = alert['acktime'] self.lastAlertSent = alert['lastAlertSent'] self.tries = alert['tries'] self.createDate = alert['createDate'] self.id = alert['id'] except Exception, e: print "error, loading alert" print e self.id = 0