Jump to: navigation, search

Difference between revisions of "Ceilometer/blueprints/alarm-api"

(Updated)
(Updated)
Line 121: Line 121:
  
 
  <nowiki>
 
  <nowiki>
class Alarm(_Base):
 
    """Representation of an alarm.
 
    """
 
  
    alarm_id = wtypes.text
+
alarm_state = wtypes.Enum(wtypes.text, 'ok', 'alarm', 'insufficient_data')
    "The UUID of the alarm"
+
 
 +
class AlarmAction(_Base):
 +
  """Action to take when alarm changes state.
 +
  """
  
    name = wtypes.text
+
  state = alarm_state
    "The name for the alarm"
+
  "The state for which the action applies."
  
    description = wtypes.text
+
  url = wtypes.text
    "The description of the alarm"
+
  "The URL to visit when the alarm state is reached"
  
    meter_name = wtypes.text
+
class ThresholdRule(_Base):
    "The name of meter"
 
  
     project_id = wtypes.text
+
     query = [Query]
     "The ID of the project or tenant that owns the alarm"
+
     "The query to find the data for computing statistics, including meter_name"
  
     user_id = wtypes.text
+
     period = int
     "The ID of the user who created the alarm"
+
     "The time range in seconds over which query"
  
 
     comparison_operator = wtypes.Enum(str, 'lt', 'le', 'eq', 'ne', 'ge', 'gt')
 
     comparison_operator = wtypes.Enum(str, 'lt', 'le', 'eq', 'ne', 'ge', 'gt')
Line 151: Line 150:
 
     statistic = wtypes.Enum(str, 'max', 'min', 'avg', 'sum', 'count')
 
     statistic = wtypes.Enum(str, 'max', 'min', 'avg', 'sum', 'count')
 
     "The statistic to compare to the threshold"
 
     "The statistic to compare to the threshold"
 +
 +
    evaluation_periods = int
 +
    "The number of historical periods to evaluate the threshold"
 +
 +
 +
class CombinationRule(_Base):
 +
 +
    operator = wtypes.Enum(str, 'or', 'and')
 +
    "How to combine the sub-alarms"
 +
 +
  alarm_ids = [wtypes.text]
 +
  "List of alarm identifiers to combine"
 +
 +
class Alarm(_Base):
 +
    """Representation of an alarm.
 +
    """
 +
 +
    alarm_id = wtypes.text
 +
    "The UUID of the alarm"
 +
 +
    name = wtypes.text
 +
    "The name for the alarm"
 +
 +
    description = wtypes.text
 +
    "The description of the alarm"
  
 
     enabled = bool
 
     enabled = bool
 
     "This alarm is enabled?"
 
     "This alarm is enabled?"
  
     evaluation_periods = int
+
     actions = [AlarmAction]
     "The number of periods to evaluate the threshold"
+
     "The actions to take when the alarm state changes"
 +
 
 +
    repeat_actions = bool
 +
    "The actions should be re-triggered on each evaluation cycle"
 +
 
 +
    threshold_rule = ThresholdRule
 +
    "If set, this alarm will be evaluated based on the threshold specification"
 +
 
 +
    combination_rule = CombinationRule
 +
    "If set, this alarm will be evaluated based on combining the settings of the specified alarms"
 +
 
  
    period = int
+
class AlarmStatus(_Base):
    "The time range in seconds over which to evaluate the threshold"
 
  
 
     timestamp = datetime.datetime
 
     timestamp = datetime.datetime
 
     "The date of the last alarm definition update"
 
     "The date of the last alarm definition update"
  
     state = wtypes.Enum(str, 'ok', 'alarm', 'insufficient data')
+
     state = alarm_states
 
     "The state offset the alarm"
 
     "The state offset the alarm"
 +
 +
    project_id = wtypes.text
 +
    "The ID of the project or tenant that owns the alarm"
 +
 +
    user_id = wtypes.text
 +
    "The ID of the user who created the alarm"
  
 
     state_timestamp = datetime.datetime
 
     state_timestamp = datetime.datetime
 
     "The date of the last alarm state changed"
 
     "The date of the last alarm state changed"
  
    ok_actions = [wtypes.text]
 
    "The actions to do when alarm state change to ok"
 
 
    alarm_actions = [wtypes.text]
 
    "The actions to do when alarm state change to alarm"
 
 
    insufficient_data_actions = [wtypes.text]
 
    "The actions to do when alarm state change to insufficient data"
 
 
    repeat_actions = bool
 
    "The actions should be re-triggered on each evaluation cycle"
 
 
    matching_metadata = {wtypes.text: wtypes.text}
 
    "The matching_metadata of the alarm"
 
 
</nowiki>
 
</nowiki>

Revision as of 13:53, 5 September 2013

Original

AlarmController

