示例#1
0
 def cleanConfig(self):
     """ clean all configs """
     LOG.info('clean agent config overrides')
     result = {}
     try:
         result = manifestutil.updateServiceCatMeta('agent', manifestutil.CFG_META, None)
         return doneResult(request, response, result = result, controller = self)
         
     except Exception as excep:
         return errorResult(request, response, error = Errors.UNKNOWN_ERROR,
                            errorMsg = 'Unknown error when clean agent configs %s - %s' %
                            (str(excep), traceback.format_exc(2)), controller = self)
     finally:
         # reload config overrides
         configutil.loadConfigOverrides()
示例#2
0
 def cleanConfig(self):
     """ clean all configs """
     LOG.info('clean agent config overrides')
     result = {}
     try:
         result = manifestutil.updateServiceMetaFile('agent', {'configs': None})
         return doneResult(request, response, result = result, controller = self)
         
     except Exception as excep:
         return errorResult(request, response, error = Errors.UNKNOWN_ERROR,
                            errorMsg = 'Unknown error when clean agent configs %s - %s' %
                            (str(excep), traceback.format_exc(2)), controller = self)
     finally:
         # reload config overrides
         configutil.loadConfigOverrides()
示例#3
0
 def pokeConfig(self):
     """ config poke """
     LOG.info('config poke agent with body: %s', request.body)
     configs = None
     result = {}
     try:
         if request.body:
             body = json.loads(request.body)
             if 'configs' in body:
                 configs = body['configs']
                 result = manifestutil.updateServiceCatMeta('agent', manifestutil.CFG_META, configs)
                 return doneResult(request, response, result = result, controller = self)
         
         raise AgentException(Errors.INVALID_REQUEST, 'Invalid request, expect configs in request body')
         
     except Exception as excep:
         return errorResult(request, response, error = Errors.UNKNOWN_ERROR,
                            errorMsg = 'Unknown error when update agent configs %s - %s' %
                            (str(excep), traceback.format_exc(2)), controller = self)
     finally:
         # reload config overrides
         configutil.loadConfigOverrides()
示例#4
0
 def pokeConfig(self):
     """ config poke """
     LOG.info('config poke agent with body: %s', request.body)
     configs = None
     result = {}
     try:
         if request.body:
             body = json.loads(request.body)
             if 'configs' in body:
                 configs = body['configs']
                 result = manifestutil.updateServiceMetaFile('agent', {'configs': configs})
                 return doneResult(request, response, result = result, controller = self)
         
         raise AgentException(Errors.INVALID_REQUEST, 'Invalid request, expect configs in request body')
         
     except Exception as excep:
         return errorResult(request, response, error = Errors.UNKNOWN_ERROR,
                            errorMsg = 'Unknown error when update agent configs %s - %s' %
                            (str(excep), traceback.format_exc(2)), controller = self)
     finally:
         # reload config overrides
         configutil.loadConfigOverrides()
