当前位置: 首页>>代码示例>>Python>>正文


Python helpers.create_alarm_definition函数代码示例

本文整理汇总了Python中monasca_tempest_tests.tests.api.helpers.create_alarm_definition函数的典型用法代码示例。如果您正苦于以下问题:Python create_alarm_definition函数的具体用法?Python create_alarm_definition怎么用?Python create_alarm_definition使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了create_alarm_definition函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_list_alarm_definitions_with_severity

    def test_list_alarm_definitions_with_severity(self):
        name = data_utils.rand_name('alarm_definition')
        expression = 'avg(cpu_utilization) >= 1000'
        alarm_definition = helpers.create_alarm_definition(
            name=name,
            description="description",
            expression=expression,
            severity="LOW")
        resp, res_body_create_alarm_def = self.monasca_client.\
            create_alarm_definitions(alarm_definition)
        self.assertEqual(201, resp.status)

        name = data_utils.rand_name('alarm_definition')
        expression = 'avg(cpu_utilization) >= 1000'
        alarm_definition = helpers.create_alarm_definition(
            name=name,
            description="description",
            expression=expression,
            severity="MEDIUM")
        resp, res_body_create_alarm_def = self.monasca_client.\
            create_alarm_definitions(alarm_definition)
        self.assertEqual(201, resp.status)

        query_param = '?severity=MEDIUM'
        resp, response_body = self.monasca_client.\
            list_alarm_definitions(query_param)
        self._verify_list_alarm_definitions_response_body(resp, response_body)
        elements = response_body['elements']
        self._verify_list_get_alarm_definitions_elements(
            elements, 1, res_body_create_alarm_def)
        links = response_body['links']
        self._verify_list_alarm_definitions_links(links)
开发者ID:Missxiaoguo,项目名称:monasca-api,代码行数:32,代码来源:test_alarm_definitions.py

示例2: test_list_alarms_by_severity

    def test_list_alarms_by_severity(self):
        metric_name = data_utils.rand_name("severity-metric")
        alarm_defs = []
        alarm_defs.append(helpers.create_alarm_definition(
            name=data_utils.rand_name("alarm-severity"),
            expression=metric_name + " > 12",
            severity='LOW'
        ))
        alarm_defs.append(helpers.create_alarm_definition(
            name=data_utils.rand_name("alarm-severity"),
            expression=metric_name + " > 12",
            severity='MEDIUM'
        ))
        alarm_defs.append(helpers.create_alarm_definition(
            name=data_utils.rand_name("alarm-severity"),
            expression=metric_name + " > 12",
            severity='HIGH'
        ))
        alarm_defs.append(helpers.create_alarm_definition(
            name=data_utils.rand_name("alarm-severity"),
            expression=metric_name + " > 12",
            severity='CRITICAL'
        ))

        alarm_def_ids = []
        for definition in alarm_defs:
            resp, response_body = self.monasca_client.create_alarm_definitions(definition)
            self.assertEqual(201, resp.status)
            alarm_def_ids.append(response_body['id'])

        metric = helpers.create_metric(name=metric_name,
                                       value=14)
        resp, response_body = self.monasca_client.create_metrics(metric)
        self.assertEqual(204, resp.status)
        for def_id in alarm_def_ids:
            self._wait_for_alarms(1, def_id)

        query_parms = '?severity=LOW'
        resp, response_body = self.monasca_client.list_alarms(query_parms)
        self.assertEqual(200, resp.status)
        for alarm in response_body['elements']:
            self.assertEqual('LOW', alarm['alarm_definition']['severity'])

        query_parms = '?severity=HIGH'
        resp, response_body = self.monasca_client.list_alarms(query_parms)
        self.assertEqual(200, resp.status)
        for alarm in response_body['elements']:
            self.assertEqual('HIGH', alarm['alarm_definition']['severity'])

        query_parms = '?severity=CRITICAL'
        resp, response_body = self.monasca_client.list_alarms(query_parms)
        self.assertEqual(200, resp.status)
        for alarm in response_body['elements']:
            self.assertEqual('CRITICAL', alarm['alarm_definition']['severity'])
开发者ID:Missxiaoguo,项目名称:monasca-api,代码行数:54,代码来源:test_alarms.py

