def startwork(config=None, logger=None): """Main start """ fullURL = getFullUrl(config) agents = getDataFromSiteFE({}, fullURL, "/sitefe/json/frontend/ips") if agents[2] != 'OK': print 'Received a failure getting information from Site Frontend %s' % str( agents) return workDir = config.get('frontend', 'privatedir') + "/forwardingService/" createDirs(workDir) copy2("/etc/httpd/conf.d/sitefe-httpd.conf", str(workDir + "httpd-copy.conf")) httpdCopy = readFile(str(workDir + "httpd-copy.conf")) try: newDict = evaldict(agents[0]) except FailedToParseError as ex: print 'Server returned not a json loadable object. Raising error. Output %s. Errors: %s' % ( str(agents), ex) return if not newDict: print 'Seems server returned empty dictionary. Exiting.' return newOut, changed = prepareNewHTTPDConfig(newDict, httpdCopy) if changed: writeNewConfig(newOut, workDir) copy2(str(workDir + "httpd-new.conf"), "/etc/httpd/conf.d/sitefe-httpd.conf") stdout = externalCommand("service httpd restart") print stdout # Restart apache... return
def getData(self, fullURL, URLPath): """ Get data from FE """ agents = getDataFromSiteFE({}, fullURL, URLPath) if agents[2] != 'OK': msg = 'Received a failure getting information from Site Frontend %s' % str( agents) self.logger.debug(msg) return {} return evaldict(agents[0])
def setHostState(self, state, deltaid): """ Push Internal action and return dict """ restOut = getDataFromSiteFE({}, self.fullURL, "/sitefe/v1/deltas/%s/internalaction/%s/%s" % (deltaid, self.hostname, state)) if restOut[1] >= 400: self.logger.info("Failed to set new state in database for %s delta \ and %s hostname. Error %s " % (deltaid, self.hostname, restOut)) raise FailedInterfaceCommand("Failed to set new state in database for %s delta \ and %s hostname. Error %s " % (deltaid, self.hostname, restOut)) return restOut
def getData(self, url): """ Get data from FE """ self.logger.info('Query: %s%s' % (self.fullURL, url)) out = getDataFromSiteFE({}, self.fullURL, url) if out[2] != 'OK': msg = 'Received a failure getting information from Site Frontend %s' % str(out) self.logger.critical(msg) return {} if self.debug: self.pretty.pprint(evaldict(out[0])) self.logger.info('End function checkdeltas') return evaldict(out[0])
def pushInternalAction(self, url, state, deltaID, hostname): """ Push Internal action and return dict """ newState = "" restOut = {} restOut = getDataFromSiteFE( {}, url, "/sitefe/v1/deltas/%s/internalaction/%s/%s" % (deltaID, hostname, state)) if restOut[1] >= 400: msg = "Failed to set new state in database for %s delta and %s hostname. Error %s " \ % (deltaID, hostname, restOut) self.logger.debug(msg) raise FailedInterfaceCommand(msg) restOutHIDs = getDataFromSiteFE({}, url, "/sitefe/v1/hostnameids/%s" % hostname) tmpOut = evaldict(restOutHIDs[0]) newState = tmpOut[deltaID] msg = 'New State on the rest is %s and requested %s' % (newState, state) self.logger.debug(msg) if newState != state: time.sleep(4) return evaldict(restOut)
def getData(self, url): """Get data from FE.""" self.logger.info('Query: %s%s' % (self.fullURL, url)) out = getDataFromSiteFE({}, self.fullURL, url) if out[2] != 'OK': msg = 'Received a failure getting information from Site Frontend %s' % str( out) self.logger.critical(msg) return {} if self.config.getboolean('general', "debug"): pretty = pprint.PrettyPrinter(indent=4) self.logger.debug(pretty.pprint(evaldict(out[0]))) return evaldict(out[0])
def startwork(config=None, logger=None): """Main start """ errors = [] agents = getDataFromSiteFE({}, "http://localhost/", "/sitefe/json/frontend/getdata") if agents[2] != 'OK': print 'Received a failure getting information from Site Frontend %s' % str( agents) return workDir = CONFIG.get('frontend', 'privatedir') + "/notificationService/" mailingSender = CONFIG.get('NotificationService', 'mailingSender') mailingList = CONFIG.get('NotificationService', 'mailingList').split(',') createDirs(workDir) jOut = {} try: jOut = evaldict(agents[0]) except FailedToParseError as ex: print 'Server returned not a json loadable object. Raising error. Output %s. Errors: %s' % ( str(agents), ex) return # We start with simple error messages for ipaddr, values in jOut.items(): # Check if there is any error first checkPluginErrors(ipaddr, values, errors) checkCertLifeTime(ipaddr, values, errors) warningsFromMonComponent(ipaddr, values, errors) # Compare errors with previous run and send email only if there is something new... lastErrors = readFile(str(workDir + "lastRunErrors.json")) if lastErrors: try: lastErrors = evaldict(lastErrors[0]) except FailedToParseError as ex: print 'Loaded object from the system is not evaluable. Raising error. \ Output %s. Errors: %s' % (str(lastErrors), ex) print 'Ignoring and continue as there was no errors before' lastErrors = [] newErrors = [] if lastErrors and errors: newErrors = compareErrors(lastErrors, errors) elif errors: # Means there is no previous errors. print errors elif lastErrors and not errors: print 'All errors were resolved...' print lastErrors, errors, newErrors if newErrors: prepareMailSend(newErrors, mailingSender, mailingList) writeNewFile(errors, workDir) return