コード例 #1
0
 def _clone_alarm_data(self):
     # We only handle alarms with resource_id and
     # project id. Even that will work for tenant alarms without
     # resource, this may get outdated on affect_resources queries
     if not self.alarm_id:
         raise exceptions.InvalidDataException('Missing alarm_id')
     client = self._get_client()
     try:
         alarm = client.alarms.get(self.alarm_id)
     except:
         raise exceptions.NotFoundException('External alarm not found')
     self.period = alarm.rule.get('period')
     self.evaluation_period = alarm.rule.get('evaluation_period')
     self.threshold = alarm.rule.get('threshold')
     self.operator = alarm.rule.get('comparison_operator')
     self.statistic = alarm.rule.get('statistic')
     self.meter = alarm.rule.get('meter_name')
     self.query = alarm.rule.get('query') or []
     self.extra_alarm_data['project_id'] = alarm.project_id
     for x in self.query:
         if x.get('field') == 'resource_id':
             self.extra_alarm_data['resource_id'] = x.get('value')
             return
     LOG.warning(
         'missing resource_id in query, should be provided in contract')
コード例 #2
0
def alarm_track_delete(alarm_track_id):
    session = get_session()
    with session.begin():
        res = model_query(m.AlarmTrack, session=session).filter_by(id=alarm_track_id)\
                                                    .delete()
        if not res:
            raise exc.NotFoundException("alarm_track not found [alarm_track_id=%s]" %
                                        alarm_track_id)
コード例 #3
0
def sla_contract_delete(sla_contract_id):
    session = get_session()
    with session.begin():
        res = model_query(m.SLAContract, session=session).\
            filter_by(id=sla_contract_id).delete()
        if not res:
            raise exc.NotFoundException("SLA Contract not found "
                                        "[contract_id=%s]" % sla_contract_id)
コード例 #4
0
def action_delete(action_id):
    session = get_session()
    with session.begin():
        res = model_query(m.Action, session=session).filter_by(id=action_id)\
                                                    .delete()
        if not res:
            raise exc.NotFoundException("Action not found [action_id=%s]" %
                                        action_id)
コード例 #5
0
def sla_contract_update(sla_contract_id, values):
    session = get_session()
    with session.begin():
        sla_contract = sla_contract_get_by_id(sla_contract_id)
        if not sla_contract:
            raise exc.NotFoundException('SLA contract not found')

        sla_contract.update(values.copy())
        sla_contract.save(session=session)
        return sla_contract
コード例 #6
0
def alarm_track_update(alarm_track_id, values):
    session = get_session()
    with session.begin():
        alarm_track = _alarm_track_get(alarm_track_id)
        if not alarm_track:
            raise exc.NotFoundException("alarm_track not found [alarm_track_id=%s]" %
                                        alarm_track_id)

        alarm_track.update(values.copy())
        alarm_track.save(session)
        return alarm_track
コード例 #7
0
def action_update(action_id, values):
    session = get_session()
    with session.begin():
        action = _action_get(action_id)
        if not action:
            raise exc.NotFoundException("action not found [action_id=%s]" %
                                        action_id)

        action.update(values.copy())
        action.save(session)
        return action
コード例 #8
0
def _alarm_track_get(alarm_track_id, multiple_records=False):
    query = model_query(m.AlarmTrack)
    obj = query.filter((m.AlarmTrack.id==alarm_track_id)|
                       (m.AlarmTrack.alarm_id==alarm_track_id))
    if multiple_records:
        obj = obj.all()
    else:
        obj = obj.first()

    if not obj:
        raise exc.NotFoundException()
    return obj
コード例 #9
0
def alarm_track_get_by_filter(filters):
    """
    :param updated_time_gt: if set, will do updated_at > updated_time_gt
    """
    query = model_query(m.AlarmTrack)
    query = query.filter_by(**filters)
    result = query.first()
    if not result:
        raise exc.NotFoundException("alarm_track not found [filters=%s]" %
                                     filters)

    return result
