def add(requestObject): # set output as html requestObject.setHeader('content-type', 'text/html') vals = {} message = "" try: # set field values, including default vals for field, defaultval in knownFields.items(): if field in requestObject.args: vals[field] = requestObject.args[field][0].strip() elif defaultval == None: message = "<h1>Error: missing required field: %s</h1>" % field break else: vals[field] = defaultval session = requestObject.getSession() authString = session.sessionNamespaces['authXml'] sourcetype = vals.get('sourcetype', '') source = vals.get('source', '') if len(sourcetype) == 0 or sourcetype == "n/a": del vals['sourcetype'] vals["authstr"] = authString input_tail.add(vals, True) message = 'Source %s successfully added.' % source except Exception as e: message += 'Failed to add source: %s' % str(e) templ = Template.Template(bundle_paths.make_path('addtail_done.html')) templ.message = html.Raw('<p class="message">%s</p>' % message) return templ.get_string()
def add(requestObject): ''' i.e. http://localhost:8000/v3/custom/addeventtype.add?... ''' # set output as html requestObject.setHeader('content-type', 'text/html') vals = {} # set field values, including default vals for field, defaultval in knownFields.items(): if field in requestObject.args: vals[field] = requestObject.args[field][0].strip() elif defaultval == None: return "<html><body><h1>Error: missing required field: %s</h1></body></html>" % field else: vals[field] = defaultval # special case example, by stripping off 'example:' ## if vals['example'].lower().startswith('example:'): ## vals['example'] = vals['example'][8:].strip() session = requestObject.getSession() authString = session.sessionNamespaces['authXml'] name = vals['name'] if _addToConf(vals, authString, requestObject): message = 'Event type successfully saved' templ = Template.Template( bundle_paths.make_path('addeventtype_done.html')) else: if (name == ''): message = 'Please provide an event type name' else: message = 'Error: Unable to save event type' templ = Template.Template(bundle_paths.make_path('addeventtype.html')) templ.query = html.Raw(su.quoteattr(vals['query'])) #templ.example = vals['example'] templ.name = vals['name'] #templ.description = vals['description'] templ.tags = vals['tags'] #templ.priority = vals['priority'] message = html.Raw('<p class="message">%s</p>' % message) templ.message = message return templ.get_string()
break else: vals[field] = defaultval session = requestObject.getSession() authString = session.sessionNamespaces['authXml'] sourcetype = vals.get('sourcetype', '') source = vals.get('source', '') if len(sourcetype) == 0 or sourcetype == "n/a": del vals['sourcetype'] vals["authstr"] = authString input_tail.add(vals, True) message = 'Source %s successfully added.' % source except Exception, e: message += 'Failed to add source: %s' % str(e) templ = Template.Template(bundle_paths.make_path('addtail_done.html')) templ.message = html.Raw('<p class="message">%s</p>' % message) return templ.get_string() if __name__ == '__main__': try: source = '/Users/davidcarasso/logs/exim.main.log' vals = {'source': source, 'sourcetype': '', 'index': 'main'} vals["authstr"] = comm.getAuthInfo('admin', 'changeme') input_tail.add(vals, True) print 'Source %s successfully added.' % source except Exception, e: print 'Failed to add source: %s' % str(e)
def get(requestObject) : requestArgs = _flattenRequestArgs(requestObject) requestObject.setHeader('content-type', 'text/html') t = _getTemplate("surrounding_events.html", requestArgs) searchCommand = _getSearchCommand(requestArgs) #tack the extra output clause back onto q searchCommand += "| outputxml format::raw maxlines::10000" requestArgs["q"] = searchCommand # get the proper search agent searchAgent = SearchAgent.Factory(requestArgs, requestObject.getSession()) # return the output from search agent agentResponse = searchAgent.run() if( searchAgent.messages ): messagesBlock = html.HTMLList() for message in searchAgent.messages: messagesBlock.append( html.Raw( message["text"] ) ) messagesBlock.append( html.br() ) messagesBlock.append( html.br() ) t.messages = messagesBlock else: t.messages = html.Raw("") parsedResponse = et.fromstring(agentResponse) eventsBlock = html.HTMLList() cdIndex = "" decIndex = "" for rNode in parsedResponse.findall(".//cols"): for cNode in rNode.findall(".//col"): if cNode.text == "_decoration": decIndex = cNode.attrib["cd"] elif cNode.text == "_cd": cdIndex = cNode.attrib["cd"] for rNode in parsedResponse.findall(".//r") : thisEventId = "0:0000000" thisDecoration = "" try : for mNode in rNode.findall(".//m") : if mNode.attrib["col"] == cdIndex : thisEventId = mNode.text elif mNode.attrib["col"] == decIndex : thisDecoration = mNode.text except Exception, e: logger.debug("could not get thisEventId") traceback.print_exc() for vNode in rNode.findall(".//v") : logger.debug("****" * 20) logger.debug(vNode.text) preElement = html.pre()[vNode.text] # the class is needed for the CSS highlighting, but an ID is also used by the JS, for the scroll-to behaviour. thisClass = "resultRow " + thisDecoration thisId = "" if (thisEventId == requestArgs["eventId"]) : thisClass += " selectedRow" thisId = "selectedItem" innerDiv = html.div(class_=thisClass, id="events" + thisEventId)[preElement] resultRowDiv = html.div(id=thisId)[innerDiv] eventsBlock.append(resultRowDiv)