Exemple #1
0
def test_alert_dashboard(log, fread, exist):
    exist.return_value = True
    path = os.path.join(os.path.dirname(__file__), "dashboard.json")
    with open(path) as f:
        fread.return_value = f.read()
    test_init.init()
    with patch.object(NS.monitoring.definitions,
                      "get_parsed_defs") as mock_defs:
        threshold = {'capacity_utilization': {'Warning': 75, 'Critical': 90}}
        mock_defs.return_value = ({
            "namespace.monitoring": {
                "thresholds": {
                    "volumes": threshold
                }
            }
        })
        resource = {
            'vol_id': '4ff7cf55-a6ef-4ea1-a8ea-f406803503a4',
            'name': 'V2',
            'sds_name': 'gluster',
            'integration_id': 'f3a74e36-0462-4fb0-9a92-3ee9d244f8a2',
            'resource_name': 'V2'
        }
        resource_json = alert_dashboard.create_resource_dashboard(
            "volumes", resource)
        new_res, resource_json, panel_id = alert_dashboard.check_duplicate(
            resource_json, [resource], 'volumes')
        if not (panel_id == 2 and new_res == []):
            raise AssertionError
        resource['name'] = 'V3'
        resource['resource_name'] = 'V3'
        resource_json = alert_dashboard.add_panel([resource], 'volumes',
                                                  resource_json, panel_id)
        if not len(resource_json["dashboard"]["rows"]) == 2:
            raise AssertionError
Exemple #2
0
def test_cpu_handler(pid, node_id):
    node_id.return_value = "1"
    pid.return_value = "123"
    test_init.init()
    obj = cpu_handler.CpuHandler()
    path = os.path.join(os.path.dirname(__file__), "cpu_alert_info.json")
    alert = json.load(open(path))
    result = obj.format_alert(alert)
    condition = {
        'alert_id': None,
        'alert_type': 'UTILIZATION',
        'severity': 'INFO',
        'significance': 'HIGH',
        'node_id': '1',
        'current_value': None,
        'source': 'GRAFANA',
        'resource': 'cpu_utilization',
        'pid': '123',
        'time_stamp': u'2018-02-07T17:28:05+05:30',
        'tags': {
            'warning_max': 80,
            'fqdn': u'dhcp122-234',
            'message': u'Cpu utilization of '
            'node dhcp122-234 is back to normal',
            'integration_id': '7616f2a4-6502-4222-'
            '85bb-c5aff4eef15d'
        }
    }
    if not result == condition:
        raise AssertionError()
    path = os.path.join(os.path.dirname(__file__), "cpu_alert_error.json")
    alert = json.load(open(path))
    result = obj.format_alert(alert)
    condition = {
        'pid': '123',
        'tags': {
            'fqdn':
            u'dhcp122-234',
            'warning_max':
            1,
            'message':
            u'Cpu utilization of node '
            'dhcp122-234 is 2.61 % which is above the '
            'WARNING threshold (1 %).',
            'integration_id':
            '7616f2a4-6502-4222-'
            '85bb-c5aff4eef15d'
        },
        'alert_id': None,
        'source': 'GRAFANA',
        'current_value': '2.61',
        'significance': 'HIGH',
        'time_stamp': u'2018-02-12T10:53:03+05:30',
        'node_id': '1',
        'alert_type': 'UTILIZATION',
        'severity': 'WARNING',
        'resource': 'cpu_utilization'
    }
    if not result == condition:
        raise AssertionError()
