예제 #1
0
    def get(self):
        sites = SiteMonitor.getAll()
        log = []
        for site in sites:
            if site.flagAtivo:
                result = self.checaSite(site.link, site.textCheck)
                
                lastStatus = Log.getLastLogSite(site.key())
                nowStatus = result.get('status',False)
                
                if nowStatus != lastStatus:
                    self.sendMail(site.link, site.name, result.get('status',False))
#                elif not nowStatus:
#                    self.sendMail(site.link, site.name, result.get('status',False))
                    
                log.append(result)
                
                save = Log(site_monitor = site.key(),
                           date_creation = datetime.now(),
                           status = result.get('status',False),
                           time_access = result.get('time_access'),
                           speed_access = result.get('speed_access'))
                save.put()
                
        return Response(log)
예제 #2
0
def create_appointment(date, time, email):
    try:
        session = Session()

        if not check_is_past_time(date, time):
            raise DWDCantCreateAppointmentBeforeException(
                CANT_CREATE_APPOINTMENT_BEFORE_MESSAGE.format(
                    date=date.strftime(DATE_FORMAT),
                    time=time,
                    email=email,
                ))

        previous_appointment = session.query(Appointment).filter(
            and_(
                Appointment.date == date,
                Appointment.time == time,
                Appointment.is_deleted == False,
            )).one_or_none()

        if previous_appointment is not None:
            raise DWDDuplicateAppointmentException(
                DUPLICATE_APPOINTMENT_MESSAGE.format(
                    appointment=previous_appointment, ))

        now = datetime.now()

        action = session.query(Action).filter(Action.name == CREATE).one()

        appointment = Appointment(date, time, email)

        log = Log(now, appointment, action, None, None, None, date, time,
                  email)

        session.add(appointment)
        session.add(log)

        session.commit()

    except DanceWithDeathException as dwde:
        raise dwde

    except Exception as e:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
        message = '    '.join(line for line in lines)
        _log.error(message)
        raise DWDCantCreateAppointmentException(
            CANT_CREATE_APPOINTMENT_MESSAGE.format(
                date=date.strftime(DATE_FORMAT),
                time=time,
                email=email,
            ))

    finally:
        session.close()

    return get_times(date), date.strftime(DATE_FORMAT)
예제 #3
0
def index():
    from db.models import File, Log
    ext_counts = File.get_extension_counts()
    latest_logs = Log.get_latest_logs()

    return render_template('index.html',
                           counts=ext_counts,
                           logs=latest_logs,
                           name=index)
예제 #4
0
def get_times(date):
    time_dict = {
        tm: {
            ENABLED:
            check_is_past_time(date, tm) if check_date_range(date) else False,
            APPOINTMENT: None
        }
        for tm in range(MIN_TIME, MAX_TIME + 1)
    }

    session = Session()
    now = datetime.now()

    try:
        action = session.query(Action).filter(Action.name == LIST).one()

        appointments = session.query(Appointment).filter(
            and_(
                Appointment.date == date,
                Appointment.is_deleted == False,
            )).all()

        for appointment in appointments:
            time_dict[appointment.time][APPOINTMENT] = {
                ID: appointment.id,
                DATE: appointment.date.strftime(DATE_FORMAT),
                TIME: appointment.time,
                EMAIL: appointment.email,
            }

        log = Log(now, None, action, None, None, None, date, None, None)

        session.add(log)

        session.commit()

    except pymysqlOperationalError as poe:
        raise DWDBrokenPipeError(BROKEN_PIPE_ERROR_MESSAGE)
    except sqlalchemyOperationalError as soe:
        raise DWDBrokenPipeError(BROKEN_PIPE_ERROR_MESSAGE)
    except Exception as e:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
        message = '    '.join(line for line in lines)
        _log.error(message)
        raise DWDCantListAppointmentsException(
            CANT_LIST_APPOINTMENTS_MESSAGE.format(
                date=date.strftime(DATE_FORMAT), ))

    finally:
        session.close()

    return time_dict
예제 #5
0
    def add_log(self, record):
        record_list = record.split()
        log = Log(
            ip=record_list[0],
            date=record_list[3][1:],
            request_type=record_list[5][1:],
            url=record_list[6],
            status_code=record_list[8],
            size=int(record_list[9])
        )

        self.connection.session.add(log)

        return log
예제 #6
0
def log_full_view(page):
    if page:
        from db.models import Log
        offset_logs = Log.get_logs_by_offset(offset=int(page)*30, limit=30)
        log_count = Log.query.count()
        more_results = False

        if offset_logs.count() >= 30:
            more_results = True

        return render_template('logs.html',
                               logs=offset_logs,
                               log_count = log_count,
                               next_page=int(page) + 1,
                               more_results=more_results,
                               name=log_full_view)
    else:
        pass
