예제 #1
0
class ReportInfo():
    
    def __init__(self):
        self._conf = Conf(os.getcwd()+'/conf/agent.ini')
        self._get_conf() 
    def _get_conf(self):
        self._report_type = self._conf.get("REPORT","report.type","udp")
        self._host_ip = self._conf.get("REPORT","host.svr.ip","")
        self._host_port = self._conf.get("REPORT","host.svr.port","9999")
        self._host_url = self._conf.get("REPORT","host.svr.url","/demo/run/api")
    def run(self,info):
        """"""
        #log("44444444444")
        try:
            if self._report_type.lower() == "udp":
                self.udp_report(self.standard_format(info))
            elif self._report_type.lower() == "http":
                (code,result)=self.timout_report(self.standard_format(info))
            else:
                #default udp
                self.udp_report(self.standard_format(info))
            code = 0
            result = "success"
        except Exception,e:
            log(str(e))
            code = 1
            result = "[ReportInfo] run error"
        return (code,result)
예제 #2
0
파일: setting.py 프로젝트: jacknjzhou/proj
 def _loadsetting():
     global _LOG_DIR,_LOG_LEVEL,_LOG_FILE,_SVR_PORT,_PROJ_NAME,_SVR_TYPE
     conf = Conf(_CONF_FILE)
     _LOG_DIR=os.getcwd()+conf.get("LOG", "dir", "/log")
     _SVR_PORT=conf.get_int("SVR","port",9999)
     _LOG_LEVEL=conf.get("LOG","level","debug")
     _LOG_FILE=conf.get("LOG","file","process")
     _PROJ_NAME=conf.get("PROJ", "name","demo")
     _SVR_TYPE = conf.get("SVR","type","udp")
     return
예제 #3
0
#!-*-encoding:utf8-*-
# @summary:upload file from local to remote host
# @author:jackson
import os
import traceback
from comm.config import Conf
from comm.log import log

conf = Conf(os.getcwd()+"/conf/server.ini")

local_dir = conf.get("UPLOAD","svr.local.dir", "/data/package/")
remote_dir = conf.get("UPLOAD","agent.remote.dir","/tmp/")
agent_user=conf.get("UPLOAD","agent.user","")
agent_pwd = conf.get("UPLOAD","agent.password","")

transfor_tool_dir = os.getcwd()+"/transfor_tools/"

def new_upload_file(ip,file_name):
    """"""
    try:
        os.chmod(transfor_tool_dir+"/*.exp",755)
        lines = os.popen(transfor_tool_dir+"upload.exp %s %s %s %s %s"%(agent_user,ip,agent_pwd,local_dir+file_name,remote_dir+file_name)).readlines()
        strLines = " ".join(lines)
        if strLines.find("rsync error") !=-1:
                log("[Upload file [%s] fail]"%str(file_name))
                return False
        if strLines.find("Password error") !=-1:
            log("[Upload file [%s] fail,password error]"%str(file_name))
            return False
        if strLines.find("Timeout") !=-1:
            log("[Upload file [%s] fail,Timeout]"%str(file_name))
예제 #4
0
#-*-encoding:utf8-*-
import os
import pprint
import time
import zmq
import multiprocessing
import traceback

from comm.log import log
from comm.config import Conf
 
conf = Conf(os.getcwd()+'/conf/zmq.ini')
p_host = conf.get("ZMQSUB", "zmq.sub.host", "192.168.56.101")
p_port = conf.get_int("ZMQSUB", "zmq.sub.port", 5556)
p_topic = conf.get("ZMQSUB", "zmq.sub.topic", "log;task")

class ZMQSubProcess(object):
    
    def __init__(self):
        pass
    
    def run(self):
        try:
            while 1:
                print "start process-1"
                p1= ProcessMain("test-41","4")
                p1.start()
                p1.join()
                print "start process-5"
                p2= ProcessMain("test-5","5")
                p2.start()
예제 #5
0
 def __init__(self):
     self._conf = Conf(os.getcwd()+'/conf/agent.ini')
     self._get_conf() 
예제 #6
0
# Collects results from workers via that socket
#
# Author: Lev Givon <lev(at)columbia(dot)edu>

import os
import sys
import time
import zmq
import logging
import logging.handlers
#from comm.log import log
from comm.daemon import Daemon
from comm.config import Conf
# from comm.log import log
# 
conf = Conf(os.getcwd()+'/conf/zmq.ini')
# p_log_host=conf.get("ZMQPROCESS","zmq.log.host","localhost")
# p_log_port=conf.get("ZMQPROCESS","zmq.log.port","5559")
# 
p_sink_host=conf.get("ZMQPROCESS","zmq.sink.host","*")
p_sink_port=conf.get("ZMQPROCESS","zmq.sink.port","5558")
# p_sink_host = '192.168.56.101'
# p_sink_port ='5558'

# from d_log import init_logger
class Sink(Daemon):
#class Sink(object):
    
    def __init__(self,pidfile):
        super(Sink,self).__init__(pidfile)
        #pass
예제 #7
0
#!-*-coding:utf8-*-
# @author:jackson
# @summary:agent download file from remote host
import os
import subprocess
import hashlib
import base64

from comm.log import log
from comm.config import Conf

