Exemple #1
0
def send_request(data):
    """
    Http request template:
    { 
        "hostname"  : "host_name",
        "data"      : [{'proc_name': 'apache2', 'status': 'unmonitored'},]
    }
    """
    try:
        host = CONF.get("api", "host")
        if not host:
            host = CONF_HOST_DEFAULT
        port = CONF.getint("api", "port")
        if not port:
            port = CONF_PORT_DEFAULT
        report_url = CONF.get("url", "report_url")
        if not report_url:
            report_url = CONF_REPORT_URL_DEFAULT

        hostname = get_hostname()
        report_url = report_url % hostname

        body = {
            "hostname": hostname,
            "data": data,
        }

        httpcon = HttpCon(host, port, report_url)
        httpcon.post(body)

    except Exception, e:
        LOG.error(e)
Exemple #2
0
def get_tasks():
    """
    Http request template:
    { 
        "hostname" : host_name,
        "data" : [{
                    "name":"apache2",
                    "cmd_start":"/etc/init.d/apache2 start",
                    "cmd_stop":"/etc/init.d/apache2 stop",
                    "cmd_restart":"/etc/init.d/apache2 restart",
                    "pid_file":"/var/run/apache2.pid"
                    },
                ]
    }
    """
    try:
        host = CONF.get("api", "host")
        if not host:
            host = CONF_HOST_DEFAULT
        port = CONF.getint("api", "port")
        if not port:
            port = CONF_PORT_DEFAULT
        proctask_url = CONF.get("url", "proctask_url")
        if not proctask_url:
            proctask_url = CONF_PROCTASK_URL_DEFAULT

        hostname = get_hostname()
        proctask_url = proctask_url % hostname

        httpcon = HttpCon(host, port, proctask_url)
        result = httpcon.get()

        return result
    except Exception, e:
        LOG.error(e)
Exemple #3
0
def send_request(data):
    """
    Http request template:
    { 
        "hostname"  : "host_name",
        "data"      : 10000.0
    }
    """
    try:
        host = CONF.get("api", "host")
        if not host:    
            host = CONF_HOST_DEFAULT
        port = CONF.getint("api", "port")
        if not port:
            port = CONF_PORT_DEFAULT
        heartbeat_url = CONF.get("url", "heartbeat_url")
        if not heartbeat_url:
           heartbeat_url = CONF_HEARTBEAT_URL_DEFAULT 

        hostname = get_hostname()
        heartbeat_url = heartbeat_url % hostname
        
        body = {
                "hostname":hostname,
                "data": data,
                }

        httpcon = HttpCon(host, port, heartbeat_url)
        httpcon.post(body)

    except Exception, e:
        LOG.error(e)
Exemple #4
0
def get_tasks():
    """
    Http request template:
    { 
        "hostname" : "host_name",
        "data" : [{
                    "name":"apache2",
                    "cmd_start":"/etc/init.d/apache2 start",
                    "cmd_stop":"/etc/init.d/apache2 stop",
                    "cmd_restart":"/etc/init.d/apache2 restart",
                    "pid_file":"/var/run/apache2.pid"
                    },
                ]
    }
    """
    try:
        host = CONF.get("api", "host")
        if not host:    
            host = CONF_HOST_DEFAULT
        port = CONF.getint("api", "port")
        if not port:
            port = CONF_PORT_DEFAULT
        dbsync_url = CONF.get("url", "dbsync_url")
        if not dbsync_url:
            dbsync_url = CONF_DBSYNC_URL_DEFAULT

        hostname = get_hostname()
        dbsync_url = dbsync_url % hostname
        
        httpcon = HttpCon(host, port, dbsync_url)
        result = httpcon.get()

        return result
    except Exception, e:
        LOG.error(e)
Exemple #5
0
def get_tasks():
    """
    Http request template:
    { 
        "hostname" : "host_name",
        "data" : [
                    {"name":"apache2","action":"start"},
                    {"name":"apache2","action":"stop"},
                    {"name":"apache2","action":"restart"},
                    {"name":"apache2","action":"unmonitor"},
                    {"name":"apache2","action":"monitor"},
                    {"name":"apache2","action":"remove"},
                ]
    }
    """
    try:
        host = CONF.get("api", "host")
        if not host:    
            host = CONF_HOST_DEFAULT
        port = CONF.getint("api", "port")
        if not port:
            port = CONF_PORT_DEFAULT
        action_url = CONF.get("url", "action_url")
        if not action_url:
           action_url = CONF_ACTION_URL_DEFAULT 

        hostname = get_hostname()
        action_url = action_url % hostname
        
        httpcon = HttpCon(host, port, action_url)
        result = httpcon.get()

        return result
    except Exception, e:
        LOG.error(e)
Exemple #6
0
def get_tasks():
    """
    Http request template:
    { 
        "hostname" : "host_name",
        "data" : [
                    {"name":"apache2","action":"start"},
                    {"name":"apache2","action":"stop"},
                    {"name":"apache2","action":"restart"},
                    {"name":"apache2","action":"unmonitor"},
                    {"name":"apache2","action":"monitor"},
                    {"name":"apache2","action":"remove"},
                ]
    }
    """
    try:
        host = CONF.get("api", "host")
        if not host:
            host = CONF_HOST_DEFAULT
        port = CONF.getint("api", "port")
        if not port:
            port = CONF_PORT_DEFAULT
        action_url = CONF.get("url", "action_url")
        if not action_url:
            action_url = CONF_ACTION_URL_DEFAULT

        hostname = get_hostname()
        action_url = action_url % hostname

        httpcon = HttpCon(host, port, action_url)
        result = httpcon.get()

        return result
    except Exception, e:
        LOG.error(e)
Exemple #7
0
def register():
    ensure_god_start()

    host = CONF.get("api", "host")
    if not host:
        host = CONF_HOST_DEFAULT

    port = CONF.getint("api", "port")
    if not port:
        port = CONF_PORT_DEFAULT

    register_url = CONF.get("url", "register_url")
    if not register_url:
        register_url = CONF_REGISTER_URL_DEFAULT

    hostname = get_hostname()
    register_url = register_url % hostname
    httpcon = HttpCon(host, port, register_url)

    body = get_body(hostname)

    result = httpcon.post(body)
    if not result:
        LOG.warn("register Failed!")
        return False

    LOG.info("register Success! request = %s" % (result))
    return True