예제 #1
0
 def handle_dictionaries(self, *args, **options):
     # Extract dictionaries
     for dcls in Dictionary.iter_cls():
         # Temporary XML
         xpath = os.path.join(self.DICT_XML_PREFIX,
                              "%s.xml.tml" % dcls._meta.name)
         self.stdout.write("Extracting dictionary XML to %s\n" % xpath)
         with open(xpath, "w") as f:
             f.write(dcls.get_config())
         # Move temporary XML
         xf = xpath[:-4]
         self.stdout.write("Rename dictionary XML to %s\n" % xf)
         os.rename(xpath, xf)
예제 #2
0
def f_lookup(seq, model=None):
    """
    $lookup (dictionary, id [,field])
    :param seq:
    :param model
    :return:
    """
    dict_name = seq[0]
    dc = Dictionary.get_dictionary_class(dict_name)
    if len(seq) == 2:
        field_name = dc._fields_order[0]
    else:
        field_name = seq[2]
    t = dc.get_field_type(field_name)
    id_expr = to_sql(seq[1])
    return "dictGet%s('%s', '%s', %s)" % (t, dict_name, field_name, id_expr)
예제 #3
0
 def get_pm_datasources(cls):
     result = []
     # Collect fields
     scope_fields = defaultdict(list)
     for mt in MetricType.objects.all().order_by("field_name"):
         scope_fields[mt.scope.table_name] += [{
             "name": mt.field_name,
             "description": mt.description,
             "type": mt.field_type,
             "dict": None,
         }]
     # Attach scopes as datasources
     for ms in MetricScope.objects.all().order_by("table_name"):
         r = {
             "name":
             ms.table_name,
             "description":
             ms.description,
             "tags": [],
             "sample":
             False,
             "fields": [
                 {
                     "name": "date",
                     "description": "Date",
                     "type": "Date",
                     "dict": None
                 },
                 {
                     "name": "ts",
                     "description": "Timestamp",
                     "type": "DateTime",
                     "dict": None
                 },
             ],
         }
         for k in ms.key_fields:
             r["fields"] += [{
                 "name": k.field_name,
                 "description": k.field_name,
                 "type": "UInt64",
                 "dict": cls.ref_dict.get(k.model, None),
                 "model": k.model,
             }]
             if cls.ref_dict.get(k.model, None):
                 for f in Dictionary.get_dictionary_class(
                         cls.ref_dict.get(k.model,
                                          None))._meta.ordered_fields:
                     r["fields"] += [{
                         "name": f.name,
                         "description": f.description or f.name,
                         "type": "UInt64",
                         "ro": True,
                         "dict": cls.ref_dict.get(k.model, None),
                         "dict_id": k.field_name,
                         "model": k.model,
                     }]
         if ms.path:
             r["fields"] += [{
                 "name": "path",
                 "description": "Metric path",
                 "type": "Array(String)",
                 "dict": None,
             }]
         r["fields"] += scope_fields[ms.table_name]
         result += [r]
     return result
예제 #4
0
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------
# test BI dictionaries
# ----------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------

# Third-party modules
import pytest

# NOC modules
from noc.core.clickhouse.dictionary import Dictionary


@pytest.fixture(params=list(Dictionary.iter_cls()))
def dictionary(request):
    return request.param


@pytest.mark.dependency(name="test_dictionary_meta")
def test_dictionary_meta(dictionary):
    assert hasattr(dictionary, "_meta")


@pytest.mark.dependency(depends=["test_dictionary_meta"])
def test_dictionary_name(dictionary):
    assert dictionary._meta.name


@pytest.mark.dependency(depends=["test_dictionary_meta"])