Exemplo n.º 1
0
    def DisplayShowall(self, matches):
        """Display all the known information about the matched hosts
        """
        revcache={}
        outstr=""
        for kn,kv in _akcache.items():
            revcache[kv.id]=kn

        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
Exemplo n.º 2
0
    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:
            outstr+="  <key>\n"
            outstr+="    <name>%s</name>\n" % escape(key)
            outstr+="    <type>%s</type>\n" % _akcache[key].get_validtype_display()
            outstr+="    <readonlyFlag>%s</readonlyFlag>\n" % _akcache[key].readonlyFlag
            outstr+="    <auditFlag>%s</auditFlag>\n" % _akcache[key].auditFlag
            outstr+="    <docpage>%s</docpage>\n" % _akcache[key].docpage
            outstr+="    <desc>%s</desc>\n" % _akcache[key].desc
            if _akcache[key].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