示例3: resource_setup

    def resource_setup(cls):
        super(TestAlarmsStateHistory, cls).resource_setup()

        start_timestamp = int(time.time() * 1000)
        end_timestamp = int(time.time() * 1000) + 1000

        # create an alarm definition
        expression = "avg(name-1) > 0"
        name = data_utils.rand_name('alarm_definition')
        alarm_definition = helpers.create_alarm_definition(
            name=name,
            expression=expression)
        resp, response_body = cls.monasca_client.create_alarm_definitions(
            alarm_definition)

        # create another alarm definition
        name1 = data_utils.rand_name('alarm_definition1')
        expression1 = "max(cpu.system_perc) > 0"
        alarm_definition1 = helpers.create_alarm_definition(
            name=name1,
            expression=expression1)
        resp, response_body1 = cls.monasca_client.create_alarm_definitions(
            alarm_definition1)

        # create another alarm definition
        name2 = data_utils.rand_name('alarm_definition2')
        expression1 = "avg(mysql.performance.slow_queries) > 10.0"
        alarm_definition2 = helpers.create_alarm_definition(
            name=name2,
            expression=expression1)
        resp, response_body2 = cls.monasca_client.create_alarm_definitions(
            alarm_definition2)

        # create some metrics
        for i in xrange(180):
            metric = helpers.create_metric()
            resp, body = cls.monasca_client.create_metrics(metric)
            cls._start_timestamp = start_timestamp + i
            cls._end_timestamp = end_timestamp + i
            time.sleep(1)
            resp, response_body = cls.monasca_client.\
                list_alarms_state_history()
            elements = response_body['elements']
            if len(elements) > 4:
                break

        if len(elements) < 3:
            cls.assertEqual(1, False)
开发者ID:achoi0330,项目名称:avos_test,代码行数:48,代码来源:test_alarms_state_history.py

示例4: test_alarm_max_function

    def test_alarm_max_function(self):
        metric_def = {
            'name': data_utils.rand_name("max_test"),
            'dimensions': {
                'dim_to_match': data_utils.rand_name("max_match")
            }
        }
        expression = "max(" + metric_def['name'] + ") > 14"
        definition = helpers.create_alarm_definition(name="Test Max Function",
                                                     description="",
                                                     expression=expression,
                                                     match_by=["dim_to_match"])
        resp, resp_body = (self.monasca_client
                           .create_alarm_definitions(definition))
        self.assertEqual(201, resp.status)
        definition_id = resp_body['id']
        time.sleep(1)

        self._send_measurement(metric_def, 1)

        alarm_id, initial_state = self._wait_for_alarm_creation(definition_id)
        self.assertEqual("UNDETERMINED", initial_state)

        self._send_measurement(metric_def, 20)

        self._wait_for_alarm_transition(alarm_id, "ALARM")
开发者ID:jobrs,项目名称:monasca-api,代码行数:26,代码来源:test_alarm_transitions.py

示例5: resource_setup

    def resource_setup(cls):
        super(TestAlarmsStateHistoryOneTransition, cls).resource_setup()

        for i in xrange(MIN_HISTORY):
            alarm_definition = helpers.create_alarm_definition(
                name=data_utils.rand_name('alarm_state_history' + str(i + 1)),
                expression="min(name-" + str(i + 1) + ") < " + str(i + 1))
            cls.monasca_client.create_alarm_definitions(alarm_definition)

        num_transitions = 0
        for timer in xrange(constants.MAX_RETRIES):
            for i in xrange(MIN_HISTORY):
                # Create some metrics to prime the system and waiting for the
                # alarms to be created and then for them to change state.
                # MIN_HISTORY number of Alarms State History are needed.
                metric = helpers.create_metric(name="name-" + str(i + 1))
                cls.monasca_client.create_metrics(metric)
                # sleep 0.05 second between metrics to make sure timestamps
                # are different
                time.sleep(0.05)
            resp, response_body = cls.monasca_client.\
                list_alarms_state_history()
            elements = response_body['elements']
            if len(elements) >= MIN_HISTORY:
                return
            else:
                num_transitions = len(elements)
            time.sleep(constants.RETRY_WAIT_SECS)
        assert False, "Required {} alarm state transitions, but found {}".\
            format(MIN_HISTORY, num_transitions)
开发者ID:Missxiaoguo,项目名称:monasca-api,代码行数:30,代码来源:test_alarms_state_history_one_transition.py