示例#5
0
def startAgentGlobals(startThreadMgr = True, startPackageMgr = True, startAgentMonitor = True):
    """
    Create and start the global objects
    """
    # cleanup incomplete manifests
    from agent.controllers.service import ServiceController
    ServiceController.cleanupServices()

    # stop the existing agents
    stopAgentGlobals()
    
    appGlobal = pylons.config['pylons.app_globals']

    # load config override from agent .metadata.json
    configutil.loadPylonConfig(pylons.config)
    configutil.loadConfigOverrides()
    configutil.loadSecureConfigOverrides()
    LOG.info("Complete loading config overrides")

    # build in memory security token cache
    appGlobal.authztoken = str(uuid.uuid4())
    appGlobal.encryptedtokens = {}
    agentauth.buildTokenCache(appGlobal.authztoken)
    LOG.info("Complete building security token cache")

    # agent health
    appGlobal.agentHealth = 'True'
    appGlobal.agentHealthFactor = None
    from datetime import datetime
    appGlobal.agentInfo = {'version': agenthealth.loadVersion(),
                           'startup': str(datetime.now())}

    appGlobal.osInfo = agenthealth.getOsInfo()
    appGlobal.diskOk = True
    LOG.info("Agent health initialized")

    # start thread mgr
    appGlobal.threadMgr = ThreadMgr(garbageFreq = pylons.config['threadMgr_garbage_freq'],
                                    maxThreadAge = pylons.config['threadMgr_thread_age'])
    if startThreadMgr:
        appGlobal.threadMgr.start()
    LOG.info("Agent thread manager started")

    # start package mgr
    appGlobal.packageMgr = PackageMgr(garbageFreq = pylons.config['packageMgr_garbage_freq'],
                                      maxPackageAge = pylons.config['packageMgr_package_age'])
    if startPackageMgr:
        appGlobal.packageMgr.start()
    LOG.info("Agent package manager started")

    #start monitor manager
    from agent.lib.monitors.monitor import AgentMonitor
    appGlobal.agentMonitor = AgentMonitor()
    if startAgentMonitor:
        appGlobal.agentMonitor.start()
    LOG.info("Agent monitor started")
    
    # Declare dictionary for storing dynamic controllers
    appGlobal.dynacontrollers = dict()

    # metrix manager initialization
    from agent.lib.monitors.metrix_manager import MetrixManager
    from agent.lib.monitors.system_monitor import SystemMonitor
    appGlobal.metrixManager = MetrixManager()
    appGlobal.systemMonitor = SystemMonitor()

    appGlobal.metrixManager.register('Configuration', validate_internals.getConfigFileFiltered, 6)
    appGlobal.metrixManager.register('Configuration Overrides', configutil.getConfigOverrides, 7)
    appGlobal.metrixManager.register(AGENT_HEALTH_VI_KEY, lambda : appGlobal.agentHealth, 1)
    appGlobal.metrixManager.register(AGENT_HEALTH_FACTOR_VI_KEY, lambda : appGlobal.agentHealthFactor, 1)
    appGlobal.metrixManager.register(OS_INFO_KEY, lambda : appGlobal.osInfo, 3)
    appGlobal.metrixManager.register(AGENT_INFO_KEY, lambda : appGlobal.agentInfo, 2)
    LOG.info("Agent health metrics registered")
    
    # start all agent modules
    modulestartthread = threading.Thread(target = ModuleController.loadModuleOnAgentStartup)
    modulestartthread.start()
    LOG.info("Local modules started")

    # start all services with active manifest, and load dynamic controllers
    servicestartthread = threading.Thread(target = ServiceController.startServicesOnAgentStartup)
    servicestartthread.start()
    LOG.info("Local services started")

    appGlobal.sdutil = shutdownAgent
