def cutover(self, dmd): try: ctx = sm.ServiceContext() except sm.ServiceMigrationError: log.info("Couldn't generate service context, skipping.") return commit = False # find the target services tsdb_services = filter( lambda sc: sc.name == 'reader' or sc.name == 'writer', ctx.services) if len(tsdb_services) == 0: log.info('reader & writer service not found, look for opentsdb') tsdb_services = filter(lambda sc: sc.name == 'opentsdb', ctx.services) log.info('found %s services to modify', len(tsdb_services)) # add new health checks to the services for svc in tsdb_services: health_check = HealthCheck( name="hbase_answering", interval=10.0, timeout=0, script=("curl -A 'HMaster rest_answering healthcheck'" " -o /dev/null -f" " -s http://localhost:61000/status/cluster")) svc.healthChecks.append(health_check) log.info("added 'HBase answering' healthcheck for %s.", svc.name) commit = True if commit: ctx.commit()
def cutover(self, dmd): try: ctx = sm.ServiceContext() except sm.ServiceMigrationError: log.info("Couldn't generate service context, skipping.") return service_ready_healthcheck = HealthCheck( name="service_ready", interval=10.0, script="echo 'QUIT' | nc -w 10 -C 127.0.0.1 50025 | grep -q '^220 '" ) zenmail_services = filter(lambda s: s.name == "zenmail", ctx.services) log.info("Found %i services named 'zenmail'." % len(zenmail_services)) for zenmail_service in zenmail_services: if not filter(lambda c: c.name == 'service_ready', zenmail_service.healthChecks): log.info("Service_ready healthcheck not found; adding.") zenmail_service.healthChecks.append(service_ready_healthcheck) else: log.info("Service_ready healthcheck found; skipping.") # Commit our changes. ctx.commit()
def cutover(self, dmd): try: ctx = sm.ServiceContext() except sm.ServiceMigrationError: log.info("Couldn't generate service context, skipping.") return script_template = "curl -A '{NAME} deadlock healthcheck' --max-time 30 -s http://localhost:{PORT}/zport/ruok" port_pattern = ".*curl -A '([A-z]+) answering healthcheck.*localhost:([0-9]+).*" pattern = re.compile(port_pattern) commit = False zopes = filter( lambda s: s.name.lower( ) in ["zope", "zauth", "zenapi", "zendebug", "zenreports"], ctx.services) log.info("Found %i Zope services." % len(zopes)) for z in zopes: if not filter(lambda c: c.name == 'deadlock_check', z.healthChecks): log.info( "The {} service is missing the deadlock_check; adding it.". format(z.name)) # we need to add the new hc. the main problem is that the zope port changes based on which # type of service/tree it comes from. answering = filter(lambda c: c.name == 'answering', z.healthChecks) if not answering: log.warn("Unable to find the zope answering healthcheck") continue # grab the service name and port out of the answering healthcheck. answering = answering[0] match = pattern.match(answering.script) if not match: log.warn("Unable to parse the zope name/port from {}: {}". format(answering.name, answering.script)) continue name = match.group(1) port = match.group(2) hc = HealthCheck( name="deadlock_check", script=script_template.format(NAME=name, PORT=port), interval=30.0, kill_count_limit=3, kill_exit_codes=[28], ) z.healthChecks.append(hc) commit = True if commit: ctx.commit()
def cutover(self, dmd): try: ctx = sm.ServiceContext() except sm.ServiceMigrationError: log.info("Couldn't generate service context, skipping.") return websocket_opened_healthcheck = HealthCheck( name="websocket_opened", interval=10.0, script="/opt/zenoss/bin/healthchecks/MetricShipper/websocket_opened" ) MetricShipper_service = filter(lambda s: s.name == "MetricShipper", ctx.services)[0] if not filter(lambda c: c.name == 'websocket_opened', MetricShipper_service.healthChecks): MetricShipper_service.healthChecks.append( websocket_opened_healthcheck) ctx.commit()
def cutover(self, dmd): try: ctx = sm.ServiceContext() except sm.ServiceMigrationError: log.info("Couldn't generate service context, skipping.") return changed = False # If the service lacks Solr, add it now. solr = filter(lambda s: s.name == "Solr", ctx.services) log.info("Found %i services named 'Solr'." % len(solr)) if not solr: imageid = os.environ['SERVICED_SERVICE_IMAGE'] log.info("No Solr found; creating new service.") new_solr = default_solr_service(imageid) infrastructure = ctx.findServices('^[^/]+/Infrastructure$')[0] ctx.deployService(json.dumps(new_solr), infrastructure) changed = True # Remove the zencatalogservice-uri global conf option from the top service zenoss = ctx.getTopService() global_conf = zenoss.context if global_conf and "global.conf.zencatalogservice-uri" in global_conf: del global_conf["global.conf.zencatalogservice-uri"] changed = True # Now healthchecks solr_answering_healthcheck = HealthCheck( name="solr_answering", interval=10.0, script= "curl -A 'Solr answering healthcheck' -s http://localhost:8983/solr/zenoss_model/admin/ping?wt=json | grep -q '\"status\":\"OK\"'" ) for svc in ctx.services: # Remove zencatalogservice, if it still exists if svc.name == "zencatalogservice": svcid = svc._Service__data['ID'] # ZEN-28127: during unittests, ctx is an instance of # FakeServiceContext which is set to None. if ctx._client is not None: ctx._client.deleteService(svcid) ctx.services.remove(svc) changed = True continue # Remove zencatalogservice response prereq and add solr one for pr in svc.prereqs[:]: if pr.name == "zencatalogservice response": svc.prereqs.remove(pr) svc.prereqs.append( sm.Prereq( name='Solr answering', script= """curl -A 'Solr answering prereq' -s http://localhost:8983/solr/zenoss_model/admin/ping?wt=json | grep -q '\"status\":\"OK\"'""" )) changed = True # If we've got a solr_answering health check, we can stop. # Otherwise, remove catalogservice health checks and add Solr ones if filter(lambda c: c.name == 'solr_answering', svc.healthChecks): continue for hc in svc.healthChecks: if hc.name == "catalogservice_answering": svc.healthChecks.remove(hc) changed = True # Get rid of erroneous "solr" endpoints that some older migrations added and the "zodb_zencatalogservice" endpoint import that zenimpactstate may have eps_to_remove = filter( lambda ep: ep.purpose == 'import' and (ep.application == 'solr' or ep.application == 'zodb_zencatalogservice'), svc.endpoints) for ep in eps_to_remove: changed = True svc.endpoints.remove(ep) for ep in svc.endpoints: if ep.purpose == 'import' and ep.application == 'zodb_.*': svc.healthChecks.append(solr_answering_healthcheck) changed = True break filterName = 'solr' filename = 'Products/ZenModel/migrate/data/%s-6.0.0.conf' % filterName with open(zenPath(filename)) as filterFile: try: filterDef = filterFile.read() except Exception as e: log.error("Error reading {0} logfilter file: {1}".format( filename, e)) return log.info("Updating log filter named {0}".format(filterName)) changed = True ctx.addLogFilter(filterName, filterDef) if changed: ctx.commit()
'zenapi': '/opt/zenoss/etc/zenapi.conf', 'zendebug': '/opt/zenoss/etc/zendebug.conf', 'zenreports': '/opt/zenoss/etc/zenreports.conf', 'Zope': '/opt/zenoss/etc/zope.conf', } ZOPE_SESSION_PATTERN = re.compile('session.url([ ]*) 127.0.0.1:11211') MEMCACHED_SESSION_ENDPOINT = Endpoint(name="memcached-session", purpose="import", application="memcached-session", portnumber=11212, protocol="tcp") MEMCACHED_SESSION_HEALTHCHECK = HealthCheck( name="memcached_session_answering", interval=10.0, script="/opt/zenoss/bin/healthchecks/memcached_session_answering") class AddMemcachedForSessions(Migrate.Step): """ Update memcache healthcheck, and add the service to Core """ version = Migrate.Version(300, 0, 0) changed = False def cutover(self, dmd): try: ctx = sm.ServiceContext() except sm.ServiceMigrationError:
def cutover(self, dmd): try: ctx = sm.ServiceContext() except sm.ServiceMigrationError: log.info("Couldn't generate service context, skipping.") return # find the target services zope_svc = None zenhub_svc = None zenpy_svc = None for s in ctx.services: if s.name.lower() == "zope": zope_svc = s if s.name.lower() == "zenhub": zenhub_svc = s if s.name.lower() == "zenpython": zenpy_svc = s # remove intended zproxy_answering or previously added HC svcs = [s for s in [zope_svc, zenhub_svc, zenpy_svc] if s is not None] for svc in svcs: log.info("Processing service:%s.", svc.name) for hc in filter( lambda hc: hc.name == "zproxy_answering" or hc.name == "central_query_answering" or hc.name == "metric_consumer_answering", svc.healthChecks): svc.healthChecks.remove(hc) log.info("Removed healthcheck:%s from service:%s.", hc.name, svc.name) # add intended health checks query_hc = HealthCheck( name="central_query_answering", interval=10.0, script="/opt/zenoss/bin/healthchecks/query_answering") metrics_hc = HealthCheck( name="metric_consumer_answering", interval=10.0, script="/opt/zenoss/bin/healthchecks/metrics_answering") # adding hc to zenpython zenpy_svc.healthChecks.append(query_hc) log.info( "Updated 'central_query_answering' healthcheck for zenpython.") # adding hc to query zenhub zenhub_svc.healthChecks.append(query_hc) log.info("Updated 'Central_query_answering' healthcheck for zenhub.") zenhub_svc.healthChecks.append(metrics_hc) log.info("Updated 'metric_consumer_answering' healthcheck for zenhub.") # now fix the original nginx config files on disk top_svc = ctx.getTopService() if top_svc.name.find("Zenoss") == 0 or top_svc.name.find( "UCS-PM") == 0: # assuming the original files are all correct cfs = filter( lambda f: f.name == "/opt/zenoss/zproxy/conf/zproxy-nginx.conf", top_svc.originalConfigs) for cf in cfs: # fix dos mode to linux cf.content = cf.content.replace('\r\n', '\n') # skip if the file already contains the new entry if cf.content.find('location ^~ /ping/') > 0: log.info( "original zproxy-nginx.conf already contains 'ping' resource" ) continue # else insert the new entry behind the markered section marker = re.compile(r"(\s*location\s+/\s+{.+?})", re.DOTALL) if not marker.search(cf.content): continue cf.content = marker.sub( r"""\1 # inserted by 5.2.0 migration script location ^~ /ping/ { include zenoss-zapp-ping-nginx.cfg; proxy_no_cache 1; proxy_cache_bypass 1; proxy_set_header Host $myhost; proxy_method HEAD; } #""", cf.content, 1) log.info("updated zproxy-nginx.conf") ctx.commit()