Пример #1
0
 def setUp(self):
     """
     Creates and sets up ICMP monitor
     """
     self.loop = asyncio.get_event_loop()
     self.subscribers = {}
     self.obj = CpeMonitoringModule()
     self._monitor = ICMPMonitoring(self.obj, polling_interval=5,
                                    service_loop=self.loop,
                                    mtr_interface=LOCALHOST)
Пример #2
0
def main():
    """Start monitord"""
    manual_ping_targets = {}
    service = MagmaService('monitord', mconfigs_pb2.MonitorD())

    # Optionally pipe errors to Sentry
    sentry_init(service_name=service.name,
                sentry_mconfig=service.shared_mconfig.sentry_config)

    # Monitoring thread loop
    mtr_interface = load_service_config("monitord")["mtr_interface"]

    # Add manual IP targets from yml file
    try:
        targets = load_service_config("monitord")["ping_targets"]
        for target, data in targets.items():
            ip_string = data.get("ip")
            if ip_string:
                ip = IPAddress(
                    version=IPAddress.IPV4,
                    address=str.encode(ip_string),
                )
                logging.debug(
                    'Adding %s:%s:%s to ping target',
                    target,
                    ip.version,
                    ip.address,
                )
                manual_ping_targets[target] = ip
    except KeyError:
        logging.warning("No ping targets configured")

    cpe_monitor = CpeMonitoringModule()
    cpe_monitor.set_manually_configured_targets(manual_ping_targets)

    icmp_monitor = ICMPJob(
        cpe_monitor,
        service.mconfig.polling_interval,
        service.loop,
        mtr_interface,
    )
    icmp_monitor.start()

    # Register a callback function for GetOperationalStates
    service.register_operational_states_callback(
        lambda: _get_serialized_subscriber_states(cpe_monitor), )

    # Run the service loop
    service.run()

    # Cleanup the service
    service.close()
Пример #3
0
class ICMPMonitoringTests(unittest.TestCase):
    """
    Test class for the ICMPMonitor class
    """

    def _add_test_subscriber(self, imsi):
        ip = IPAddress(version=IPAddress.IPV4, address=b'127.0.0.1')
        self.subscribers[imsi] = ip

    async def _ping_local(self):
        return await self._monitor._ping_targets(
            [LOCALHOST],
            self.subscribers,
        )

    def setUp(self):
        """
        Creates and sets up ICMP monitor
        """
        self.loop = asyncio.get_event_loop()
        self.subscribers = {}
        self.obj = CpeMonitoringModule()
        self._monitor = ICMPJob(
            self.obj, polling_interval=5,
            service_loop=self.loop,
            mtr_interface=LOCALHOST,
        )

    def test_ping_subscriber_saves_response(self):
        imsi = 'IMSI00000000001'
        self._add_test_subscriber(imsi)
        self.loop.run_until_complete(self._ping_local())
        sub_states = self.obj.get_subscriber_state()
        self.loop.close()
        self.assertTrue(imsi in sub_states)
Пример #4
0
def main():
    """ main() for monitord service"""
    manual_ping_targets = {}
    service = MagmaService('monitord', mconfigs_pb2.MonitorD())

    # Optionally pipe errors to Sentry
    sentry_init()

    # Monitoring thread loop
    mtr_interface = load_service_config("monitord")["mtr_interface"]

    # Add manual IP targets from yml file
    try:
        targets = load_service_config("monitord")["ping_targets"]
        for target, data in targets.items():
            if "ip" in data:
                ip = IPAddress(version=IPAddress.IPV4,
                               address=str.encode(data["ip"]))
                logging.debug(
                    'Adding {}:{}:{} to ping target'.format(target, ip.version,
                                                            ip.address))
                manual_ping_targets[target] = ip
    except KeyError:
        logging.warning("No ping targets configured")

    cpe_monitor = CpeMonitoringModule()
    cpe_monitor.set_manually_configured_targets(manual_ping_targets)

    icmp_monitor = ICMPMonitoring(cpe_monitor,
                                  service.mconfig.polling_interval,
                                  service.loop, mtr_interface)
    icmp_monitor.start()

    # Register a callback function for GetOperationalStates
    service.register_operational_states_callback(
        _get_serialized_subscriber_states(cpe_monitor))

    # Run the service loop
    service.run()

    # Cleanup the service
    service.close()
Пример #5
0
def _get_serialized_subscriber_states(cpe_monitor: CpeMonitoringModule):
    return serialize_subscriber_states(cpe_monitor.get_subscriber_state())