示例#6
0
def startAgentGlobals(startThreadMgr=True,
                      startPackageMgr=True,
                      startAgentMonitor=True):
    """
    Create and start the global objects
    """
    # cleanup incomplete manifests
    from agent.controllers.service import ServiceController
    ServiceController.cleanupServices()

    # stop the existing agents
    stopAgentGlobals()

    appGlobal = pylons.config['pylons.app_globals']

    # load config override from agent .metadata.json
    configutil.loadPylonConfig(pylons.config)
    configutil.loadConfigOverrides()
    LOG.info("Complete loading config overrides")

    # build in memory security token cache
    appGlobal.authztoken = str(uuid.uuid4())
    appGlobal.encryptedtokens = {}
    agentauth.buildTokenCache(appGlobal.authztoken)
    LOG.info("Complete building security token cache")

    # agent health
    appGlobal.agentHealth = 'True'
    appGlobal.agentHealthFactor = None
    from datetime import datetime
    appGlobal.agentInfo = {
        'version_wiri': agenthealth.loadVersion(),
        'startup_time': str(datetime.now())
    }

    appGlobal.osInfo = agenthealth.getOsInfo()
    appGlobal.diskOk = True
    appGlobal.autoRestartEnabled = asbool(
        pylons.config['auto_restart_enabled'])
    LOG.info("Agent health initialized")

    # start thread mgr
    appGlobal.threadMgr = ThreadMgr(
        garbageFreq=pylons.config['threadMgr_garbage_freq'],
        maxThreadAge=pylons.config['threadMgr_thread_age'])
    if startThreadMgr:
        appGlobal.threadMgr.start()
    LOG.info("Agent thread manager started")

    # start package mgr
    appGlobal.packageMgr = PackageMgr(
        garbageFreq=pylons.config['packageMgr_garbage_freq'],
        maxPackageAge=pylons.config['packageMgr_package_age'])
    if startPackageMgr:
        appGlobal.packageMgr.start()
    LOG.info("Agent package manager started")

    # now load saved .metadata for previously saved hwPath, serverAddress, and serverAuth
    enrollMeta = manifestutil.readJsonServiceMeta('agent', ['hwPath'])
    hwPath = enrollMeta.get('hwPath')
    if hwPath is not None:
        appGlobal.hwPath = hwPath
    LOG.info("Agent hwPath loaded")

    #start monitor manager
    from agent.lib.monitors.monitor import AgentMonitor
    appGlobal.agentMonitor = AgentMonitor()
    if startAgentMonitor:
        appGlobal.agentMonitor.start()
    LOG.info("Agent monitor started")

    # start graphite udp server
    #     from agent.lib.monitors.graphited import GraphiteDServer
    #     from multiprocessing import Pipe
    #     graphiteEnabled = configutil.getConfigAsBool('graphite_enabled')
    #     if startAgentMonitor and graphiteEnabled:
    #         output_p, input_p = Pipe()
    #         appGlobal.graphited = GraphiteDServer(input_p)
    #         appGlobal.graphited.start()
    #         udpMsgProcessThread = threading.Thread(target=GraphiteDServer.read_queue, args=(output_p,))
    #         udpMsgProcessThread.daemon = True
    #         udpMsgProcessThread.start()
    #         LOG.info("Agent graphited started")

    # Declare dictionary for storing dynamic controllers
    appGlobal.dynacontrollers = dict()

    # metrix manager initialization
    from agent.lib.monitors.metrix_manager import MetrixManager
    from agent.lib.monitors.system_monitor import SystemMonitor
    appGlobal.metrixManager = MetrixManager()
    appGlobal.systemMonitor = SystemMonitor()
    appGlobal.metrixManager.register('OS', appGlobal.systemMonitor.getOSinfo,
                                     1)
    appGlobal.metrixManager.register('Node Name',
                                     appGlobal.systemMonitor.getNodeName, 1)
    appGlobal.metrixManager.register('Free Memory(KB)',
                                     appGlobal.systemMonitor.getFreeMemory, 2)
    appGlobal.metrixManager.register('CPU Usage(%)',
                                     appGlobal.systemMonitor.getCpuUsage, 2)

    appGlobal.metrixManager.register('Version', agenthealth.loadVersion, 5)
    appGlobal.metrixManager.register('Configuration',
                                     validate_internals.getConfigFile, 6)
    appGlobal.metrixManager.register('Configuration Overrides',
                                     configutil.getConfigOverrides, 7)
    appGlobal.metrixManager.register(
        'hwPath', lambda: appGlobal.hwPath
        if hasattr(appGlobal, 'hwPath') else None, 5)
    appGlobal.metrixManager.register(AGENT_HEALTH_VI_KEY,
                                     lambda: appGlobal.agentHealth, 1)
    appGlobal.metrixManager.register(AGENT_HEALTH_FACTOR_VI_KEY,
                                     lambda: appGlobal.agentHealthFactor, 1)
    appGlobal.metrixManager.register(OS_INFO_KEY, lambda: appGlobal.osInfo, 2)
    appGlobal.metrixManager.register(AGENT_INFO_KEY,
                                     lambda: appGlobal.agentInfo, 2)
    LOG.info("Agent health metrics registered")

    # start all agent modules
    modulestartthread = threading.Thread(
        target=ModuleController.loadModuleOnAgentStartup)
    modulestartthread.start()
    LOG.info("Local modules started")

    # start all services with active manifest, and load dynamic controllers
    servicestartthread = threading.Thread(
        target=ServiceController.startServicesOnAgentStartup)
    servicestartthread.start()
    LOG.info("Local services started")

    appGlobal.sdutil = shutdownAgent