这种问题发生的原因是因为用户在升级linux服务器时没有首先在SCOM里面把该linux agent删除,导致SCOM OperationsManager 数据库里面出现两个重复的linxu 服务器名。
因此必须到数据库里面找到重复的linux服务器名,并删除不需要的记录。
1. 首先我们要在OperationsManager database 里面找到重复的服务器 :
-------------------------------
DECLARE @NeededTypeName NVARCHAR(256)
DECLARE@ManagedTypeIdForManagedEntitiesByManagedTypeAndDerived UNIQUEIDENTIFIER
SET @NeededTypeName = N'Microsoft.Unix.OperatingSystem' --Enter the Class on which we are looking for duplicate entries
SET @ManagedTypeIdForManagedEntitiesByManagedTypeAndDerived= (
SELECT ManagedTypeId
FROM ManagedType
WHERE TypeName = @NeededTypeName
)
SELECT
[ManagedEntityGenericView].[Id],
[ManagedEntityGenericView].[Name],
[ManagedEntityGenericView].[Path],
[ManagedEntityGenericView].[FullName],
[ManagedEntityGenericView].[LastModified],
[ManagedEntityGenericView].[TypedManagedEntityId],
NULL AS SourceEntityId
FROM dbo.ManagedEntityGenericView
INNER JOIN (
SELECT DISTINCT [BaseManagedEntityId]
FROM dbo.[TypedManagedEntity] TME WITH(NOLOCK)
JOIN [dbo].[DerivedManagedTypes] DT
ON DT.[DerivedTypeId] =TME.[ManagedTypeId]
WHERE
DT.[BaseTypeId] =@ManagedTypeIdForManagedEntitiesByManagedTypeAndDerived AND
TME.IsDeleted = 0
) AS ManagedTypeIdForManagedEntitiesByManagedTypeAndDerived
ONManagedTypeIdForManagedEntitiesByManagedTypeAndDerived.[BaseManagedEntityId] =[Id]
WHERE
[IsDeleted] = 0 AND
[TypedMonitoringObjectIsDeleted] = 0 AND
[ManagedEntityGenericView].[Path] IN (
SELECT [BaseManagedEntity].[Path]
FROM [BaseManagedEntity]
GROUP BY [BaseManagedEntity].[Path]
HAVING COUNT([BaseManagedEntity].[Path]) > 1
)
ORDER BY [ManagedEntityGenericView].[Path]
-------------------------------
2. 复制出我们要删除的记录的TypedManagedEntityId GUIDs值,然后替换掉以下命令的GUID,并运行命令进行删除。
-------------------------------
DECLARE @TypedManagedEntityId uniqueidentifier
DECLARE @LastErr INT
DECLARE @TimeGenerated DATETIME
SET @TimeGenerated = GETUTCDATE()
DECLARE EntitiesToBeRemovedCursor CURSOR LOCAL FORWARD_ONLYREAD_ONLY FOR
SELECT TME.TypedManagedEntityId
FROM TypedManagedEntity TME
WHERE TME.TypedManagedEntityId IN (‘02E86C0B-D082-A407-5877-0E69B8F5D9DC’) -- Enterall the GUID here, each between quotes and separated by comma
OPEN EntitiesToBeRemovedCursor
FETCH NEXT FROM EntitiesToBeRemovedCursor
INTO @TypedManagedEntityId
WHILE @@FETCH_STATUS = 0
BEGIN
BEGIN TRAN
EXEC @LastErr = [p_TypedManagedEntityDelete]@TypedManagedEntityId, @TimeGenerated
IF @LastErr <> 0
GOTO Err
COMMIT TRAN
FETCH NEXT FROM EntitiesToBeRemovedCursor
INTO @TypedManagedEntityId
END
CLOSE EntitiesToBeRemovedCursor
DEALLOCATE EntitiesToBeRemovedCursor
GOTO Done
Err:
ROLLBACK TRAN
GOTO Done
Done:
SELECT '!!! SUCCESS !!!'
-------------------------------