Exemple #3
0
def test_create():
    with mock.patch("tendrl.commons.utils.log_utils.log") as mock_log:
        test_init.init()
        with mock.patch.object(datasource_utils, "create_datasource",
                               pass_create_datasource):
            datasource.create()
            mock_log.assert_called_with(
                'debug', 'monitoring_integration',
                {'message': 'Datasource created successfully'})
        with mock.patch.object(datasource_utils, "create_datasource",
                               update_create_datasource):
            with mock.patch.object(datasource_utils, "get_data_source",
                                   get_data_source_fail):
                datasource.create()
                mock_log.assert_called_with(
                    'debug', 'monitoring_integration',
                    {'message': 'Unable to find datasource id'})
            with mock.patch.object(datasource_utils, "get_data_source",
                                   get_data_source):
                with mock.patch.object(datasource_utils, "update_datasource",
                                       update):
                    datasource.create()
                    mock_log.assert_called_with(
                        'debug', 'monitoring_integration',
                        {'message': 'Datasource is updated successfully'})
                with mock.patch.object(datasource_utils, "update_datasource",
                                       fail_update):
                    datasource.create()
                    mock_log.assert_called_with(
                        'debug', 'monitoring_integration',
                        {'message': 'Unable to update datasource'})
def test_create(create_notification, create_ds, context, write, client):
    write.return_value = etcd.Client()
    client.return_value = etcd.Client()
    context.return_value = True
    create_ds.return_value = True
    create_notification.return_value = True
    test_init.init()
    with mock.patch("tendrl.commons.utils.log_utils.log"):
        with patch.object(grafana_org_utils, "get_org_id") as org_utils:
            org_utils.return_value = '{"id": 2}'
            with patch.object(grafana_org_utils, "get_auth_keys") as auth_key:
                auth_key.return_value = [
                    {
                        "name": "grafana_auth_key",
                        "role": "Admin"
                    }
                ]
                with patch.object(NS.monitoring.objects.AlertOrganization,
                                  "load") as load:
                    obj = NS.monitoring.objects.AlertOrganization(
                        auth_key="grafana_key")
                    load.return_value = obj
                    alert_organization.create()
                    if not NS.config.data["org_id"] == 2:
                        raise AssertionError()
                    if not NS.config.data["grafana_auth_key"] == \
                            "grafana_key":
                        raise AssertionError()
        with patch.object(grafana_org_utils, "get_org_id") as org_utils:
            org_utils.return_value = '{"message": "Organization not found"}'
            with patch.object(grafana_org_utils, "create_org") as create_org:
                create_org.return_value = 3
                with patch.object(grafana_org_utils,
                                  "get_auth_keys") as auth_key:
                    auth_key.return_value = []
                    with patch.object(grafana_org_utils,
                                      "create_api_token") as api_token:
                        api_token.return_value = "grafana_key_new"
                        alert_organization.create()
                        if not NS.config.data["org_id"] == 3:
                            raise AssertionError()
                        if not NS.config.data["grafana_auth_key"] ==  \
                                "grafana_key_new":
                            raise AssertionError()
        with patch.object(grafana_org_utils, "get_org_id") as org_utils:
            org_utils.return_value = '{}'
            with patch.object(grafana_org_utils, "get_auth_keys") as auth_key:
                auth_key.return_value = {}
                alert_organization.create()
                if not NS.config.data["org_id"] is None:
                    raise AssertionError()
                if not NS.config.data["grafana_auth_key"] is None:
                    raise AssertionError()
        with patch.object(grafana_org_utils, "get_org_id") as org_utils:
            org_utils.return_value = {}