示例6: test_list_alarm_definitions_with_multiple_dimensions

    def test_list_alarm_definitions_with_multiple_dimensions(self):
        # Create an alarm definition with random dimensions
        name = data_utils.rand_name('alarm_definition')
        dimensions = {data_utils.rand_name('key-1'): data_utils.rand_name('value-1'),
                      data_utils.rand_name('key-2'): data_utils.rand_name('value-2')}
        dimension_strings = [key + '=' + value for key, value in dimensions.items()]
        expression = 'avg(cpu_utilization{' + ','.join(dimension_strings) + '}) >= 1000'

        alarm_definition = helpers.create_alarm_definition(
            name=name,
            description="description",
            expression=expression)
        resp, res_body_create_alarm_def = self.monasca_client.\
            create_alarm_definitions(alarm_definition)
        self.assertEqual(201, resp.status)

        # List alarms
        query_dimensions = [key + ':' + value for key, value in dimensions.items()]
        query_parms = '?dimensions=' + ','.join(query_dimensions)
        resp, response_body = self.monasca_client.list_alarm_definitions(query_parms)
        self._verify_list_alarm_definitions_response_body(resp, response_body)

        elements = response_body['elements']
        self._verify_list_get_alarm_definitions_elements(
            elements, 1, res_body_create_alarm_def)

        links = response_body['links']
        self._verify_list_alarm_definitions_links(links)
开发者ID:Missxiaoguo,项目名称:monasca-api,代码行数:28,代码来源:test_alarm_definitions.py

示例7: test_alarm_last_with_deterministic

    def test_alarm_last_with_deterministic(self):
        metric_def = {'name': data_utils.rand_name("last_deterministic_test"),
                      'dimensions': {
                          'dim_to_match': data_utils.rand_name("last_match")
                      }}
        expression = "last(" + metric_def['name'] + ",deterministic) > 14"
        definition = helpers.create_alarm_definition(name="Test Last Deterministic Function",
                                                     description="",
                                                     expression=expression,
                                                     match_by=["dim_to_match"])
        resp, resp_body = self.monasca_client.create_alarm_definitions(definition)
        self.assertEqual(201, resp.status)
        definition_id = resp_body['id']
        time.sleep(1)

        self._send_measurement(metric_def, 1)

        alarm_id, initial_state = self._wait_for_alarm_creation(definition_id)
        self.assertEqual("OK", initial_state)

        self._send_measurement(metric_def, 20)

        self._wait_for_alarm_transition(alarm_id, "ALARM")

        self._send_measurement(metric_def, 3)

        self._wait_for_alarm_transition(alarm_id, "OK")
开发者ID:artur-ba,项目名称:monasca-api,代码行数:27,代码来源:test_alarm_transitions.py

示例8: test_create_alarm_definition_with_notification

    def test_create_alarm_definition_with_notification(self):
        notification_name = data_utils.rand_name('notification-')
        notification_type = 'EMAIL'
        notification_address = '[email protected]'
        resp, response_body = self.monasca_client.create_notification_method(
            name=notification_name, type=notification_type,
            address=notification_address)
        notification_id = self._verify_create_notification_method(
            resp, response_body, notification_name, notification_type,
            notification_address)

        # Create an alarm definition
        alarm_def_name = data_utils.rand_name('monitoring_alarm_definition')
        expression = "mem_total_mb > 0"
        alarm_definition = helpers.create_alarm_definition(
            name=alarm_def_name,
            expression=expression,
            alarm_actions=[notification_id],
            ok_actions=[notification_id],
            undetermined_actions=[notification_id],
            severity="LOW")
        resp, response_body = self.monasca_client.create_alarm_definitions(
            alarm_definition)
        self._verify_create_alarm_definitions(resp, response_body,
                                              alarm_definition)
        self.assertEqual(notification_id, response_body['ok_actions'][0])
        self.assertEqual(notification_id, response_body['alarm_actions'][0])
        self.assertEqual(notification_id,
                         response_body['undetermined_actions'][0])

        self._delete_notification(notification_id)
开发者ID:Missxiaoguo,项目名称:monasca-api,代码行数:31,代码来源:test_alarm_definitions.py