class AlarmController(rest.RestController):
    """Manages operations on a single alarm.
    """

    @wsme_pecan.wsexpose(Alarm, wtypes.text)
    def get(self):
        """Return this alarm."""

    @wsme.validate(Alarm)
    @wsme_pecan.wsexpose(Alarm, wtypes.text, body=Alarm)
    def put(self, data):
        """Modify this alarm."""

    @wsme_pecan.wsexpose(None, wtypes.text, status_code=204)
    def delete(self):
        """Delete this alarm."""

    # TODO(eglynn): add pagination marker to signature once overall
    #               API support for pagination is finalized
    @wsme_pecan.wsexpose([AlarmChange], [Query])
    def history(self, q=[]):
        """Assembles the alarm history requested.

        :param q: Filter rules for the changes to be described.
        """

AlarmsController

class AlarmsController(rest.RestController):
    """Manages operations on the alarms collection.
    """

    @wsme.validate(Alarm)
    @wsme_pecan.wsexpose(Alarm, body=Alarm, status_code=201)
    def post(self, data):
        """Create a new alarm."""

    @wsme_pecan.wsexpose([Alarm], [Query])
    def get_all(self, q=[]):
        """Return all alarms, based on the query provided.

        :param q: Filter rules for the alarms to be returned.
        """

Alarm class

class Alarm(_Base):
    """Representation of an alarm.
    """

    alarm_id = wtypes.text
    "The UUID of the alarm"

    name = wtypes.text
    "The name for the alarm"

    description = wtypes.text
    "The description of the alarm"

    meter_name = wtypes.text
    "The name of meter"

    project_id = wtypes.text
    "The ID of the project or tenant that owns the alarm"

    user_id = wtypes.text
    "The ID of the user who created the alarm"

    comparison_operator = wtypes.Enum(str, 'lt', 'le', 'eq', 'ne', 'ge', 'gt')
    "The comparison against the alarm threshold"

    threshold = float
    "The threshold of the alarm"

    statistic = wtypes.Enum(str, 'max', 'min', 'avg', 'sum', 'count')
    "The statistic to compare to the threshold"

    enabled = bool
    "This alarm is enabled?"

    evaluation_periods = int
    "The number of periods to evaluate the threshold"

    period = int
    "The time range in seconds over which to evaluate the threshold"

    timestamp = datetime.datetime
    "The date of the last alarm definition update"

    state = wtypes.Enum(str, 'ok', 'alarm', 'insufficient data')
    "The state offset the alarm"

    state_timestamp = datetime.datetime
    "The date of the last alarm state changed"

    ok_actions = [wtypes.text]
    "The actions to do when alarm state change to ok"

    alarm_actions = [wtypes.text]
    "The actions to do when alarm state change to alarm"

    insufficient_data_actions = [wtypes.text]
    "The actions to do when alarm state change to insufficient data"

    repeat_actions = bool
    "The actions should be re-triggered on each evaluation cycle"

    matching_metadata = {wtypes.text: wtypes.text}
    "The matching_metadata of the alarm"

Updated


alarm_state = wtypes.Enum(wtypes.text, 'ok', 'alarm', 'insufficient_data')

class AlarmAction(_Base):
   """Action to take when alarm changes state.
   """

  state = alarm_state
  "The state for which the action applies."

  url = wtypes.text
  "The URL to visit when the alarm state is reached"

class ThresholdRule(_Base):

    query = [Query]
    "The query to find the data for computing statistics, including meter_name"

    period = int
    "The time range in seconds over which query"

    comparison_operator = wtypes.Enum(str, 'lt', 'le', 'eq', 'ne', 'ge', 'gt')
    "The comparison against the alarm threshold"

    threshold = float
    "The threshold of the alarm"

    statistic = wtypes.Enum(str, 'max', 'min', 'avg', 'sum', 'count')
    "The statistic to compare to the threshold"

    evaluation_periods = int
    "The number of historical periods to evaluate the threshold"


class CombinationRule(_Base):

    operator = wtypes.Enum(str, 'or', 'and')
    "How to combine the sub-alarms"

   alarm_ids = [wtypes.text]
   "List of alarm identifiers to combine"

class Alarm(_Base):
    """Representation of an alarm.
    """

    alarm_id = wtypes.text
    "The UUID of the alarm"

    name = wtypes.text
    "The name for the alarm"

    description = wtypes.text
    "The description of the alarm"

    enabled = bool
    "This alarm is enabled?"

    actions = [AlarmAction]
    "The actions to take when the alarm state changes"

    repeat_actions = bool
    "The actions should be re-triggered on each evaluation cycle"

    threshold_rule = ThresholdRule
    "If set, this alarm will be evaluated based on the threshold specification"

    combination_rule = CombinationRule
    "If set, this alarm will be evaluated based on combining the settings of the specified alarms"


class AlarmStatus(_Base):

    timestamp = datetime.datetime
    "The date of the last alarm definition update"

    state = alarm_states
    "The state offset the alarm"

    project_id = wtypes.text
    "The ID of the project or tenant that owns the alarm"

    user_id = wtypes.text
    "The ID of the user who created the alarm"

    state_timestamp = datetime.datetime
    "The date of the last alarm state changed"