Exemple #5
0
def test_swap_handler(pid, node_id):
    node_id.return_value = "1"
    pid.return_value = "123"
    test_init.init()
    obj = swap_handler.SwapHandler()
    path = os.path.join(os.path.dirname(__file__),
                        "swap_alert_info.json")
    alert = json.load(open(path))
    result = obj.format_alert(alert)
    condition = {'alert_id': None,
                 'alert_type': 'UTILIZATION',
                 'severity': 'INFO',
                 'time_stamp': u'2018-02-07T17:40:02+05:30',
                 'pid': '123',
                 'tags': {'warning_max': 50,
                          'message': u'Swap utilization of node '
                          'dhcp122-234 is back to normal',
                          'fqdn': u'dhcp122-234',
                          'integration_id': '7616f2a4-6502-4222-85bb-'
                          'c5aff4eef15d'
                          },
                 'resource': 'swap_utilization',
                 'node_id': '1',
                 'current_value': None,
                 'source': 'GRAFANA',
                 'significance': 'HIGH'
                 }
    if not result == condition:
        raise AssertionError()
    path = os.path.join(os.path.dirname(__file__),
                        "swap_alert_error.json")
    alert = json.load(open(path))
    result = obj.format_alert(alert)
    condition = {'alert_type': 'UTILIZATION',
                 'alert_id': None,
                 'resource': 'swap_utilization',
                 'time_stamp': u'2018-02-12T11:16:23+05:30',
                 'pid': '123',
                 'tags': {'warning_max': 70,
                          'message': u'Swap utilization of node '
                          'dhcp122-234 is 80.0 % which is above '
                          'the WARNING threshold (70 %).',
                          'fqdn': u'dhcp122-234',
                          'integration_id': '7616f2a4-6502-4222-85bb-'
                          'c5aff4eef15d'
                          },
                 'source': 'GRAFANA',
                 'significance': 'HIGH',
                 'current_value': '80.0',
                 'severity': 'WARNING',
                 'node_id': '1'
                 }
    if not result == condition:
        raise AssertionError()
def test_create_alert_dashboard(log, post, fread, exist):
    post.return_value = maps.NamedDict(status_code=200)
    exist.return_value = True
    path = os.path.join(os.path.dirname(__file__), "dashboard.json")
    with open(path) as f:
        fread.return_value = f.read()
    test_init.init()
    with patch.object(NS.monitoring.definitions,
                      "get_parsed_defs") as mock_defs:
        threshold = {'capacity_utilization': {'Warning': 75, 'Critical': 90}}
        mock_defs.return_value = ({
            "namespace.monitoring": {
                "thresholds": {
                    "volumes": threshold
                }
            }
        })
        alert_dashboard.create_resource_dashboard(
            "volumes", {
                'vol_id':
                u'4ff7cf55-a6ef-4ea1-a8ea-f406803503a4',
                'name':
                u'V2',
                'subvolume': [{
                    'bricks': [u'dhcp122-137:_gluster_brick2'],
                    'subvolume': u'subvolume1'
                }, {
                    'bricks': [u'dhcp122-234:_gluster_brick2'],
                    'subvolume': u'subvolume2'
                }, {
                    'bricks': [u'dhcp122-3:_gluster_brick2'],
                    'subvolume': u'subvolume0'
                }]
            }, 'gluster', 'f3a74e36-0462-4fb0-9a92-3ee9d244f8a2')
        log.assert_called_with('debug', 'monitoring_integration', {
            'message':
            'Alert dashboard for '
            'volumes- is created successfully'
        })
