def extractLevel1Feed(**kwargs): """ we need only the contents of the feed returned possibly with it being filtered serverContent > response from the server (assuming the status is 200) filter > a list of all the cli field names to filter on eg. ['web-port', 'splunkd-port', 'minfreemb'] With the above list the returned feed is filtered to display only the 'web-port', 'splunkd-port', 'minfreemb' values. Mapping b/w cli-eai field names happens in the background. """ atom = rest.format.parseFeedDocument(kwargs['serverContent']) if isinstance(atom, AtomEntry): d = nodeToPrimitive(atom.rawcontents) elif isinstance(atom, AtomFeed): d = nodeToPrimitive(atom[0].rawcontents) display = '' #logger.debug(str(d)) #logger.debug(kwargs['filter']) if kwargs.has_key('filter'): try: display += d[kwargs['filter'][0]] except TypeError: display = NO_INFO #if the contents of the desired tag in the returned feed is empty, the dict will contain None. Will get TypeError if a '+' op is attempted. So return NO_INFO. else: for k,v in d.items(): display += '%s:\t%s\n' % (k,v) return display
def displayJobs(**kwargs): """ """ if kwargs['cmd'] == 'list': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) if atomFeed: print ASYNC_SEARCH_JOBS for entry in atomFeed: d = nodeToPrimitive(entry.rawcontents) print '\tJob id: %s, ttl: %s\n' % (d['sid'], d['ttl']) else: print ASYNC_SEARCH_NONE elif kwargs['cmd'] == 'remove': if isinstance(kwargs['eaiArgsList']['jobid'], list): #we have tried to do a remove jobs all if kwargs['eaiArgsList']['jobid']: print ASYNC_REMOVE_ALL % ','.join(kwargs['eaiArgsList']['jobid']) else: print ASYNC_SEARCH_NONE else: print 'Job id "%s" removed.' % kwargs['eaiArgsList']['jobid'] elif kwargs['cmd'] == 'show': atom = rest.format.parseFeedDocument(kwargs['serverContent']) d = nodeToPrimitive(atom.rawcontents) print atom.title print '-'*len(atom.title) print '\n'.join(map(lambda x: '%s:%s' % (x[0], x[1]), d.items())) elif kwargs['cmd'] == 'display': try: searchjob = getJob(kwargs['eaiArgsList']['jobid'], sessionKey=kwargs['sessionKey']) except: displayGenericError(cmd=kwargs['cmd'], obj='jobs', err_msg='Job id "%s" not found' % kwargs['eaiArgsList']['jobid']) return displaySyncSearch(searchjob=searchjob, **kwargs)
def displayDistSearch(**kwargs): """ called for distributed search stuff """ if kwargs['cmd'] == 'enable' and kwargs['obj'] == 'dist-search': print DIST_SEARCH_ENABLE print RESTART_SPLUNK elif kwargs['cmd'] == 'disable' and kwargs['obj'] == 'dist-search': print DIST_SEARCH_DISABLE print RESTART_SPLUNK elif kwargs['cmd'] == 'display' and kwargs['obj'] == 'dist-search': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) for entry in atomFeed: if entry.title == 'distributedSearch': d = nodeToPrimitive(entry.rawcontents) if not util.normalizeBoolean(d['disabled']): print DIST_SEARCH_DISPLAY_ENABLED return print DIST_SEARCH_DISPLAY_DISABLED elif kwargs['cmd'] == 'add': print SEARCH_SERVER_ADD elif kwargs['cmd'] == 'remove': print SEARCH_SERVER_REMOVE elif kwargs['cmd'] == 'edit': print DIST_SEARCH_EDIT elif kwargs['cmd'] == 'list' and kwargs['obj'] == 'search-server': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) servers_present = False for entry in atomFeed: d = nodeToPrimitive(entry.rawcontents) if d.has_key('status'): servers_present = True print DIST_SEARCH_LIST % (entry.title, d['status'], d['peerType']) if not servers_present: print DIST_SEARCH_LIST_NONE elif kwargs['cmd'] == 'display' and kwargs['obj'] == 'discoverable': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) for entry in atomFeed: d = nodeToPrimitive(entry.rawcontents) if d.has_key('autoAddServers') and util.normalizeBoolean(d['autoAddServers']): print DISPLAY_DISCOVERABLE_ENABLED else: print DISPLAY_DISCOVERABLE_DISABLED break elif kwargs['cmd'] == 'enable' and kwargs['obj'] == 'discoverable': print ENABLE_DISCOVERABLE print RESTART_SPLUNK elif kwargs['cmd'] == 'disable' and kwargs['obj'] == 'discoverable': print DISABLE_DISCOVERABLE print RESTART_SPLUNK
def displayApp(**kwargs): """ called for displaying applications stuff. """ if kwargs['cmd'] == 'display': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) print '\n' for atomEntry in atomFeed: d = nodeToPrimitive(atomEntry.rawcontents) appName = atomEntry.title enabled = 'DISABLED' if util.normalizeBoolean( d['disabled']) else 'ENABLED' visible = 'VISIBLE' if util.normalizeBoolean( d['visible']) else 'INVISIBLE' configured = 'CONFIGURED' if util.normalizeBoolean( d['configured']) else 'UNCONFIGURED' print ' %-25s %-8s %-9s %-12s\n' % (appName, enabled, visible, configured) elif kwargs['cmd'] == 'enable': print APP_ENABLED % kwargs['eaiArgsList']['name'] print RESTART_SPLUNK elif kwargs['cmd'] == 'disable': print APP_DISABLED % kwargs['eaiArgsList']['name'] print RESTART_SPLUNK elif kwargs['cmd'] == 'remove': print APP_REMOVED % kwargs['eaiArgsList']['name'] elif kwargs['cmd'] == 'create': print APP_CREATED % kwargs['eaiArgsList']['name'] elif kwargs['cmd'] == 'edit': print APP_EDITED % kwargs['eaiArgsList']['name'] print RESTART_SPLUNK elif kwargs['cmd'] == 'package': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) d = nodeToPrimitive(atomFeed[0].rawcontents) print APP_PACKAGED % (d['name'], d['path']) elif kwargs['cmd'] == 'install': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) d = nodeToPrimitive(atomFeed[0].rawcontents) print APP_INSTALLED % (d['name'], d['status'])
def displayUser(**kwargs): """ called for displaying all user related commands. """ if kwargs['cmd'] == 'list': atom = rest.format.parseFeedDocument(kwargs['serverContent']) display = '' for entry in atom: d = nodeToPrimitive(entry.rawcontents) display += 'username:\t\t%s\n' % entry.title display += 'full-name:\t\t%s\n' % d['realname'] try: display += 'role:\t\t\t%s\n' % ':'.join(d['roles']) #SPL-23772 except TypeError: display += 'role:\t\t\t\n' display += '\n' elif kwargs['cmd'] == 'remove': display = USER_REMOVE elif kwargs['cmd'] == 'add': display = USER_ADD elif kwargs['cmd'] == 'edit': display = USER_EDIT % kwargs['eaiArgsList']['name'] print display
def displayTcp(**kwargs): """ called for displaying all tcp related commands. """ if kwargs['cmd'] == 'list': atom = rest.format.parseFeedDocument(kwargs['serverContent']) display = '' for entry in atom: d = nodeToPrimitive(entry.rawcontents) try: display += '\n\t%s for data from host %s' % (entry.title, d['restrictToHost']) except KeyError: display += '\n\t%s for data from any host' % entry.title if display: print TCP_LIST % display else: print TCP_LIST_NONE elif kwargs['cmd'] == 'remove': print str(dict({'removed':['tcp://%s' % kwargs['eaiArgsList']['name']]})) elif kwargs['cmd'] == 'add': print TCP_ADD % kwargs['eaiArgsList'] elif kwargs['cmd'] == 'edit': print TCP_EDIT
def displaySavedsearch(**kwargs): """ called for displaying all saved searches. """ if kwargs['cmd'] == 'add': display = SAVED_SEARCH_ADD % kwargs['eaiArgsList']['name'] elif kwargs['cmd'] == 'remove': display = SAVED_SEARCH_REMOVE % kwargs['eaiArgsList']['name'] elif kwargs['cmd'] == 'edit': display = SAVED_SEARCH_EDIT % kwargs['eaiArgsList']['name'] elif kwargs['cmd'] == 'list': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) display = '' for atomEntry in atomFeed: d = nodeToPrimitive(atomEntry.rawcontents) alert = event = '' display += 'name:\t\t%s\n' % atomEntry.title if int(d['is_scheduled']): alert = 'true' else: alert = 'false' display += 'alert:\t\t%s\n' % alert print display
def displayReceiver(**kwargs): """ called for displaying receiver configuration stuff. """ atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) if kwargs['cmd'] == 'display' and kwargs['obj'] == 'listen': at_least_one = False try: if len(atomFeed): for ele in atomFeed: d = nodeToPrimitive(ele.rawcontents) if not util.normalizeBoolean(d['disabled']): print TCP_RECEIVE % ele.title at_least_one = True if not at_least_one: print TCP_RECEIVE_NONE else: print TCP_RECEIVE_NONE except IndexError: print TCP_RECEIVE_NONE elif kwargs['cmd'] == 'enable' and kwargs['obj'] == 'listen': print TCP_RECEIVE_ADD % kwargs['eaiArgsList']['name'] elif kwargs['cmd'] == 'disable' and kwargs['obj'] == 'listen': if len(atomFeed): print TCP_RECEIVE_DISABLE % atomFeed[0].title else: print TCP_RECEIVE_REMOVE
def get_index_app(servResp, argList): """""" atom = rest.format.parseFeedDocument(servResp) for entry in atom: d = nodeToPrimitive(entry.rawcontents) if entry.title == argList["name"]: return d["eai:acl"]["app"]
def get_index_app(servResp, argList): """""" atom = rest.format.parseFeedDocument(servResp) for entry in atom: d = nodeToPrimitive(entry.rawcontents) if entry.title == argList['name']: return d['eai:acl']['app']
def _convert_content(self, xml): """ Convert an Atom entry's <content> node into a Python datastructure. """ try: return format.nodeToPrimitive(xml.xpath("a:content", namespaces=NSMAP)[0][0]) except: return None
def displayApp(**kwargs): """ called for displaying applications stuff. """ if kwargs['cmd'] == 'display': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) print '\n' for atomEntry in atomFeed: d = nodeToPrimitive(atomEntry.rawcontents) appName = atomEntry.title enabled = 'DISABLED' if util.normalizeBoolean(d['disabled']) else 'ENABLED' visible = 'VISIBLE' if util.normalizeBoolean(d['visible']) else 'INVISIBLE' configured = 'CONFIGURED' if util.normalizeBoolean(d['configured']) else 'UNCONFIGURED' print ' %-25s %-8s %-9s %-12s\n' % (appName, enabled, visible, configured) elif kwargs['cmd'] == 'enable': print APP_ENABLED % kwargs['eaiArgsList']['name'] print RESTART_SPLUNK elif kwargs['cmd'] == 'disable': print APP_DISABLED % kwargs['eaiArgsList']['name'] print RESTART_SPLUNK elif kwargs['cmd'] == 'remove': print APP_REMOVED % kwargs['eaiArgsList']['name'] elif kwargs['cmd'] == 'create': print APP_CREATED % kwargs['eaiArgsList']['name'] elif kwargs['cmd'] == 'edit': print APP_EDITED % kwargs['eaiArgsList']['name'] print RESTART_SPLUNK elif kwargs['cmd'] == 'package': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) d = nodeToPrimitive(atomFeed[0].rawcontents) print APP_PACKAGED % (d['name'], d['path']) elif kwargs['cmd'] == 'install': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) d = nodeToPrimitive(atomFeed[0].rawcontents) print APP_INSTALLED % (d['name'], d['status'])
def testListNodeToPrimitive(self): # generate the XML root = etree.Element('{%s}list' % srf.SPLUNK_NS) for i in testData['list']: el = etree.SubElement(root, '{%s}item' % srf.SPLUNK_NS) el.text = i converted = srf.nodeToPrimitive(root) self.assertEqual(converted, testData['list'])
def testDictNodeToPrimitive(self): # generate the XML root = etree.Element('{%s}dict' % srf.SPLUNK_NS) for k, v in testData['dict'].items(): el = etree.SubElement(root, '{%s}key' % srf.SPLUNK_NS) el.set('name', k) el.text = v converted = srf.nodeToPrimitive(root) self.assertEqual(converted, testData['dict'])
def testDictNodeToPrimitive(self): # generate the XML root = etree.Element('{%s}dict' % srf.SPLUNK_NS) for k,v in testData['dict'].items(): el = etree.SubElement(root, '{%s}key' % srf.SPLUNK_NS) el.set('name',k) el.text = v converted = srf.nodeToPrimitive(root) self.assertEqual(converted, testData['dict'])
def displayMonitor(**kwargs): """ called for displaying all monitor related commands. """ if kwargs['cmd'] == 'remove': print MONITOR_REMOVE % kwargs['eaiArgsList'] elif kwargs['cmd'] == 'add': print MONITOR_ADD % kwargs['eaiArgsList'] elif kwargs['cmd'] == 'edit': print MONITOR_EDIT % kwargs['eaiArgsList'] elif kwargs['cmd'] == 'list': atom = rest.format.parseFeedDocument(kwargs['serverContent']) dir_entries = '' file_entries = '' for entry in atom: d = nodeToPrimitive(entry.rawcontents) # entry.links is a list of tuples, link name->href. if len([x for x in entry.links if x[0] == 'members']) > 0: dir_entries += '\n\t%s' % entry.title dir_files = extractTitleFeed(filter( lambda t: t[0] == 'members', entry.links), sessionKey=kwargs['sessionKey']) if dir_files: for f in dir_files: dir_entries += '\n\t\t%s' % f else: dir_entries += '\n\t\t[No files in this directory monitored.]' else: if kwargs['eaiArgsList'].has_key( 'show-hidden') and util.normalizeBoolean( kwargs['eaiArgsList']['show-hidden']): file_entries += '\t%s\n' % entry.title elif not isInternalTail(entry.title): file_entries += '\t%s\n' % entry.title if not file_entries: file_entries = 'Monitored Files:\n\t\t[No files monitored.]' else: file_entries = 'Monitored Files:\n' + file_entries.encode('utf-8') if not dir_entries: dir_entries = 'Monitored Directories:\n\t\t[No directories monitored.]' else: dir_entries = 'Monitored Directories:' + dir_entries.encode( 'utf-8') display = '%s\n%s' % (dir_entries, file_entries) print display
def displayRoleMappings(**kwargs): """ list role-mappings """ if kwargs['cmd'] == 'list': atom = rest.format.parseFeedDocument(kwargs['serverContent']) for entry in atom: d = nodeToPrimitive(entry.rawcontents) if d['roles']: print 'Splunk role %s maps to : %s' % (entry.title, d['roles']) else: print 'Splunk role %s maps to : (none)' % (entry.title)
def displayAuthMethod(**kwargs): """ called for displaying auth-method stuff """ if kwargs['cmd'] == 'show': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) for entry in atomFeed: if entry.title == 'active_authmodule': d = nodeToPrimitive(entry.rawcontents) try: print AUTH_METHOD_SHOW % d['active_authmodule'] except KeyError: print AUTH_METHOD_NONE1 elif kwargs['cmd'] == 'reload': print AUTH_METHOD_RELOAD elif kwargs['cmd'] == 'add': print AUTH_METHOD_ADD % kwargs['eaiArgsList']['authType'] elif kwargs['cmd'] == 'list': print AUTH_METHOD_LIST atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) for entry in atomFeed: if entry.title == 'services': continue print '\nSettings for %s:' % entry.title d = nodeToPrimitive(entry.rawcontents) for k, v in d.items(): print ' %-30s%s' % (k + ':', ((v != '') and v or '(empty)'))
def displayMonitor(**kwargs): """ called for displaying all monitor related commands. """ if kwargs['cmd'] == 'remove': print MONITOR_REMOVE % kwargs['eaiArgsList'] elif kwargs['cmd'] == 'add': print MONITOR_ADD % kwargs['eaiArgsList'] elif kwargs['cmd'] == 'edit': print MONITOR_EDIT % kwargs['eaiArgsList'] elif kwargs['cmd'] == 'list': atom = rest.format.parseFeedDocument(kwargs['serverContent']) dir_entries = '' file_entries = '' for entry in atom: d = nodeToPrimitive(entry.rawcontents) # entry.links is a list of tuples, link name->href. if len([x for x in entry.links if x[0] == 'members']) > 0: dir_entries += '\n\t%s' % entry.title dir_files = extractTitleFeed(filter(lambda t: t[0] == 'members', entry.links), sessionKey=kwargs['sessionKey']) if dir_files: for f in dir_files: dir_entries += '\n\t\t%s' % f else: dir_entries += '\n\t\t[No files in this directory monitored.]' else: if kwargs['eaiArgsList'].has_key('show-hidden') and util.normalizeBoolean(kwargs['eaiArgsList']['show-hidden']): file_entries += '\t%s\n' % entry.title elif not isInternalTail(entry.title): file_entries += '\t%s\n' % entry.title if not file_entries: file_entries = 'Monitored Files:\n\t\t[No files monitored.]' else: file_entries = 'Monitored Files:\n' + file_entries.encode('utf-8') if not dir_entries: dir_entries = 'Monitored Directories:\n\t\t[No directories monitored.]' else: dir_entries = 'Monitored Directories:' + dir_entries.encode('utf-8') display = '%s\n%s' % (dir_entries, file_entries) print display
def displayIndex(**kwargs): """ called for displaying all index related commands. """ if kwargs['cmd'] == 'add': print 'Index "%s" added' % kwargs['eaiArgsList']['name'] print RESTART_SPLUNK elif kwargs['cmd'] == 'edit': print 'Index "%s" edited' % kwargs['eaiArgsList']['name'] print RESTART_SPLUNK elif kwargs['cmd'] == 'remove': print 'Index "%s" removed' % kwargs['eaiArgsList']['name'] print RESTART_SPLUNK elif kwargs['cmd'] == 'disable': print INDEX_DISABLED % kwargs['eaiArgsList']['name'] print RESTART_SPLUNK elif kwargs['cmd'] == 'enable': print INDEX_ENABLED % kwargs['eaiArgsList']['name'] print RESTART_SPLUNK elif kwargs['cmd'] == 'list': atom = rest.format.parseFeedDocument(kwargs['serverContent']) display = '' for entry in atom: d = nodeToPrimitive(entry.rawcontents) if d['defaultDatabase'] == entry.title: display += '%s * Default *' % entry.title else: display += '%s' % entry.title #SPL-27068 if util.normalizeBoolean(d['disabled']): display += ' * Disabled *' display += '\n' if not kwargs['eaiArgsList']['name']: display += '\t%s\n\t%s\n\t%s\n' % (d['homePath_expanded'], d['coldPath_expanded'], d['thawedPath_expanded']) else: #we have asked about a specific index, so show everything for k in d.keys(): display += '\t%s : %s\n' % (k, d[k]) print INDEX_LIST print display
def displayIndex(**kwargs): """ called for displaying all index related commands. """ if kwargs['cmd'] == 'add': print 'Index "%s" added' % kwargs['eaiArgsList']['name'] print RESTART_SPLUNK elif kwargs['cmd'] == 'edit': print 'Index "%s" edited' % kwargs['eaiArgsList']['name'] print RESTART_SPLUNK elif kwargs['cmd'] == 'remove': print 'Index "%s" removed' % kwargs['eaiArgsList']['name'] print RESTART_SPLUNK elif kwargs['cmd'] == 'disable': print INDEX_DISABLED % kwargs['eaiArgsList']['name'] print RESTART_SPLUNK elif kwargs['cmd'] == 'enable': print INDEX_ENABLED % kwargs['eaiArgsList']['name'] print RESTART_SPLUNK elif kwargs['cmd'] == 'list': atom = rest.format.parseFeedDocument(kwargs['serverContent']) display = '' for entry in atom: d = nodeToPrimitive(entry.rawcontents) if d['defaultDatabase'] == entry.title: display += '%s * Default *' % entry.title else: display += '%s' % entry.title #SPL-27068 if util.normalizeBoolean(d['disabled']): display += ' * Disabled *' display += '\n' if not kwargs['eaiArgsList']['name']: display += '\t%s\n\t%s\n\t%s\n' % (d['homePath_expanded'], d['coldPath_expanded'], d['thawedPath_expanded']) else: #we have asked about a specific index, so show everything for k in d.keys(): display += '\t%s : %s\n' % (k,d[k]) print INDEX_LIST print display
def displayForwardServer(**kwargs): """ called for displaying forward-server stuff. """ if kwargs['cmd'] == 'display' and kwargs['obj'] == 'local-index': local_index = extractLevel1Feed(serverContent=kwargs['serverContent'], filter=['indexAndForward']) local_index = util.normalizeBoolean(local_index) if not local_index: print LOCAL_INDEX_NONE elif local_index: print LOCAL_INDEX_ENABLE elif kwargs['cmd'] == 'enable' and kwargs['obj'] == 'local-index': print LOCAL_INDEX_ENABLE print FORWARD_COND print RESTART_SPLUNK elif kwargs['cmd'] == 'disable' and kwargs['obj'] == 'local-index': print LOCAL_INDEX_DISABLE print FORWARD_COND print RESTART_SPLUNK elif kwargs['cmd'] == 'list': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) ok_list = nok_list = '' for entry in atomFeed: d = nodeToPrimitive(entry.rawcontents) if d.has_key('status') and d['status'] == 'connect_done': ok_list += '\n\t%s' % entry.title else: nok_list += '\n\t%s' % entry.title print FORWARD_SERVER_LIST % (ok_list, nok_list) elif kwargs['cmd'] == 'add': display = FORWARD_SERVER_ADD % kwargs['eaiArgsList']['name'] print display print RESTART_SPLUNK elif kwargs['cmd'] == 'remove': print FORWARD_SERVER_REMOVE % kwargs['eaiArgsList']['name'] print RESTART_SPLUNK elif kwargs['cmd'] == 'edit': print RESTART_SPLUNK
def displayUdp(**kwargs): """ called for displaying all udp related commands. """ if kwargs['cmd'] == 'add': print UDP_ADD % kwargs['eaiArgsList'] elif kwargs['cmd'] == 'edit': print UDP_EDIT % kwargs['eaiArgsList'] elif kwargs['cmd'] == 'list': atom = rest.format.parseFeedDocument(kwargs['serverContent']) ports = '' for entry in atom: d = nodeToPrimitive(entry.rawcontents) if d.has_key('group') and d['group'] == 'listenerports': ports += '\n\t%s' % entry.title if ports: print UDP_LIST % ports else: print UDP_LIST_NONE elif kwargs['cmd'] == 'remove': print UDP_REMOVE % kwargs['eaiArgsList']
def displayDeployment(**kwargs): """ called for displayin deployment client/server stuff """ if kwargs['cmd'] == 'refresh' and kwargs['obj'] == 'deploy-clients': print REFRESH_DEPL_CLIENTS elif kwargs['cmd'] == 'show' and kwargs['obj'] == 'deploy-poll': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) if not atomFeed.entries: print DEPLOY_POLL_SHOW_NONE else: d = {} for entry in atomFeed: if entry.title == 'deployment-client': d = nodeToPrimitive(entry.rawcontents) try: print DEPLOY_POLL_SHOW % d['targetUri'] except KeyError: print DEPLOY_POLL_SHOW_NONE break elif kwargs['cmd'] == 'list' and kwargs['obj'] == 'server-class': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) if not atomFeed.entries: print DEPLOYMENT_SERVER_NO_SERVER_CLASS else: print DEPLOYMENT_SERVER_CLASS for entry in atomFeed: print '\t%s' % entry.title elif kwargs['cmd'] == 'list' and kwargs['obj'] == 'deploy-clients': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) if not atomFeed.entries: print DEPLOYMENT_CLIENT_NONE else: for entry in atomFeed: print "\nDeployment client: %s" % entry.title d = nodeToPrimitive(entry.rawcontents) for k in d.keys(): if k.startswith('eai:acl'): continue print "\t\t %s: %s" % (k,d[k]) elif kwargs['cmd'] == 'reload' and kwargs['obj'] == 'deploy-server': print RELOAD_DEPLOY_SERVER elif kwargs['cmd'] == 'set' and kwargs['obj'] == 'deploy-multicast': print '"set deploy-multicast" is currently not supported. Use "set deploy-poll" instead.' elif kwargs['cmd'] == 'set' and kwargs['obj'] == 'deploy-poll': print 'Configuration updated.' elif kwargs['cmd'] == 'show' and kwargs['obj'] == 'deploy-multicast': print 'Only deploy-poll is supported currently.' elif kwargs['cmd'] == 'enable' and kwargs['obj'] == 'deploy-server': print DEPLOYMENT_SERVER_ENABLED elif kwargs['cmd'] == 'disable' and kwargs['obj'] == 'deploy-server': print DEPLOYMENT_SERVER_DISABLED elif kwargs['cmd'] == 'enable' and kwargs['obj'] == 'deploy-client': print DEPLOYMENT_CLIENT_ENABLED elif kwargs['cmd'] == 'disable' and kwargs['obj'] == 'deploy-client': print DEPLOYMENT_CLIENT_DISABLED elif kwargs['cmd'] == 'display': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) d = {} for entry in atomFeed: if kwargs['obj'] == 'deploy-server' and entry.title == 'default': d = nodeToPrimitive(entry.rawcontents) try: if not util.normalizeBoolean(d['disabled']): print DEPLOYMENT_SERVER_ENABLED return except: break if kwargs['obj'] == 'deploy-server': print DEPLOYMENT_SERVER_DISABLED elif kwargs['obj'] == 'deploy-clients': print DEPLOYMENT_CLIENT_DISABLED
def displayDeployment(**kwargs): """ called for displayin deployment client/server stuff """ if kwargs['cmd'] == 'refresh' and kwargs['obj'] == 'deploy-clients': print REFRESH_DEPL_CLIENTS_REMOVED elif kwargs['cmd'] == 'show' and kwargs['obj'] == 'deploy-poll': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) if not atomFeed.entries: print DEPLOY_POLL_SHOW_NONE else: d = {} for entry in atomFeed: if entry.title == 'deployment-client': d = nodeToPrimitive(entry.rawcontents) try: print DEPLOY_POLL_SHOW % d['targetUri'] except KeyError: print DEPLOY_POLL_SHOW_NONE break elif kwargs['cmd'] == 'list' and kwargs['obj'] == 'deploy-clients': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) if not atomFeed.entries: print DEPLOYMENT_CLIENT_NONE else: for entry in atomFeed: print "\nDeployment client: %s" % entry.title d = nodeToPrimitive(entry.rawcontents) for k in d.keys(): if k.startswith('eai:acl'): continue print "\t\t %s: %s" % (k, d[k]) elif kwargs['cmd'] == 'reload' and kwargs['obj'] == 'deploy-server': print RELOAD_DEPLOY_SERVER atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) if not atomFeed.entries: print 'empty atomFeed; BUG!' sys.exit(21) else: for entry in atomFeed: # there will be only 1 entry d = nodeToPrimitive(entry.rawcontents) for k in d.keys(): if k == 'requireRestart': print RESTART_SPLUNK elif kwargs['cmd'] == 'set' and kwargs['obj'] == 'deploy-poll': print 'Configuration updated.' elif kwargs['cmd'] == 'enable' and kwargs['obj'] == 'deploy-server': print DEPLOYMENT_SERVER_ENABLED elif kwargs['cmd'] == 'disable' and kwargs['obj'] == 'deploy-server': print DEPLOYMENT_SERVER_DISABLED elif kwargs['cmd'] == 'enable' and kwargs['obj'] == 'deploy-client': print DEPLOYMENT_CLIENT_ENABLED elif kwargs['cmd'] == 'disable' and kwargs['obj'] == 'deploy-client': print DEPLOYMENT_CLIENT_DISABLED elif kwargs['cmd'] == 'display': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) d = {} for entry in atomFeed: if kwargs['obj'] == 'deploy-server' and entry.title == 'default': d = nodeToPrimitive(entry.rawcontents) try: if not util.normalizeBoolean(d['disabled']): print DEPLOYMENT_SERVER_ENABLED return except: break if kwargs['obj'] == 'deploy-client' and entry.title == 'default': d = nodeToPrimitive(entry.rawcontents) try: if not util.normalizeBoolean(d['disabled']): print DEPLOYMENT_CLIENT_ENABLED return except: break if kwargs['obj'] == 'deploy-server': print DEPLOYMENT_SERVER_DISABLED elif kwargs['obj'] == 'deploy-clients': print DEPLOYMENT_CLIENT_DISABLED
def displayDeployment(**kwargs): """ called for displayin deployment client/server stuff """ if kwargs['cmd'] == 'refresh' and kwargs['obj'] == 'deploy-clients': print REFRESH_DEPL_CLIENTS_REMOVED elif kwargs['cmd'] == 'show' and kwargs['obj'] == 'deploy-poll': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) if not atomFeed.entries: print DEPLOY_POLL_SHOW_NONE else: d = {} for entry in atomFeed: if entry.title == 'deployment-client': d = nodeToPrimitive(entry.rawcontents) try: print DEPLOY_POLL_SHOW % d['targetUri'] except KeyError: print DEPLOY_POLL_SHOW_NONE break elif kwargs['cmd'] == 'list' and kwargs['obj'] == 'deploy-clients': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) if not atomFeed.entries: print DEPLOYMENT_CLIENT_NONE else: for entry in atomFeed: print "\nDeployment client: %s" % entry.title d = nodeToPrimitive(entry.rawcontents) for k in d.keys(): if k.startswith('eai:acl'): continue print "\t\t %s: %s" % (k,d[k]) elif kwargs['cmd'] == 'reload' and kwargs['obj'] == 'deploy-server': print RELOAD_DEPLOY_SERVER atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) if not atomFeed.entries: print 'empty atomFeed; BUG!' sys.exit(21) else: for entry in atomFeed: # there will be only 1 entry d = nodeToPrimitive(entry.rawcontents) for k in d.keys(): if k == 'requireRestart': print RESTART_SPLUNK elif kwargs['cmd'] == 'set' and kwargs['obj'] == 'deploy-poll': print 'Configuration updated.' elif kwargs['cmd'] == 'enable' and kwargs['obj'] == 'deploy-server': print DEPLOYMENT_SERVER_ENABLED elif kwargs['cmd'] == 'disable' and kwargs['obj'] == 'deploy-server': print DEPLOYMENT_SERVER_DISABLED elif kwargs['cmd'] == 'enable' and kwargs['obj'] == 'deploy-client': print DEPLOYMENT_CLIENT_ENABLED elif kwargs['cmd'] == 'disable' and kwargs['obj'] == 'deploy-client': print DEPLOYMENT_CLIENT_DISABLED elif kwargs['cmd'] == 'display': atomFeed = rest.format.parseFeedDocument(kwargs['serverContent']) d = {} for entry in atomFeed: if kwargs['obj'] == 'deploy-server' and entry.title == 'default': d = nodeToPrimitive(entry.rawcontents) try: if not util.normalizeBoolean(d['disabled']): print DEPLOYMENT_SERVER_ENABLED return except: break if kwargs['obj'] == 'deploy-client' and entry.title == 'default': d = nodeToPrimitive(entry.rawcontents) try: if not util.normalizeBoolean(d['disabled']): print DEPLOYMENT_CLIENT_ENABLED return except: break if kwargs['obj'] == 'deploy-server': print DEPLOYMENT_SERVER_DISABLED elif kwargs['obj'] == 'deploy-clients': print DEPLOYMENT_CLIENT_DISABLED
def displaySettings(**kwargs): """ called for displaying all settings related commands. """ #SPL-24723 if kwargs['obj'] == 'license': atom = rest.format.parseFeedDocument(kwargs['serverContent']) product = licenselevel = expdate = daysRemainingStr = peakUsage = licenseviolations = currentDailyUsageAmount = expirationState = maxViolations = violationPeriod = '' for entry in atom: d = nodeToPrimitive(entry.rawcontents) try: currentDailyUsageAmount = d['currentDailyUsageAmount'] except: pass try: expirationState = d['expirationState'] except: pass try: maxViolations = d['maxViolations'] except: pass try: violationPeriod = d['violationPeriod'] except: pass if d.has_key('licenseType'): if d['licenseType'] == 'pro': product = 'Enterprise' else: product = d['licenseType'] if d.has_key('licenseDailyUsageLimit'): licenselevel = float( d["licenseDailyUsageLimit"] ) / 1048576 if d.has_key('remainingTime'): secondsRemaining = int(d["remainingTime"]) daysRemaining = ((secondsRemaining / (24 * 3600)) + 1) daysRemainingStr = "expired" if (daysRemaining < 0) else str(daysRemaining) + ( " days" if (daysRemaining > 1) else " day" ) if d.has_key('peakIndexingThroughput'): peakUsage= float(d["peakIndexingThroughput"]) / 1048576 if d.has_key("expirationDate"): expdate = util.parseISO(d["expirationDate"]) if d.has_key("licenseViolations"): for violation in d["licenseViolations"]: violationDate = violation.split(' ', 1)[0] violationString = violation.split(' ', 1)[1] licenseviolations += '%s at %s\n' % (violationString, util.parseISO(violationDate)) print 'Product: \t\t\t%s' % product print 'License level: \t\t\t%s MB' % licenselevel print 'Days remaining: \t\t%s' % daysRemainingStr print 'Peak usage: \t\t\t%s MB' % peakUsage print 'Expiration date: \t\t%s' % expdate print 'License violations: \t\t%s' % licenseviolations print 'Current Daily Usage Amount: \t%s' % currentDailyUsageAmount print 'Expiration State: \t\t%s' % expirationState print 'Max Violations: \t\t%s' % maxViolations print 'Violation Period: \t\t%s' % violationPeriod elif kwargs['obj'] == 'config': display = '' for k in kwargs['conf'].keys(): display += '[%s]\n' % kwargs['conf'][k].name for item in kwargs['conf'][k].items(): display += '%s = %s\n' % (item[0], item[1]) print display elif kwargs['cmd'] in ['enable', 'disable'] and kwargs['obj'] in ['web-ssl', 'webserver']: print RESTART_SPLUNK elif kwargs['cmd'] == 'show': if kwargs['obj'] == 'web-port': print SHOW_WEBPORT % extractLevel1Feed(serverContent=kwargs['serverContent'], filter=['httpport']) elif kwargs['obj'] == 'splunkd-port': print SHOW_SPLUNKDPORT % extractLevel1Feed(serverContent=kwargs['serverContent'], filter=['mgmtHostPort']) elif kwargs['obj'] == 'default-hostname': print SHOW_HOSTNAME % extractLevel1Feed(serverContent=kwargs['serverContent'], filter=['host']) elif kwargs['obj'] == 'minfreemb': print SHOW_MINFREEMB % extractLevel1Feed(serverContent=kwargs['serverContent'], filter=['minFreeSpace']) elif kwargs['obj'] == 'servername': print SHOW_SERVERNAME % extractLevel1Feed(serverContent=kwargs['serverContent'], filter=['serverName']) elif kwargs['obj'] == 'datastore-dir': print SHOW_DATASTOREDIR % extractLevel1Feed(serverContent=kwargs['serverContent'], filter=['SPLUNK_DB']) elif kwargs['obj'] == 'default-index': for ele in kwargs['defIndex']: try: print INDEX_NAME_MAP[ele] except KeyError: print ele else: print NO_INFO elif kwargs['cmd'] == 'set': if kwargs['obj'] == 'default-hostname': print SET_HOSTNAME print RESTART_SPLUNK elif kwargs['obj'] in ['web-port', 'minfreemb', 'servername']: print RESTART_SPLUNK elif kwargs['obj'] == 'splunkd-port': print SET_SPLUNKDPORT print RESTART_SPLUNK elif kwargs['obj'] == 'datastore-dir': print SET_DATASTOREDIR % kwargs['eaiArgsList']['SPLUNK_DB'] print RESTART_SPLUNK elif kwargs['obj'] == 'default-index': print SET_DEFAULT_INDEX % kwargs['eaiArgsList']['srchIndexesDefault'] else: print NO_INFO else: print NO_INFO