def format(self, objects):
     result = collections.OrderedDict()
     for key, value in objects.items():
         pairs = zip(value["name"].split("."), value["oid"].split("."))
         parent = pairs[0][0]
         for name, oid in pairs[1:]:
             child = ".".join([parent, name])
             if (parent, child) not in result:
                 result_key = (get_snmp_name(parent), get_snmp_name(child))
                 if child == key:
                     result[result_key] = copy.deepcopy(value)
                 result.setdefault(result_key, {})["oid"] = oid
                 parent = child
     return result
 def check_services(self, metrics, service_map, name):
     with open(service_map) as handler:
         services = yaml.load(handler.read()).get(self.host)
     if not services:
         return
     for service in services:
         if not fnmatch.filter(metrics.keys(), '%s.%s.*' % (name, service)):
             logger.warn('seems service %s is unavailable on host %s',
                         get_snmp_name('%s.%s' % (name, service)),
                         self.host)
 def get_leaf(self, oid, name, node, data):
     leaf = {}
     leaf["value"] = self.get_value(data, node["path"])
     leaf["type"] = node.get("type", "OCTET STRING")
     leaf["unit"] = node.get("unit", "")
     leaf["description"] = node.get("description")
     leaf["name"] = name
     leaf["oid"] = oid
     leaf["snmp"] = get_snmp_name(name)
     return leaf
def test_get_snmp_name(name, expected):
    assert get_snmp_name(name) == expected