示例9: test_create_alarms_with_sub_expressions_and_match_by

 def test_create_alarms_with_sub_expressions_and_match_by(self):
     # Create an alarm definition with sub-expressions and match_by
     name = data_utils.rand_name('alarm_definition_3')
     expression = "max(cpu.idle_perc{service=monitoring}) < 10 or " \
                  "max(cpu.user_perc{service=monitoring}) > 60"
     match_by = ['hostname']
     alarm_definition = helpers.create_alarm_definition(
         name=name, description="description", expression=expression,
         match_by=match_by)
     resp, response_body = self.monasca_client.create_alarm_definitions(
         alarm_definition)
     alarm_definition_id = response_body['id']
     self._create_metrics_for_match_by_sub_expressions(
         num=2, alarm_definition_id=alarm_definition_id)
     query_param = '?alarm_definition_id=' + str(alarm_definition_id)
     resp, response_body = self.monasca_client.list_alarms(query_param)
     self._verify_list_alarms_elements(resp, response_body,
                                       expect_num_elements=2)
     elements = response_body['elements']
     hostnames = []
     for i in xrange(2):
         self.assertEqual(len(elements[i]['metrics']), 2)
     for i in xrange(2):
         for j in xrange(2):
             hostnames.append(elements[i]['metrics'][j]['dimensions'][
                 'hostname'])
     self.assertEqual(hostnames[0], hostnames[1])
     self.assertEqual(hostnames[2], hostnames[3])
     self.assertNotEqual(hostnames[0], hostnames[2])
开发者ID:skydiator,项目名称:monasca-api,代码行数:29,代码来源:test_alarms.py

示例10: test_create_alarms_with_match_by_list

 def test_create_alarms_with_match_by_list(self):
     # Create an alarm definition with match_by as a list
     name = data_utils.rand_name('alarm_definition')
     expression = "max(cpu.idle_perc{service=monitoring}) < 10"
     match_by = ['hostname', 'device']
     alarm_definition = helpers.create_alarm_definition(
         name=name, description="description", expression=expression,
         match_by=match_by)
     resp, response_body = self.monasca_client.create_alarm_definitions(
         alarm_definition)
     alarm_definition_id = response_body['id']
     query_param = '?alarm_definition_id=' + str(alarm_definition_id)
     # create some metrics
     self._create_metrics_for_match_by_sub_expressions_list(
         num=4, alarm_definition_id=alarm_definition_id)
     resp, response_body = self.monasca_client.list_alarms(query_param)
     self._verify_list_alarms_elements(resp, response_body,
                                       expect_num_elements=4)
     elements = response_body['elements']
     dimensions = []
     for i in xrange(4):
         self.assertEqual(len(elements[i]['metrics']), 1)
         dimensions.append(elements[i]['metrics'][0]['dimensions'])
     for i in xrange(4):
         for j in xrange(4):
             if i != j:
                 self.assertNotEqual(dimensions[i], dimensions[j])
开发者ID:skydiator,项目名称:monasca-api,代码行数:27,代码来源:test_alarms.py

示例11: _create_alarms_for_test_alarms

 def _create_alarms_for_test_alarms(self, num):
     metric_name = data_utils.rand_name('name')
     key = data_utils.rand_name('key')
     value = data_utils.rand_name('value')
     alarm_definition_ids = []
     for i in xrange(num):
         # create an alarm definition
         expression = "max(" + metric_name + ") > 0"
         name = data_utils.rand_name('name-1')
         alarm_definition = helpers.create_alarm_definition(
             name=name, expression=expression)
         resp, response_body = self.monasca_client.create_alarm_definitions(
             alarm_definition)
         alarm_definition_ids.append(response_body['id'])
     expected_metric = helpers.create_metric(name=metric_name,
                                             dimensions={key: value})
     # create some metrics
     for j in xrange(num):
         for i in xrange(constants.MAX_RETRIES):
             self.monasca_client.create_metrics(expected_metric)
             time.sleep(constants.RETRY_WAIT_SECS)
             query_param = '?alarm_definition_id=' + \
                           str(alarm_definition_ids[j])
             resp, response_body = self.monasca_client.list_alarms(
                 query_param)
             elements = response_body['elements']
             if len(elements) >= 1:
                 break
     return alarm_definition_ids, expected_metric
开发者ID:skydiator,项目名称:monasca-api,代码行数:29,代码来源:test_alarms.py