コード例 #10
0
def action_get_by_filter(filters, updated_time_gt=None, order='-created_at'):
    """
    :param updated_time_gt: if set, will do updated_at > updated_time_gt
    """
    query = model_query(m.Action)
    ignore_status = filters.pop('ignore_status', None)
    query = query.filter_by(**filters)
    if updated_time_gt:
        query = query.filter((m.Action.updated_at >= updated_time_gt) |
                             (m.Action.create_at >= updated_time_gt))
    if ignore_status:
        query = query.filter(m.Action.status != ignore_status)
    result = query.order_by(get_order(order)).first()
    if not result:
        raise exc.NotFoundException("action not found [filters=%s]" %
                                     filters)

    return result
コード例 #11
0
    def alert(self,
              ctx,
              alarm_id,
              source=None,
              contract_id=None,
              resource_id=None,
              project_id=None):
        if contract_id:
            alarm = alarm_manager.get_by_contract_id(ctx, contract_id)
            contract_ids = [contract_id]
        else:
            alarm = alarm_manager.get_by_id(ctx, alarm_id)
            contract_ids = AlarmTrack.get_contracts_by_alarm_id(alarm_id)

        contracts = []
        for x in contract_ids:
            try:
                contracts.append(sla_contract.get_by_contract_id(x))
            except exc.NotFoundException:
                pass
        if not contracts:
            raise exc.NotFoundException('No contracts or alarms found')

        if alarm.type == SLA_TYPES['HOST_DOWN']['alarm']:
            return self._process_host_down_alarm(ctx,
                                                 alarm,
                                                 contracts,
                                                 source,
                                                 resource_id=resource_id)
        elif alarm.type == SLA_TYPES['VM_ERROR']['alarm']:
            return self._process_vm_error_alarm(ctx,
                                                alarm,
                                                contracts,
                                                source,
                                                resource_id=resource_id)
        else:
            return self._process_resource_alarm(ctx,
                                                alarm,
                                                contracts,
                                                source,
                                                resource_id=resource_id,
                                                project_id=project_id)
コード例 #12
0
def alarms_by_contract_resource_project(meter, project=None, resource=None):
    """ Retrieve ordered by priority.
        The first one should be triggered. because is the best match.
    """
    contract_q = model_query(m.SLAContract).\
                            filter( or_((m.SLAContract.project_id == project) &
                                    (m.SLAContract.resource_id == resource)) |
                                    or_((m.SLAContract.resource_id == None) &
                                    (m.SLAContract.project_id == project)) |
                                    or_((m.SLAContract.project_id == None) &
                                        (m.SLAContract.resource_id == None))). \
                            subquery()

    query = model_query(m.AlarmTrack)
    query = query.filter(m.AlarmTrack.meter==meter)

    obj = query.join(contract_q, m.AlarmTrack.contract_id==contract_q.c.id)
    obj = obj.order_by(desc(contract_q.c.resource_id))
    obj = obj.order_by(desc(contract_q.c.project_id)).all()
    
    
    if not obj:
        raise exc.NotFoundException()
    return obj
コード例 #13
0
def _alarm_tracks_get_all(filters, order='-created_at'):
    query = model_query(m.AlarmTrack)
    res = query.filter_by(**filters).order_by(get_order(order)).all()
    if not res:
        raise exc.NotFoundException('alarms not found for filters')
    return res
コード例 #14
0
def sla_contract_get_by_id(sla_contract_id):
    query = model_query(m.SLAContract)
    obj = query.filter_by(id=sla_contract_id).first()
    if not obj:
        raise exc.NotFoundException('SLA Contract not found')
    return obj
コード例 #15
0
def _action_get(action_id):
    query = model_query(m.Action)
    obj = query.filter(m.Action.id==action_id).first()
    if not obj:
        raise exc.NotFoundException()
    return obj
コード例 #16
0
 def get_plugin(self, name):
     try:
         return self.mgr[name].plugin
     except Exception:
         raise exceptions.NotFoundException('Plugin %s not found' % name)