def _target_polling_points(key, _configuration): """Get list of dicts of SNMP information in configuration file. Args: group: Group name to filter results by Returns: result: List of IPTargetPollingPoints objects """ # Initialize key variables result = [] datapoint_key = 'oids' # Get configuration snippet sub_key = 'polling_groups' sub_config = configuration.search(key, sub_key, _configuration, die=True) # Create snmp objects groups = _validate_oids(sub_config) for group in groups: # Ignore bad values if isinstance(group, dict) is False: continue # Process data if 'ip_targets' and datapoint_key in group: for ip_target in group['ip_targets']: poll_targets = configuration.get_polling_points( group[datapoint_key]) dpt = IPTargetPollingPoints(ip_target) 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 = '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 test_get_polling_points(self): """Testing function _polling_points.""" # Initialize key values oids = ['.1.3.6.1.2.1.2.2.1.10', '.1.3.6.1.2.1.2.2.1.16'] data = [ {'address': '.1.3.6.1.2.1.2.2.1.10', 'multiplier': 8}, {'address': '.1.3.6.1.2.1.2.2.1.16', 'multiplier': 8}] # Test with good data result = configuration.get_polling_points(data) self.assertTrue(isinstance(result, list)) self.assertTrue(bool(result)) for index, value in enumerate(result): self.assertTrue(isinstance(value, PollingPoint)) self.assertEqual(value.address, oids[index]) self.assertEqual(value.multiplier, 8)
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
def _target_polling_points(_configuration): """Get list of dicts of SNMP information in configuration file. Args: _configuration: Configuration to process Returns: result: List of IPTargetPollingPoints objects """ # Initialize key variables result = [] datapoint_key = 'oids' # Get configuration snippet key = 'polling_groups' sub_config = _configuration.get(key) if sub_config is None: log_message = '''\ "{}" parameter not found in configuration file. Will not poll.''' log.log2info(55000, log_message) return result # Create snmp objects groups = _validate_oids(sub_config) for group in groups: # Ignore bad values if isinstance(group, dict) is False: continue # Process data if 'ip_targets' and datapoint_key in group: for ip_target in group['ip_targets']: poll_targets = configuration.get_polling_points( group[datapoint_key]) dpt = IPTargetPollingPoints(ip_target) 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 IPTargetPollingPoints objects """ # Initialize key variables result = [] datapoint_key = 'points' # 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(60003, log_message) return result # Create snmp objects for group in groups: # Ignore bad values if isinstance(group, dict) is False: continue # Process data if 'ip_targets' and datapoint_key in group: for ip_target in group['ip_targets']: poll_targets = configuration.get_polling_points( group[datapoint_key]) dpt = IPTargetPollingPoints(ip_target) 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 IPTargetPollingPoints objects """ # Initialize key variables result = [] datapoint_key = 'points' # Get configuration snippet key = PATTOO_AGENT_BACNETIPD 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 if 'ip_targets' and datapoint_key in group: for ip_target in group['ip_targets']: poll_targets = configuration.get_polling_points( group[datapoint_key]) dpt = IPTargetPollingPoints(ip_target) dpt.add(poll_targets) if dpt.valid is True: result.append(dpt) return result
def _create_drv(self, data, register_type): """Create a list of TargetRegisterVariables for polling. Args: data: Configuration dict Returns: result: list of TargetRegisterVariables """ # Initialize key variables result = [] dpts = [] # Only return valid value if isinstance(data, dict) is True: # Screen data for keys and correct type if register_type not in ['input_registers', 'holding_registers']: return [] if isinstance(data['ip_targets'], list) is False and isinstance( data[register_type], list) is False: return [] # Get the modbus unit value unit = _get_unit(data) # Create polling targets for ip_target in data['ip_targets']: poll_targets = configuration.get_polling_points( data[register_type]) dpt = IPTargetPollingPoints(ip_target) dpt.add(poll_targets) if dpt.valid is True: dpts.append(dpt) # Unpack the IPTargetPollingPoints for dpt in dpts: ip_target = dpt.target m_dict = {} variables = [] # Extract data from IPTargetPollingPoints for item in dpt.data: multiplier = item.multiplier if multiplier not in m_dict: m_dict[multiplier] = [item.address] else: m_dict[multiplier].append(item.address) # Create RegisterVariable objects for multiplier, registers in sorted(m_dict.items()): register_counts = _create_register_counts(registers) for register, count in register_counts: variables.append( _create_register_variable(register_type, register=register, count=count, unit=unit, multiplier=multiplier)) # Create TargetRegisterVariables object drv = TargetRegisterVariables(ip_target) drv.add(variables) result.append(drv) # Return return result