Exemple #1
0
    def target_polling_points(self):
        """Get list polling target information in configuration file.

        Args:
            group: Group name to filter results by

        Returns:
            result: List of TargetPollingPoints objects

        """
        # Initialize key variables
        result = []

        # Get configuration snippet
        key = 'polling_groups'
        groups = self._agent_config.get(key)

        if groups is None:
            log_message = '''\
    "{}" parameter not found in configuration file. Will not poll.'''
            log.log2info(70003, log_message)
            return result

        # Create snmp objects
        for group in groups:
            # Ignore bad values
            if isinstance(group, dict) is False:
                continue

            # Process data
            ip_target = group.get('ip_target')
            ip_port = group.get('ip_port')
            username = group.get('username')
            password = group.get('password')
            auth = OPCUAauth(
                ip_target=ip_target,
                ip_port=ip_port,
                username=username,
                password=password)
            nodes = group.get('nodes')
            poll_targets = configuration.get_polling_points(nodes)
            dpt = TargetPollingPoints(auth)
            dpt.add(poll_targets)
            if dpt.valid is True:
                result.append(dpt)
        return result
    def target_polling_points(self):
        """Get list polling target information in configuration file.

        Args:
            group: Group name to filter results by

        Returns:
            result: List of TargetPollingPoints objects

        """
        # Initialize key variables
        result = []

        # Get configuration snippet
        key = PATTOO_AGENT_OPCUAD
        sub_key = 'polling_groups'
        groups = configuration.search(key,
                                      sub_key,
                                      self._agent_config,
                                      die=True)

        # Create snmp objects
        for group in groups:
            # Ignore bad values
            if isinstance(group, dict) is False:
                continue

            # Process data
            ip_target = group.get('ip_target')
            ip_port = group.get('ip_port')
            username = group.get('username')
            password = group.get('password')
            auth = OPCUAauth(ip_target=ip_target,
                             ip_port=ip_port,
                             username=username,
                             password=password)
            nodes = group.get('nodes')
            poll_targets = configuration.get_polling_points(nodes)
            dpt = TargetPollingPoints(auth)
            dpt.add(poll_targets)
            if dpt.valid is True:
                result.append(dpt)
        return result
Exemple #3
0
    def test_add(self):
        """Testing function append."""
        # Initialize TargetPollingPoints
        target = 'localhost'
        dpt = TargetPollingPoints(target)
        self.assertEqual(dpt.target, target)
        self.assertFalse(dpt.valid)

        # Add bad values
        values = [True, False, None, 'foo']
        for value in values:
            dpt.add(value)
            self.assertFalse(dpt.valid)

        # Add good values
        address = 20
        multiplier = 6
        value = PollingPoint(address=address, multiplier=multiplier)
        dpt.add(value)
        self.assertTrue(dpt.valid)
        self.assertEqual(len(dpt.data), 1)
        for item in dpt.data:
            self.assertEqual(item.address, address)
            self.assertEqual(item.multiplier, multiplier)

        # Try adding bad values and the results must be the same
        values = [True, False, None, 'foo']
        for value in values:
            dpt.add(value)
            self.assertTrue(dpt.valid)
            self.assertEqual(len(dpt.data), 1)
            item = dpt.data[0]
            self.assertEqual(item.address, address)
            self.assertEqual(item.multiplier, multiplier)