예제 #7
0
def delete_appointment(id):
    try:
        session = Session()
        now = datetime.now()

        action = session.query(Action).filter(Action.name == DELETE).one()

        appointment = session.query(Appointment).filter(
            Appointment.id == id).one()

        date = appointment.date
        time = appointment.time

        if not check_is_past_time(date, time):
            raise DWDCantDeleteAppointmentBeforeException(
                CANT_DELETE_APPOINTMENT_BEFORE_MESSAGE.format(
                    appointment=appointment, ))

        log = Log(now, appointment, action, appointment.date, appointment.time,
                  appointment.email)

        appointment.is_deleted = True

        session.add(log)

        session.commit()

    except DanceWithDeathException as dwde:
        raise dwde

    except Exception as e:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
        message = '    '.join(line for line in lines)
        _log.error(message)

        raise DWDCantDeleteAppointmentException(
            CANT_DELETE_APPOINTMENT_MESSAGE.format(id=id, ))

    finally:
        session.close()

    return get_times(date), date.strftime(DATE_FORMAT)
예제 #8
0
def update_appointment(id, new_date, new_time, new_email):
    try:
        session = Session()
        now = datetime.now()

        action = session.query(Action).filter(Action.name == UPDATE).one()

        appointment = session.query(Appointment).filter(
            Appointment.id == id).one()

        old_date = appointment.date
        old_time = appointment.time
        old_email = appointment.email

        if not check_is_past_time(old_date, old_time):
            raise DWDCantUpdateAppointmentBeforeException(
                CANT_UPDATE_APPOINTMENT_BEFORE_MESSAGE.format(
                    appointment=appointment, ))

        if new_date is None:
            new_date = old_date

        if new_time is None:
            new_time = old_time

        if new_email is None:
            new_email = old_email

        previous_appointment = session.query(Appointment).filter(
            and_(
                Appointment.date == new_date,
                Appointment.time == new_time,
                Appointment.is_deleted == False,
            )).one_or_none()

        if previous_appointment is not None and previous_appointment != appointment:
            raise DWDDuplicateAppointmentException(
                DUPLICATE_APPOINTMENT_MESSAGE.format(
                    appointment=previous_appointment, ))

        log = Log(now, appointment, action, old_date, old_time, old_email,
                  new_date, new_time, new_email)

        appointment.date = new_date
        appointment.time = new_time
        appointment.email = new_email

        session.add(log)

        session.commit()

    except DanceWithDeathException as dwde:
        raise dwde

    except Exception as e:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
        message = '    '.join(line for line in lines)
        _log.error(message)

        raise DWDCantUpdateAppointmentException(
            CANT_UPDATE_APPOINTMENT_MESSAGE.format(
                id=id,
                date=new_date.strftime(DATE_FORMAT),
                time=time,
                email=email,
            ))

    finally:
        session.close()

    return get_times(new_date), new_date.strftime(DATE_FORMAT)
예제 #9
0
    def get(self): 
        param = self.request.args 
        
        if param.has_key('site') and\
           param.has_key('start_date') and param.has_key('end_date'):
            
            site = param.get('site')
            start_date = param.get('start_date').split('/')
            end_date = param.get('end_date').split('/')
            
            result = Log.getLogGrafic(site,date(int(start_date[2]),int(start_date[1]),int(start_date[0])),
                                           date(int(end_date[2]),int(end_date[1]),int(end_date[0])+1)
                                     )
                
            L_time_access = []
            L_speed_access = []
            status_OK = 0
            status_Failed = 0
            
            for item in result:
                S = {}
                T = {}
                T['axisX'] = S['axisX'] = item.date_creation.strftime('%d-%m %H:%M')
                
                T['axisY'] = item.time_access
                S['axisY'] = item.speed_access
                
                L_speed_access.append(S)
                L_time_access.append(T)
                
                if item.status:
                    status_OK += 1
                else:
                    status_Failed += 1 
            
            
            L_status = [{'axisX':'OK',
                         'axisY':status_OK},
                        {'axisX':'Down',
                         'axisY':status_Failed}]
            
            if len(L_time_access) > 20:
                L_time_access = self.GeraMedia(L_time_access)
                
            if len(L_speed_access) > 20:
                L_speed_access = self.GeraMedia(L_speed_access)
                
            self.context['resultSite'] = [{'id':'time_access',
                                           'name':"Tempo de Acesso",
                                           'nameX':"Periodo (dias)",
                                           'nameY':'Tempo (seg)',
                                           'type':'line',
                                           'data':L_time_access},
                                          {'id':'speed_access',
                                           'name':'Velocidade de acesso',
                                           'nameX':"Periodo (dias)",
                                           'nameY':'Velocidade (KB/s)',
                                           'type':'line',
                                           'data':L_speed_access},
                                          {'id':'status',
                                           'name':'Historico de Status',
                                           'nameX':"Status",
                                           'nameY':'Quantidate',
                                           'type':'bar',
                                           'data':L_status}
                                          ]
        
        else:
             self.context['resultSite'] = []

        return self.render_response('ajaxgraphic.html', **self.context)
예제 #10
0
def purge_log():
    from db.models import File, Log
    Log.pruneLogs()