Exemple #1
0
def cmdbInfo(unit):
    if request.method == "POST":
        try:
            key = request.json.get("key")
            if verify_key(key) and request.json.get("obj") == "cmdb":
                info = cmdb()
                data = info.run_task(request.json.get("content"))
                return jsonify(data)
            else:
                work_log.error("req verify_key or obj error")
                return "", 404
        except Exception as e:
            work_log.error("req cmdb error")
            work_log.error(str(e))
            return str(e), 500
Exemple #2
0
def v2_local():
    work_log.debug(str(request.path))
    try:
        key = request.json.get("key")
        if verify_key(key) and request.json.get("obj") == "local":
            info = LocalTask(request.json.get("content"))
            data = info.run()
            return jsonify(data)
        else:
            work_log.error("req verify_key or obj error")
            return "", 404
    except Exception as e:
        work_log.error("host run error")
        work_log.error(str(e))
        return jsonify({"recode": 9, "redata": str(e)})
Exemple #3
0
def v2_monitor():
    work_log.info("request MonitorTask interface ip: %s" %
                  (request.remote_addr))
    try:
        key = request.json.get("key")
        if verify_key(key) and request.json.get("obj") == "monitor":
            info = MonitorTask()
            data = info.run(request.json.get("content"))
            work_log.info(str(data))
            return jsonify(data)
        else:
            work_log.error("format error")
            return "", 404
    except Exception as e:
        work_log.error(str(e))
        return jsonify({"recode": 1, "redata": "run error"})
Exemple #4
0
def v2_service():
    work_log.debug(str(request.path))
    work_log.debug("request service interface, ip: %s " %
                   (request.remote_addr))
    try:
        key = request.json.get("key")
        if verify_key(key) and request.json.get("obj") == "service":
            info = Service()
            data = info.run_task(request.json.get("content"))
            work_log.info(str(data))
            return jsonify(data)
        else:
            work_log.error("req verify_key or obj error")
            return "", 404
    except Exception as e:
        work_log.error("req format error")
        work_log.error(str(e))
        return "", 404
Exemple #5
0
def v2_down():
    '''原理:从指定服务器上下载文件到临时目录,再返回一个文件的get下载路径'''
    work_log.debug("---------------")
    work_log.debug(str(request.path))
    work_log.info("request host interface ip: %s" % (request.remote_addr))

    try:
        key = request.json.get("key")
        if not verify_key(key) and request.json.get("obj") != "file":
            work_log.error("req verify_key or obj error")
            return "", 404
    except Exception as e:
        work_log.error(str(e))
        work_log.error("req verify_key or obj error")
        return "", 404

    info = DownRemoteFile(request.json.get("content"))
    data = info.down()
    return jsonify(data)
Exemple #6
0
def v2_network():
    work_log.debug(str(request.path))
    work_log.debug("request network interface, ip: %s " % (request.remote_addr))
    if request.method == "GET":
        ping_ipaddr = request.args.get("ping")
        checkurl = request.args.get("checkurl")

        if ping_ipaddr:
            info = NetWork()
            data = info.ping(ping_ipaddr)
            return jsonify(data)
        elif checkurl:
            info = Service()
            data = info.check_url(checkurl)
            return jsonify(data)
        else:
            work_log.error(str("req format error"))
            return "", 404

    elif request.method == "POST":
        try:
            key = request.json.get("key")
            if verify_key(key) and request.json.get("obj") == "network":
                info = NetWork()
                data = info.run_task(request.json.get("content"))
                work_log.info(str(data))
                return jsonify(data)
            else:
                work_log.error("req verify_key or obj error")
                return "", 404
        except Exception as e:
            work_log.error("req error")
            work_log.error(str(e))
            return "", 404
    else:
        return "", 404