I replied:
Thank you for clarifying the situation. This is a major issue for us due to the fact that I am the network administrator, and all of our network devices are not in DNS for security. They are in host files in our management servers. Because of this, undocumented change to the new version (at least not a WELL documented change) of IPAM, I have lost hostname information on 400 management interfaces, and countless VLAN interfaces.
Is there a way to extract the information from the hostname field in the backed up database (we created before the upgrade), and import to the active database in the new custom field?
Matthews answer:
Understood, I know the frustration. What I have may work for you as it was created for a similar bug that was removing hostname information from IPs. It's a number of queries that you would run in the database to pull the information from the ip history, then incorporating into a custom field of your creation.
As always, before any modifications are done to your database, it is recommend that it be backed up before hand. Here are the steps below you need to do for the implementation of these queries:
Steps:
1) Set the transient interval period to unlimited (safety purposes for now)
2) Automatic Scanning has been disabled for all subnets. You can do so by selecting all the subnets, hitting Edit and disabling automatic scanning. This can be enabled after all is completed.
3) Run the script to retrieve the hostnames from IP History. (Hostname retrieval.sql)
4) For all those ip nodes the status is set to used.
5) Created a Custom field where you want the hostname information to be populated to. You will first need to modify the query Insert missing rows (Custom Field - Missing rows.sql) to place the custom hostname field in. Please replace 'Assigned_Hostname' with the Custom Field Name created in IPAM
6) Modify the query update 'CustomHostname' in rows (Custom Field - Update CustomHostname in rows.sql) for the custom hostname as well. Please replace 'Assigned_Hostname' with the Custom Field Name created in IPAM
7) Once you do this run the script to insert the missing rows followed by updating the custom hostname. (Custom Field - Missing rows.sql followed by Custom Field - Update CustomHostname in rows.sql)
8) As the scanning is disabled, we have provided the script to re-calculate the subnet usage counts. Run the recalculate subnet usage script.
The scripts themselves are attached, but I have also included them within the email body itself. I recommend having the database backed up as always and engaging your DBA. If you have any questions, please let me know.
************************************************Hostname retrieval.sql************************************************************************************
IF EXISTS (SELECT * FROM sys.objects WHERE [name]='IPAM_HostnamesBackup' AND [type]='u')
DROP TABLE [IPAM_HostnamesBackup]
GO
WITH [Hostnames] AS
(
SELECT ROW_NUMBER() OVER (PARTITION BY [IPNodeId] ORDER BY [Time] DESC) AS [RowNumber], [IPNodeId], [Time], [FromValue],[IntoValue]
FROM [IPAM_IPHistory]
WHERE [HistoryType]='3' AND [ModifiedBy] < 1000 AND [FromValue] IS NOT NULL AND [FromValue]<>'' AND
[IntoValue] IS NOT NULL AND [IntoValue]=''
)
SELECT [IPNodeId], [Time], [FromValue]
INTO [IPAM_HostnamesBackup]
FROM [Hostnames] WHERE [RowNumber] = 1
GO
SELECT host.[IPNodeId], host.[FromValue] FROM [IPAM_HostnamesBackup] host
WHERE NOT EXISTS(SELECT 1 FROM [IPAM_NodeAttrData] attr WHERE attr.[IPNodeId]=host.[IPNodeId])
**************************************************************************************************************************************************************
************************************************Update CustomHoastname in rows.sql******************************************************************
UPDATE [IPAM_NodeAttrData] SET [Assigned_Hostname] = host.[FromValue]
FROM [IPAM_NodeAttrData] attr
INNER JOIN [IPAM_HostnamesBackup] host ON attr.[IPNodeId] = host.[IPNodeId]
**************************************************************************************************************************************************************
************************************************Update Recalculate subnet usage.sql******************************************************************
DECLARE @sid int
DECLARE subnets CURSOR FOR SELECT GroupId FROM IPAM_Group WHERE GroupType IN (8)
OPEN subnets
FETCH NEXT FROM subnets INTO @sid
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC IPAM_spTouchSubnetCounts @sid
FETCH NEXT FROM subnets INTO @sid
END
CLOSE subnets
DEALLOCATE subnets
EXEC IPAM_spTouchGroupCounts 0
**************************************************************************************************************************************************************
************************************************Custom Field - missing rows.sql******************************************************************
INSERT INTO [IPAM_NodeAttrData] ([IPNodeId], [Assigned_Hostname])
SELECT host.[IPNodeId], host.[FromValue] FROM [IPAM_HostnamesBackup] host
WHERE NOT EXISTS(SELECT 1 FROM [IPAM_NodeAttrData] attr WHERE attr.[IPNodeId]=host.[IPNodeId])
**************************************************************************************************************************************************************
THIS WORKED TO RECOVER MY MISSING HOSTNAMES.