def _process_pair_xlate_group(args): """Process pair_xlate_group cli arguments. Args: args: CLI argparse parser arguments Returns: None """ # Initialize key variables exists = pair_xlate_group.idx_exists(args.idx_pair_xlate_group) if bool(exists) is True: # Check for duplicates duplicate = pair_xlate_group.exists(args.name) if bool(duplicate) is True: log_message = ('''\ Translation group "{}" already exists.'''.format(args.name)) log.log2die(20075, log_message) # Update if args.idx_pair_xlate_group != 1: pair_xlate_group.update_name(args.idx_pair_xlate_group, args.name) else: log_message = 'Cannot change Translation group "1".' log.log2die(20072, log_message) else: log_message = ('''\ Translation group "{}" not found.'''.format(args.idx_pair_xlate_group)) log.log2die(20074, log_message)
def test_assign(self): """Testing method / function assign.""" # Add an entry to the database name = data.hashstring(str(random())) pair_xlate_group.insert_row(name) # Make sure it exists idx_pair_xlate_group = pair_xlate_group.exists(name) # Verify the index exists result = pair_xlate_group.idx_exists(idx_pair_xlate_group) self.assertTrue(result) # Prepare for adding an entry to the database agent_id = data.hashstring(str(random())) agent_target = data.hashstring(str(random())) agent_program = data.hashstring(str(random())) # Make sure it does not exist result = agent.exists(agent_id, agent_target) self.assertFalse(bool(result)) # Add an entry to the database agent.insert_row(agent_id, agent_target, agent_program) idx_agent = agent.exists(agent_id, agent_target) # Assign agent.assign(idx_agent, idx_pair_xlate_group) # Get assigned idx_pair_xlate_group for the agent group with db.db_query(20099) as session: result = session.query(Agent.idx_pair_xlate_group).filter( Agent.idx_agent == idx_agent).one() idx_new = result.idx_pair_xlate_group self.assertEqual(idx_pair_xlate_group, idx_new)
def test_insert_row(self): """Testing method / function insert_row.""" # Add an entry to the database name = data.hashstring(str(random())) pair_xlate_group.insert_row(name) # Make sure it exists idx_pair_xlate_group = pair_xlate_group.exists(name) # Verify the index exists result = pair_xlate_group.idx_exists(idx_pair_xlate_group) self.assertTrue(result)
def _process_agent(args): """Process agent cli arguments. Args: args: CLI arguments Returns: None """ # Validate parameters if bool(pair_xlate_group.idx_exists(args.idx_pair_xlate_group)) is False: log_message = ('''\ idx_pair_xlate_group "{}" not found.'''.format(args.idx_pair_xlate_group)) log.log2die(20068, log_message) if bool(agent.idx_exists(args.idx_agent)) is False: log_message = ('idx_agent "{}" not found.'.format(args.idx_agent)) log.log2die(20060, log_message) # Assign agent.assign(args.idx_agent, args.idx_pair_xlate_group)
def _insert_pair_xlate_group(): """Insert starting default entries into the PairXlate table. Args: None Returns: None """ # Initialize key variables default_name = 'Pattoo Default' idx_pair_xlate_groups = {} language_dict = {} pair_xlate_data = [ ('OPC UA Agents', [('en', 'pattoo_agent_opcuad_opcua_server', 'OPC UA Server', '')]), ('IfMIB Agents', [('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.31.1.1.1.9', 'Interface Broadcast Packets (HC inbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.31.1.1.1.8', 'Interface Multicast Packets (HC inbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.31.1.1.1.6', 'Interface Traffic (HC inbound)', 'Bits / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.31.1.1.1.7', 'Interface Unicast Packets (inbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.31.1.1.1.13', 'Interface Broadcast Packets (HC outbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.31.1.1.1.12', 'Interface Multicast Packets (HC outbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.31.1.1.1.10', 'Interface Traffic (HC outbound)', 'Bits / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.31.1.1.1.11', 'Interface Unicast Packets (HC outbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.31.1.1.1.3', 'Interface Broadcast Packets (inbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.2.2.1.13', 'Interface Discard Errors (inbound)', 'Errors / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.2.2.1.14', 'Interface Errors (inbound)', 'Errors / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.31.1.1.1.2', 'Interface Multicast Packets (inbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.2.2.1.10', 'Interface Traffic (inbound)', 'Bits / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.2.2.1.11', 'Interface Traffic (inbound)', 'Bits / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.31.1.1.1.5', 'Interface Broadcast Packets (outbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.2.2.1.19', 'Interface Discard Errors (outbound)', 'Errors / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.2.2.1.20', 'Interface Errors (outbound)', 'Errors / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.31.1.1.1.4', 'Interface Multicast Packets (outbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.2.2.1.16', 'Interface Traffic (outbound)', 'Bits / Second'), ('en', 'pattoo_agent_snmpd_.1.3.6.1.2.1.2.2.1.17', 'Interface Unicast Packets (outbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmp_ifmibd_ifalias', 'Interface Alias', ''), ('en', 'pattoo_agent_snmp_ifmibd_ifdescr', 'Interface Description', ''), ('en', 'pattoo_agent_snmp_ifmibd_ifhcinbroadcastpkts', 'Interface Broadcast Packets (HC inbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmp_ifmibd_ifhcinmulticastpkts', 'Interface Multicast Packets (HC inbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmp_ifmibd_ifhcinoctets', 'Interface Traffic (HC inbound)', 'Bits / Second'), ('en', 'pattoo_agent_snmp_ifmibd_ifhcinucastpkts', 'Interface Unicast Packets (HC inbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmp_ifmibd_ifhcoutbroadcastpkts', 'Interface Broadcast Packets (HC outbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmp_ifmibd_ifhcoutmulticastpkts', 'Interface Multicast Packets (HC outbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmp_ifmibd_ifhcoutoctets', 'Interface Traffic (HC outbound)', 'Bits / Second'), ('en', 'pattoo_agent_snmp_ifmibd_ifhcoutucastpkts', 'Interface Unicast Packets (HC outbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmp_ifmibd_ifinbroadcastpkts', 'Interface Broadcast Packets (inbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmp_ifmibd_ifinmulticastpkts', 'Interface Multicast Packets (inbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmp_ifmibd_ifinoctets', 'Interface Traffic (inbound)', 'Bits / Second'), ('en', 'pattoo_agent_snmp_ifmibd_ifname', 'Interface Name', ''), ('en', 'pattoo_agent_snmp_ifmibd_ifoutbroadcastpkts', 'Interface Broadcast Packets (outbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmp_ifmibd_ifoutmulticastpkts', 'Interface Multicast Packets (outbound)', 'Packets / Second'), ('en', 'pattoo_agent_snmp_ifmibd_ifoutoctets', 'Interface Traffic (outbound)', 'Bits / Second'), ('en', 'pattoo_agent_snmp_ifmibd_oid', 'SNMP OID', ''), ('en', 'pattoo_agent_snmpd_ifalias', 'Interface Alias', ''), ('en', 'pattoo_agent_snmpd_ifdescr', 'Interface Description', ''), ('en', 'pattoo_agent_snmpd_ifname', 'Interface Name', ''), ('en', 'pattoo_agent_snmpd_oid', 'SNMP OID', '')]), ('Linux Agents', [('en', 'pattoo_agent_linux_autonomousd_processor', 'Processor Type', ''), ('en', 'pattoo_agent_linux_autonomousd_release', 'OS Release', ''), ('en', 'pattoo_agent_linux_autonomousd_type', 'OS Type', ''), ('en', 'pattoo_agent_linux_autonomousd_version', 'OS Version', ''), ('en', 'pattoo_agent_linux_autonomousd_cpus', 'OS CPU Count', ''), ('en', 'pattoo_agent_linux_autonomousd_hostname', 'Hostname', ''), ('en', 'pattoo_agent_linux_autonomousd_disk_partition_device', 'Disk Partition', ''), ('en', 'pattoo_agent_linux_autonomousd_disk_partition_fstype', 'Filesystem Type', ''), ('en', 'pattoo_agent_linux_autonomousd_disk_partition_mountpoint', 'Mount Point', ''), ('en', 'pattoo_agent_linux_autonomousd_disk_partition_opts', 'Partition Options', ''), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_percent_user', 'User (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_percent_nice', 'Nice (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_percent_system', 'System (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_percent_idle', 'Idle (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_percent_iowait', 'IO Wait (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_percent_irq', 'IRQ (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_percent_softirq', 'Soft IRQ (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_percent_steal', 'Steal (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_percent_guest', 'Guest (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_percent_guest_nice', 'Guest / Nice (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_user', 'User (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_nice', 'Nice (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_system', 'System (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_idle', 'Idle (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_iowait', 'IO Wait (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_irq', 'IRQ (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_softirq', 'Soft IRQ (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_steal', 'Steal (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_guest', 'Guest (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_times_guest_nice', 'Guest / Nice (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_cpu_stats_ctx_switches', 'CPU (Context Switches)', 'Events / Second'), ('en', 'pattoo_agent_linux_autonomousd_cpu_stats_interrupts', 'CPU (Context Switches)', 'Events / Second'), ('en', 'pattoo_agent_linux_autonomousd_cpu_stats_soft_interrupts', 'CPU (Soft Interrupts)', 'Events / Second'), ('en', 'pattoo_agent_linux_autonomousd_cpu_stats_syscalls', 'CPU (System Calls)', 'Events / Second'), ('en', 'pattoo_agent_linux_autonomousd_memory_total', 'Memory (Total)', 'Bytes'), ('en', 'pattoo_agent_linux_autonomousd_memory_available', 'Memory (Available)', 'Bytes'), ('en', 'pattoo_agent_linux_autonomousd_memory_percent', 'Memory (Percent)', 'Percentage Utilization'), ('en', 'pattoo_agent_linux_autonomousd_memory_used', 'Memory (Used)', 'Bytes'), ('en', 'pattoo_agent_linux_autonomousd_memory_free', 'Memory (Free)', 'Bytes'), ('en', 'pattoo_agent_linux_autonomousd_memory_active', 'Memory (Active)', 'Bytes'), ('en', 'pattoo_agent_linux_autonomousd_memory_inactive', 'Memory (Inactive)', 'Bytes'), ('en', 'pattoo_agent_linux_autonomousd_memory_buffers', 'Memory (Buffers)', 'Bytes'), ('en', 'pattoo_agent_linux_autonomousd_memory_cached', 'Memory (Cached)', 'Bytes'), ('en', 'pattoo_agent_linux_autonomousd_memory_shared', 'Memory (Shared)', 'Bytes'), ('en', 'pattoo_agent_linux_autonomousd_memory_slab', 'Memory (Slab)', 'Bytes'), ('en', 'pattoo_agent_linux_autonomousd_swap_memory_total', 'Swap Memory (Total)', 'Bytes'), ('en', 'pattoo_agent_linux_autonomousd_swap_memory_used', 'Swap Memory (Used)', 'Bytes'), ('en', 'pattoo_agent_linux_autonomousd_swap_memory_free', 'Swap Memory (Free)', 'Bytes'), ('en', 'pattoo_agent_linux_autonomousd_swap_memory_percent', 'Swap Memory (Percent)', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_swap_memory_sin', 'Swap Memory (In)', 'Bytes / Second'), ('en', 'pattoo_agent_linux_autonomousd_swap_memory_sout', 'Swap Memory (Out)', 'Bytes / Second'), ('en', 'pattoo_agent_linux_autonomousd_disk_partition_disk_usage_total', 'Disk size', 'Bytes'), ('en', 'pattoo_agent_linux_autonomousd_disk_partition_disk_usage_used', 'Disk Utilization', 'Percent'), ('en', 'pattoo_agent_linux_autonomousd_disk_partition_disk_usage_free', 'Disk Free', 'Bytes'), ('en', 'pattoo_agent_linux_autonomousd_disk_partition_disk_usage_percent', 'Disk Percentage Utilization', ''), ('en', 'pattoo_agent_linux_autonomousd_disk_io_read_count', 'Disk I/O (Read Count)', 'Reads / Second'), ('en', 'pattoo_agent_linux_autonomousd_disk_partition', 'Disk Partition', ''), ('en', 'pattoo_agent_linux_autonomousd_disk_io_write_count', 'Disk I/O (Write Count)', 'Writes / Second'), ('en', 'pattoo_agent_linux_autonomousd_disk_io_read_bytes', 'Disk I/O (Bytes Read)', 'Bytes / Second'), ('en', 'pattoo_agent_linux_autonomousd_disk_io_write_bytes', 'Disk I/O (Bytes Written)', 'Bytes / Second'), ('en', 'pattoo_agent_linux_autonomousd_disk_io_read_time', 'Disk I/O (Read Time)', ''), ('en', 'pattoo_agent_linux_autonomousd_disk_io_write_time', 'Disk I/O (Write Time)', ''), ('en', 'pattoo_agent_linux_autonomousd_disk_io_read_merged_count', 'Disk I/O (Read Merged Count)', 'Reads / Second'), ('en', 'pattoo_agent_linux_autonomousd_disk_io_write_merged_count', 'Disk I/O (Write Merged Count)', 'Writes / Second'), ('en', 'pattoo_agent_linux_autonomousd_disk_io_busy_time', 'Disk I/O (Busy Time)', ''), ('en', 'pattoo_agent_linux_autonomousd_network_io_bytes_sent', 'Network I/O (Bandwidth Inbound)', 'Bits / Second'), ('en', 'pattoo_agent_linux_autonomousd_network_io_interface', 'Network Interface', ''), ('en', 'pattoo_agent_linux_autonomousd_network_io_bytes_recv', 'Network I/O (Bandwidth Outbound)', 'Bits / Second'), ('en', 'pattoo_agent_linux_autonomousd_network_io_packets_sent', 'Network I/O (Packets Sent)', 'Packets / Second'), ('en', 'pattoo_agent_linux_autonomousd_network_io_packets_recv', 'Network I/O (Packets Received)', 'Packets / Second'), ('en', 'pattoo_agent_linux_autonomousd_network_io_errin', 'Network I/O (Errors Inbound)', 'Errors / Second'), ('en', 'pattoo_agent_linux_autonomousd_network_io_errout', 'Network I/O (Errors Outbound)', 'Errors / Second'), ('en', 'pattoo_agent_linux_autonomousd_network_io_dropin', 'Network I/O (Drops Inbound)', 'Drops / Second'), ('en', 'pattoo_agent_linux_autonomousd_network_io_dropout', 'Network I/O (Drops Outbound)', 'Drops / Second'), ('en', 'pattoo_agent_linux_autonomousd_cpu_frequency', 'CPU Frequency', 'Frequency'), ('en', 'pattoo_agent_linux_spoked_processor', 'Processor Type', ''), ('en', 'pattoo_agent_linux_spoked_release', 'OS Release', ''), ('en', 'pattoo_agent_linux_spoked_type', 'OS Type', ''), ('en', 'pattoo_agent_linux_spoked_version', 'OS Version', ''), ('en', 'pattoo_agent_linux_spoked_cpus', 'OS CPU Count', ''), ('en', 'pattoo_agent_linux_spoked_hostname', 'Hostname', ''), ('en', 'pattoo_agent_linux_spoked_disk_partition_device', 'Disk Partition', ''), ('en', 'pattoo_agent_linux_spoked_disk_partition_fstype', 'Filesystem Type', ''), ('en', 'pattoo_agent_linux_spoked_disk_partition_mountpoint', 'Mount Point', ''), ('en', 'pattoo_agent_linux_spoked_disk_partition_opts', 'Partition Options', ''), ('en', 'pattoo_agent_linux_spoked_cpu_times_percent_user', 'User (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_percent_nice', 'Nice (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_percent_system', 'System (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_percent_idle', 'Idle (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_percent_iowait', 'IO Wait (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_percent_irq', 'IRQ (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_percent_softirq', 'Soft IRQ (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_percent_steal', 'Steal (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_percent_guest', 'Guest (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_percent_guest_nice', 'Guest / Nice (Percent CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_user', 'User (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_nice', 'Nice (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_system', 'System (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_idle', 'Idle (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_iowait', 'IO Wait (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_irq', 'IRQ (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_softirq', 'Soft IRQ (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_steal', 'Steal (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_guest', 'Guest (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_times_guest_nice', 'Guest / Nice (CPU Usage)', 'Percent'), ('en', 'pattoo_agent_linux_spoked_cpu_stats_ctx_switches', 'CPU (Context Switches)', 'Events / Second'), ('en', 'pattoo_agent_linux_spoked_cpu_stats_interrupts', 'CPU (Context Switches)', 'Events / Second'), ('en', 'pattoo_agent_linux_spoked_cpu_stats_soft_interrupts', 'CPU (Soft Interrupts)', 'Events / Second'), ('en', 'pattoo_agent_linux_spoked_cpu_stats_syscalls', 'CPU (System Calls)', 'Events / Second'), ('en', 'pattoo_agent_linux_spoked_memory_total', 'Memory (Total)', 'Bytes'), ('en', 'pattoo_agent_linux_spoked_memory_available', 'Memory (Available)', 'Bytes'), ('en', 'pattoo_agent_linux_spoked_memory_percent', 'Memory (Percent)', ''), ('en', 'pattoo_agent_linux_spoked_memory_used', 'Memory (Used)', 'Bytes'), ('en', 'pattoo_agent_linux_spoked_memory_free', 'Memory (Free)', 'Bytes'), ('en', 'pattoo_agent_linux_spoked_memory_active', 'Memory (Active)', 'Bytes'), ('en', 'pattoo_agent_linux_spoked_memory_inactive', 'Memory (Inactive)', 'Bytes'), ('en', 'pattoo_agent_linux_spoked_memory_buffers', 'Memory (Buffers)', 'Bytes'), ('en', 'pattoo_agent_linux_spoked_memory_cached', 'Memory (Cached)', 'Bytes'), ('en', 'pattoo_agent_linux_spoked_memory_shared', 'Memory (Shared)', 'Bytes'), ('en', 'pattoo_agent_linux_spoked_memory_slab', 'Memory (Slab)', 'Bytes'), ('en', 'pattoo_agent_linux_spoked_swap_memory_total', 'Swap Memory (Total)', 'Bytes'), ('en', 'pattoo_agent_linux_spoked_swap_memory_used', 'Swap Memory (Used)', 'Bytes'), ('en', 'pattoo_agent_linux_spoked_swap_memory_free', 'Swap Memory (Free)', 'Bytes'), ('en', 'pattoo_agent_linux_spoked_swap_memory_percent', 'Swap Memory (Percent)', ''), ('en', 'pattoo_agent_linux_spoked_swap_memory_sin', 'Swap Memory (In)', 'Bytes / Second'), ('en', 'pattoo_agent_linux_spoked_swap_memory_sout', 'Swap Memory (Out)', 'Bytes / Second'), ('en', 'pattoo_agent_linux_spoked_disk_partition_disk_usage_total', 'Disk size', 'Bytes'), ('en', 'pattoo_agent_linux_spoked_disk_partition_disk_usage_used', 'Disk Utilization', 'Percent'), ('en', 'pattoo_agent_linux_spoked_disk_partition_disk_usage_free', 'Disk Free', 'Bytes'), ('en', 'pattoo_agent_linux_spoked_disk_partition_disk_usage_percent', 'Disk Percentage Utilization', ''), ('en', 'pattoo_agent_linux_spoked_disk_io_read_count', 'Disk I/O (Read Count)', 'Reads / Second'), ('en', 'pattoo_agent_linux_spoked_disk_partition', 'Disk Partition', ''), ('en', 'pattoo_agent_linux_spoked_disk_io_write_count', 'Disk I/O (Write Count)', 'Writes / Second'), ('en', 'pattoo_agent_linux_spoked_disk_io_read_bytes', 'Disk I/O (Bytes Read)', 'Bytes / Second'), ('en', 'pattoo_agent_linux_spoked_disk_io_write_bytes', 'Disk I/O (Bytes Written)', 'Bytes / Second'), ('en', 'pattoo_agent_linux_spoked_disk_io_read_time', 'Disk I/O (Read Time)', ''), ('en', 'pattoo_agent_linux_spoked_disk_io_write_time', 'Disk I/O (Write Time)', ''), ('en', 'pattoo_agent_linux_spoked_disk_io_read_merged_count', 'Disk I/O (Read Merged Count)', 'Reads / Second'), ('en', 'pattoo_agent_linux_spoked_disk_io_write_merged_count', 'Disk I/O (Write Merged Count)', 'Writes / Second'), ('en', 'pattoo_agent_linux_spoked_disk_io_busy_time', 'Disk I/O (Busy Time)', ''), ('en', 'pattoo_agent_linux_spoked_network_io_bytes_sent', 'Network I/O (Bandwidth Inbound)', 'Bits / Second'), ('en', 'pattoo_agent_linux_spoked_network_io_interface', 'Network Interface', ''), ('en', 'pattoo_agent_linux_spoked_network_io_bytes_recv', 'Network I/O (Bandwidth Outbound)', 'Bits / Second'), ('en', 'pattoo_agent_linux_spoked_network_io_packets_sent', 'Network I/O (Packets Sent)', 'Packets / Second'), ('en', 'pattoo_agent_linux_spoked_network_io_packets_recv', 'Network I/O (Packets Received)', 'Packets / Second'), ('en', 'pattoo_agent_linux_spoked_network_io_errin', 'Network I/O (Errors Inbound)', 'Errors / Second'), ('en', 'pattoo_agent_linux_spoked_network_io_errout', 'Network I/O (Errors Outbound)', 'Errors / Second'), ('en', 'pattoo_agent_linux_spoked_network_io_dropin', 'Network I/O (Drops Inbound)', 'Drops / Second'), ('en', 'pattoo_agent_linux_spoked_network_io_dropout', 'Network I/O (Drops Outbound)', 'Drops / Second'), ('en', 'pattoo_agent_linux_spoked_cpu_frequency', 'CPU Frequency', '')]) ] # Insert into PairXlateGroup if pair_xlate_group.idx_exists(1) is False: # Create the default PairXlateGroup pair_xlate_group.insert_row(default_name) # Create PairXlateGroup for some pattoo agents for name, rows in pair_xlate_data: # Get PairXlateGroup index value after creating an entry pair_xlate_group.insert_row(name) idx_pair_xlate_group = pair_xlate_group.exists(name) idx_pair_xlate_groups[name] = idx_pair_xlate_group # Insert values into the PairXlate table for PairXlateGroup for row in rows: if len(row) != 4: log_message = ( 'Translation line "{}" is invalid.'.format(row)) log.log2die_safe(20140, log_message) (code, _key, _value, _units) = row idx_language = language_dict.get(language) if bool(idx_language) is False: idx_language = language.exists(code) language_dict[code] = idx_language pair_xlate.insert_row(_key, _value, _units, idx_language, idx_pair_xlate_group)
def update(_df, idx_pair_xlate_group): """Import data into the . Args: _df: Pandas DataFrame with the following headings ['language', 'key', 'translation', 'units'] idx_pair_xlate_group: PairXlateGroup table index Returns: None """ # Initialize key variables languages = {} headings_expected = ['language', 'key', 'translation', 'units'] headings_actual = [] valid = True count = 0 # Check if group exists if pair_xlate_group.idx_exists(idx_pair_xlate_group) is False: log_message = ('''\ idx_pair_xlate_group {} does not exist'''.format(idx_pair_xlate_group)) log.log2die(20077, log_message) # Test columns for item in _df.columns: headings_actual.append(item) for item in headings_actual: if item not in headings_expected: valid = False if valid is False: log_message = ('''Imported data must have the following headings "{}"\ '''.format('", "'.join(headings_expected))) log.log2die(20053, log_message) # Process the DataFrame for _, row in _df.iterrows(): # Initialize variables at the top of the loop count += 1 code = row['language'].lower() key = str(row['key']) translation = str(row['translation']) units = str(row['units']) # Store the idx_language value in a dictionary to improve speed idx_language = languages.get(code) if bool(idx_language) is False: idx_language = language.exists(code) if bool(idx_language) is True: languages[code] = idx_language else: log_message = ('''\ Language code "{}" on line {} of imported translation file not found during \ key-pair data importation. Please correct and try again. All other valid \ entries have been imported.\ '''.format(code, count)) log.log2see(20078, log_message) continue # Update the database if pair_xlate_exists(idx_pair_xlate_group, idx_language, key) is True: # Update the record update_row(key, translation, units, idx_language, idx_pair_xlate_group) else: # Insert a new record insert_row(key, translation, units, idx_language, idx_pair_xlate_group)