Exemplo n.º 1
0
def get_report_data(start, until):
    events = backend.get_outage_events()
    # see report.tpl for definitions
    # this simple model ignores overlapping outages!
    tttf = 0
    tttd = 0
    tttr = 0
    age = 0  # time spent since start
    last_failure = start
    reportpoints = []
    # TODO there's some assumptions on tag order and such. if your events are
    # badly tagged, things could go wrong.
    # TODO honor start/until
    origin_event = Event(start, "start", [])
    reportpoints.append(
        Reportpoint(origin_event, 0, 100, 0, tttf, 0, tttd, 0, tttr))
    outages_seen = {}
    for event in events:
        if event.timestamp > until:
            break
        age = float(event.timestamp - start)
        ttd = 0
        ttr = 0
        if 'start' in event.tags:
            outages_seen[event.outage] = {'start': event.timestamp}
            ttf = event.timestamp - last_failure
            tttf += ttf
            last_failure = event.timestamp
        elif 'detected' in event.tags:
            ttd = event.timestamp - outages_seen[event.outage]['start']
            tttd += ttd
            outages_seen[event.outage]['ttd'] = ttd
        elif 'resolved' in event.tags:
            ttd = outages_seen[event.outage]['ttd']
            ttr = event.timestamp - outages_seen[event.outage]['start']
            tttr += ttr
            outages_seen[event.outage]['ttr'] = ttr
        else:
            # the outage changed impact. for now just ignore this, cause we
            # don't do anything with impact yet.
            pass
        muptime = float(age - tttr) * 100 / age
        reportpoints.append(
            Reportpoint(event, len(outages_seen), muptime, ttf, tttf, ttd,
                        tttd, ttr, tttr))

    age = until - start
    end_event = Event(until, "end", [])
    muptime = float(age - tttr) * 100 / age
    reportpoints.append(
        Reportpoint(end_event, len(outages_seen), muptime, 0, tttf, 0, tttd, 0,
                    tttr))
    return reportpoints
Exemplo n.º 2
0
def events_add_script():
    try:
        event = Event(timestamp=int(request.forms.event_timestamp),
                      desc=request.forms.event_desc,
                      tags=request.forms.event_tags.split())
    except Exception, e:
        response.status = 400
        return 'Could not create new event: %s' % e
Exemplo n.º 3
0
def add_post_handler_default(request, config):
    (ts, desc, tags) = add_post_validate_and_parse_base_attributes(request)
    extra_attributes = add_post_validate_and_parse_extra_attributes(request, config)
    unknown_attributes = add_post_validate_and_parse_unknown_attributes(request, config)
    extra_attributes.update(unknown_attributes)

    event = Event(timestamp=ts, desc=desc, tags=tags, extra_attributes=extra_attributes)
    return event
Exemplo n.º 4
0
def events_edit_post(event_id):
    try:
        # TODO: do the same validation here as in add
        ts = local_datepick_to_unix_timestamp(request.forms.event_datetime)
        # (select2 tags form field uses comma)
        tags = request.forms.event_tags.split(',')
        event = Event(timestamp=ts, desc=request.forms.event_desc, tags=tags, event_id=event_id)
    except Exception, e:
        return render_last_page(['/events/edit/'], errors=[('Could not recreate event from received information. Go back to previous page to retry', e)])
Exemplo n.º 5
0
def create_event():
    """
    Adds a event according to the entered info.
    """
    post_body = json.loads(request.data)
    event = Event(
        name=post_body.get('name', ''),
        date=post_body.get('date', ''),
        time=post_body.get('time', ''),
        tags=post_body.get('tags', ''),
        description=post_body.get('description', 'Not Specified'),
        organizerName=post_body.get('organizerName', 'Not Specified'),
        organizerContact=post_body.get('organizerContact', 'Not Specified'),
        dorm_id=post_body.get('dorm_id'),
    )
    db.session.add(event)
    db.session.commit()
    return json.dumps({'success': True, 'data': event.serialize()}), 201
Exemplo n.º 6
0
        if not log_user:
          message = 'User does not exist'
          logging.warn(message)
          return error_response(404, message)
        if not log_user.user_can_update(auth_user):
          message = 'Forbidden'
          logging.warn(message)
          return error_response(403, message)

    events_json = data['events']

    new_points = 0
    events = []
    for event_json in events_json:
      try:
        Event.validate(event_json)
        # make sure item id is valid bson object id.
        event_json['itemId'] = ObjectId(event_json['itemId'])
        # make sure timestamp is valid time
        event_json['timestamp'] = datetime.fromtimestamp(event_json['timestamp'])
        event = Event(event_json)
        event.set_user(log_user)
        event.save()
        events.append(event)
      except ValidationError, e:
        logging.warn(e)
        return error_response(400, e.error)

    for event in events:
      if event.outcome is True:
        new_points = new_points + 10