def run_prerun(): _setup_logging() if helpers.is_live_cd(): _log.info('live cd, skipping cron action') return _update_graphs(quick=True)
def run_hourly(): _setup_logging() if helpers.is_live_cd(): _log.info('live cd, skipping cron action') return _rdf_database_stats() _interface_stats()
def run_everyfiveminutes(): _setup_logging() if helpers.is_live_cd(): _log.info('live cd, skipping cron action') return if os.path.exists(constants.DEBUGGRAPHS_MARKERFILE): _draw_debug_graphs()
def show_cron_watchdog_notify(): _setup_logging() if helpers.is_live_cd(): _log.info('live cd, skipping cron action') return _log.warning('trying to show cron watchdog notify') try: from codebay.l2tpserver import gnomehelpers gnomehelpers.show_notification(constants.CRON_WATCHDOG_WARNING_TITLE, constants.CRON_WATCHDOG_WARNING_TEXT, timeout=constants.CRON_WATCHDOG_WARNING_TIMEOUT, critical=True) except: _log.exception("show_cron_watchdog_notify() failed")
def run_minutely(): # We want to do the cron watchdog check immediately for two reasons # First, we don't want to do any RDF operations before we're happy # with the watchdog check, as we may get stuck otherwise. Second, # we don't want to do any log operations either, as opening the log # device when the syslog daemon is missing causes trouble. Hence, # we run watchdog checks, and try to log any interesting things # after a possible watchdog action has been initiated. # # Also, sqlite-based RDF database may cause some trouble here. Watchdog # check is not dependent on RDF, but graph update is and may block for a # long time if a lock is held by someone. Further, sqlite does not ensure # fairness for those competing for database access, so we may starve or # become a bit hungry here. # # However, cron happily starts multiple instances of this script in parallel # (once every minute), so even if we deadlock to RDF database, the watchdog # here will successfully reboot. # XXX: _check_ui_health() is currently not fixed to work with it, but # this would ideally happen after the _check_ui_health() call _setup_logging() if helpers.is_live_cd(): _log.info('live cd, skipping cron action') return _check_ui_health() # XXX: graphs update may take time in which case we do not want to start # new update again while the old is still running if os.path.exists(constants.CRON_MINUTELY_RUNNING_MARKERFILE): _log.warning('detected cron run_minutely still running, stopping before actual operations') return try: helpers.write_datetime_marker_file(constants.CRON_MINUTELY_RUNNING_MARKERFILE) try: _update_graphs(quick=False) except: _log.exception('graph update failed') try: _update_snmp() except: _log.exception('snmp update failed') finally: if os.path.exists(constants.CRON_MINUTELY_RUNNING_MARKERFILE): os.unlink(constants.CRON_MINUTELY_RUNNING_MARKERFILE)
def _do_mgmt_identify_args(self): root = self.rdf_root licinfo = self.rdf_root.getS(ns_ui.licenseInfo, rdf.Type(ns_ui.LicenseInfo)) uiconfig = self.rdf_root.getS(ns_ui.uiConfig, rdf.Type(ns_ui.UiConfig)) args = {} try: ui_root = helpers.get_ui_config() if ui_root.hasS(ns_ui.licenseKey) and ui_root.getS( ns_ui.licenseKey, rdf.String) != '': args['licenseKey'] = ui_root.getS(ns_ui.licenseKey, rdf.String) elif ui_root.hasS(ns_ui.testLicenseKey) and ui_root.getS( ns_ui.testLicenseKey, rdf.String) != '': args['licenseKey'] = ui_root.getS(ns_ui.testLicenseKey, rdf.String) else: raise Exception('no configured license') except: args['licenseKey'] = '' # anonymous try: t = helpers.get_boot_uuid() if t is None: args['bootUuid'] = '' else: args['bootUuid'] = t except: args['bootUuid'] = '' try: t = helpers.get_installation_uuid() if t is None: args['installationUuid'] = '' else: args['installationUuid'] = t except: args['installationUuid'] = '' try: t = helpers.get_cookie_uuid() if t is None: args['cookieUuid'] = '' else: args['cookieUuid'] = t except: args['cookieUuid'] = '' args['address'] = '0.0.0.0' # overridden by managementconnection args['port'] = 0 # overridden by managementconnection try: args['softwareVersion'] = helpers.get_product_version() except: args['softwareVersion'] = '' args['softwareBuildInfo'] = '' # XXX args['hardwareType'] = '' # XXX args['hardwareInfo'] = '' # XXX try: if self.force_update: args['automaticUpdates'] = True else: args['automaticUpdates'] = uiconfig.getS( ns_ui.automaticUpdates, rdf.Boolean) except: args['automaticUpdates'] = True try: args['isLiveCd'] = helpers.is_live_cd() except: args['isLiveCd'] = False return args
def is_live_cd(self): return helpers.is_live_cd()
def mgmt_identify_args(self): args = {} try: # prefer actual license, then test (demo) license, then anonymous ui_root = helpers.get_ui_config() if ui_root.hasS(ns_ui.licenseKey) and ui_root.getS(ns_ui.licenseKey, rdf.String) != "": args["licenseKey"] = ui_root.getS(ns_ui.licenseKey, rdf.String) elif ui_root.hasS(ns_ui.testLicenseKey) and ui_root.getS(ns_ui.testLicenseKey, rdf.String) != "": args["licenseKey"] = ui_root.getS(ns_ui.testLicenseKey, rdf.String) else: raise Exception("no configured license") except: args["licenseKey"] = "" # anonymous try: t = helpers.get_boot_uuid() if t is None: args["bootUuid"] = "" else: args["bootUuid"] = t except: args["bootUuid"] = "" try: t = helpers.get_installation_uuid() if t is None: args["installationUuid"] = "" else: args["installationUuid"] = t except: args["installationUuid"] = "" try: t = helpers.get_cookie_uuid() if t is None: args["cookieUuid"] = "" else: args["cookieUuid"] = t except: args["cookieUuid"] = "" args["address"] = "0.0.0.0" # XXX: overwritten args["port"] = 0 # XXX: overwritten try: args["softwareVersion"] = helpers.get_product_version() except: args["softwareVersion"] = "" args["softwareBuildInfo"] = "" # XXX args["hardwareType"] = "" # XXX args["hardwareInfo"] = "" # XXX try: args["automaticUpdates"] = helpers.get_ui_config().getS(ns_ui.automaticUpdates, rdf.Boolean) except: args["automaticUpdates"] = True try: args["isLiveCd"] = helpers.is_live_cd() except: args["isLiveCd"] = False return args
def _do_mgmt_identify_args(self): root = self.rdf_root licinfo = self.rdf_root.getS(ns_ui.licenseInfo, rdf.Type(ns_ui.LicenseInfo)) uiconfig = self.rdf_root.getS(ns_ui.uiConfig, rdf.Type(ns_ui.UiConfig)) args = {} try: ui_root = helpers.get_ui_config() if ui_root.hasS(ns_ui.licenseKey) and ui_root.getS(ns_ui.licenseKey, rdf.String) != '': args['licenseKey'] = ui_root.getS(ns_ui.licenseKey, rdf.String) elif ui_root.hasS(ns_ui.testLicenseKey) and ui_root.getS(ns_ui.testLicenseKey, rdf.String) != '': args['licenseKey'] = ui_root.getS(ns_ui.testLicenseKey, rdf.String) else: raise Exception('no configured license') except: args['licenseKey'] = '' # anonymous try: t = helpers.get_boot_uuid() if t is None: args['bootUuid'] = '' else: args['bootUuid'] = t except: args['bootUuid'] = '' try: t = helpers.get_installation_uuid() if t is None: args['installationUuid'] = '' else: args['installationUuid'] = t except: args['installationUuid'] = '' try: t = helpers.get_cookie_uuid() if t is None: args['cookieUuid'] = '' else: args['cookieUuid'] = t except: args['cookieUuid'] = '' args['address'] = '0.0.0.0' # overridden by managementconnection args['port'] = 0 # overridden by managementconnection try: args['softwareVersion'] = helpers.get_product_version() except: args['softwareVersion'] = '' args['softwareBuildInfo'] = '' # XXX args['hardwareType'] = '' # XXX args['hardwareInfo'] = '' # XXX try: if self.force_update: args['automaticUpdates'] = True else: args['automaticUpdates'] = uiconfig.getS(ns_ui.automaticUpdates, rdf.Boolean) except: args['automaticUpdates'] = True try: args['isLiveCd'] = helpers.is_live_cd() except: args['isLiveCd'] = False return args