Exemple #1
0
    def show_command_outputs_for_check(self):
        """
        Display command outputs text for selected result/check
        This method must call only when filtering on one Result.id, i.e. 
        Condition(xxx, FilterData.CHECK_ID)
        """
        result = self.get_first_result()

        if not result:
            logger.error('Invalid check id (not existing)')
        else:
            Output.title2('Results for check {category} > {check}:'.format(
                category=result.category, check=result.check))

            if result.service.host.hostname:
                hostname = ' (' + result.service.host.hostname + ')'
            else:
                hostname = ''

            Output.title2('Target: host={ip}{hostname} | port={port}/{proto} | ' \
                'service {service}'.format(
                ip       = result.service.host.ip,
                hostname = hostname,
                port     = result.service.port,
                proto    = {Protocol.TCP: 'tcp', Protocol.UDP: 'udp'}.get(
                    result.service.protocol),
                service  = result.service.name))

            print()
            for o in result.command_outputs:
                Output.title3(o.cmdline)
                print()
                print(o.output)
                print()
Exemple #2
0
    def show_command_outputs(self, result_id):
        result_check = self.sqlsess.query(Result).join(Service).join(
            Host).filter(Result.id == result_id).first()
        if not result_check:
            logger.error('Invalid check id')
            return

        command_outputs = self.sqlsess.query(CommandOutput).filter(
            CommandOutput.result_id == result_id).all()

        Output.title2('Results for check {category} > {check}:'.format(
            category=result_check.category, check=result_check.check))
        Output.title2(
            'Target: host={ip}{hostname} | port={port}/{proto} | service {service}'
            .format(ip=result_check.service.host.ip,
                    hostname=' (' + result_check.service.host.hostname +
                    ')' if result_check.service.host.hostname else '',
                    port=result_check.service.port,
                    proto={
                        Protocol.TCP: 'tcp',
                        Protocol.UDP: 'udp'
                    }.get(result_check.service.protocol),
                    service=result_check.service.name))

        print()
        for o in command_outputs:
            Output.title3(o.cmdline)
            print()
            print(o.output)
            print()