Hello,
I have temp table created as such:
CREATE TABLE #Raw_NIC_Imported_TMP(
[MACAddress] [varchar](50) NOT NULL,
[Host] [varchar](255) NOT NULL,
[IPAddress] [varchar](50) NOT NULL,
[IPSubnet] [varchar](50) NULL,
[DefaultIPGateway] [varchar](50) NULL,
[DNSServer1] [varchar](50) NULL,
[DNSServer2] [varchar](50) NULL,
[WINSPrimary] [varchar](50) NULL,
[WINSSecondary] [varchar](50) NULL,
[InterfaceName] [varchar](255) NULL,
CONSTRAINT [PK_IPAddress1] PRIMARY KEY CLUSTERED ( [IPAddress] ASC )
);
The contents of the file varies depending on which computers get audited. So one truth is that if a system is audited, all of its network adapters are captured along with all of their assigned IP Addresses.
Example Data:
MACAddress Host IPAddress IPSubnet DefaultIPGateway DNSServer1 DNSServer2 WINSPrimary WINSSecondary InterfaceName
00:1F:C9:4E:B5:01 SVR1.my.domain 10.191.32.11 255.255.255.0 10.191.32.254 10.10.2.20 10.10.2.22 NULL NULL Broadcom NetXtreme 57xx Gigabit Controller
00:50:56:D0:00:01 SVR1.my.domain 192.168.43.1 255.255.255.0 NULL NULL NULL NULL NULL VMware Virtual Ethernet Adapter for VMnet1
00:50:56:F0:00:08 SVR1.my.domain 192.168.61.1 255.255.255.0 NULL NULL NULL NULL NULL VMware Virtual Ethernet Adapter for VMnet8
00:50:56:C0:00:08 SVR3.my.domain 192.168.66.1 255.255.255.0 NULL NULL NULL NULL NULL VMware Virtual Ethernet Adapter for VMnet8
78:2B:AB:1A:0F:1E SVR3.my.domain 10.191.32.1 255.255.255.0 10.191.32.254 10.10.2.20 10.10.2.22 NULL NULL Broadcom BCM5716C NetXtreme II GigE (NDIS VBD Client) #11
00:50:56:E0:00:01 SVR3.my.domain 192.168.160.1 255.255.255.0 NULL NULL NULL NULL NULL VMware Virtual Ethernet Adapter for VMnet1
I have already set up a MERGE process that inserts or updates the production table below that that handles new additions or updates to existing entries.
CREATE TABLE tbl_Raw_NIC_Imported(
[MACAddress] [varchar](50) NOT NULL,
[Host] [varchar](255) NOT NULL,
[IPAddress] [varchar](50) NOT NULL,
[IPSubnet] [varchar](50) NULL,
[DefaultIPGateway] [varchar](50) NULL,
[DNSServer1] [varchar](50) NULL,
[DNSServer2] [varchar](50) NULL,
[WINSPrimary] [varchar](50) NULL,
[WINSSecondary] [varchar](50) NULL,
[InterfaceName] [varchar](255) NULL,
CONSTRAINT [PK_IPAddress1] PRIMARY KEY CLUSTERED ( [IPAddress] ASC ))
);
Example Data:
MACAddress Host IPAddress IPSubnet DefaultIPGateway DNSServer1 DNSServer2 WINSPrimary WINSSecondary InterfaceName
00:1F:C9:4E:B5:01 SVR1.my.domain 10.191.32.11 255.255.255.0 10.191.32.254 10.10.2.20 10.10.2.22 NULL NULL Broadcom NetXtreme 57xx Gigabit Controller
00:22:19:8B:65:F0 SVR1.my.domain 10.191.32.10 255.255.255.0 10.191.32.254 10.10.2.20 10.10.2.22 NULL NULL Broadcom BCM5708C NetXtreme II GigE (NDIS VBD Client)
00:50:56:D0:00:01 SVR1.my.domain 192.168.43.1 255.255.255.0 NULL NULL NULL NULL NULL VMware Virtual Ethernet Adapter for VMnet1
00:50:56:F0:00:08 SVR1.my.domain 192.168.61.1 255.255.255.0 NULL NULL NULL NULL NULL VMware Virtual Ethernet Adapter for VMnet8
00:50:56:C0:00:08 SVR3.my.domain 192.168.66.1 255.255.255.0 NULL NULL NULL NULL NULL VMware Virtual Ethernet Adapter for VMnet8
78:2B:AB:1A:0F:1E SVR3.my.domain 10.191.32.1 255.255.255.0 10.191.32.254 10.10.2.20 10.10.2.22 NULL NULL Broadcom BCM5716C NetXtreme II GigE (NDIS VBD Client) #11
00:50:56:E0:00:01 SVR3.my.domain 192.168.160.1 255.255.255.0 NULL NULL NULL NULL NULL VMware Virtual Ethernet Adapter for VMnet1
I have two questions as follows:
1. I would like to reverse the process in a manner of speaking. The production table is to be a true picture of the current state so I don't want adapters configurations that are no longer in use. Would someone be willing to explain or show how I might do a comparison between the PROD tbl and the TMP tbl to identify that the TMP tbl lacks the following entry and then remove it from the PROD tbl? During the merge, I match ON (TargetTable.IPAddress = SourceTable.IPAddress) AND (TargetTable.Host = SourceTable.Host).
00:22:19:8B:65:F0 SVR1.my.domain 10.191.32.10 255.255.255.0 10.191.32.254 10.10.2.20 10.10.2.22 NULL NULL Broadcom BCM5708C NetXtreme II GigE (NDIS VBD Client)
2. Within the answer to number one, how could it be composed so that it writes the lines that are removed from the PROD tbl to the HISTORY tbl?
CREATE TABLE tbl_Raw_NIC_History(
[MACAddress] [varchar](50) NOT NULL,
[Host] [varchar](255) NOT NULL,
[IPAddress] [varchar](50) NOT NULL,
[IPSubnet] [varchar](50) NULL,
[DefaultIPGateway] [varchar](50) NULL,
[DNSServer1] [varchar](50) NULL,
[DNSServer2] [varchar](50) NULL,
[WINSPrimary] [varchar](50) NULL,
[WINSSecondary] [varchar](50) NULL,
[InterfaceName] [varchar](255) NULL,
[DateRemoved] [DATETIME] NOT NULL DEFAULT (GETDATE()));
Any assistance would be greatly appreciated. I have been struggling with trying to find the correct search terms to locate an example on the Internet.
Thanks in advance,
Casey