def getHostConfigurations(configPath='/etc/nginx/nginx.conf'):

  nginxConfigData = loadNginxConfig(configPath)
  serverData = {}
  for k in nginxConfigData.get_value(nginxConfigData.get([('http',), ]) ):
    if type(k) is dict:
      values = k['value']
      servernames = []
      for entry in values:
        if type(entry) is tuple:
          if entry[0].lower() == 'server_name':
            servernames = entry[1].split()
            conf = {}
            for v in values:
              if type(v) is tuple:
                entryKey = v[0]
                entryValue = v[1]
                if entryKey in conf.keys():
                  # We've already found an entry with this key name. Convert
                  # this dict entry to a list, and append.
                  if type(conf[entryKey]) is list:
                    conf[entryKey].append(entryValue)
                  else:
                    t = [conf[entryKey]]
                    t.append(entryValue)
                    conf[entryKey] = t
                  conf[entryKey].sort()
                else:
                  conf[entryKey] = entryValue
            for s in servernames:
              # Yes, we will end up with duplicated dict entries when a server
              # entry has more than one DNS name. This makes it easier to find
              # the entry corresponding to a given DNS name.
              serverData[s] = conf
  return serverData
pynginxconfig returns an ugly data structure, but it is better than parsing
dataset/ETHPy150Open NumentaCorp/agamotto/agamotto/nginx.py/getHostConfigurations