def DisplayShowall(self, matches): """Display all the known information about the matched hosts """ revcache = {} outstr = "" for aks in AllowedKey.objects.all(): revcache[aks.id] = aks.key for host in matches: output = [] keyvals = {} keyorig = {} keyctime = {} keymtime = {} # Get all the keyvalues for this host for k in KeyValue.objects.filter(hostid=host): keyname = revcache[k.keyid_id] if keyname not in keyvals: keyvals[keyname] = [] keyvals[keyname].append(k.value) keyorig[keyname] = k.origin keyctime[keyname] = k.createdate keymtime[keyname] = k.modifieddate # Generate the output string for each key/value pair for key, values in keyvals.items(): if self.namespace.origin: originstr = "\t[Origin: %s]" % keyorig[key] else: originstr = "" if self.namespace.times: timestr = "\t[Created: %s Modified: %s]" % (keyctime[key], keymtime[key]) else: timestr = "" output.append(" %s: %-15s%s%s" % (key, self.namespace.sep[0].join(values), originstr, timestr)) output.sort() # Generate the output for the hostname if self.namespace.origin: originstr = "\t[Origin: %s]" % _hostcache[host].origin else: originstr = "" if self.namespace.times: timestr = "\t[Created: %s Modified: %s]" % (_hostcache[host].createdate, _hostcache[host].modifieddate) else: timestr = "" # Output the pregenerated output outstr += "%s%s%s\n" % (_hostcache[host].hostname, originstr, timestr) if self.namespace.aliases: outstr += " [Aliases: %s]\n" % (", ".join(getAliases(_hostcache[host].hostname))) for str in output: outstr += "%s\n" % str return outstr
def gen_host(self, host, kvs, revcache): outstr = "" output = [] keyvals = {} keyorig = {} keyctime = {} keymtime = {} # Get all the keyvalues for this host for k in kvs: if k.hostid_id != host: continue keyname = revcache[k.keyid_id] if keyname not in keyvals: keyvals[keyname] = [] keyvals[keyname].append(k.value) keyorig[keyname] = k.origin keyctime[keyname] = k.createdate keymtime[keyname] = k.modifieddate # Generate the output string for each key/value pair for key, values in keyvals.items(): values.sort() if self.namespace.origin: originstr = "\t[Origin: %s]" % keyorig[key] else: originstr = "" if self.namespace.times: timestr = "\t[Created: %s Modified: %s]" % (keyctime[key], keymtime[key]) else: timestr = "" output.append(" %s: %-15s%s%s" % (key, self.namespace.sep[0].join(values), originstr, timestr)) output.sort() # Generate the output for the hostname if self.namespace.origin: originstr = "\t[Origin: %s]" % _hostcache[host].origin else: originstr = "" if self.namespace.times: timestr = "\t[Created: %s Modified: %s]" % (_hostcache[host].createdate, _hostcache[host].modifieddate) else: timestr = "" # Output the pregenerated output output.insert(0, "%s%s%s" % (_hostcache[host].hostname, originstr, timestr)) if self.namespace.aliases: output.insert(0, " [Aliases: %s]" % (", ".join(getAliases(_hostcache[host].hostname)))) outstr += "\n".join(output) return outstr
def DisplayXML(self, matches): """Display hosts and other printables in XML format """ from xml.sax.saxutils import escape, quoteattr outstr = "" if self.namespace.showall: columns = [k.key for k in AllowedKey.objects.all()] columns.sort() else: columns = self.printout[:] cache = self.loadPrintoutCache(columns, matches) outstr += "<hostinfo>\n" outstr += ' <query date="%s">%s</query>\n' % (time.ctime(), escape(" ".join(sys.argv))) for key in columns: k = getAK(key) outstr += " <key>\n" outstr += " <name>%s</name>\n" % escape(key) outstr += " <type>%s</type>\n" % k.get_validtype_display() outstr += " <readonlyFlag>%s</readonlyFlag>\n" % k.readonlyFlag outstr += " <auditFlag>%s</auditFlag>\n" % k.auditFlag outstr += " <numericFlag>%s</numericFlag>\n" % k.numericFlag outstr += " <docpage>%s</docpage>\n" % k.docpage outstr += " <desc>%s</desc>\n" % k.desc if k.restrictedFlag: outstr += " <restricted>\n" rvlist = RestrictedValue.objects.filter(keyid__key=key) for rv in rvlist: outstr += " <value>%s</value>\n" % escape(rv.value) outstr += " </restricted>\n" outstr += " </key>\n" for host in matches: if self.namespace.aliases: aliaslist = getAliases(_hostcache[host].hostname) if self.namespace.origin: hostorigin = ' origin="%s" ' % _hostcache[host].origin else: hostorigin = '' if self.namespace.times: hostdates = ' modified="%s" created="%s" ' % (_hostcache[host].modifieddate, _hostcache[host].createdate) else: hostdates = '' outstr += ' <host docpage="%s" %s%s>\n' % (_hostcache[host].docpage, hostorigin, hostdates) outstr += " <hostname>%s</hostname>\n" % escape(_hostcache[host].hostname) if self.namespace.aliases and aliaslist: outstr += " <aliaslist>\n" for alias in aliaslist: outstr += " <alias>%s</alias>\n" % escape(alias) outstr += " </aliaslist>\n" outstr += " <data>\n" for p in columns: if host not in cache[p] or len(cache[p][host]) == 0: pass else: for c in cache[p][host]: outstr += ' <confitem key="%s"' % p if self.namespace.origin: outstr += ' origin=%s' % quoteattr(c['origin']) if self.namespace.times: outstr += ' modified="%s" created="%s"' % (c['modifieddate'], c['createdate']) outstr += '>%s</confitem>\n' % escape(c['value']) outstr += " </data>\n" outstr += " </host>\n" outstr += "</hostinfo>\n" return outstr
def DisplayXML(self, matches): """Display hosts and other printables in XML format """ from xml.sax.saxutils import escape, quoteattr outstr = "" if self.namespace.showall: columns = [k.key for k in AllowedKey.objects.all()] columns.sort() else: columns = self.printout[:] cache = self.loadPrintoutCache(columns, matches) outstr += "<hostinfo>\n" outstr += ' <query date="%s">%s</query>\n' % ( time.ctime(), escape(" ".join(sys.argv))) for key in columns: k = getAK(key) outstr += " <key>\n" outstr += " <name>%s</name>\n" % escape(key) outstr += " <type>%s</type>\n" % k.get_validtype_display() outstr += " <readonlyFlag>%s</readonlyFlag>\n" % k.readonlyFlag outstr += " <auditFlag>%s</auditFlag>\n" % k.auditFlag outstr += " <docpage>%s</docpage>\n" % k.docpage outstr += " <desc>%s</desc>\n" % k.desc if k.restrictedFlag: outstr += " <restricted>\n" rvlist = RestrictedValue.objects.filter(keyid__key=key) for rv in rvlist: outstr += " <value>%s</value>\n" % escape(rv.value) outstr += " </restricted>\n" outstr += " </key>\n" for host in matches: if self.namespace.aliases: aliaslist = getAliases(_hostcache[host].hostname) if self.namespace.origin: hostorigin = ' origin="%s" ' % _hostcache[host].origin else: hostorigin = '' if self.namespace.times: hostdates = ' modified="%s" created="%s" ' % ( _hostcache[host].modifieddate, _hostcache[host].createdate) else: hostdates = '' outstr += ' <host docpage="%s" %s%s>\n' % ( _hostcache[host].docpage, hostorigin, hostdates) outstr += " <hostname>%s</hostname>\n" % escape( _hostcache[host].hostname) if self.namespace.aliases and aliaslist: outstr += " <aliaslist>\n" for alias in aliaslist: outstr += " <alias>%s</alias>\n" % escape(alias) outstr += " </aliaslist>\n" outstr += " <data>\n" for p in columns: if host not in cache[p] or len(cache[p][host]) == 0: pass else: for c in cache[p][host]: outstr += ' <confitem key="%s"' % p if self.namespace.origin: outstr += ' origin=%s' % quoteattr(c['origin']) if self.namespace.times: outstr += ' modified="%s" created="%s"' % ( c['modifieddate'], c['createdate']) outstr += '>%s</confitem>\n' % escape(c['value']) outstr += " </data>\n" outstr += " </host>\n" outstr += "</hostinfo>\n" return outstr