def generateCrashLogs(): '''This should be safe''' entries = [] loc = util.make_splunkhome_path(['var', 'log', 'splunk']) for name in sorted(os.listdir(loc), reverse=True): if name.startswith('crash') and name.endswith('log'): info = os.stat(os.path.join(loc,name)) if info.st_mtime > (time.time() - CRASH_WINDOW*60): h = open(os.path.join(loc,name), 'r') contents = '[UNREADABLE]' try: contents = ''.join(h.readlines()) finally: h.close() tmpItem = { 'filename': name, 'delta': time.time() - info.st_mtime, 'contents': contents } entries.append(tmpItem) if entries: output = ['<div id="crashes">'] output.append('<h2>Splunkd has recently crashed:</h2>') output.append('<dl>') for i, item in enumerate(entries): output.append('<dt><a href="javascript:void(0)" onclick="toggle(\'%s\')">%s</a> (%d minutes(s) ago)</dt>' % ('cl%s' % i, item['filename'], item['delta']/60)) output.append('<dd id="%s">%s</dd>' % ('cl%s' % i, su.escape(item['contents']))) output.append('</dl>') output.append('</div>') return ''.join(output) else: return ''
def _scanSystemModules(self): system_modules = [] system_modules_path = util.make_splunkhome_path(['share', 'splunk', 'search_mrsparkle', 'modules']) for module_dir in os.listdir(system_modules_path): if os.path.isdir(os.path.join(system_modules_path, module_dir) ): system_modules.append(module_dir) self.modules[module_dir] = appserver.mrsparkle.SYSTEM_NAMESPACE return system_modules
def generateCrashLogs(): '''This should be safe''' entries = [] loc = util.make_splunkhome_path(['var', 'log', 'splunk']) for name in sorted(os.listdir(loc), reverse=True): if name.startswith('crash') and name.endswith('log'): info = os.stat(os.path.join(loc, name)) if info.st_mtime > (time.time() - CRASH_WINDOW * 60): h = open(os.path.join(loc, name), 'r') contents = '[UNREADABLE]' try: contents = ''.join(h.readlines()) finally: h.close() tmpItem = { 'filename': name, 'delta': time.time() - info.st_mtime, 'contents': contents } entries.append(tmpItem) if entries: output = ['<div id="crashes">'] output.append('<h2>Splunkd has recently crashed:</h2>') output.append('<dl>') for i, item in enumerate(entries): output.append( '<dt><a href="javascript:void(0)" onclick="toggle(\'%s\')">%s</a> (%d minutes(s) ago)</dt>' % ('cl%s' % i, item['filename'], item['delta'] / 60)) output.append('<dd id="%s">%s</dd>' % ('cl%s' % i, su.escape(item['contents']))) output.append('</dl>') output.append('</div>') return ''.join(output) else: return ''
def refresh(self, force=True): """ Refresh the list of applications installed on the local machine """ apps_path = util.get_apps_dir() if self.loaded and not force: return True else: newapps = os.listdir(apps_path) ### will return a list to be appended by refresh() self.loaded = True # scan patch directory patch_dir = util.make_splunkhome_path(['share', 'splunk', 'search_mrsparkle', 'exposed', 'css', 'skins', 'default', 'patches']) patches = {} if os.path.exists(patch_dir): for patch_file in os.listdir(patch_dir): m = re.search("(\w+)\.css$", patch_file) if m: patches[m.group(1)] = '/static/css/skins/default/patches/%s' % patch_file for fn in newapps: path = os.path.join(apps_path, fn) if not os.path.isdir(path): continue self.apps[fn] = { 'full_path' : path, 'modules' : [], 'static' : {}, 'patch' : {'css': []}, } # See if the app defines any modules if os.path.exists(os.path.join(path, 'appserver', 'modules')): modules = self.apps[fn]['modules'] = self._scanAppModules(fn) for module in modules: self.modules[module] = fn # See if the app defines any static content if os.path.isdir(os.path.join(path, 'appserver', 'static')): self.apps[fn]['static'] = self._scanAppStaticContent( os.path.join(path, 'appserver', 'static') ) application_css_path = os.path.join(path, 'appserver', 'static', 'application.css') if os.path.exists(application_css_path): f = open(application_css_path, 'r') hash = hashlib.md5() hash.update(f.read()) digest = hash.hexdigest() f.close() patch_file_name = '%s-%s.css' % (fn, digest) if digest in patches: self.apps[fn]['patch']['css'].append(patches[digest]) # scan in the system built-in/default modules and put them in the system namespace self.apps[appserver.mrsparkle.SYSTEM_NAMESPACE] = { 'full_path': util.make_splunkhome_path(['share', 'splunk', 'search_mrsparkle']), 'modules' : self._scanSystemModules() } return True