def __init__(self, configIn, loggerIn, args=None): self.config, self.logger = getDefaultConfigAgent(COMPONENT, configIn, loggerIn) self.workDir = self.config.get('general', 'private_dir') + "/DTNRM/NetTester/jsons/" self.fdtworker = FDTWorker(self.config, self.logger) self.senseclient = self.config.get('general', 'sense_client') self.customInput = args createDirs(self.workDir) self.IPs = [] self.vlanConfDir = self.config.get('general', 'private_dir') + "/DTNRM/RulerAgent/" self.logger.info("==== NetTester Start Work.") self.agentdb = contentDB(logger=self.logger, config=self.config)
def __init__(self, config, logger): # You can call and use the DTNRM Libraries for getting configuration # or site frontend URL from configuration file, so that any information # is available at the plugin level self.config, self.logger = getDefaultConfigAgent(COMPONENT, config, logger) self.workDir = self.config.get('general', 'private_dir') + "/DTNRM/DTNRMPrint/" createDirs(self.workDir) self.fullURL = getFullUrl(self.config, self.config.get('general', 'siteName')) self.hostname = self.config.get('agent', 'hostname') self.logger.info("====== DTNRMPrint Start Work at __init__. Hostname: %s", self.hostname) self.debug = self.config.getboolean('general', "debug")
def __init__(self, config, logger): self.config, self.logger = getDefaultConfigAgent( COMPONENT, config, logger) self.workDir = self.config.get('general', 'private_dir') + "/DTNRM/QOS/" self.configDir = self.config.get('general', 'private_dir') + "/DTNRM/RulerAgent/" self.hostname = self.config.get('agent', 'hostname') createDirs(self.workDir) self.debug = self.config.getboolean('general', "debug") self.agentdb = contentDB(logger=self.logger, config=self.config)
def __init__(self, config, logger): self.config, self.logger = getDefaultConfigAgent(COMPONENT, config, logger) self.workDir = self.config.get('general', 'private_dir') + "/DTNRM/RulerAgent/" createDirs(self.workDir) self.fullURL = getFullUrl(self.config, self.config.get('general', 'siteName')) self.noRules = False if self.config.has_option('agent', 'norules'): self.noRules = self.config.getboolean('agent', 'norules') self.hostname = self.config.get('agent', 'hostname') self.logger.info("====== Ruler Start Work. Hostname: %s", self.hostname) self.debug = self.config.getboolean('general', "debug") self.pretty = pprint.PrettyPrinter(indent=4) self.agentdb = contentDB(logger=self.logger, config=self.config) self.vInterface = VInterfaces(self.config, self.logger) self.qosruler = QOS(self.config, self.logger)
def execute(configIn=None, loggerIn=None): """ Execute main script for DTN-RM Agent output preparation """ config, logger = getDefaultConfigAgent(COMPONENT, configIn, loggerIn) if not config.getboolean(COMPONENT, 'enabled'): logger.info('Component is not enabled in configuration.') return success, outConfig = getNetdataConfig() if not success: logger.warning('Failure receiving netdata configuration file. Exiting') exit(1) workDir = config.get('agent', 'PRIVATE_DIR') + "/DTNRM/" agentDB = contentDB(logger=logger, config=config) # TODO Implement enabled option and debug per each component. # if not config.getboolean(COMPONENT, 'enabled'): # return # http://vocms025.cern.ch:19999/api/v1/alarms?active&_=1508422746160 agents = makeGETRequest("http://localhost:19999/api/v1/alarms?active") out = { 'netdata.warnings': 0, 'netdata.critical': 0, 'sense.nodes': 1, 'sense.vlansInUse': 0, 'sense.vlansFree': 0, 'sense.vlansTotal': 0, 'sense.agentError': 0, 'sense.agentWarning': 0, 'sense.agent.recurringactions.status': 0, 'sense.agent.recurringactions.runtime': 0, 'sense.agent.ruler.status': 0, 'sense.agent.ruler.runtime': 0 } for _dKey, dVals in agents[1]['alarms'].items(): if dVals['status'] == 'WARNING': out['netdata.warnings'] += 1 elif dVals['status'] == 'CRITICAL': out['netdata.critical'] += 1 agentOut = agentDB.getFileContentAsJson(workDir + "/latest-out.json") for _interf, interfDict in agentOut['NetInfo'].items(): if 'vlan_range' in interfDict: lowR, highR = interfDict['vlan_range'].split(',') total = int(highR) - int(lowR) if total < 0: # TODO print error out['sense.agentError'] += 1 else: out['sense.vlansTotal'] += total out['sense.vlansInUse'] = len(interfDict['vlans']) free = out['sense.vlansTotal'] - out['sense.vlansInUse'] if free < 0: # TODO: print error out['sense.agentError'] += 1 else: out['sense.vlansFree'] = free if 'destination' in outConfig: splVal = outConfig['destination'].split(':') if len(splVal) == 3: destHostname = splVal[1] destPort = splVal[2] elif len(splVal) == 2: destHostname = splVal[0] destPort = splVal[1] else: print 'FAILURE. Was expecting protocol:ip:port or ip:port... Got Value: %s' % outConfig[ 'destination'] return else: print 'FAILURE. Backend is not configured' return metrics = potsdb.Client(destHostname, port=destPort, qsize=1000, host_tag=True, mps=100, check_host=True) for key, value in out.items(): metrics.send("monit.%s" % key, value, **outConfig['tags']) # waits for all outstanding metrics to be sent and background thread closes metrics.wait()
def startWork(config=None, logger=None): """ Execute main script for DTN-RM Agent output preparation """ workDir = config.get('general', 'private_dir') + "/DTNRM/" createDirs(workDir) dic = prepareJsonOut(config, logger) fullUrl = getFullUrl(config) dic = appendConfig(config, dic) if config.getboolean('general', "debug"): pretty = pprint.PrettyPrinter(indent=4) logger.debug(pretty.pformat(dic)) agent = contentDB(logger=logger, config=config) agent.dumpFileContentAsJson(workDir + "/latest-out.json", dic) logger.info('Will try to publish information to SiteFE') fullUrl += '/sitefe' outVals = publishToSiteFE(dic, fullUrl, '/json/frontend/updatehost') if outVals[2] != 'OK' or outVals[1] != 200: if outVals[3]: publishToSiteFE(dic, fullUrl, '/json/frontend/addhost') def execute(config, logger): startWork(config, logger) if __name__ == '__main__': CONFIG, LOGGER = getDefaultConfigAgent('agent') execute(CONFIG, LOGGER)