conf = Conf(os.getcwd()+'/conf/agent.ini')
p_ip = conf.get("DOWNLOAD", "pkg.svr.ip", "")
p_dir = conf.get("DOWNLOAD", "pkg.svr.dir", "/data/package")
p_user = conf.get("DOWNLOAD", "pkg.svr.user", "root")
p_password = conf.get("DOWNLOAD","pkg.svr.password","")



class DownLoadFile(object):
    
    def __init__(self):
        self._local_dir = "/tmp"
    
    def download_from_remote(self,pkg_path="",pkg_name="",md5_info=""):
        """"""
        #step-0:before download,check file is exist or not
        check_result = self.check_download(pkg_name, md5_info)
        if check_result:
            log("file or package already exist")
            return True
예제 #8
0
import random
import time
#from module.agent.callback_task_info import CallbackTaskInfo
#from comm.ret_data import ReturnData
from comm.config import Conf
from module.sql import Sql
from comm.redis_helper import RedisHelper

try:
    import simplejson as json
except:
    import json

from comm.log import log

conf = Conf(os.getcwd()+'/conf/cache.ini')
#local_dir = conf.get("UPLOAD", "svr.local.dir", "/data/package")

#get config connect db info,as global variable
db_ip=conf.get("DBServer","db.svr.ip","")
db_port=conf.get_int("DBServer","db.svr.port",3306)
db_user=conf.get("DBServer","db.svr.user","root")
db_pwd=conf.get("DBServer","db.svr.pwd","matrix")
db_name=conf.get("DBServer","db.name","oss_res")

redis_ip=conf.get("Redis","redis.svr.ip","")
redis_port=conf.get_int("Redis","redis.svr.port",6379)

class SyncCacheInfo(object):
    
    def __init__(self):
예제 #9
0
from comm.log import log
from comm.config import Conf

from comm.run_cmd import exec_cmd
from comm.run_cmd import get_local_ip
from comm.time_summary import stamp2time
try:
    import simplejson as json
except:
    import json
    
import traceback

from module.sql import Sql
    
conf = Conf(os.getcwd()+'/conf/server.ini')
local_dir = conf.get("UPLOAD", "svr.local.dir", "/data/package")

#get config connect db info,as global variable
db_ip=conf.get("DBServer","db.svr.ip","")
db_port=conf.get_int("DBServer","db.svr.port",3306)
db_user=conf.get("DBServer","db.svr.user","root")
db_pwd=conf.get("DBServer","db.svr.pwd","root")
db_name=conf.get("DBServer","db.name","")

from module.cron.host_usage_info import memory_stat
from module.cron.cpu_usage import CPUUsage

class PkgInfoMgr(object):
    
    def __init__(self,router_obj=None):
예제 #10
0
# Task sink
# Binds PULL socket to tcp://localhost:5558
# Collects results from workers via that socket
#
# Author: Lev Givon <lev(at)columbia(dot)edu>

import os
import sys
import time
import zmq
#from comm.log import log
from comm.daemon import Daemon
from comm.mp_log import log
from comm.config import Conf

conf = Conf(os.getcwd()+'/conf/zmq.ini')
p_log_host=conf.get("ZMQPROCESS","zmq.log.host","*")
p_log_port=conf.get("ZMQPROCESS","zmq.log.port","5559")


class TLog(Daemon):
    
    def __init__(self,pidfile):
        super(TLog,self).__init__(pidfile)
    
    def run(self):
        
        try:
            context = zmq.Context()
            
            # Socket to receive messages on
예제 #11
0
파일: send.py 프로젝트: jacknjzhou/proj
#!-*-encoding:utf8-*-
import os
import pika
import traceback
from comm.log import log
from comm.config import Conf

CONF_FILE=os.getcwd()+'/conf/conf.ini'
conf_obj = Conf(CONF_FILE)
rmq_host = conf_obj.get("MQ","host.ip","localhost")

def send_callback(info,queue_name ="callback"):
    try:
        connection = pika.BlockingConnection(pika.ConnectionParameters(
                host='localhost'))
        channel = connection.channel()

        channel.queue_declare(queue="task_queue")
        channel.basic_publish(exchange='',
                              routing_key=queue_name,
                              body=info)
        print " [x] Sent Info into queue:",queue_name
        connection.close()
    except Exception,e:
        print "send callback Error."
        log(traceback.print_exc())

if __name__ =="__main__":
    send_callback("ddddd")
예제 #12
0
import subprocess

from comm.daemon import Daemon
from comm.config import Conf

#add external class
try:
    from module.zmq_queue.tpkg.step_define import METHOD_MAP
except:
    from step_define import METHOD_MAP
try:
    from module.zmq_queue.tpkg.send_format import stream_json_format
except:
    from send_format import stream_json_format
#
conf = Conf(os.getcwd()+'/conf/zmq.ini')
p_ventilator_host=conf.get("ZMQPROCESS","zmq.ventilator.host","localhost")
p_ventilator_port=conf.get("ZMQPROCESS","zmq.ventilator.port","5557")
 
p_sink_host=conf.get("ZMQPROCESS","zmq.sink.host","localhost")
p_sink_port=conf.get("ZMQPROCESS","zmq.sink.port","5558")

# p_ventilator_host="192.168.56.101"
# p_ventilator_port ="5557"
# 
# p_sink_host="192.168.56.101"
# p_sink_port="5558"

class Worker(object):
    def __init__(self,name=""):
        self._name=name