Beispiel #1
0
def page_host_inv_api():
    try:
        request = html.get_request()

        # The user can either specify a single host or provide a list of host names. In case
        # multiple hosts are handled, there is a top level dict added with "host > invdict" pairs
        hosts = request.get("hosts")
        if hosts:
            result = {}
            for host_name in hosts:
                result[host_name] = inventory_of_host(host_name, request)

        else:
            host_name = request.get("host")
            if host_name == None:
                raise MKUserError("host", _("You need to provide a \"host\"."))

            result = inventory_of_host(host_name, request)

            if not result and not has_inventory(host_name):
                raise MKGeneralException(
                    _("Found no inventory data for this host."))

        response = {"result_code": 0, "result": result}

    except MKException, e:
        response = {"result_code": 1, "result": "%s" % e}
Beispiel #2
0
def get(tree, path):
    if path[0] != '.':
        raise MKGeneralException(
            _("Invalid inventory path. Must start with dot."))
    path = path[1:]

    node = tree

    # The root node of the tree MUST be dictionary
    # This info is taken from the host_inventory column in a livestatus table
    # Older versions, which do not know this column, report None as fallback value
    # This workaround prevents the inevitable crash
    if node == None:
        node = {}

    current_what = "."
    while path not in ('.', ':', ''):
        parts = re.split("[:.]", path)
        name = parts[0]
        path = path[len(name):]
        if path:
            what = path[0]
            path = path[1:]
        else:
            what = None  # leaf node

        if current_what == '.':  # node is a dict
            if name not in node:
                if what == '.':
                    node = {}
                elif what == ':':
                    node = []
                else:
                    node = None
            else:
                node = node[name]

        elif current_what == ':':  # node is a list
            index = int(name)
            if index >= len(node) or index < 0:
                if what == '.':
                    node = {}
                elif what == ':':
                    node = []
                else:
                    node = None
            else:
                node = node[index]

        current_what = what
        if what == None:
            return node  # return leaf node

    return node
Beispiel #3
0
def write_xml(response):
    try:
        import dicttoxml
    except ImportError:
        raise MKGeneralException(
            _("You need to have the \"dicttoxml\" python module installed to "
              "be able to use the XML format."))

    unformated_xml = dicttoxml.dicttoxml(response)

    from xml.dom.minidom import parseString
    dom = parseString(unformated_xml)

    html.write(dom.toprettyxml())
Beispiel #4
0
 def verify_not_using_threaded_mpm(self):
     if apache.mpm_query(apache.AP_MPMQ_IS_THREADED) != 0:
         raise MKGeneralException(
             _("You are trying to Check_MK together with a threaded Apache multiprocessing module (MPM). "
               "Check_MK is only working with the prefork module. Please change the MPM module to make "
               "Check_MK work."))