Exemple #7
0
def test_volume_handler(cluster_name, pid, short_name):
    short_name.return_value = '7616f2a4-6502-4222-85bb-c5aff4eef15d'
    pid.return_value = "123"
    cluster_name.return_value = "c1"
    test_init.init()
    obj = volume_utilization_handler.VolumeHandler()
    path = os.path.join(os.path.dirname(__file__), "volume_alert_info.json")
    alert = json.load(open(path))
    result = obj.format_alert(alert)
    result['time_stamp'] = '2018-02-07T17:30:08+05:30'
    condition = {
        'severity': 'INFO',
        'source': 'GRAFANA',
        'pid': '123',
        'time_stamp': u'2018-02-07T17:30:08+05:30',
        'alert_id': None,
        'resource': 'volume_utilization',
        'significance': 'HIGH',
        'current_value': None,
        'node_id': None,
        'alert_type': 'UTILIZATION',
        'tags': {
            'cluster_name':
            'c1',
            'message':
            u'Volume utilization on '
            'V1 in 7616f2a4-6502-4222-'
            '85bb-c5aff4eef15d back to normal',
            'warning_max':
            75,
            'volume_name':
            u'V1',
            'integration_id':
            u'7616f2a4-6502-4222'
            '-85bb-c5aff4eef15d',
            'cluster_short_name':
            '7616f2a4-6502-4222-'
            '85bb-c5aff4eef15d',
            'plugin_instance':
            u'tendrl.clusters.'
            '7616f2a4-6502-4222-85bb-c5aff4eef15d.'
            'volumes.V1.pcnt_used'
        }
    }
    if not result == condition:
        raise AssertionError()
    path = os.path.join(os.path.dirname(__file__), "volume_alert_error.json")
    alert = json.load(open(path))
    result = obj.format_alert(alert)
    result['time_stamp'] = '2018-02-12T13:36:25+05:30'
    condition = {
        'time_stamp': u'2018-02-12T13:36:25+05:30',
        'significance': 'HIGH',
        'alert_type': 'UTILIZATION',
        'node_id': None,
        'severity': 'WARNING',
        'resource': 'volume_utilization',
        'pid': '123',
        'tags': {
            'cluster_name':
            'c1',
            'volume_name':
            u'V1',
            'cluster_short_name':
            '7616f2a4-6502-4222-'
            '85bb-c5aff4eef15d',
            'plugin_instance':
            u'tendrl.clusters.'
            '7616f2a4-6502-4222-85bb-c5aff4eef15d.'
            'volumes.V1.pcnt_used',
            'warning_max':
            14,
            'integration_id':
            u'7616f2a4-6502-4222'
            '-85bb-c5aff4eef15d',
            'message':
            u'Volume utilization on V1 in'
            ' 7616f2a4-6502-4222-85bb-c5aff4eef1'
            '5d at 20.86 % and nearing full capacity'
        },
        'source': 'GRAFANA',
        'current_value': '20.86',
        'alert_id': None
    }
    if not result == condition:
        raise AssertionError()
def test_brick_handler(vol_name, cluster_name, pid, node_id):
    vol_name.return_value = "vol1"
    node_id.return_value = "1"
    pid.return_value = "123"
    cluster_name.return_value = "c1"
    test_init.init()
    obj = brick_utilization_handler.BrickHandler()
    path = os.path.join(os.path.dirname(__file__), "brick_alert_info.json")
    alert = json.load(open(path))
    result = obj.format_alert(alert)
    condition = {
        'significance': 'HIGH',
        'alert_type': 'UTILIZATION',
        'node_id': '1',
        'resource': 'brick_utilization',
        'time_stamp': u'2018-02-07T17:24:16+05:30',
        'alert_id': None,
        'current_value': None,
        'tags': {
            'plugin_instance':
            u'tendrl.clusters.'
            '7616f2a4-6502-4222-85bb-c5aff4eef15d.'
            'nodes.dhcp122-234.bricks.|gluster|brick1'
            '.utilization.percent-percent_bytes',
            'fqdn':
            u'dhcp122-234',
            'brick_path':
            u'|gluster|brick1',
            'cluster_name':
            'c1',
            'integration_id':
            u'7616f2a4-6502-4222-85bb'
            '-c5aff4eef15d',
            'warning_max':
            75,
            'message':
            u'Brick utilization of dhcp122-234'
            ':|gluster|brick1 under volume vol1 in cluster '
            '7616f2a4-6502-4222-85bb-c5aff4eef15d is back '
            'normal',
            'volume_name':
            'vol1'
        },
        'source': 'GRAFANA',
        'severity': 'INFO',
        'pid': '123'
    }
    if not result == condition:
        raise AssertionError()
    obj = brick_utilization_handler.BrickHandler()
    path = os.path.join(os.path.dirname(__file__), "brick_alert_error.json")
    alert = json.load(open(path))
    result = obj.format_alert(alert)
    condition = {
        'severity': 'WARNING',
        'significance': 'HIGH',
        'alert_type': 'UTILIZATION',
        'alert_id': None,
        'time_stamp': u'2018-02-12T13:13:03+05:30',
        'tags': {
            'plugin_instance':
            u'tendrl.clusters.7616f2a4'
            '-6502-4222-85bb-c5aff4eef15d.nodes.dhcp122-'
            '234.bricks.|gluster|brick1.utilization.'
            'percent-percent_bytes',
            'fqdn':
            u'dhcp122-234',
            'message':
            u'Brick utilization of dhcp122-234:|'
            'gluster|brick1 under volume vol1 in cluster '
            '7616f2a4-6502-4222-85bb-c5aff4eef15d is 20.75 % '
            'which is above WARNING threshold (17 %)',
            'integration_id':
            u'7616f2a4-6502-4222-85bb-'
            'c5aff4eef15d',
            'cluster_name':
            'c1',
            'brick_path':
            u'|gluster|brick1',
            'warning_max':
            17,
            'volume_name':
            'vol1'
        },
        'pid': '123',
        'node_id': '1',
        'resource': 'brick_utilization',
        'source': 'GRAFANA',
        'current_value': '20.75'
    }
    if not result == condition:
        raise AssertionError()
