コード例 #1
0
ファイル: __init__.py プロジェクト: bkupidura/meact
  def _check_status(self, sensor_check_status):
    check_status_result = True
    for check_status in sensor_check_status:
      _, check_status_result = utils.treshold_helper(check_status['threshold'],
              self.status.get(check_status['name']))
      if not check_status_result:
        break

    return check_status_result
コード例 #2
0
ファイル: __init__.py プロジェクト: bkupidura/meact
  def _action_helper(self, sensor_data, sensor_config, action_config=None):

    LOG.debug("Action helper '%s' '%s'", sensor_data, sensor_config['actions'])
    for sensor_action in sensor_config['actions']:

      #Check if config is for given board
      if not sensor_action.action_for_board(sensor_data['board_id']):
        continue

      #Check threshold function
      sensor_data['sensor_data'], threshold_result = utils.treshold_helper(sensor_action['threshold'],
              sensor_data['sensor_data'])

      if not threshold_result:
        continue

      #Format message
      try:
        sensor_data['message'] = sensor_action['message_template'].format(**sensor_data)
      except (KeyError, ValueError) as e:
        LOG.error("Fail to format message '%s' with data '%s'", sensor_action['message_template'], sensor_data)
        continue

      #Check status threshold function
      if not self._check_status(sensor_action['check_status']):
        continue

      #Check metrics threshold function
      if not self._check_metric(sensor_action['check_metric'], sensor_data):
        continue

      #Check last action time
      if not self._check_action_interval(sensor_data, sensor_action['id'],
              sensor_action['action_interval']):
        continue

      LOG.info("Action execute for data '%s'", sensor_data)
      if self._action_execute(sensor_data,
              sensor_action['action'],
              action_config,
              sensor_action['action_config']):
        try:
          database.insert_action(self.db, sensor_data['board_id'],
                  sensor_data['sensor_type'], sensor_action['id'])
        except OperationalError as e:
          LOG.error("Fail to save action '%s'", e)
コード例 #3
0
ファイル: __init__.py プロジェクト: bkupidura/meact
  def _check_metric(self, sensor_check_metric, sensor_data):
    check_metric_result = True
    for check_metric in sensor_check_metric:
      board_ids = check_metric.get('board_ids', [])
      board_ids = map(lambda x: x.format(**sensor_data), board_ids)

      try:
        metrics = self._get_value_count(check_metric['value_count'],
                board_ids,
	        check_metric.get('sensor_type'),
	        check_metric.get('start_offset'),
	        check_metric.get('end_offset'))
      except OperationalError as e:
        LOG.error("Fail to get metrics '%s'", e)
        check_metric_result = False
        break

      _, check_metric_result = utils.treshold_helper(check_metric['threshold'],
              metrics)

      if not check_metric_result:
        break

    return check_metric_result