コード例 #1
0
def receive_traceroute_request(traceroute_channel, method, properties, body):

    print(f"traceroute worker: received message")
    traceroute_info = json.loads(body)
    print(f"traceroute info: {traceroute_info}")

    channel.basic_ack(delivery_tag=method.delivery_tag)

    if "intuitiveNMS" not in traceroute_info:
        intuitivenms_ip = "localhost"
    else:
        intuitivenms_ip = traceroute_info["intuitiveNMS"]

    traceroute_thread = TracerouteThread(intuitivenms_ip, serial_no,
                                         traceroute_info)
    traceroute_thread.start()

    print('\n\n [*] Traceroute Worker: waiting for messages.')
コード例 #2
0
    def check(self, test_type, schedule, metadata={}, **kwargs):
        # Parse input data
        schedule = ScheduleProxy(**schedule)
        if not hasattr(schedule, "metadata"): schedule.metadata = cPickle.dumps(metadata)
        elif not metadata and schedule.metadata: metadata = cPickle.loads(schedule.metadata)
        if test_type == 'service': schedule.check_type = schedule.service_type
        elif test_type == 'resource': schedule.check_type = schedule.resource_check_method

        if test_type != 'traceroute':
            # Load checker
            try:
                checker = self.checker_plugins[schedule.check_type]
            except KeyError:
                return self._reportResult(test_type, None, datetime.now(), -1, 0, "Unable to find plugin for %s" % schedule.check_type)     

        # Set schedule ip address
        if schedule.ip_address == None:
            if iplib.is_dot(schedule.fqdn):
                schedule.ip_address = schedule.fqdn
            else:
                try: schedule.ip_address = socket.gethostbyname(schedule.fqdn)
                except:
                    if test_type != 'traceroute' and checker.textkey == 'resource.snmp':
                        return self._reportResourceResults(test_type, schedule, datetime.now(), None, "Unable to resolve host name %s" % schedule.fqdn)
                    else:
                        return self._reportResult(test_type, schedule, datetime.now(), 0, 0, "Unable to resolve host name %s" % schedule.fqdn)

        if test_type != 'traceroute':
            try:
                if hasattr(schedule, "fqdn") and not kwargs.get("nodns"):
                    r = DNS.Request(schedule.fqdn, qtype='A').req()
                    for a in r.answers:
                        if a['typename'] != 'A': continue
                        schedule.ip_address = a['data']
                        schedule.dns_ttl_expiration = datetime.now() + timedelta(seconds=min(self.max_allowed_ttl, int(a['ttl'])))
            except: 
                logging.getLogger("checker").error("Could not find DNS info for %s: %s" % (schedule.fqdn, traceback.format_exc()))
                pass
               
            # Run checker
            if checker.textkey == 'resource.snmp':
                checker.check(schedule)
                return self._reportResourceResults(**checker.test_results)
            else:
                checker.port = None
                if hasattr(checker, "default_port"): checker.port = checker.default_port
                if schedule.port: checker.port = int(schedule.port)

                ret = checker.check(schedule, metadata)
                return self._reportResult(test_type, schedule, *ret)
        else:
            # Run traceroute
            start = time.time()
            metadata = TracerouteThread.doTraceroute(schedule)
            duration = time.time() - start
            return self._reportResult(test_type, schedule, datetime.now(), 1, duration, metadata)
コード例 #3
0
    def process_command(self, worker_info):

        if "intuitiveNMS" not in worker_info:
            self.intuitivenms = "localhost"
        else:
            self.intuitivenms = worker_info["intuitiveNMS"]

        if self.worker_type == "capture":
            worker_thread = CaptureThread(self.intuitivenms, self.serial_no,
                                          worker_info)
        elif self.worker_type == "portscan":
            worker_thread = PortscanThread(self.intuitivenms, self.serial_no,
                                           worker_info)
        elif self.worker_type == "traceroute":
            worker_thread = TracerouteThread(self.intuitivenms, self.serial_no,
                                             worker_info)
        else:
            print(f"Invalid worker_type: {self.worker_type}, exiting")
            return

        worker_thread.start()
コード例 #4
0
def process_work_request(work_type, work_info):

    if "quokka" not in work_info:
        print(f"!!! 'quokka' not present in work_info, cannot continue")
        return
    else:
        quokka = work_info["quokka"]
        print(f"---> work request received, will send results to {quokka}")

    if work_type == CAPTURE:
        work_thread = CaptureThread(quokka, work_info)
    elif work_type == PORTSCAN:
        work_thread = PortscanThread(quokka, work_info)
    elif work_type == TRACEROUTE:
        work_thread = TracerouteThread(quokka, work_info)
    elif work_type == SNOOP:
        work_thread = CaptureThread(quokka, work_info, snoop=True)
    else:
        print(
            f" !!! Invalid work_type: {work_type}, should have been caught earlier"
        )
        return

    work_thread.start()
コード例 #5
0
def process_work_request(work_type, work_info):

    if "quokka" not in work_info:
        quokka = "localhost:5001"

    else:
        quokka = work_info["quokka"]

    if work_type == CAPTURE:
        work_thread = CaptureThread(quokka, work_info)

    elif work_type == PORTSCAN:
        work_thread = PortscanThread(quokka, work_info)

    elif work_type == TRACEROUTE:
        work_thread = TracerouteThread(quokka, work_info)

    else:
        print(
            f" !!! Invalid work_type: {work_type}, should have been caught earlier"
        )
        return

    work_thread.start()