示例12: test_create_alarm_definition_with_special_chars_in_expression

    def test_create_alarm_definition_with_special_chars_in_expression(self):
        notification_name = data_utils.rand_name("notification-")
        notification_type = "EMAIL"
        address = "[email protected]"

        resp, response_body = self.monasca_client.create_notification_method(
            notification_name, type=notification_type, address=address
        )
        notification_id = self._verify_create_notification_method(
            resp, response_body, notification_name, notification_type, address
        )

        # Create an alarm definition
        alarm_def_name = data_utils.rand_name("monitoring_alarm")
        alarm_definition = helpers.create_alarm_definition(
            name=alarm_def_name,
            expression="avg(mem_total_mb{dev=\usr\local\bin}) " "gt 0",
            alarm_actions=[notification_id],
            ok_actions=[notification_id],
            undetermined_actions=[notification_id],
            severity="LOW",
        )
        self.assertRaises(
            exceptions.UnprocessableEntity, self.monasca_client.create_alarm_definitions, alarm_definition
        )
开发者ID:Rubab-Syed,项目名称:monasca-api,代码行数:25,代码来源:test_alarm_definitions.py

示例13: test_list_alarms_by_multiple_metric_dimensions

    def test_list_alarms_by_multiple_metric_dimensions(self):
        metric = helpers.create_metric(
            name=data_utils.rand_name("multi-dimension"),
            dimensions={data_utils.rand_name("key-1"): data_utils.rand_name("value-1"),
                        data_utils.rand_name("key-2"): data_utils.rand_name("value-2")},
            value=20
        )
        dimension_strings = [key + '=' + value for key, value in metric['dimensions'].items()]
        alarm_def = helpers.create_alarm_definition(
            name=data_utils.rand_name("multi-dimensions"),
            expression=metric['name'] + "{" + ','.join(dimension_strings) + '} > 15'
        )

        resp, response_body = self.monasca_client.create_alarm_definitions(alarm_def)
        self.assertEqual(201, resp.status)
        alarm_def_id = response_body['id']

        resp, response_body = self.monasca_client.create_metrics(metric)
        self.assertEqual(204, resp.status)
        self._wait_for_alarms(1, alarm_def_id)

        query_dimensions = [key + ':' + value for key, value in metric['dimensions'].items()]
        query_parms="?metric_dimensions=" + ','.join(query_dimensions)

        resp, response_body = self.monasca_client.list_alarms(query_parms)
        self._verify_list_alarms_elements(resp, response_body,
                                          expect_num_elements=1)
        element = response_body['elements'][0]
        metric = element['metrics'][0]
        self._verify_metric_in_alarm(metric, metric)
        self.assertEqual(alarm_def_id,
                         element['alarm_definition']['id'])
开发者ID:Missxiaoguo,项目名称:monasca-api,代码行数:32,代码来源:test_alarms.py

示例14: test_create_alarm_definition_with_name_exceeds_max_length

 def test_create_alarm_definition_with_name_exceeds_max_length(self):
     long_name = "x" * (constants.MAX_ALARM_DEFINITION_NAME_LENGTH + 1)
     expression = "max(cpu.system_perc) > 0"
     alarm_definition = helpers.create_alarm_definition(
         name=long_name, description="description", expression=expression)
     self.assertRaises(exceptions.UnprocessableEntity,
                       self.monasca_client.create_alarm_definitions,
                       alarm_definition)
开发者ID:Missxiaoguo,项目名称:monasca-api,代码行数:8,代码来源:test_alarm_definitions.py

示例15: test_create_alarm_definition

 def test_create_alarm_definition(self):
     # Create an alarm definition
     name = data_utils.rand_name("alarm_definition")
     expression = "max(cpu.system_perc) > 0"
     alarm_definition = helpers.create_alarm_definition(
         name=name, description="description", expression=expression, match_by=["hostname"], severity="MEDIUM"
     )
     resp, response_body = self.monasca_client.create_alarm_definitions(alarm_definition)
     self._verify_create_alarm_definitions(resp, response_body, alarm_definition)
开发者ID:Rubab-Syed,项目名称:monasca-api,代码行数:9,代码来源:test_alarm_definitions.py


注:本文中的monasca_tempest_tests.tests.api.helpers.create_alarm_definition函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。