def test_memory_handler(pid, node_id, short_name):
    short_name.return_value = '7616f2a4-6502-4222-85bb-c5aff4eef15d'
    node_id.return_value = "1"
    pid.return_value = "123"
    test_init.init()
    obj = memory_handler.MemoryHandler()
    path = os.path.join(os.path.dirname(__file__), "memory_alert_info.json")
    alert = json.load(open(path))
    result = obj.format_alert(alert)
    result['time_stamp'] = '2018-02-07T17:29:01+05:30'
    condition = {
        'pid': '123',
        'tags': {
            'warning_max':
            80,
            'fqdn':
            u'dhcp122-234',
            'message':
            u'Memory utilization on '
            'node dhcp122-234 in 7616f2a4-6502-4222-85bb-'
            'c5aff4eef15d back to normal',
            'integration_id':
            '7616f2a4-6502-4222-85bb-'
            'c5aff4eef15d',
            'cluster_short_name':
            '7616f2a4-6502-4222-'
            '85bb-c5aff4eef15d'
        },
        'current_value': None,
        'source': 'GRAFANA',
        'alert_id': None,
        'alert_type': 'UTILIZATION',
        'time_stamp': u'2018-02-07T17:29:01+05:30',
        'significance': 'HIGH',
        'node_id': '1',
        'resource': 'memory_utilization',
        'severity': 'INFO',
    }
    if not result == condition:
        raise AssertionError()
    path = os.path.join(os.path.dirname(__file__), "memory_alert_error.json")
    alert = json.load(open(path))
    result = obj.format_alert(alert)
    result['time_stamp'] = '2018-02-12T11:30:19+05:30'
    condition = {
        'resource': 'memory_utilization',
        'source': 'GRAFANA',
        'significance': 'HIGH',
        'alert_type': 'UTILIZATION',
        'severity': 'WARNING',
        'current_value': '29.47',
        'node_id': '1',
        'tags': {
            'fqdn':
            u'dhcp122-234',
            'message':
            u'Memory utilization on '
            'node dhcp122-234 in '
            '7616f2a4-6502-4222-85bb-'
            'c5aff4eef15d '
            'at 29.47 % and running out of memory',
            'warning_max':
            23,
            'integration_id':
            '7616f2a4-6502-4222-85bb-'
            'c5aff4eef15d',
            'cluster_short_name':
            '7616f2a4-6502-4222-'
            '85bb-c5aff4eef15d'
        },
        'time_stamp': u'2018-02-12T11:30:19+05:30',
        'alert_id': None,
        'pid': '123'
    }
    if not result == condition:
        raise AssertionError()