diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index e1394fd..061e567 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/SQL Queries/Data Warehouse/ConfigChurn_DW.sql b/SQL Queries/Data Warehouse/ConfigChurn_DW.sql new file mode 100644 index 0000000..94422f5 --- /dev/null +++ b/SQL Queries/Data Warehouse/ConfigChurn_DW.sql @@ -0,0 +1,24 @@ +select ManagedEntityTypeSystemName, DiscoverySystemName, count(*) As 'Changes' +from +(select distinct +MP.ManagementPackSystemName, +MET.ManagedEntityTypeSystemName, +PropertySystemName, +D.DiscoverySystemName, D.DiscoveryDefaultName, +MET1.ManagedEntityTypeSystemName As 'TargetTypeSystemName', MET1.ManagedEntityTypeDefaultName 'TargetTypeDefaultName', +ME.Path, ME.Name, +C.OldValue, C.NewValue, C.ChangeDateTime +from dbo.vManagedEntityPropertyChange C +inner join dbo.vManagedEntity ME on ME.ManagedEntityRowId=C.ManagedEntityRowId +inner join dbo.vManagedEntityTypeProperty METP on METP.PropertyGuid=C.PropertyGuid +inner join dbo.vManagedEntityType MET on MET.ManagedEntityTypeRowId=ME.ManagedEntityTypeRowId +inner join dbo.vManagementPack MP on MP.ManagementPackRowId=MET.ManagementPackRowId +inner join dbo.vManagementPackVersion MPV on MPV.ManagementPackRowId=MP.ManagementPackRowId +left join dbo.vDiscoveryManagementPackVersion DMP on DMP.ManagementPackVersionRowId=MPV.ManagementPackVersionRowId + AND CAST(DefinitionXml.query('data(/Discovery/DiscoveryTypes/DiscoveryClass/@TypeID)') AS nvarchar(max)) like '%'+MET.ManagedEntityTypeSystemName+'%' +left join dbo.vManagedEntityType MET1 on MET1.ManagedEntityTypeRowId=DMP.TargetManagedEntityTypeRowId +left join dbo.vDiscovery D on D.DiscoveryRowId=DMP.DiscoveryRowId +where ChangeDateTime > dateadd(hh,-24,getutcdate()) +) As #T +group by ManagedEntityTypeSystemName, DiscoverySystemName +order by count(*) DESC \ No newline at end of file diff --git a/SQL Queries/Data Warehouse/ConfigChurn_Properties_DW.sql b/SQL Queries/Data Warehouse/ConfigChurn_Properties_DW.sql new file mode 100644 index 0000000..3626575 --- /dev/null +++ b/SQL Queries/Data Warehouse/ConfigChurn_Properties_DW.sql @@ -0,0 +1,25 @@ +select distinct +ME.Path, +ME.Name, +MET.ManagedEntityTypeSystemName, +PropertySystemName, +C.OldValue, +C.NewValue, +C.ChangeDateTime, +MP.ManagementPackSystemName, +D.DiscoverySystemName, +D.DiscoveryDefaultName, +MET1.ManagedEntityTypeSystemName As 'TargetTypeSystemName', +MET1.ManagedEntityTypeDefaultName 'TargetTypeDefaultName' +from dbo.vManagedEntityPropertyChange C +inner join dbo.vManagedEntity ME on ME.ManagedEntityRowId=C.ManagedEntityRowId +inner join dbo.vManagedEntityTypeProperty METP on METP.PropertyGuid=C.PropertyGuid +inner join dbo.vManagedEntityType MET on MET.ManagedEntityTypeRowId=ME.ManagedEntityTypeRowId +inner join dbo.vManagementPack MP on MP.ManagementPackRowId=MET.ManagementPackRowId +inner join dbo.vManagementPackVersion MPV on MPV.ManagementPackRowId=MP.ManagementPackRowId +left join dbo.vDiscoveryManagementPackVersion DMP on DMP.ManagementPackVersionRowId=MPV.ManagementPackVersionRowId + AND CAST(DefinitionXml.query('data(/Discovery/DiscoveryTypes/DiscoveryClass/@TypeID)') AS nvarchar(max)) like '%'+MET.ManagedEntityTypeSystemName+'%' +left join dbo.vManagedEntityType MET1 on MET1.ManagedEntityTypeRowId=DMP.TargetManagedEntityTypeRowId +left join dbo.vDiscovery D on D.DiscoveryRowId=DMP.DiscoveryRowId +where ChangeDateTime > dateadd(hh,-24,getutcdate()) +ORDER BY ChangeDateTime DESC \ No newline at end of file diff --git a/SQL Queries/Data Warehouse/DW_AggregationHistory.sql b/SQL Queries/Data Warehouse/DW_AggregationHistory.sql new file mode 100644 index 0000000..8ec03fc --- /dev/null +++ b/SQL Queries/Data Warehouse/DW_AggregationHistory.sql @@ -0,0 +1,13 @@ +SELECT ds.DatasetDefaultName, + sdah.AggregationDateTime, + sdah.AggregationTypeId, + sdah.FirstAggregationStartDateTime, + sdah.FirstAggregationDurationSeconds, + sdah.LastAggregationStartDateTime, + sdah.LastAggregationDurationSeconds, + sdah.DirtyInd, + sdah.DataLastReceivedDateTime, + sdah.AggregationCount +FROM StandardDatasetAggregationHistory sdah +JOIN Dataset ds ON sdah.DatasetId = ds.DatasetId +ORDER BY StandardDatasetAggregationHistoryRowId DESC \ No newline at end of file diff --git a/SQL Queries/Data Warehouse/DW_AggregationStatus.sql b/SQL Queries/Data Warehouse/DW_AggregationStatus.sql new file mode 100644 index 0000000..671cd9d --- /dev/null +++ b/SQL Queries/Data Warehouse/DW_AggregationStatus.sql @@ -0,0 +1,29 @@ +WITH AggregationInfo AS ( + SELECT + AggregationType = CASE + WHEN AggregationTypeId = 0 THEN 'Raw' + WHEN AggregationTypeId = 20 THEN 'Hourly' + WHEN AggregationTypeId = 30 THEN 'Daily' + ELSE NULL + END + ,AggregationTypeId + ,MIN(AggregationDateTime) as 'TimeUTC_NextToAggregate' + ,COUNT(AggregationDateTime) as 'Count_OutstandingAggregations' + ,DatasetId + FROM StandardDatasetAggregationHistory + WHERE LastAggregationDurationSeconds IS NULL + GROUP BY DatasetId, AggregationTypeId +) +SELECT +SDS.SchemaName +,AI.AggregationType +,AI.TimeUTC_NextToAggregate +,Count_OutstandingAggregations +,SDA.MaxDataAgeDays +,SDA.LastGroomingDateTime +,SDS.DebugLevel +,AI.DataSetId +FROM StandardDataSet AS SDS WITH(NOLOCK) +JOIN AggregationInfo AS AI WITH(NOLOCK) ON SDS.DatasetId = AI.DatasetId +JOIN dbo.StandardDatasetAggregation AS SDA WITH(NOLOCK) ON SDA.DatasetId = SDS.DatasetId AND SDA.AggregationTypeID = AI.AggregationTypeID +ORDER BY SchemaName DESC \ No newline at end of file diff --git a/SQL Queries/Data Warehouse/DW_DatasetSpace.sql b/SQL Queries/Data Warehouse/DW_DatasetSpace.sql new file mode 100644 index 0000000..5cc96d4 --- /dev/null +++ b/SQL Queries/Data Warehouse/DW_DatasetSpace.sql @@ -0,0 +1,303 @@ + DECLARE + @DatasetId uniqueidentifier + ,@AggregationTypeId int + ,@ServerName sysname + ,@DatabaseName sysname + ,@SchemaName sysname + ,@DatasetName nvarchar(256) + ,@DatasetDescription nvarchar(max) + ,@AggregationTypeName nvarchar(50) + ,@MaxDataAgeDays int + ,@DataFileGroupName sysname + ,@IndexFileGroupName sysname + ,@StandardDatasetTableMapRowId int + ,@TableGuid uniqueidentifier + ,@TableNameSuffix varchar(100) + ,@StartDateTime datetime + ,@EndDateTime datetime + ,@StandardDatasetAggregationStorageRowId int + ,@DependentTableInd tinyint + ,@BaseTableName nvarchar(90) + ,@TableName nvarchar(max) + ,@RowCount bigint + ,@SizeKb bigint + ,@RowCountForDailyAvg bigint + ,@SizeKbForDailyAvg bigint + ,@MinStartDateTime datetime + ,@MaxEndDateTime datetime + ,@TotalHours bigint + ,@TableCreatedDateTime datetime + ,@DomainTableRowId int + + DECLARE @TableSize TABLE ( + TableName sysname NOT NULL + ,[RowCount] bigint NOT NULL + ,Reserved varchar(30) NOT NULL + ,Data varchar(30) NOT NULL + ,IndexSize varchar(30) NOT NULL + ,Unused varchar(30) NOT NULL + ) + + DECLARE @Result TABLE ( + DatasetId uniqueidentifier NOT NULL + ,ServerName sysname NOT NULL + ,DatabaseName sysname NOT NULL + ,DatasetName nvarchar(256) NOT NULL + ,AggregationTypeId int NOT NULL + ,AggregationTypeName nvarchar(50) NOT NULL + ,MaxDataAgeDays int NOT NULL + ,[RowCount] bigint NULL + ,MinStartDateTime datetime NULL + ,SizeKb bigint NOT NULL + ,DailySizeKb float NULL + ,DailyRowCount bigint NULL + ,TotalSizeKb float NULL + ,TotalRowCount bigint NULL + ,DataFileGroupName sysname NOT NULL + ,IndexFileGroupName sysname NOT NULL + ) + + SET @DatasetId = '00000000-0000-0000-0000-000000000000' + + WHILE EXISTS (SELECT * + FROM vDataset d + JOIN StandardDataset sd ON (d.DatasetId = sd.DatasetId) + JOIN vMemberDatabase mdb ON (d.MemberDatabaseRowId = mdb.MemberDatabaseRowId) + WHERE (d.DatasetId > @DatasetId) + AND (d.InstallCompletedInd = 1) + ) + BEGIN + SELECT TOP 1 + @DatasetId = d.DatasetId + ,@SchemaName = sd.SchemaName + ,@DatasetName = d.DatasetDefaultName + ,@DatasetDescription = d.DatasetDefaultDescription + ,@ServerName = mdb.ServerName + ,@DatabaseName = mdb.DatabaseName + FROM vDataset d + JOIN StandardDataset sd ON (d.DatasetId = sd.DatasetId) + JOIN vMemberDatabase mdb ON (d.MemberDatabaseRowId = mdb.MemberDatabaseRowId) + WHERE (d.DatasetId > @DatasetId) + AND (d.InstallCompletedInd = 1) + ORDER BY d.DatasetId + + SET @AggregationTypeId = -1 + + WHILE EXISTS (SELECT * + FROM StandardDatasetAggregation + WHERE (DatasetId = @DatasetId) + AND (AggregationTypeId > @AggregationTypeId) + ) + BEGIN + SELECT TOP 1 + @AggregationTypeId = a.AggregationTypeId + ,@AggregationTypeName = at.AggregationTypeDefaultName + ,@MaxDataAgeDays = a.MaxDataAgeDays + ,@DataFileGroupName = a.DataFileGroupName + ,@IndexFileGroupName = a.IndexFileGroupName + FROM StandardDatasetAggregation a + JOIN vAggregationType at ON (a.AggregationTypeId = at.AggregationTypeId) + WHERE (a.DatasetId = @DatasetId) + AND (a.AggregationTypeId > @AggregationTypeId) + ORDER BY a.AggregationTypeId + + SET @RowCount = 0 + SET @SizeKb = 0 + SET @TotalHours = 0 + SET @MinStartDateTime = NULL + SET @RowCountForDailyAvg = 0 + SET @SizeKbForDailyAvg = 0 + + SET @StandardDatasetTableMapRowId = 0 + + WHILE EXISTS (SELECT * + FROM StandardDatasetTableMap + WHERE (DatasetId = @DatasetId) + AND (AggregationTypeId = @AggregationTypeId) + AND (StandardDatasetTableMapRowId > @StandardDatasetTableMapRowId) + ) + BEGIN + SELECT TOP 1 + @StandardDatasetTableMapRowId = StandardDatasetTableMapRowId + ,@TableGuid = TableGuid + ,@TableNameSuffix = TableNameSuffix + ,@StartDateTime = StartDateTime + ,@EndDateTime = EndDateTime + FROM StandardDatasetTableMap + WHERE (DatasetId = @DatasetId) + AND (AggregationTypeId = @AggregationTypeId) + AND (StandardDatasetTableMapRowId > @StandardDatasetTableMapRowId) + ORDER BY StandardDatasetTableMapRowId + + SET @StandardDatasetAggregationStorageRowId = 0 + + WHILE EXISTS (SELECT * + FROM StandardDatasetAggregationStorage + WHERE (DatasetId = @DatasetId) + AND (AggregationTypeId = @AggregationTypeId) + AND (StandardDatasetAggregationStorageRowId > @StandardDatasetAggregationStorageRowId) + ) + BEGIN + SELECT TOP 1 + @StandardDatasetAggregationStorageRowId = StandardDatasetAggregationStorageRowId + ,@DependentTableInd = DependentTableInd + ,@BaseTableName = BaseTableName + FROM StandardDatasetAggregationStorage + WHERE (DatasetId = @DatasetId) + AND (AggregationTypeId = @AggregationTypeId) + AND (StandardDatasetAggregationStorageRowId > @StandardDatasetAggregationStorageRowId) + ORDER BY StandardDatasetAggregationStorageRowId + + SELECT @TableCreatedDateTime = create_date + FROM sys.objects o + JOIN sys.schemas s ON (o.schema_id = s.schema_id) + WHERE (s.name = @SchemaName) + AND (o.name = @BaseTableName + '_' + @TableNameSuffix) + + IF (@StartDateTime < @TableCreatedDateTime) + SET @StartDateTime = @TableCreatedDateTime + + IF (@EndDateTime > GETUTCDATE()) + SET @EndDateTime = GETUTCDATE() + + SET @TableName = QUOTENAME(@SchemaName) + '.' + QUOTENAME(@BaseTableName + '_' + @TableNameSuffix) + + DELETE @TableSize + + INSERT @TableSize (TableName, [RowCount], Reserved, Data, IndexSize, Unused) + EXEC sp_spaceused @TableName + + SELECT + @RowCount = @RowCount + CASE WHEN @DependentTableInd = 0 THEN [RowCount] ELSE 0 END + ,@SizeKb = @SizeKb + CAST(REPLACE(REPLACE(Reserved, 'KB', ''), ' ', '') as bigint) + FROM @TableSize + + IF (@StartDateTime IS NOT NULL) AND (@EndDateTime IS NOT NULL) + BEGIN + SET @TotalHours = @TotalHours + ABS(DATEDIFF(hour, @StartDateTime, @EndDateTime)) + + SELECT + @RowCountForDailyAvg = @RowCountForDailyAvg + CASE WHEN @DependentTableInd = 0 THEN [RowCount] ELSE 0 END + ,@SizeKbForDailyAvg = @SizeKbForDailyAvg + CAST(REPLACE(REPLACE(Reserved, 'KB', ''), ' ', '') as bigint) + FROM @TableSize + + SET @MinStartDateTime = + CASE + WHEN @MinStartDateTime IS NULL THEN @StartDateTime + WHEN @StartDateTime < @MinStartDateTime THEN @StartDateTime + ELSE @MinStartDateTime + END + + SET @MaxEndDateTime = + CASE + WHEN @MaxEndDateTime IS NULL THEN @EndDateTime + WHEN @EndDateTime > @MaxEndDateTime THEN @EndDateTime + ELSE @MaxEndDateTime + END + END + END + END + + SET @TotalHours = ABS(DATEDIFF(hour, @MinStartDateTime, @MaxEndDateTime)) + + INSERT @Result ( + DatasetId + ,ServerName + ,DatabaseName + ,DatasetName + ,AggregationTypeId + ,AggregationTypeName + ,MaxDataAgeDays + ,[RowCount] + ,MinStartDateTime + ,SizeKb + ,DailyRowCount + ,DailySizeKb + ,DataFileGroupName + ,IndexFileGroupName + ) + SELECT + @DatasetId + ,@ServerName + ,@DatabaseName + ,@DatasetName + ,@AggregationTypeId + ,@AggregationTypeName + ,@MaxDataAgeDays + ,@RowCount + ,@MinStartDateTime + ,@SizeKb + ,ROUND(CASE WHEN @TotalHours > 0 THEN @RowCountForDailyAvg / CAST(@TotalHours AS float) * 24.0 ELSE NULL END, 0) + ,CASE WHEN @TotalHours > 0 THEN @SizeKbForDailyAvg / CAST(@TotalHours AS float) * 24.0 ELSE NULL END + ,ISNULL(@DataFileGroupName, 'default') + ,ISNULL(@IndexFileGroupName, 'default') + END + END + + IF EXISTS (SELECT * FROM sys.objects WHERE name = 'MaintenanceSetting') + BEGIN + DELETE @TableSize + + SET @DomainTableRowId = 0 + + WHILE EXISTS (SELECT * + FROM DomainTable + WHERE (DomainTableRowId > @DomainTableRowId) + ) + BEGIN + SELECT TOP 1 + @DomainTableRowId = DomainTableRowId + ,@TableName = QUOTENAME(SchemaName) + '.' + QUOTENAME(TableName) + FROM DomainTable + WHERE (DomainTableRowId > @DomainTableRowId) + ORDER BY DomainTableRowId + + INSERT @TableSize (TableName, [RowCount], Reserved, Data, IndexSize, Unused) + EXEC sp_spaceused @TableName + END + + INSERT @Result ( + DatasetId + ,ServerName + ,DatabaseName + ,DatasetName + ,AggregationTypeId + ,AggregationTypeName + ,MaxDataAgeDays + ,SizeKb + ,DataFileGroupName + ,IndexFileGroupName + ) + SELECT + '00000000-0000-0000-0000-000000000000' + ,ServerName + ,DatabaseName + ,'Configuration dataset' + ,at.AggregationTypeId + ,at.AggregationTypeDefaultName + ,CASE + WHEN ms.InstanceMaxAgeDays > ms.ManagementPackMaxAgeDays THEN ms.ManagementPackMaxAgeDays + ELSE ms.InstanceMaxAgeDays + END + ,ISNULL((SELECT SUM(CAST(REPLACE(REPLACE(Reserved, 'KB', ''), ' ', '') as bigint)) FROM @TableSize), 0) + ,'default' + ,'default' + FROM vMemberDatabase mdb + CROSS JOIN vAggregationType at + CROSS JOIN MaintenanceSetting ms + WHERE (mdb.MasterDatabaseInd = 1) + AND (at.AggregationTypeId = 0) + END + + UPDATE @Result + SET TotalSizeKb = DailySizeKb * MaxDataAgeDays + ,TotalRowCount = DailyRowCount * MaxDataAgeDays + + SELECT + DatasetName + ,AggregationTypeName + ,MaxDataAgeDays + ,SizeGB = ROUND((CAST(SizeKb AS float) / 1000000.00),2) + ,PercentOfDW = ROUND((CAST(SizeKb AS float) / (SELECT SUM(SizeKb) FROM @Result) * 100),2) + FROM @Result + ORDER BY PercentOfDW DESC \ No newline at end of file diff --git a/SQL Queries/Data Warehouse/DW_Greyed_Out_Reason_Codes.sql b/SQL Queries/Data Warehouse/DW_Greyed_Out_Reason_Codes.sql new file mode 100644 index 0000000..b148001 --- /dev/null +++ b/SQL Queries/Data Warehouse/DW_Greyed_Out_Reason_Codes.sql @@ -0,0 +1,6 @@ +SELECT ME.Path, HSO.StartDateTime AS OutageStartDateTime, DATEDIFF (DD, HSO.StartDateTime, GETUTCDATE()) +AS OutageDays, HSO.ReasonCode, DS.Name AS ReasonString FROM vManagedEntity AS ME +INNER JOIN vHealthServiceOutage AS HSO ON HSO.ManagedEntityRowId = ME.ManagedEntityRowId +INNER JOIN vStringResource AS SR ON HSO.ReasonCode = REPLACE(LEFT(SR.StringResourceSystemName, LEN(SR.StringResourceSystemName) - CHARINDEX('.', REVERSE(SR.StringResourceSystemName))), 'System.Availability.StateData.Reasons.', '') +INNER JOIN vDisplayString AS DS ON DS.ElementGuid = SR.StringResourceGuid WHERE (HSO.EndDateTime IS NULL) AND (SR.StringResourceSystemName LIKE 'System.Availability.StateData.Reasons.[0-9]%') AND DS.LanguageCode = 'ENU' +ORDER BY OutageStartDateTime \ No newline at end of file diff --git a/SQL Queries/Data Warehouse/DW_Perf_byCounter.sql b/SQL Queries/Data Warehouse/DW_Perf_byCounter.sql index c74a2a6..fda24c5 100644 --- a/SQL Queries/Data Warehouse/DW_Perf_byCounter.sql +++ b/SQL Queries/Data Warehouse/DW_Perf_byCounter.sql @@ -1,3 +1,4 @@ +/*Top 30 performance insertions: */ select TOP 30 PR.CounterName,PR.ObjectName, vR.ruledefaultname As RuleName, COUNT(PR.countername) AS Total from Perf.vPerfRaw perf join ManagedEntity ME on perf.ManagedEntityRowId = ME.ManagedEntityRowId @@ -6,4 +7,4 @@ join PerformanceRule PR on PRI.RuleRowId = PR.RuleRowId join vRule vR on vR.rulerowid = PR.RuleRowId where perf.DateTime > GetUTCDate() -48 GROUP BY PR.ObjectName, PR.CounterName, vr.ruledefaultname -ORDER BY COUNT (PR.CounterName) DESC \ No newline at end of file +ORDER BY COUNT (PR.CounterName) dESC \ No newline at end of file diff --git a/SQL Queries/Data Warehouse/DW_Perf_byManagedEntity.sql b/SQL Queries/Data Warehouse/DW_Perf_byManagedEntity.sql new file mode 100644 index 0000000..7310629 --- /dev/null +++ b/SQL Queries/Data Warehouse/DW_Perf_byManagedEntity.sql @@ -0,0 +1,10 @@ +select r.RuleDefaultName, pr.ObjectName, pr.CounterName, mp.ManagementPackDefaultName as MPName, COUNT(me.ManagedEntityDefaultName) AS Total +from Perf.vPerfRaw perf +join vPerformanceRuleInstance PRI on perf.PerformanceRuleInstanceRowId = PRI.PerformanceRuleInstanceRowId +join vPerformanceRule pr on PRI.RuleRowId = PR.RuleRowId +join vManagedEntity me on perf.ManagedEntityRowId = ME.ManagedEntityRowId +join [dbo].[vRule] r on r.RuleRowId = PR.RuleRowId +join vManagementPack mp on r.ManagementPackRowId = mp.ManagementPackRowId +where perf.DateTime > GetUTCDate() -48 +GROUP BY PR.ObjectName, PR.CounterName, r.ruledefaultname, mp.ManagementPackDefaultName +ORDER BY COUNT (me.ManagedEntityDefaultName) DESC \ No newline at end of file diff --git a/SQL Queries/Data Warehouse/DW_Retention.sql b/SQL Queries/Data Warehouse/DW_Retention.sql new file mode 100644 index 0000000..5d18efd --- /dev/null +++ b/SQL Queries/Data Warehouse/DW_Retention.sql @@ -0,0 +1,8 @@ +SELECT ds.datasetDefaultName AS 'Dataset Name', + sda.AggregationTypeId AS 'Agg Type 0=raw, 20=Hourly, 30=Daily', + sda.MaxDataAgeDays AS 'Retention Time in Days', + sda.LastGroomingDateTime, + sda.GroomingIntervalMinutes +FROM dataset ds, StandardDatasetAggregation sda +WHERE ds.datasetid = sda.datasetid +ORDER by ds.datasetDefaultName \ No newline at end of file diff --git a/SQL Queries/Data Warehouse/DW_StagingBacklog.sql b/SQL Queries/Data Warehouse/DW_StagingBacklog.sql new file mode 100644 index 0000000..e7f2f70 --- /dev/null +++ b/SQL Queries/Data Warehouse/DW_StagingBacklog.sql @@ -0,0 +1,19 @@ +SELECT 'ManagedEntityStage' AS 'TableName',count(*) AS 'Count' FROM ManagedEntityStage +UNION ALL +SELECT 'HealthServiceOutageStage' AS 'TableName',count(*) AS 'Count' FROM HealthServiceOutageStage +UNION ALL +SELECT 'MaintenanceModeStage' AS 'TableName',count(*) AS 'Count' FROM MaintenanceModeStage +UNION ALL +SELECT 'RelationshipStage' AS 'TableName',count(*) AS 'Count' FROM RelationshipStage +UNION ALL +SELECT 'TypedManagedEntityStage' AS 'TableName',count(*) AS 'Count' FROM TypedManagedEntityStage +UNION ALL +SELECT 'Alert.AlertStage' AS 'TableName',count(*) AS 'Count' FROM Alert.AlertStage +UNION ALL +SELECT 'Alert.AlertStage2Process' AS 'TableName',count(*) AS 'Count' FROM Alert.AlertStage2Process +UNION ALL +SELECT 'Event.EventStage' AS 'TableName',count(*) AS 'Count' FROM Event.EventStage +UNION ALL +SELECT 'Perf.PerformanceStage' AS 'TableName',count(*) AS 'Count' FROM Perf.PerformanceStage +UNION ALL +SELECT 'State.StateStage' AS 'TableName',count(*) AS 'Count' FROM State.StateStage \ No newline at end of file diff --git a/SQL Queries/Data Warehouse/DW_WriterLoginName.sql b/SQL Queries/Data Warehouse/DW_WriterLoginName.sql new file mode 100644 index 0000000..812422d --- /dev/null +++ b/SQL Queries/Data Warehouse/DW_WriterLoginName.sql @@ -0,0 +1 @@ +SELECT [ManagementGroupDefaultName],[WriterLoginName] FROM [dbo].[ManagementGroup] \ No newline at end of file diff --git a/SQL Queries/Data Warehouse/Index_Maint_DW.sql b/SQL Queries/Data Warehouse/Index_Maint_DW.sql new file mode 100644 index 0000000..2eefa5e --- /dev/null +++ b/SQL Queries/Data Warehouse/Index_Maint_DW.sql @@ -0,0 +1,9 @@ +select basetablename, optimizationstartdatetime, optimizationdurationseconds, + beforeavgfragmentationinpercent, afteravgfragmentationinpercent, + optimizationmethod, onlinerebuildlastperformeddatetime +from StandardDatasetOptimizationHistory sdoh +inner join StandardDatasetAggregationStorageIndex sdasi +on sdoh.StandardDatasetAggregationStorageIndexRowId = sdasi.StandardDatasetAggregationStorageIndexRowId +inner join StandardDatasetAggregationStorage sdas +on sdasi.StandardDatasetAggregationStorageRowId = sdas.StandardDatasetAggregationStorageRowId +ORDER BY optimizationdurationseconds DESC \ No newline at end of file diff --git a/SQL Queries/Data Warehouse/MG_SQLPatchVersion_DW.sql b/SQL Queries/Data Warehouse/MG_SQLPatchVersion_DW.sql new file mode 100644 index 0000000..92d6f28 --- /dev/null +++ b/SQL Queries/Data Warehouse/MG_SQLPatchVersion_DW.sql @@ -0,0 +1,2 @@ +-- Get the Data Warehouse Update Rollup Version. +select * from [dbo].[SqlPatchVersion] \ No newline at end of file diff --git a/SQL Queries/Data Warehouse/SQL_Backups_DW.sql b/SQL Queries/Data Warehouse/SQL_Backups_DW.sql new file mode 100644 index 0000000..deedb6d --- /dev/null +++ b/SQL Queries/Data Warehouse/SQL_Backups_DW.sql @@ -0,0 +1,9 @@ +SELECT + database_name AS [Database] + , type AS BackupType + , MAX(backup_start_date) AS LastBackupDate + , GETDATE() AS CurrentDate + , DATEDIFF(DD,MAX(backup_start_date),GETDATE()) AS DaysSinceBackup +FROM msdb.dbo.backupset BS JOIN master.dbo.sysdatabases SD ON BS.database_name = SD.[name] +GROUP BY database_name, type +ORDER BY database_name, type \ No newline at end of file diff --git a/SQL Queries/Data Warehouse/SQL_BlockingSessions_DW.sql b/SQL Queries/Data Warehouse/SQL_BlockingSessions_DW.sql new file mode 100644 index 0000000..6ab6cc7 --- /dev/null +++ b/SQL Queries/Data Warehouse/SQL_BlockingSessions_DW.sql @@ -0,0 +1 @@ +Sp_who2 \ No newline at end of file diff --git a/SQL Queries/Data Warehouse/SQL_DBSize_DW.sql b/SQL Queries/Data Warehouse/SQL_DBSize_DW.sql new file mode 100644 index 0000000..dc2efe9 --- /dev/null +++ b/SQL Queries/Data Warehouse/SQL_DBSize_DW.sql @@ -0,0 +1,10 @@ +SELECT convert(decimal(12,0),round(sf.size/128.000,2)) AS 'FileSize(MB)', +convert(decimal(12,0),round(fileproperty(sf.name,'SpaceUsed')/128.000,2)) AS 'SpaceUsed(MB)', +convert(decimal(12,0),round((sf.size-fileproperty(sf.name,'SpaceUsed'))/128.000,2)) AS 'FreeSpace(MB)', +CASE smf.is_percent_growth WHEN 1 THEN CONVERT(VARCHAR(10),smf.growth) +' %' ELSE convert(VARCHAR(10),smf.growth/128) +' MB' END AS 'AutoGrow', +convert(decimal(12,0),round(sf.maxsize/128.000,2)) AS 'AutoGrowthMB(MAX)', +left(sf.NAME,15) AS 'NAME', +left(sf.FILENAME,120) AS 'PATH', +sf.FILEID +from dbo.sysfiles sf +JOIN sys.master_files smf on smf.physical_name = sf.filename \ No newline at end of file diff --git a/SQL Queries/Data Warehouse/SQL_ErrorLogLocation_DW.sql b/SQL Queries/Data Warehouse/SQL_ErrorLogLocation_DW.sql new file mode 100644 index 0000000..eb1b5c3 --- /dev/null +++ b/SQL Queries/Data Warehouse/SQL_ErrorLogLocation_DW.sql @@ -0,0 +1 @@ +xp_readerrorlog 0, 1, N'Logging SQL Server messages in file' diff --git a/SQL Queries/Data Warehouse/SQL_LargeTables_DW.sql b/SQL Queries/Data Warehouse/SQL_LargeTables_DW.sql new file mode 100644 index 0000000..350ed15 --- /dev/null +++ b/SQL Queries/Data Warehouse/SQL_LargeTables_DW.sql @@ -0,0 +1,24 @@ +SELECT TOP 1000 +a2.name AS 'Tablename', +CAST((a1.reserved + ISNULL(a4.reserved,0))* 8/1024.0 AS DECIMAL(10, 0)) AS 'TotalSpace(MB)', +CAST(a1.data * 8/1024.0 AS DECIMAL(10, 0)) AS 'DataSize(MB)', +CAST((CASE WHEN (a1.used + ISNULL(a4.used,0)) > a1.data THEN (a1.used + ISNULL(a4.used,0)) - a1.data ELSE 0 END) * 8/1024.0 AS DECIMAL(10, 0)) AS 'IndexSize(MB)', +CAST((CASE WHEN (a1.reserved + ISNULL(a4.reserved,0)) > a1.used THEN (a1.reserved + ISNULL(a4.reserved,0)) - a1.used ELSE 0 END) * 8/1024.0 AS DECIMAL(10, 0)) AS 'Unused(MB)', +a1.rows as 'RowCount', +(row_number() over(order by (a1.reserved + ISNULL(a4.reserved,0)) desc))%2 as l1, +a3.name AS 'Schema' +FROM (SELECT ps.object_id, SUM (CASE WHEN (ps.index_id < 2) THEN row_count ELSE 0 END) AS [rows], +SUM (ps.reserved_page_count) AS reserved, +SUM (CASE WHEN (ps.index_id < 2) THEN (ps.in_row_data_page_count + ps.lob_used_page_count + ps.row_overflow_used_page_count) +ELSE (ps.lob_used_page_count + ps.row_overflow_used_page_count) END ) AS data, +SUM (ps.used_page_count) AS used +FROM sys.dm_db_partition_stats ps +GROUP BY ps.object_id) AS a1 +LEFT OUTER JOIN (SELECT it.parent_id, SUM(ps.reserved_page_count) AS reserved, +SUM(ps.used_page_count) AS used +FROM sys.dm_db_partition_stats ps +INNER JOIN sys.internal_tables it ON (it.object_id = ps.object_id) +WHERE it.internal_type IN (202,204) +GROUP BY it.parent_id) AS a4 ON (a4.parent_id = a1.object_id) +INNER JOIN sys.all_objects a2 ON ( a1.object_id = a2.object_id ) +INNER JOIN sys.schemas a3 ON (a2.schema_id = a3.schema_id) \ No newline at end of file diff --git a/SQL Queries/Data Warehouse/SQL_LoginMappings_DW.sql b/SQL Queries/Data Warehouse/SQL_LoginMappings_DW.sql new file mode 100644 index 0000000..a5dc2c4 --- /dev/null +++ b/SQL Queries/Data Warehouse/SQL_LoginMappings_DW.sql @@ -0,0 +1 @@ +EXEC master..sp_helplogins \ No newline at end of file diff --git a/SQL Queries/Data Warehouse/SQL_Properties_DW.sql b/SQL Queries/Data Warehouse/SQL_Properties_DW.sql new file mode 100644 index 0000000..3e47941 --- /dev/null +++ b/SQL Queries/Data Warehouse/SQL_Properties_DW.sql @@ -0,0 +1,28 @@ +SELECT +(SELECT is_broker_enabled +FROM sys.databases +WHERE name=db_name()) AS 'Is_Broker_Enabled', +(SELECT value +FROM sys.configurations +WHERE name = 'clr enabled') AS 'Is_CLR_Enabled', +serverproperty('machinename') AS ServerName, +case when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) like '8.0%' then 'SQL Server 2000' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) like '9.0%' then 'SQL Server 2005' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) like '10.0%' then 'SQL Server 2008' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) like '10.5%' then 'SQL Server 2008 R2' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) like '11.0%' then 'SQL Server 2012' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) like '12.0%' then 'SQL Server 2014' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) like '13.0%' then 'SQL Server 2016' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) like '14.0%' then 'SQL Server 2017' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) = '15.0.4123.1' then 'SQL Server 2019 CU10' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) like '15.0%' then 'SQL Server 2019' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) > '15.0.4123.1' then 'newer than SQL Server 2019 CU10' +else 'unknown' end as [Version], +CONVERT(nvarchar(50), serverproperty('Edition')) AS Edition, +CONVERT(nvarchar(50), serverproperty('ProductVersion')) AS ProductVersion, +CONVERT(nvarchar(50), serverproperty('ProductLevel')) AS ProductLevel, +CONVERT(nvarchar(50), serverproperty('IsClustered')) AS IsClustered, +CONVERT(nvarchar(50), serverproperty('IsFullTextInstalled')) AS IsFullTextInstalled, +CONVERT(nvarchar(50), serverproperty('Collation')) AS Collation, +CONVERT(nvarchar(50), serverproperty('ComputerNamePhysicalNetBIOS')) AS ComputerNamePhysicalNetBIOS, +CONVERT(nvarchar(50), serverproperty('ComputerNamePhysicalNetBIOS')) AS 'SqlHost' \ No newline at end of file diff --git a/SQL Queries/OperationsManager/APM_Status.sql b/SQL Queries/OperationsManager/APM_Status.sql new file mode 100644 index 0000000..419233d --- /dev/null +++ b/SQL Queries/OperationsManager/APM_Status.sql @@ -0,0 +1 @@ +select max(UTCEVENTDATE) AS "Last Updated Time", GETUTCDATE() AS "Current UTC Time" FROM APM.EVENT(NOLOCK) \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Advisor_Settings.sql b/SQL Queries/OperationsManager/Advisor_Settings.sql new file mode 100644 index 0000000..4974a10 --- /dev/null +++ b/SQL Queries/OperationsManager/Advisor_Settings.sql @@ -0,0 +1 @@ +select * [dbo].[MT_Microsoft$SystemCenter$Advisor$Settings] \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Alerts_ByCount.sql b/SQL Queries/OperationsManager/Alerts_ByCount.sql new file mode 100644 index 0000000..c01cd55 --- /dev/null +++ b/SQL Queries/OperationsManager/Alerts_ByCount.sql @@ -0,0 +1,5 @@ +SELECT TOP 20 SUM(1) AS AlertCount, AlertStringName, AlertStringDescription, MonitoringRuleId, Name +FROM Alertview WITH (NOLOCK) +WHERE TimeRaised is not NULL +GROUP BY AlertStringName, AlertStringDescription, MonitoringRuleId, Name +ORDER BY AlertCount DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Alerts_ByDay.sql b/SQL Queries/OperationsManager/Alerts_ByDay.sql new file mode 100644 index 0000000..587cde4 --- /dev/null +++ b/SQL Queries/OperationsManager/Alerts_ByDay.sql @@ -0,0 +1,5 @@ +SELECT CONVERT(VARCHAR(20), TimeAdded, 102) AS DayAdded, COUNT(*) AS NumAlertsPerDay +FROM Alert WITH (NOLOCK) +WHERE TimeRaised is not NULL +GROUP BY CONVERT(VARCHAR(20), TimeAdded, 102) +ORDER BY DayAdded DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Alerts_ByRepeat.sql b/SQL Queries/OperationsManager/Alerts_ByRepeat.sql new file mode 100644 index 0000000..716c5f1 --- /dev/null +++ b/SQL Queries/OperationsManager/Alerts_ByRepeat.sql @@ -0,0 +1,5 @@ +SELECT TOP 20 SUM(RepeatCount+1) AS RepeatCount, AlertStringName, AlertStringDescription, MonitoringRuleId, Name +FROM Alertview WITH (NOLOCK) +WHERE Timeraised is not NULL +GROUP BY AlertStringName, AlertStringDescription, MonitoringRuleId, Name +ORDER BY RepeatCount DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/ConfigChurn_OpsDB.sql b/SQL Queries/OperationsManager/ConfigChurn_OpsDB.sql new file mode 100644 index 0000000..5191154 --- /dev/null +++ b/SQL Queries/OperationsManager/ConfigChurn_OpsDB.sql @@ -0,0 +1,19 @@ +--see all of the configuration changes made in the last 24 hours in OpsDb +SELECT + TOP 100 EntityTypeId, + TypeName, + COUNT(*) as "Number of changes" +FROM + dbo.EntityChangeLog E + join ManagedType MT on MT.ManagedTypeId = e.EntityTypeId +WHERE + e.LastModified < GETUTCDATE() -1 +GROUP BY + E.EntityTypeId, + TypeName +HAVING + ( + COUNT(*) + ) > 10 +order by + [Number of changes] desc diff --git a/SQL Queries/OperationsManager/Config_Logs.sql b/SQL Queries/OperationsManager/Config_Logs.sql new file mode 100644 index 0000000..08a6d23 --- /dev/null +++ b/SQL Queries/OperationsManager/Config_Logs.sql @@ -0,0 +1,11 @@ +SELECT WorkItemRowId, +WorkItemName, +REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(WorkItemStateId,20,'Successful'),15,'Timed out'),12,'Abandoned'),10,'Failed'),1,'Running') as 'WorkItemState', +ServerName, +InstanceName, +StartedDateTimeUtc, +LastActivityDateTimeUtc, +CompletedDateTimeUtc, +DurationSeconds +FROM CS.workitem +ORDER BY WorkItemRowId DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Configuration_OpsDB.sql b/SQL Queries/OperationsManager/Configuration_OpsDB.sql new file mode 100644 index 0000000..e66448b --- /dev/null +++ b/SQL Queries/OperationsManager/Configuration_OpsDB.sql @@ -0,0 +1,11 @@ +SELECT + ManagedTypePropertyName, + SettingValue, + mtv.DisplayName, + gs.LastModified +FROM + GlobalSettings gs + INNER JOIN ManagedTypeProperty mtp on gs.ManagedTypePropertyId = mtp.ManagedTypePropertyId + INNER JOIN ManagedTypeView mtv on mtp.ManagedTypeId = mtv.Id +ORDER BY + mtv.DisplayName \ No newline at end of file diff --git a/SQL Queries/OperationsManager/CriticalState_Monitors.sql b/SQL Queries/OperationsManager/CriticalState_Monitors.sql new file mode 100644 index 0000000..e6d4f5e --- /dev/null +++ b/SQL Queries/OperationsManager/CriticalState_Monitors.sql @@ -0,0 +1,15 @@ +--List of all monitors in a critical state + +SELECT +mv.DisplayName AS 'MonitorDisplayName', +mv.Name AS 'MonitorName', +bme.Path, +bme.DisplayName, +bme.FullName AS 'Target', +s.LastModified AS 'StateLastModified' +FROM State s +JOIN BaseManagedEntity bme ON s.BaseManagedEntityId = bme.BaseManagedEntityId +JOIN MonitorView mv ON mv.Id = s.MonitorId +WHERE s.HealthState = 3 +AND mv.IsUnitMonitor = 1 +ORDER BY mv.DisplayName \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Discoveries.sql b/SQL Queries/OperationsManager/Discoveries.sql new file mode 100644 index 0000000..3de4400 --- /dev/null +++ b/SQL Queries/OperationsManager/Discoveries.sql @@ -0,0 +1,14 @@ +SELECT +d.DiscoveryId, +d.DiscoveryName, +mpv.FriendlyName as 'MPDisplayName', +d.DiscoveryAccessibility, +REPLACE(REPLACE(REPLACE(d.DiscoveryEnabled, '4', 'True'),'0', 'False'), '3', 'onEssentialMonitoring') as 'DiscoveryEnabled', +CASE WHEN bme.DisplayName IS NULL then mt.TypeName else bme.DisplayName END as 'DiscoveryTarget', +REPLACE(REPLACE(d.DiscoveryConfirmDelivery, 0, 'False'), '1', 'True') as 'DiscoveryConfirmDelivery', +REPLACE(REPLACE(d.DiscoveryRemotable, 0, 'False'),'1', 'True') as 'DiscoveryRemotable', +d.TimeAdded +FROM Discovery AS d LEFT JOIN +ManagementPackView AS mpv ON d.ManagementPackId = mpv.Id LEFT JOIN +BaseManagedEntity AS bme ON d.DiscoveryTarget = bme.BaseManagedEntityId LEFT JOIN +ManagedType AS mt ON d.DiscoveryTarget = mt.ManagedTypeId \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Event29181_CastNotValid.sql b/SQL Queries/OperationsManager/Event29181_CastNotValid.sql new file mode 100644 index 0000000..9e2e626 --- /dev/null +++ b/SQL Queries/OperationsManager/Event29181_CastNotValid.sql @@ -0,0 +1,26 @@ +select + DiscoveryName, + MPName, + MPFriendlyName, + MPVersion, + MPIsSealed, + MPLastModified, + MPCreated, + PrincipalName +from + discovery d + join + ManagementPack MP + on MP.ManagementPackId = d.ManagementPackId + join + DiscoverySource DS + on DS.DiscoveryRuleId = d.DiscoveryId + join + DiscoverySourceToTypedManagedEntity DSTME + on DSTME.DiscoverySourceId = DS.DiscoverySourceId + join + MTV_HealthService MHS + on MHS.BaseManagedEntityId = DSTME.TypedManagedEntityId +where + MaximumQueueSize is null + or DisplayName = '' \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Event29181_System.DBNull-Continued.sql b/SQL Queries/OperationsManager/Event29181_System.DBNull-Continued.sql new file mode 100644 index 0000000..6e3833b --- /dev/null +++ b/SQL Queries/OperationsManager/Event29181_System.DBNull-Continued.sql @@ -0,0 +1,36 @@ +declare @DiscoverySourceId uniqueidentifier; +declare @TimeGenerated datetime; +set + @TimeGenerated = GETUTCDATE(); +set + @DiscoverySourceId = dbo.fn_DiscoverySourceId_User(); +SELECT + TME.[TypedManagedEntityid] +FROM + MTV_HealthService HS + INNER JOIN + dbo.[BaseManagedEntity] BHS + ON BHS.[BaseManagedEntityId] = HS.[BaseManagedEntityId] + INNER JOIN + dbo.[TypedManagedEntity] TME + ON TME.[BaseManagedEntityId] = BHS.[TopLevelHostEntityId] + AND TME.[IsDeleted] = 0 + INNER JOIN + dbo.[DerivedManagedTypes] DMT + ON DMT.[DerivedTypeId] = TME.[ManagedTypeId] + INNER JOIN + dbo.[ManagedType] BT + ON DMT.[BaseTypeId] = BT.[ManagedTypeId] + AND BT.[TypeName] = N'Microsoft.Windows.Computer' + LEFT OUTER JOIN + dbo.Relationship HSC + ON HSC.[SourceEntityId] = HS.[BaseManagedEntityId] + AND HSC.[RelationshipTypeId] = dbo.fn_RelationshipTypeId_HealthServiceCommunication() + AND HSC.[IsDeleted] = 0 + INNER JOIN + DiscoverySourceToTypedManagedEntity DSTME + ON DSTME.[TypedManagedEntityId] = TME.[TypedManagedEntityId] + AND DSTME.[DiscoverySourceId] = @DiscoverySourceId +WHERE + HS.[IsAgent] = 1 + AND HSC.[RelationshipId] IS NULL; \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Event29181_System.DBNull.sql b/SQL Queries/OperationsManager/Event29181_System.DBNull.sql new file mode 100644 index 0000000..e1cbab8 --- /dev/null +++ b/SQL Queries/OperationsManager/Event29181_System.DBNull.sql @@ -0,0 +1,13 @@ +SELECT + PrincipalName, + DisplayName, + MaximumQueueSize, + IsManagementServer, + IsGateway, + HeartbeatEnabled, + HeartbeatInterval, + Port +FROM + MTV_HealthService +where + PrincipalName IS NULL \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Events_ByComputer.sql b/SQL Queries/OperationsManager/Events_ByComputer.sql new file mode 100644 index 0000000..e454c88 --- /dev/null +++ b/SQL Queries/OperationsManager/Events_ByComputer.sql @@ -0,0 +1,4 @@ +SELECT top 20 LoggingComputer as ComputerName, COUNT(*) AS TotalEvents, Number as EventID +FROM EventallView with (NOLOCK) +GROUP BY LoggingComputer, Number +ORDER BY TotalEvents DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Events_ByDay.sql b/SQL Queries/OperationsManager/Events_ByDay.sql new file mode 100644 index 0000000..ae70e4c --- /dev/null +++ b/SQL Queries/OperationsManager/Events_ByDay.sql @@ -0,0 +1,7 @@ +SELECT CASE WHEN(GROUPING(CONVERT(VARCHAR(20), TimeAdded, 102)) = 1) +THEN 'All Days' +ELSE CONVERT(VARCHAR(20), TimeAdded, 102) END AS DayAdded, +COUNT(*) AS EventsPerDay +FROM EventAllView +GROUP BY CONVERT(VARCHAR(20), TimeAdded, 102) WITH ROLLUP +ORDER BY DayAdded DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Events_ByNumber.sql b/SQL Queries/OperationsManager/Events_ByNumber.sql new file mode 100644 index 0000000..e603f05 --- /dev/null +++ b/SQL Queries/OperationsManager/Events_ByNumber.sql @@ -0,0 +1,6 @@ +SELECT top 50 Number as EventID, + COUNT(*) AS TotalEvents, + Publishername as EventSource +FROM EventAllView WITH (NOLOCK) +GROUP BY Number, Publishername +ORDER BY TotalEvents DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Grooming_Logs_OpsDB.sql b/SQL Queries/OperationsManager/Grooming_Logs_OpsDB.sql new file mode 100644 index 0000000..2846911 --- /dev/null +++ b/SQL Queries/OperationsManager/Grooming_Logs_OpsDB.sql @@ -0,0 +1,7 @@ +select InternalJobHistoryId, +Command, +REPLACE(REPLACE(StatusCode,0,'Failed'),1,'Successful') as 'Status', +TimeStarted, +TimeFinished +from InternalJobHistory +order by InternalJobHistoryId DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/HealthService_Down.sql b/SQL Queries/OperationsManager/HealthService_Down.sql new file mode 100644 index 0000000..9f1f100 --- /dev/null +++ b/SQL Queries/OperationsManager/HealthService_Down.sql @@ -0,0 +1,7 @@ +SELECT bme.BaseManagedEntityId,bme.DisplayName,s.LastModified as LastModifiedUTC +FROM state AS s, BaseManagedEntity AS bme +WHERE s.basemanagedentityid = bme.basemanagedentityid +AND s.monitorid +IN (SELECT MonitorId FROM Monitor WHERE MonitorName = 'Microsoft.SystemCenter.HealthService.ComputerDown') +AND s.Healthstate = '3' AND bme.IsDeleted = '0' +ORDER BY s.Lastmodified DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/HealthService_Heartbeat.sql b/SQL Queries/OperationsManager/HealthService_Heartbeat.sql new file mode 100644 index 0000000..5e2ac08 --- /dev/null +++ b/SQL Queries/OperationsManager/HealthService_Heartbeat.sql @@ -0,0 +1,8 @@ +SELECT bme.DisplayName AS 'AgentName', +s.LastModified as 'LastModifiedUTC' +FROM state AS s, BaseManagedEntity AS bme +WHERE s.basemanagedentityid = bme.basemanagedentityid +AND s.monitorid +IN (SELECT MonitorId FROM Monitor WHERE MonitorName = 'Microsoft.SystemCenter.HealthService.Heartbeat') +AND s.Healthstate = '3' AND bme.IsDeleted = '0' +ORDER BY s.Lastmodified DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/HealthService_Inventory.sql b/SQL Queries/OperationsManager/HealthService_Inventory.sql new file mode 100644 index 0000000..b0789bb --- /dev/null +++ b/SQL Queries/OperationsManager/HealthService_Inventory.sql @@ -0,0 +1,20 @@ +SELECT BaseManagedEntityId, +DisplayName, +Version, +ActionAccountIdentity, +ActiveDirectoryManaged, +CreateListener, +ProxyingEnabled, +HeartbeatEnabled, +HeartbeatInterval, +IsManuallyInstalled, +InstallTime, +Port, +ProxyingEnabled, +IsAgent, +IsGateway, +IsManagementServer, +IsRHS, +PatchList, +MaximumQueueSize +FROM MTV_HealthService diff --git a/SQL Queries/OperationsManager/HealthService_Pending.sql b/SQL Queries/OperationsManager/HealthService_Pending.sql new file mode 100644 index 0000000..fa1a7f8 --- /dev/null +++ b/SQL Queries/OperationsManager/HealthService_Pending.sql @@ -0,0 +1 @@ +SELECT * FROM AgentPendingAction \ No newline at end of file diff --git a/SQL Queries/OperationsManager/HeathService_Avail_Last_7days.sql b/SQL Queries/OperationsManager/HeathService_Avail_Last_7days.sql new file mode 100644 index 0000000..d3ac252 --- /dev/null +++ b/SQL Queries/OperationsManager/HeathService_Avail_Last_7days.sql @@ -0,0 +1,21 @@ +-- Get only changes made in the last 7 days to the AvailabilityHistory Table +select BME.Path, +Case AV.ReasonCode +When 0 then 'Unknown' +When 1 then 'Unavailable - No heartbeat' +When 17 then 'Connector Service Paused' +When 25 then 'Action Account Issue' +When 41 then 'Config Data Handling Issue' +When 42 then 'Config Data Loading Issue' +When 43 then 'System Workflows Unloaded' +When 49 then 'Entity State Collection Stalled' +When 50 then 'Monitor State Collection Stalled' +When 51 then 'Alert Collection Stalled' +When 97 then 'Solution Event Source Not Open' +When 98 then 'Cannot Parse Config' +End as [Reason for Change], +AV.TimeStarted, +AV.TimeFinished from AvailabilityHistory AV +join BaseManagedEntity BME on AV.BaseManagedEntityId=BME.BaseManagedEntityId +WHERE AV.TimeStarted > DATEADD(day, -7, GETUTCDATE()) +order by AV.TimeStarted desc \ No newline at end of file diff --git a/SQL Queries/OperationsManager/IndexMaint_OpsDB.sql b/SQL Queries/OperationsManager/IndexMaint_OpsDB.sql new file mode 100644 index 0000000..33d9a4e --- /dev/null +++ b/SQL Queries/OperationsManager/IndexMaint_OpsDB.sql @@ -0,0 +1,16 @@ +SELECT dtioh.OptimizationDurationSeconds AS 'DurationSeconds', +dt.TableName, +'Reindex' AS 'OperationType', +dtioh.OptimizationStartDateTime AS 'StartTime' +FROM DomainTableIndexOptimizationHistory dtioh +JOIN DomainTable dt ON dt.DomainTableRowId = dtioh.DomainTableIndexRowId +WHERE dtioh.OptimizationDurationSeconds > 0 +UNION ALL +SELECT dtsuh.UpdateDurationSeconds AS 'DurationSeconds', +dt.TableName, +'Statistics' AS 'OperationType', +dtsuh.UpdateStartDateTime AS 'StartTime' +FROM DomainTableStatisticsUpdateHistory dtsuh +JOIN DomainTable dt ON dt.DomainTableRowId = dtsuh.DomainTableRowId +WHERE dtsuh.UpdateDurationSeconds > 0 +ORDER BY DurationSeconds DESC, StartTime DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Instances_ByHost.sql b/SQL Queries/OperationsManager/Instances_ByHost.sql new file mode 100644 index 0000000..49f19e9 --- /dev/null +++ b/SQL Queries/OperationsManager/Instances_ByHost.sql @@ -0,0 +1,19 @@ +DECLARE @RelationshipTypeId_Manages UNIQUEIDENTIFIER +SELECT @RelationshipTypeId_Manages = dbo.fn_RelationshipTypeId_Manages() +SELECT TOP 50 bme.DisplayName, SUM(1) AS HostedInstances +FROM BaseManagedEntity bme +RIGHT JOIN ( +SELECT + HBME.BaseManagedEntityId AS HS_BMEID, + TBME.FullName AS TopLevelEntityName, + BME.FullName AS BaseEntityName, + TYPE.TypeName AS TypedEntityName +FROM BaseManagedEntity BME WITH(NOLOCK) + INNER JOIN TypedManagedEntity TME WITH(NOLOCK) ON BME.BaseManagedEntityId = TME.BaseManagedEntityId AND BME.IsDeleted = 0 AND TME.IsDeleted = 0 + INNER JOIN BaseManagedEntity TBME WITH(NOLOCK) ON BME.TopLevelHostEntityId = TBME.BaseManagedEntityId AND TBME.IsDeleted = 0 + INNER JOIN ManagedType TYPE WITH(NOLOCK) ON TME.ManagedTypeID = TYPE.ManagedTypeID + LEFT JOIN Relationship R WITH(NOLOCK) ON R.TargetEntityId = TBME.BaseManagedEntityId AND R.RelationshipTypeId = @RelationshipTypeId_Manages AND R.IsDeleted = 0 + LEFT JOIN BaseManagedEntity HBME WITH(NOLOCK) ON R.SourceEntityId = HBME.BaseManagedEntityId +) AS dt ON dt.HS_BMEID = bme.BaseManagedEntityId +GROUP by BME.displayname +order by HostedInstances DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Instances_ByType.sql b/SQL Queries/OperationsManager/Instances_ByType.sql new file mode 100644 index 0000000..fbd51b9 --- /dev/null +++ b/SQL Queries/OperationsManager/Instances_ByType.sql @@ -0,0 +1,6 @@ +SELECT mt.TypeName, COUNT(*) AS NumEntitiesByType +FROM BaseManagedEntity bme WITH(NOLOCK) + LEFT JOIN ManagedType mt WITH(NOLOCK) ON mt.ManagedTypeID = bme.BaseManagedTypeID +WHERE bme.IsDeleted = 0 +GROUP BY mt.TypeName +ORDER BY COUNT(*) DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Instances_ByTypeAndHost.sql b/SQL Queries/OperationsManager/Instances_ByTypeAndHost.sql new file mode 100644 index 0000000..b163b02 --- /dev/null +++ b/SQL Queries/OperationsManager/Instances_ByTypeAndHost.sql @@ -0,0 +1,19 @@ +DECLARE @RelationshipTypeId_Manages UNIQUEIDENTIFIER +SELECT @RelationshipTypeId_Manages = dbo.fn_RelationshipTypeId_Manages() +SELECT TOP 500 bme.DisplayName, SUM(1) AS HostedInstances, dt.TypedEntityName +FROM BaseManagedEntity bme +RIGHT JOIN ( +SELECT + HBME.BaseManagedEntityId AS HS_BMEID, + TBME.FullName AS TopLevelEntityName, + BME.FullName AS BaseEntityName, + TYPE.TypeName AS TypedEntityName +FROM BaseManagedEntity BME WITH(NOLOCK) + INNER JOIN TypedManagedEntity TME WITH(NOLOCK) ON BME.BaseManagedEntityId = TME.BaseManagedEntityId AND BME.IsDeleted = 0 AND TME.IsDeleted = 0 + INNER JOIN BaseManagedEntity TBME WITH(NOLOCK) ON BME.TopLevelHostEntityId = TBME.BaseManagedEntityId AND TBME.IsDeleted = 0 + INNER JOIN ManagedType TYPE WITH(NOLOCK) ON TME.ManagedTypeID = TYPE.ManagedTypeID + LEFT JOIN Relationship R WITH(NOLOCK) ON R.TargetEntityId = TBME.BaseManagedEntityId AND R.RelationshipTypeId = @RelationshipTypeId_Manages AND R.IsDeleted = 0 + LEFT JOIN BaseManagedEntity HBME WITH(NOLOCK) ON R.SourceEntityId = HBME.BaseManagedEntityId +) AS dt ON dt.HS_BMEID = bme.BaseManagedEntityId +GROUP by BME.displayname, dt.TypedEntityName +order by HostedInstances DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Instances_ByType_MT.sql b/SQL Queries/OperationsManager/Instances_ByType_MT.sql new file mode 100644 index 0000000..4a7f2e2 --- /dev/null +++ b/SQL Queries/OperationsManager/Instances_ByType_MT.sql @@ -0,0 +1,6 @@ +SELECT st.name AS 'MT_TableName', sdbs.row_count AS 'RowCount' +FROM sys.tables st +JOIN sys.dm_db_partition_stats sdbs ON st.object_id = sdbs.object_id +JOIN ManagedType mt on mt.ManagedTypeTableName = st.name +WHERE sdbs.index_id < 2 +ORDER BY sdbs.row_count DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Instances_Hosted_AMSRP.sql b/SQL Queries/OperationsManager/Instances_Hosted_AMSRP.sql new file mode 100644 index 0000000..af09de9 --- /dev/null +++ b/SQL Queries/OperationsManager/Instances_Hosted_AMSRP.sql @@ -0,0 +1,4 @@ +SELECT TargetObjectDisplayName, TargetObjectFullName +FROM RelationshipGenericView +WHERE SourceObjectDisplayName = 'All Management Servers Resource Pool' +ORDER BY TargetObjectFullName,TargetObjectDisplayName \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Instances_TotalBME.sql b/SQL Queries/OperationsManager/Instances_TotalBME.sql new file mode 100644 index 0000000..d3b2568 --- /dev/null +++ b/SQL Queries/OperationsManager/Instances_TotalBME.sql @@ -0,0 +1 @@ +select count(*) from BaseManagedEntity \ No newline at end of file diff --git a/SQL Queries/OperationsManager/MG_GlobalSettings.sql b/SQL Queries/OperationsManager/MG_GlobalSettings.sql new file mode 100644 index 0000000..35aa6c0 --- /dev/null +++ b/SQL Queries/OperationsManager/MG_GlobalSettings.sql @@ -0,0 +1,5 @@ +SELECT mtp.ManagedTypePropertyName AS 'Property', + gs.SettingValue +FROM GlobalSettings gs +JOIN ManagedTypeProperty mtp ON mtp.ManagedTypePropertyId = gs.ManagedTypePropertyId +ORDER BY mtp.ManagedTypePropertyName \ No newline at end of file diff --git a/SQL Queries/OperationsManager/MG_Info.sql b/SQL Queries/OperationsManager/MG_Info.sql new file mode 100644 index 0000000..17530b8 --- /dev/null +++ b/SQL Queries/OperationsManager/MG_Info.sql @@ -0,0 +1 @@ +select * from __MOMManagementGroupInfo__ \ No newline at end of file diff --git a/SQL Queries/OperationsManager/MG_Overview.sql b/SQL Queries/OperationsManager/MG_Overview.sql new file mode 100644 index 0000000..8e3ee23 --- /dev/null +++ b/SQL Queries/OperationsManager/MG_Overview.sql @@ -0,0 +1,11 @@ +SELECT MG_Name, MOMAdminGroup, REPLACE(REPLACE(EnableErrorReports,1,'True'),0,'False') AS EnableErrorReports, LanguageCode, MS_Count, GW_Count, Agent_Count, Agent_Pending, Unix_Count, NetworkDevice_Count +FROM (SELECT ManagementGroupName AS 'MG_Name' FROM __MOMManagementGroupInfo__) AS MG_Name, +(SELECT MOMAdminGroup FROM __MOMManagementGroupInfo__) AS MOMAdminGroup, +(SELECT LanguageCode FROM __MOMManagementGroupInfo__) AS LanguageCode, +(SELECT EnableErrorReports FROM __MOMManagementGroupInfo__) AS EnableErrorReports, +(SELECT COUNT(*) AS 'MS_Count' FROM MTV_HealthService WHERE IsManagementServer = 1 AND IsGateway = 0) AS MS_Count, +(SELECT COUNT(*) AS 'GW_Count' FROM MTV_HealthService WHERE IsManagementServer = 1 AND IsGateway = 1) AS GW_Count, +(SELECT COUNT(*) AS 'Agent_Count' FROM MTV_HealthService WHERE IsManagementServer = 0 AND IsGateway = 0) AS Agent_Count, +(SELECT COUNT(*) AS 'Agent_Pending' FROM AgentPendingAction) AS Agent_Pending, +(SELECT COUNT(*) AS 'Unix_Count' FROM MTV_Microsoft$Unix$Computer) AS Unix_Count, +(SELECT Count(*) AS 'NetworkDevice_Count' FROM MTV_System$NetworkManagement$Node) AS NetworkDevice_Count \ No newline at end of file diff --git a/SQL Queries/OperationsManager/MG_ResourcePools.sql b/SQL Queries/OperationsManager/MG_ResourcePools.sql new file mode 100644 index 0000000..b343efc --- /dev/null +++ b/SQL Queries/OperationsManager/MG_ResourcePools.sql @@ -0,0 +1,62 @@ +SET NOCOUNT ON +DECLARE + @Statement nvarchar(max) + ,@MicrosoftSystemCenterManagementService nvarchar(255) + ,@ManagementService_HealthServiceId nvarchar(255) + ,@BaseManagedEntityDisplayName nvarchar(255) + + SELECT @MicrosoftSystemCenterManagementService = ManagedTypeViewName + FROM dbo.ManagedType + WHERE (ManagedTypeId = dbo.fn_ManagedTypeId_MicrosoftSystemCenterManagementService()) + PRINT @MicrosoftSystemCenterManagementService + + SELECT @ManagementService_HealthServiceId = ColumnName + FROM dbo.ManagedTypeProperty + WHERE (ManagedTypeId = dbo.fn_ManagedTypeId_MicrosoftSystemCenterManagementService()) + AND (ManagedTypePropertyId = dbo.fn_ManagedTypePropertyId_MicrosoftSystemCenterManagementService_HealthServiceId()) + PRINT @ManagementService_HealthServiceId + + SELECT @BaseManagedEntityDisplayName = S.COLUMN_NAME + FROM INFORMATION_SCHEMA.COLUMNS AS S + WHERE S.TABLE_NAME COLLATE DATABASE_DEFAULT IN + (SELECT ManagedTypeViewName AS [TABLE_NAME] FROM dbo.ManagedType) + AND S.TABLE_NAME = @MicrosoftSystemCenterManagementService + AND S.COLUMN_NAME like 'DisplayName%' + PRINT @BaseManagedEntityDisplayName + + IF (OBJECT_ID('tempdb..#PoolMember') IS NOT NULL) + DROP TABLE #PoolMember + CREATE TABLE #PoolMember ( + +ManagementServiceId uniqueidentifier NOT NULL + ,HealthServiceId uniqueidentifier NULL + ,ResourcePool varchar(255) + ,Member varchar(255) + ) + + set @Statement = ' + INSERT #PoolMember ( + ManagementServiceId + ,HealthServiceId + ,ResourcePool + ,Member + ) + SELECT + TargetEntityId + ,' + QUOTENAME(@ManagementService_HealthServiceId) + ' + ,BME.DisplayName AS ResourcePool + ,[MS].' + QUOTENAME(@BaseManagedEntityDisplayName) + ' AS Member + FROM dbo.Relationship R + JOIN ' + QUOTENAME(@MicrosoftSystemCenterManagementService) + ' MS ON (R.TargetEntityId = MS.BaseManagedEntityId) + JOIN BaseManagedEntity BME ON BME.BaseManagedEntityId = R.SourceEntityId + WHERE (RelationshipTypeId = dbo.fn_ManagedTypeId_MicrosoftSystemCenterManagementServicePoolContainsManagementService()) + AND (R.IsDeleted = 0) AND (BME.IsDeleted = 0)' + + Print @Statement + Exec (@Statement) + +Select + ResourcePool, + Member + from #PoolMember + Order By ResourcePool ASC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/MG_SQLPatchVersion_OpsDB.sql b/SQL Queries/OperationsManager/MG_SQLPatchVersion_OpsDB.sql new file mode 100644 index 0000000..e7072ef --- /dev/null +++ b/SQL Queries/OperationsManager/MG_SQLPatchVersion_OpsDB.sql @@ -0,0 +1,2 @@ +-- Get the OpsMgr Update Rollup Version. +select * from [dbo].[SqlPatchVersion] \ No newline at end of file diff --git a/SQL Queries/OperationsManager/MG_UserRoles.sql b/SQL Queries/OperationsManager/MG_UserRoles.sql new file mode 100644 index 0000000..9f5664c --- /dev/null +++ b/SQL Queries/OperationsManager/MG_UserRoles.sql @@ -0,0 +1,4 @@ +SELECT Description, SUSER_SNAME([MemberSID]) as "RoleMember" +FROM AzMan_AzRoleAssignment A +join AzMan_Role_SIDMember B +on A.ID = b.RoleID \ No newline at end of file diff --git a/SQL Queries/OperationsManager/MP_Removals.sql b/SQL Queries/OperationsManager/MP_Removals.sql new file mode 100644 index 0000000..8099542 --- /dev/null +++ b/SQL Queries/OperationsManager/MP_Removals.sql @@ -0,0 +1,2 @@ +SELECT * FROM MPRemovalLog +ORDER BY MPRemovalDate DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Maintenance_Mode.sql b/SQL Queries/OperationsManager/Maintenance_Mode.sql new file mode 100644 index 0000000..8b19b9e --- /dev/null +++ b/SQL Queries/OperationsManager/Maintenance_Mode.sql @@ -0,0 +1,27 @@ +SELECT +FullName as [Object in Maintenance], +TimeAdded as [Time Added], +StartTime as [Start Time], +ScheduledEndTime as [Scheduled End Time], +dbo.MaintenanceMode.[User] as [User], +Case ReasonCode +When 0 then 'Other (Planned)' +When 1 then 'Other (Unplanned)' +When 2 then 'Hardware: Maintenance (Planned)' +When 3 then 'Hardware: Maintenance (Unplanned)' +When 4 then 'Hardware: Installation (Planned)' +When 5 then 'Hardware: Installation (Unplanned)' +When 6 then 'Operating System: Reconfiguration (Planned)' +When 7 then 'Operating System: Reconfiguration (Unplanned)' +When 8 then 'Application: Maintenance (Planned)' +When 9 then 'Application: Maintenance (Unplanned)' +When 10 then 'Application: Installation (Planned)' +When 11 then 'Application: Unresponsive' +When 12 then 'Application: Unstable' +When 13 then 'Security issue' +When 14 then 'Loss of network connectivity (Unplanned)' +End as [Reason for Maintenance], +Comments +FROM BaseManagedEntity INNER JOIN +MaintenanceMode ON BaseManagedEntity.BaseManagedEntityId = MaintenanceMode.BaseManagedEntityId +WHERE IsInMaintenanceMode = 1 \ No newline at end of file diff --git a/SQL Queries/OperationsManager/ManagementPacks.sql b/SQL Queries/OperationsManager/ManagementPacks.sql new file mode 100644 index 0000000..930633b --- /dev/null +++ b/SQL Queries/OperationsManager/ManagementPacks.sql @@ -0,0 +1,15 @@ +select +mpv.Id, +mpv.DisplayName, +mpv.Name, +mpv.FriendlyName, +mpv.Version, +mpv.Sealed, +mpv.LastModified, +mpv.TimeCreated, +mpv.Description, +mpv.LanguageCode AS 'Language' +--CAST(mp.MPXML AS xml) AS 'XML' +from ManagementPackView mpv +inner join ManagementPack mp +on mpv.id = mp.ManagementPackId \ No newline at end of file diff --git a/SQL Queries/OperationsManager/ManagementServers.sql b/SQL Queries/OperationsManager/ManagementServers.sql new file mode 100644 index 0000000..18a5226 --- /dev/null +++ b/SQL Queries/OperationsManager/ManagementServers.sql @@ -0,0 +1,7 @@ +SELECT *,REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REASONCODE,17,'The Health Service windows service is paused.'),25,'The Health Service Action Account is misconfigured or has invalid credentials.'),41,'The Health Service failed to parse the new configuration.'),42,'The Health Service failed to load the new configuration.'),43,'A System Rule failed to load.'),49,'Collection of Object State Change Events is stalled.'),50,'Collection of Monitor State Change Events is stalled.'),51,'Collection of Alerts is stalled.'),97,'The Health Service is unable to register with the Event Log Service. The Health Service cannot log additional Heartbeat and Connector events.'),98,'The Health Service is unable to parse configuration XML.'),1,'Reason Unknown. POSSIBLY due to Health Service not heartbeating within 3 minutes to SDK?') AS ReasonCodeResult +FROM MTV_HealthService mtv +LEFT JOIN AvailabilityHistory ahist +ON ahist.BaseManagedEntityId = mtv.BaseManagedEntityId +WHERE mtv.IsManagementServer = 1 +OR mtv.IsGateway = 1 +ORDER BY mtv.DisplayName diff --git a/SQL Queries/OperationsManager/NetworkDevice_ByPool.sql b/SQL Queries/OperationsManager/NetworkDevice_ByPool.sql new file mode 100644 index 0000000..4d02a24 --- /dev/null +++ b/SQL Queries/OperationsManager/NetworkDevice_ByPool.sql @@ -0,0 +1,8 @@ +select BME.DisplayName as 'ResourcePool' ,Count(R.RelationshipId) as 'DeviceCount' from BaseManagedEntity BME WITH(NOLOCK) +join ManagedType MT WITH(NOLOCK) on BME.BaseManagedTypeId = MT.ManagedTypeId +join Relationship R WITH(NOLOCK) on BME.BaseManagedEntityId = R.SourceEntityId +join BaseManagedEntity BME2 WITH(NOLOCK) on R.TargetEntityId = BME2.BaseManagedEntityId +where MT.BaseManagedTypeId IN (SELECT ManagedTypeId FROM ManagedType WHERE TypeName LIKE '%pool') +and BME2.BaseManagedTypeId = (SELECT ManagedTypeId FROM ManagedType WHERE TypeName = 'System.NetworkManagement.Node') +and R.RelationshipTypeId = (SELECT RelationshipTypeId FROM RelationshipType WHERE RelationshipTypeName = 'Microsoft.SystemCenter.ManagementActionPointManagesEntity') +group by BME.DisplayName \ No newline at end of file diff --git a/SQL Queries/OperationsManager/NetworkDevice_Inventory.sql b/SQL Queries/OperationsManager/NetworkDevice_Inventory.sql new file mode 100644 index 0000000..922763a --- /dev/null +++ b/SQL Queries/OperationsManager/NetworkDevice_Inventory.sql @@ -0,0 +1,12 @@ +SELECT +[SNMPVersion_3E123035_1664_20F4_43ED_875F388621BB] as 'SNMPVersion', +[Description_C79E2645_F509_8EEE_210C_CD6108E2364A] as 'Description', +[SupportsSNMP_D84DEAD4_3A54_52C6_BE26_B43FC589D0A5] as 'SNMPSupport', +[Certification_770F2AEC_DBDA_C9CC_E680_0C3EB68BA002] as 'Certified', +[SNMPAddress_3D25AA04_B3ED_7489_F61C_6A8AD21115FE] as 'SNMPAddress', +[Model_4BD92846_5429_2E69_6653_C6A6F7D9D484] as 'Model', +[AccessMode_2E4EC094_2362_BBF8_123C_141066AD5A78] as 'AccessMode', +[Vendor_16EE4AB2_CBCC_BAD3_B249_A56E6BF207D0] as 'Vendor', +[sysName_EBD2EE76_4A80_E1A2_D2C1_615B586EAD36] as 'SystemName', +[DisplayName] as 'DisplayName' +FROM [MT_System$NetworkManagement$Node] \ No newline at end of file diff --git a/SQL Queries/OperationsManager/NetworkDevice_Ports.sql b/SQL Queries/OperationsManager/NetworkDevice_Ports.sql new file mode 100644 index 0000000..691f3e6 --- /dev/null +++ b/SQL Queries/OperationsManager/NetworkDevice_Ports.sql @@ -0,0 +1,31 @@ +;WITH +CTE as ( +SELECT + n.DisplayName as 'NetworkDeviceName', + n.Vendor_16EE4AB2_CBCC_BAD3_B249_A56E6BF207D0 as Vendor, + n.Model_4BD92846_5429_2E69_6653_C6A6F7D9D484 as Model, + b.Path,count(b.path) as DiscoveredPortCount +FROM MT_System$NetworkManagement$Port p WITH(NOLOCK) +JOIN BaseManagedEntity b WITH(NOLOCK) on p.BaseManagedEntityId=b.BaseManagedEntityId +JOIN dbo.MTV_System$NetworkManagement$Node n WITH (NOLOCK) on b.TopLevelHostEntityId=n.BaseManagedEntityId +GROUP BY n.DisplayName, n.Vendor_16EE4AB2_CBCC_BAD3_B249_A56E6BF207D0, n.Model_4BD92846_5429_2E69_6653_C6A6F7D9D484, b.Path +), + +cte1 as ( +SELECT + b.Path,count(b.path) as MonitoredPortCount +FROM MT_System$NetworkManagement$Port p WITH(NOLOCK) +JOIN state s WITH(NOLOCK) on p.BaseManagedEntityId=s.BaseManagedEntityId +JOIN BaseManagedEntity b WITH(NOLOCK) on s.BaseManagedEntityId=b.BaseManagedEntityId +join Monitor m WITH(NOLOCK) on m.MonitorId = s.MonitorId +WHERE m.MonitorName='System.Health.EntityState' and s.HealthState<>0 +GROUP BY b.Path +) + +SELECT + c1.NetworkDeviceName, + c1.Vendor, + c1.Model, + c1.DiscoveredPortCount, + case when (c2.MonitoredPortCount IS NULL) THEN 0 ELSE c2.MonitoredPortCount END AS MonitoredPortCount +FROM cte c1 left join cte1 c2 on c1.Path=c2.Path diff --git a/SQL Queries/OperationsManager/Notifications_Channels.sql b/SQL Queries/OperationsManager/Notifications_Channels.sql new file mode 100644 index 0000000..09287ee --- /dev/null +++ b/SQL Queries/OperationsManager/Notifications_Channels.sql @@ -0,0 +1,4 @@ +exec sp_executesql N'-- ModuleTypesForNotifications +SELECT [ModuleTypeView].[Id],[ModuleTypeView].[Name],[ModuleTypeView].[ManagementPackId],[ModuleTypeView].[Accessibility],[ModuleTypeView].[OutputMonitoringDataTypeId],[ModuleTypeView].[Role],[ModuleTypeView].[CanGuaranteeDelivery],[ModuleTypeView].[IncludeSchemaTypes],[ModuleTypeView].[IsPassThrough],[ModuleTypeView].[IsStateful],[ModuleTypeView].[IsTriggerOnly],[ModuleTypeView].[Batching],[ModuleTypeView].[ImplementationXml],[ModuleTypeView].[ConfigurationXsd],[ModuleTypeView].[InputMonitoringDataTypes],[ModuleTypeView].[RunAs],[ModuleTypeView].[TimeAdded],[ModuleTypeView].[LastModified],[ModuleTypeView].[HasUIPageSet],[ModuleTypeView].[DisplayName],[ModuleTypeView].[Description],[ModuleTypeView].[LanguageCode],[ModuleTypeView].[AssemblyQualifiedName] +FROM dbo.fn_ModuleTypeView(@LanguageCode1, @LanguageCode2) AS ModuleTypeView +WHERE ((ModuleTypeView.Role = 3 AND ModuleTypeView.ManagementPackId = @ManagementPackId))',N'@LanguageCode1 varchar(3),@LanguageCode2 varchar(3),@ManagementPackId uniqueidentifier',@LanguageCode1='ENU',@LanguageCode2=NULL,@ManagementPackId='DCFDEDC4-68BD-42B4-1E9A-BA94B1577732' \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Notifications_Subscribers.sql b/SQL Queries/OperationsManager/Notifications_Subscribers.sql new file mode 100644 index 0000000..9201a3f --- /dev/null +++ b/SQL Queries/OperationsManager/Notifications_Subscribers.sql @@ -0,0 +1 @@ +select * from [dbo].[ModuleType] WHERE MDTName = 'Microsoft.SystemCenter.Notification.Recipients' \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Notifications_Subscriptions.sql b/SQL Queries/OperationsManager/Notifications_Subscriptions.sql new file mode 100644 index 0000000..7703541 --- /dev/null +++ b/SQL Queries/OperationsManager/Notifications_Subscriptions.sql @@ -0,0 +1,37 @@ +-- This is the 2 queries joined together to provide the data that we want +Select Subscriptions.DisplayName, Subscriptions.RuleId, +Case subscriptions.enabled When 0 Then 'No' Else 'Yes' End as SubscriptionEnabled, +Subscribers.SubscriberName, Subscribers.DeviceName, Subscribers.DeviceProtocol, +Subscribers.DeviceAddress +FROM ( +--This is the whole subscriber query with Address +Select r.SubscriberName, r.SubscriberId, +D.C.value('Name[1]','varchar(4000)') DeviceName, +D.C.value('Protocol[1]','varchar(4000)') DeviceProtocol, +D.C.value('Address[1]','varchar(4000)') DeviceAddress +FROM (Select N.C.value('Name[1]','varchar(4000)') SubscriberName, + N.C.value('RecipientId[1]','varchar(4000)') SubscriberId, + n.c.query('.') as xmlquery +from (Select cast(MDTImplementationXML as xml) Recxml FROM [dbo].[ModuleType] mt +Where MDTName = 'Microsoft.SystemCenter.Notification.Recipients' )a Cross Apply Recxml.nodes('//Recipient') N(C)) r +Cross Apply xmlquery.nodes('//Device') D(C) +) Subscribers +Join +(--These are the subscriptions +Select r.RuleId, r.RuleModuleId, r.enabled, R.DisplayName, +D.C.value('RecipientId[1]','varchar(4000)') SubscriberId +FROM (Select RuleId, rm.RuleModuleId, enabled, r.DisplayName, + cast(RuleModuleConfiguration as XML) xmlquery + FROM + RuleModule rm + join RuleView r on rm.RuleId = r.Id + where r.Category = 'Notification' + and RuleModuleName = 'CD1' + --and Enabled <> 0 + ) r +Cross Apply xmlquery.nodes('//DirectoryReference') D(C) +) Subscriptions on Subscribers.SubscriberId = Subscriptions.SubscriberId +--Where ((Subscriptions.RuleId = Replace(Replace(@SubscriptionId,'{',''),'}','') + --or @SubscriptionId IS NULL) +--and DeviceProtocol in ('SMS','SMTP')) +order by 1,2 \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Orphaned.sql b/SQL Queries/OperationsManager/Orphaned.sql new file mode 100644 index 0000000..8dd05af --- /dev/null +++ b/SQL Queries/OperationsManager/Orphaned.sql @@ -0,0 +1,28 @@ +--find orphans +declare @DiscoverySourceId uniqueidentifier; +declare @TimeGenerated datetime; +set @TimeGenerated = GETUTCDATE(); +set @DiscoverySourceId = dbo.fn_DiscoverySourceId_User(); +SELECT TME.[TypedManagedEntityid] +FROM MTV_HealthService HS +INNER JOIN dbo.[BaseManagedEntity] BHS +ON BHS.[BaseManagedEntityId] = HS.[BaseManagedEntityId] +-- get host managed computer instances +INNER JOIN dbo.[TypedManagedEntity] TME +ON TME.[BaseManagedEntityId] = BHS.[TopLevelHostEntityId] +AND TME.[IsDeleted] = 0 +INNER JOIN dbo.[DerivedManagedTypes] DMT +ON DMT.[DerivedTypeId] = TME.[ManagedTypeId] +INNER JOIN dbo.[ManagedType] BT +ON DMT.[BaseTypeId] = BT.[ManagedTypeId] +AND BT.[TypeName] = N'Microsoft.Windows.Computer' +-- only with missing primary +LEFT OUTER JOIN dbo.Relationship HSC +ON HSC.[SourceEntityId] = HS.[BaseManagedEntityId] +AND HSC.[RelationshipTypeId] = dbo.fn_RelationshipTypeId_HealthServiceCommunication() +AND HSC.[IsDeleted] = 0 +INNER JOIN DiscoverySourceToTypedManagedEntity DSTME +ON DSTME.[TypedManagedEntityId] = TME.[TypedManagedEntityId] +AND DSTME.[DiscoverySourceId] = @DiscoverySourceId +WHERE HS.[IsAgent] = 1 +AND HSC.[RelationshipId] IS NULL; \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Overrides.sql b/SQL Queries/OperationsManager/Overrides.sql new file mode 100644 index 0000000..6a1c9f9 --- /dev/null +++ b/SQL Queries/OperationsManager/Overrides.sql @@ -0,0 +1,112 @@ + Select WorkflowType, WorkflowName, Overview.OverrideName, OverrideableParameterName, OverrideValue, OverrideDescription, OverrideEnforced, OverrideScope, TargetedInstanceName, TargetedInstancePath, ORMPName, ORMPDescription, ORMPSealed, MPTargetClass, TargetManagementPack, ModuleOverrideId, ORMPLanguage, OverrideLastModified, OverrideCreatedOn from ( + SELECT 'Rule' AS 'WorkflowType', + rv.displayname AS WorkflowName, + OverrideName, + op.OverrideableParameterName, + mo.value AS OverrideValue, + lt.ltvalue AS OverrideDescription, + mo.enforced AS OverrideEnforced, + mt.typename AS OverrideScope, + bme.displayname AS TargetedInstanceName, + bme.path AS TargetedInstancePath, + mpv.displayname AS ORMPName, + mpv.description AS ORMPDescription, + mpv.sealed AS ORMPSealed, + mpv.LanguageCode AS ORMPLanguage, + mo.lastmodified AS OverrideLastModified, + mo.timeadded AS OverrideCreatedOn + --op.TimeAdded AS MPTimeCreated + FROM moduleoverride mo + INNER JOIN managementpackview mpv + ON mpv.id = mo.managementpackid + INNER JOIN ruleview rv + ON rv.id = mo.parentid + INNER JOIN managedtype mt + ON mt.managedtypeid = mo.typecontext + LEFT JOIN localizedtext lt + ON lt.ltstringid = mo.moduleoverrideid + LEFT JOIN basemanagedentity bme + ON bme.basemanagedentityid = mo.instancecontext + LEFT JOIN overrideableparameter op + ON mo.overrideableparameterid = op.overrideableparameterid + --Where (lt.LTStringType = 2 and mpv.LanguageCode = 'ENU') + --Where (mpv.Sealed = 0 and mpv.LanguageCode = 'ENU') + --Where mpv.Sealed = 0 + UNION ALL + SELECT 'Monitor' AS 'WorkflowType', + mv.displayname AS WorkflowName, + OverrideName, + op.OverrideableParameterName, + mto.value AS OverrideValue, + lt.ltvalue AS OverrideDescription, + mto.enforced AS OverrideEnforced, + mt.typename AS OverrideScope, + bme.displayname AS TargetedInstanceName, + bme.path AS TargetedInstancePath, + mpv.displayname AS ORMPName, + mpv.description AS ORMPDescription, + mpv.sealed AS ORMPSealed, + mpv.LanguageCode AS ORMPLanguage, + mto.lastmodified AS OverrideLastModified, + mto.timeadded AS OverrideCreatedOn + --mpv.TimeCreated AS MPTimeCreated + FROM monitoroverride mto + INNER JOIN managementpackview mpv + ON mpv.id = mto.managementpackid + INNER JOIN monitorview mv + ON mv.id = mto.monitorid + INNER JOIN managedtype mt + ON mt.managedtypeid = mto.typecontext + LEFT JOIN localizedtext lt + ON lt.ltstringid = mto.monitoroverrideid + LEFT JOIN basemanagedentity bme + ON bme.basemanagedentityid = mto.instancecontext + LEFT JOIN overrideableparameter op + ON mto.overrideableparameterid = op.overrideableparameterid + --Where (lt.LTStringType = 2 and mpv.LanguageCode = 'ENU') + --Where (mpv.Sealed = 0 and mpv.LanguageCode = 'ENU') + --Where mpv.Sealed = 0 + UNION ALL + SELECT 'Discovery' AS 'WorkflowType', + dv.displayname AS WorkflowName, + OverrideName, + op.OverrideableParameterName, + mo.value AS OverrideValue, + lt.ltvalue AS OverrideDescription, + mo.enforced AS OverrideEnforced, + mt.typename AS OverrideScope, + bme.displayname AS TargetedInstanceName, + bme.path AS TargetedInstancePath, + mpv.displayname AS ORMPName, + mpv.description AS ORMPDescription, + mpv.sealed AS ORMPSealed, + mpv.LanguageCode AS ORMPLanguage, + mo.lastmodified AS OverrideLastModified, + mo.timeadded AS OverrideCreatedOn + --mpv.TimeCreated AS MPTimeCreated + FROM moduleoverride mo + INNER JOIN managementpackview mpv + ON mpv.id = mo.managementpackid + INNER JOIN discoveryview dv + ON dv.id = mo.parentid + INNER JOIN managedtype mt + ON mt.managedtypeid = mo.typecontext + LEFT JOIN localizedtext lt + ON lt.ltstringid = mo.moduleoverrideid + LEFT JOIN basemanagedentity bme + ON bme.basemanagedentityid = mo.instancecontext + LEFT JOIN overrideableparameter op + ON mo.overrideableparameterid = op.overrideableparameterid + --Where (lt.LTStringType = 2 and mpv.LanguageCode = 'ENU') + --Where (mpv.Sealed = 0 and mpv.LanguageCode = 'ENU') + )Overview + + +LEFT JOIN ( + SELECT mo.ModuleOverrideId, mo.OverrideName, mpv.DisplayName as 'MPTargetClass', mpv.FriendlyName as [TargetManagementPack] FROM ModuleOverride mo + INNER JOIN Managedtype mt on mt.ManagedTypeId = mo.TypeContext + INNER JOIN ManagementPackView mpv on mpv.ID = mt.ManagementPackId + Where mpv.LanguageCode = 'ENU' +) OverridesOverview ON OverridesOverview.OverrideName = Overview.OverrideName + +ORDER BY OverrideLastModified DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Parent_Child_Issue.sql b/SQL Queries/OperationsManager/Parent_Child_Issue.sql new file mode 100644 index 0000000..0cb8c87 --- /dev/null +++ b/SQL Queries/OperationsManager/Parent_Child_Issue.sql @@ -0,0 +1,20 @@ +SELECT c1.ParentAgentRowId, a1.NetworkName 'Parent', +c1.ChildAgentRowId, a1.NetworkName 'Child' +FROM CS.CommunicationRelationship c1 +JOIN CS.Agent a1 +ON c1.ParentAgentRowId = a1.AgentRowId +WHERE c1.ParentAgentRowId = c1.ChildAgentRowId +And c1.DeletedInd = 0 +UNION +SELECT c2.ParentAgentRowId, a2p.NetworkName 'Parent', +c2.ChildAgentRowId, a2c.NetworkName 'Child' +FROM CS.CommunicationRelationship c2 +JOIN CS.Agent a2p +ON c2.ParentAgentRowId = a2p.AgentRowId +JOIN CS.Agent a2c +ON c2.ChildAgentRowId = a2c.AgentRowId +JOIN CS.CommunicationRelationship c2r +ON c2.ParentAgentRowId = c2r.ChildAgentRowId +AND c2.ChildAgentRowId = c2r.ParentAgentRowId +WHERE c2.DeletedInd = 0 +AND c2r.DeletedInd = 0 \ No newline at end of file diff --git a/SQL Queries/OperationsManager/PartitionAndGroom_Retention.sql b/SQL Queries/OperationsManager/PartitionAndGroom_Retention.sql new file mode 100644 index 0000000..eda91db --- /dev/null +++ b/SQL Queries/OperationsManager/PartitionAndGroom_Retention.sql @@ -0,0 +1,11 @@ +SELECT [ObjectName] + ,[IsPartitioned] + ,[InsertViewName] + ,[GroomingSproc] + ,[DaysToKeep] + ,[GroomingRunTime] + ,[DataGroomedMaxTime] + ,[IsInternal] + FROM [PartitionAndGroomingSettings] + WHERE ObjectId NOT IN ('18','17','16','15','10','11') + ORDER BY ObjectName \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Perf_ByDay.sql b/SQL Queries/OperationsManager/Perf_ByDay.sql new file mode 100644 index 0000000..613c57b --- /dev/null +++ b/SQL Queries/OperationsManager/Perf_ByDay.sql @@ -0,0 +1,6 @@ +SELECT CASE WHEN(GROUPING(CONVERT(VARCHAR(20), TimeSampled, 102)) = 1) +THEN 'All Days' ELSE CONVERT(VARCHAR(20), TimeSampled, 102) +END AS DaySampled, COUNT(*) AS PerfInsertPerDay +FROM PerformanceDataAllView with (NOLOCK) +GROUP BY CONVERT(VARCHAR(20), TimeSampled, 102) WITH ROLLUP +ORDER BY DaySampled DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Perf_byCounter.sql b/SQL Queries/OperationsManager/Perf_byCounter.sql index f4747bd..6168186 100644 --- a/SQL Queries/OperationsManager/Perf_byCounter.sql +++ b/SQL Queries/OperationsManager/Perf_byCounter.sql @@ -1,8 +1,9 @@ -/*Top 30 performance insertions by perf object and counter name: */ -SELECT TOP (30) pcv.ObjectName, r.DisplayName AS 'RuleName', pcv.CounterName, pcv.RuleId, COUNT(pcv.CounterName) AS Total +/*Top 30 performance insertions by perf object and counter name: */ +SELECT TOP (30) pcv.ObjectName, r.DisplayName AS 'RuleName', pcv.CounterName, MPV.DisplayName AS 'MPDisplayName', pcv.RuleId, COUNT(pcv.CounterName) AS Total FROM PerformanceDataAllView AS pdv INNER JOIN PerformanceCounterView AS pcv ON pdv.PerformanceSourceInternalId = pcv.PerformanceSourceInternalId INNER JOIN RuleView AS r ON pcv.RuleId = r.Id INNER JOIN + ManagementPackView AS MPV ON r.ManagementPackId = MPV.Id -GROUP BY pcv.ObjectName, pcv.CounterName, pcv.RuleId, r.DisplayName -ORDER BY Total DESC +GROUP BY pcv.ObjectName, pcv.CounterName, MPV.DisplayName, pcv.RuleId, r.DisplayName +ORDER BY Total DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Recently_Changed_Disc_OpsDB.sql b/SQL Queries/OperationsManager/Recently_Changed_Disc_OpsDB.sql new file mode 100644 index 0000000..beca3f1 --- /dev/null +++ b/SQL Queries/OperationsManager/Recently_Changed_Disc_OpsDB.sql @@ -0,0 +1,14 @@ +-- Gather all Discoveries Modified in the last 180 days. +SELECT DiscoveryName, + mp.MPFriendlyName, + REPLACE(REPLACE(REPLACE(DiscoveryEnabled, '4', 'True'),'0', 'False'), '3', 'onEssentialMonitoring') as 'DiscoveryEnabled', + CASE WHEN bme.DisplayName IS NULL then mt.TypeName else bme.DisplayName END as 'DiscoveryTarget', + d.LastModified, + d.TimeAdded +FROM Discovery d LEFT JOIN +BaseManagedEntity AS bme ON d.DiscoveryTarget = bme.BaseManagedEntityId INNER JOIN +ManagedType AS mt ON d.DiscoveryTarget = mt.ManagedTypeId INNER JOIN +ManagementPack mp +ON d.ManagementPackId = mp.ManagementPackId +WHERE d.LastModified > DATEADD(day, -180, GETUTCDATE()) +ORDER BY d.LastModified DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Recently_Changed_Mon_OpsDB.sql b/SQL Queries/OperationsManager/Recently_Changed_Mon_OpsDB.sql new file mode 100644 index 0000000..7be8566 --- /dev/null +++ b/SQL Queries/OperationsManager/Recently_Changed_Mon_OpsDB.sql @@ -0,0 +1,13 @@ +SELECT MonitorName, + mp.MPFriendlyName + MonitorEnabled, + CAST(ConfigurationXML AS xml), + MonitorCategory, + MonitorPriority, + m.LastModified, + m.TimeAdded +FROM Monitor m +INNER JOIN ManagementPack mp +ON m.ManagementPackId = mp.ManagementPackId +WHERE m.LastModified > DATEADD(day, -4, GETUTCDATE()) +ORDER BY m.LastModified DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Recently_Changed_Rule_OpsDB.sql b/SQL Queries/OperationsManager/Recently_Changed_Rule_OpsDB.sql new file mode 100644 index 0000000..d7df21e --- /dev/null +++ b/SQL Queries/OperationsManager/Recently_Changed_Rule_OpsDB.sql @@ -0,0 +1,10 @@ +SELECT RuleName, + mp.MPFriendlyName, + RuleCategory, + RuleEnabled, + r.LastModified +FROM Rules r +INNER JOIN ManagementPack mp +ON r.ManagementPackId = mp.ManagementPackId +WHERE r.LastModified > DATEADD(day, -4, GETUTCDATE()) +ORDER BY r.LastModified DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Relationships.sql b/SQL Queries/OperationsManager/Relationships.sql new file mode 100644 index 0000000..e7c99ca --- /dev/null +++ b/SQL Queries/OperationsManager/Relationships.sql @@ -0,0 +1,4 @@ +SELECT COUNT(*) AS 'ContainedMembers', SourceObjectDisplayName, SourceObjectFullName +FROM RelationshipGenericView +GROUP BY SourceObjectDisplayName,SourceObjectFullName +ORDER BY COUNT(*) DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Resource_Pool_OpsDB.sql b/SQL Queries/OperationsManager/Resource_Pool_OpsDB.sql new file mode 100644 index 0000000..6792902 --- /dev/null +++ b/SQL Queries/OperationsManager/Resource_Pool_OpsDB.sql @@ -0,0 +1,15 @@ +select +BaseManagedEntity.DisplayName as 'ServerName' +--,cs.WorkFlowExecutionLocationAgent.AgentRowId +--,cs.workflowexecutionlocation.WorkflowExecutionLocationRowId +,cs.workflowexecutionlocation.DisplayName as 'Resource Pool' +,cs.agent.AgentGuid +from cs.WorkFlowExecutionLocationAgent +inner join cs.workflowexecutionlocation +ON cs.WorkFlowExecutionLocationAgent.WorkFlowExecutionLocationAgentRowId = cs.workflowexecutionlocation.WorkflowExecutionLocationRowId +inner join CS.agent +ON CS.agent.AgentRowId=cs.WorkFlowExecutionLocationAgent.AgentRowId +inner join BaseManagedEntity +ON BaseManagedEntity.BaseManagedEntityId = CS.agent.AgentGuid +-- Take the last line off to get all +where cs.workflowexecutionlocation.AgentPoolInd = '1' \ No newline at end of file diff --git a/SQL Queries/OperationsManager/RunAsProfiles.sql b/SQL Queries/OperationsManager/RunAsProfiles.sql new file mode 100644 index 0000000..9d6a72c --- /dev/null +++ b/SQL Queries/OperationsManager/RunAsProfiles.sql @@ -0,0 +1,21 @@ +--get all Run As profiles and associated accounts, + --credentials, Secure Storage ID values and targets +SELECT [Profile].SecureReferenceName ProfileName + , Account.Name AccountName + , Account.Domain + , Account.UserName + , Account.LastModified + , [Override].OverrideName + , [Override].Value SSID + , bme.FullName + , mt.TypeName +FROM CredentialManagerSecureStorage AS Account +JOIN SecureReferenceOverride AS [Override] +ON CONVERT (varchar(80), Account.SecureStorageId, 2) = [Override].Value +JOIN SecureReference AS [Profile] +ON [Override].SecureReferenceId = [Profile].SecureReferenceId +JOIN ManagedType mt +ON [Override].TypeContext = mt.ManagedTypeId +LEFT JOIN BaseManagedEntity bme +ON [Override].InstanceContext = bme.BaseManagedEntityId +ORDER BY ProfileName \ No newline at end of file diff --git a/SQL Queries/OperationsManager/SQL_Backups_OpsDB.sql b/SQL Queries/OperationsManager/SQL_Backups_OpsDB.sql new file mode 100644 index 0000000..deedb6d --- /dev/null +++ b/SQL Queries/OperationsManager/SQL_Backups_OpsDB.sql @@ -0,0 +1,9 @@ +SELECT + database_name AS [Database] + , type AS BackupType + , MAX(backup_start_date) AS LastBackupDate + , GETDATE() AS CurrentDate + , DATEDIFF(DD,MAX(backup_start_date),GETDATE()) AS DaysSinceBackup +FROM msdb.dbo.backupset BS JOIN master.dbo.sysdatabases SD ON BS.database_name = SD.[name] +GROUP BY database_name, type +ORDER BY database_name, type \ No newline at end of file diff --git a/SQL Queries/OperationsManager/SQL_BlockingSessions_OpsDB.sql b/SQL Queries/OperationsManager/SQL_BlockingSessions_OpsDB.sql new file mode 100644 index 0000000..6ab6cc7 --- /dev/null +++ b/SQL Queries/OperationsManager/SQL_BlockingSessions_OpsDB.sql @@ -0,0 +1 @@ +Sp_who2 \ No newline at end of file diff --git a/SQL Queries/OperationsManager/SQL_Broker_OpsDB.sql b/SQL Queries/OperationsManager/SQL_Broker_OpsDB.sql new file mode 100644 index 0000000..67f983b --- /dev/null +++ b/SQL Queries/OperationsManager/SQL_Broker_OpsDB.sql @@ -0,0 +1,23 @@ +WITH xCTE ([ObjectName], [PartitionId], [Rows], [Type]) AS +( +SELECT so.name, p.partition_id, p.row_count, so.type +FROM sys.objects so +LEFT JOIN sys.dm_db_partition_stats p ON p.object_id = so.object_id +WHERE so.name IN ('sysdercv', 'sysdesend', 'sysxmitqueue', 'sysconvgroup', 'sysremsvcbinds') +AND p.index_id = 1 --Only care about clustered index +UNION ALL +SELECT so.name, p.partition_id, p.rows, so.type +FROM sys.objects so +LEFT JOIN sys.objects so2 ON so.object_id = so2.parent_object_id +LEFT JOIN sys.partitions p ON p.object_id = so2.object_id +WHERE so.type='S' --type "S" = System tables +AND p.index_id = 1 --Only care about clustered index +AND so.is_ms_shipped = 0 --Do not care about MS shipped broker queues +) +SELECT ObjectName, Type +, CAST((reserved_page_count * 8.0)/1024.0 AS DECIMAL(10, 2)) AS 'Reserved Space (mb)' +, CAST((used_page_count * 8.0)/1024.0 AS DECIMAL(10, 2)) AS 'Used Space (mb)' +, [Rows] as 'Rows' +FROM xCTE x +LEFT JOIN sys.dm_db_partition_stats s ON x.PartitionId = s.partition_id +ORDER BY 'Reserved Space (mb)' DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/SQL_DBSize_OpsDB.sql b/SQL Queries/OperationsManager/SQL_DBSize_OpsDB.sql new file mode 100644 index 0000000..dc2efe9 --- /dev/null +++ b/SQL Queries/OperationsManager/SQL_DBSize_OpsDB.sql @@ -0,0 +1,10 @@ +SELECT convert(decimal(12,0),round(sf.size/128.000,2)) AS 'FileSize(MB)', +convert(decimal(12,0),round(fileproperty(sf.name,'SpaceUsed')/128.000,2)) AS 'SpaceUsed(MB)', +convert(decimal(12,0),round((sf.size-fileproperty(sf.name,'SpaceUsed'))/128.000,2)) AS 'FreeSpace(MB)', +CASE smf.is_percent_growth WHEN 1 THEN CONVERT(VARCHAR(10),smf.growth) +' %' ELSE convert(VARCHAR(10),smf.growth/128) +' MB' END AS 'AutoGrow', +convert(decimal(12,0),round(sf.maxsize/128.000,2)) AS 'AutoGrowthMB(MAX)', +left(sf.NAME,15) AS 'NAME', +left(sf.FILENAME,120) AS 'PATH', +sf.FILEID +from dbo.sysfiles sf +JOIN sys.master_files smf on smf.physical_name = sf.filename \ No newline at end of file diff --git a/SQL Queries/OperationsManager/SQL_ErrorLogLocation_OpsDB.sql b/SQL Queries/OperationsManager/SQL_ErrorLogLocation_OpsDB.sql new file mode 100644 index 0000000..eb1b5c3 --- /dev/null +++ b/SQL Queries/OperationsManager/SQL_ErrorLogLocation_OpsDB.sql @@ -0,0 +1 @@ +xp_readerrorlog 0, 1, N'Logging SQL Server messages in file' diff --git a/SQL Queries/OperationsManager/SQL_LargeTables_OpsDB.sql b/SQL Queries/OperationsManager/SQL_LargeTables_OpsDB.sql new file mode 100644 index 0000000..093592f --- /dev/null +++ b/SQL Queries/OperationsManager/SQL_LargeTables_OpsDB.sql @@ -0,0 +1,24 @@ +SELECT TOP 1000 +a2.name AS 'Tablename', +CAST((a1.reserved + ISNULL(a4.reserved,0))* 8/1024.0 AS DECIMAL(10, 0)) AS 'TotalSpace(MB)', +CAST(a1.data * 8/1024.0 AS DECIMAL(10, 0)) AS 'DataSize(MB)', +CAST((CASE WHEN (a1.used + ISNULL(a4.used,0)) > a1.data THEN (a1.used + ISNULL(a4.used,0)) - a1.data ELSE 0 END) * 8/1024.0 AS DECIMAL(10, 0)) AS 'IndexSize(MB)', +CAST((CASE WHEN (a1.reserved + ISNULL(a4.reserved,0)) > a1.used THEN (a1.reserved + ISNULL(a4.reserved,0)) - a1.used ELSE 0 END) * 8/1024.0 AS DECIMAL(10, 0)) AS 'Unused(MB)', +a1.rows as 'RowCount', +(row_number() over(order by (a1.reserved + ISNULL(a4.reserved,0)) desc))%2 as l1, +a3.name AS 'Schema' +FROM (SELECT ps.object_id, SUM (CASE WHEN (ps.index_id < 2) THEN row_count ELSE 0 END) AS [rows], +SUM (ps.reserved_page_count) AS reserved, +SUM (CASE WHEN (ps.index_id < 2) THEN (ps.in_row_data_page_count + ps.lob_used_page_count + ps.row_overflow_used_page_count) +ELSE (ps.lob_used_page_count + ps.row_overflow_used_page_count) END ) AS data, +SUM (ps.used_page_count) AS used +FROM sys.dm_db_partition_stats ps +GROUP BY ps.object_id) AS a1 +LEFT OUTER JOIN (SELECT it.parent_id, SUM(ps.reserved_page_count) AS reserved, +SUM(ps.used_page_count) AS used +FROM sys.dm_db_partition_stats ps +INNER JOIN sys.internal_tables it ON (it.object_id = ps.object_id) +WHERE it.internal_type IN (202,204) +GROUP BY it.parent_id) AS a4 ON (a4.parent_id = a1.object_id) +INNER JOIN sys.all_objects a2 ON ( a1.object_id = a2.object_id ) +INNER JOIN sys.schemas a3 ON (a2.schema_id = a3.schema_id) \ No newline at end of file diff --git a/SQL Queries/OperationsManager/SQL_LoginMappings_OpsDB.sql b/SQL Queries/OperationsManager/SQL_LoginMappings_OpsDB.sql new file mode 100644 index 0000000..a5dc2c4 --- /dev/null +++ b/SQL Queries/OperationsManager/SQL_LoginMappings_OpsDB.sql @@ -0,0 +1 @@ +EXEC master..sp_helplogins \ No newline at end of file diff --git a/SQL Queries/OperationsManager/SQL_Properties_OpsDB.sql b/SQL Queries/OperationsManager/SQL_Properties_OpsDB.sql new file mode 100644 index 0000000..3e47941 --- /dev/null +++ b/SQL Queries/OperationsManager/SQL_Properties_OpsDB.sql @@ -0,0 +1,28 @@ +SELECT +(SELECT is_broker_enabled +FROM sys.databases +WHERE name=db_name()) AS 'Is_Broker_Enabled', +(SELECT value +FROM sys.configurations +WHERE name = 'clr enabled') AS 'Is_CLR_Enabled', +serverproperty('machinename') AS ServerName, +case when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) like '8.0%' then 'SQL Server 2000' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) like '9.0%' then 'SQL Server 2005' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) like '10.0%' then 'SQL Server 2008' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) like '10.5%' then 'SQL Server 2008 R2' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) like '11.0%' then 'SQL Server 2012' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) like '12.0%' then 'SQL Server 2014' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) like '13.0%' then 'SQL Server 2016' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) like '14.0%' then 'SQL Server 2017' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) = '15.0.4123.1' then 'SQL Server 2019 CU10' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) like '15.0%' then 'SQL Server 2019' +when CONVERT(sysname, SERVERPROPERTY('ProductVersion')) > '15.0.4123.1' then 'newer than SQL Server 2019 CU10' +else 'unknown' end as [Version], +CONVERT(nvarchar(50), serverproperty('Edition')) AS Edition, +CONVERT(nvarchar(50), serverproperty('ProductVersion')) AS ProductVersion, +CONVERT(nvarchar(50), serverproperty('ProductLevel')) AS ProductLevel, +CONVERT(nvarchar(50), serverproperty('IsClustered')) AS IsClustered, +CONVERT(nvarchar(50), serverproperty('IsFullTextInstalled')) AS IsFullTextInstalled, +CONVERT(nvarchar(50), serverproperty('Collation')) AS Collation, +CONVERT(nvarchar(50), serverproperty('ComputerNamePhysicalNetBIOS')) AS ComputerNamePhysicalNetBIOS, +CONVERT(nvarchar(50), serverproperty('ComputerNamePhysicalNetBIOS')) AS 'SqlHost' \ No newline at end of file diff --git a/SQL Queries/OperationsManager/State_ByDay.sql b/SQL Queries/OperationsManager/State_ByDay.sql new file mode 100644 index 0000000..8ce0ccb --- /dev/null +++ b/SQL Queries/OperationsManager/State_ByDay.sql @@ -0,0 +1,6 @@ +SELECT CASE WHEN(GROUPING(CONVERT(VARCHAR(20), TimeGenerated, 102)) = 1) +THEN 'All Days' ELSE CONVERT(VARCHAR(20), TimeGenerated, 102) +END AS DayGenerated, COUNT(*) AS StateChangesPerDay +FROM StateChangeEvent WITH (NOLOCK) +GROUP BY CONVERT(VARCHAR(20), TimeGenerated, 102) WITH ROLLUP +ORDER BY DayGenerated DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/State_ByMonitor.sql b/SQL Queries/OperationsManager/State_ByMonitor.sql new file mode 100644 index 0000000..756b7b5 --- /dev/null +++ b/SQL Queries/OperationsManager/State_ByMonitor.sql @@ -0,0 +1,11 @@ +select distinct top 50 count(sce.StateId) as NumStateChanges, +m.DisplayName as MonitorDisplayName, +m.Name as MonitorIdName, +mt.typename AS TargetClass +from StateChangeEvent sce with (nolock) +join state s with (nolock) on sce.StateId = s.StateId +join monitorview m with (nolock) on s.MonitorId = m.Id +join managedtype mt with (nolock) on m.TargetMonitoringClassId = mt.ManagedTypeId +where m.IsUnitMonitor = 1 +group by m.DisplayName, m.Name,mt.typename +order by NumStateChanges desc \ No newline at end of file diff --git a/SQL Queries/OperationsManager/State_ByMonitorAndDay.sql b/SQL Queries/OperationsManager/State_ByMonitorAndDay.sql new file mode 100644 index 0000000..68f7778 --- /dev/null +++ b/SQL Queries/OperationsManager/State_ByMonitorAndDay.sql @@ -0,0 +1,10 @@ +select +CONVERT(varchar(20),timegenerated,102) as Day, MonitorName, count(*) AS TotalStateChanges +from statechangeevent with(nolock) +inner join state with(nolock) on statechangeevent.stateid = state.stateid +inner join basemanagedentity with(nolock) on state.basemanagedentityid = basemanagedentity.basemanagedentityid +inner join managedtype with(nolock) on basemanagedentity.basemanagedtypeid = managedtype.managedtypeid +inner join monitor with(nolock) +on monitor.monitorid = state.monitorid and monitor.IsUnitMonitor = '1' +group by CONVERT(varchar(20),timegenerated,102), monitorname +order by CONVERT(varchar(20),timegenerated,102) DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/State_ByMonitor_7days.sql b/SQL Queries/OperationsManager/State_ByMonitor_7days.sql new file mode 100644 index 0000000..d0f3491 --- /dev/null +++ b/SQL Queries/OperationsManager/State_ByMonitor_7days.sql @@ -0,0 +1,12 @@ +select distinct top 50 count(sce.StateId) as NumStateChanges, +m.DisplayName as MonitorDisplayName, +m.Name as MonitorIdName, +mt.typename AS TargetClass +from StateChangeEvent sce with (nolock) +join state s with (nolock) on sce.StateId = s.StateId +join monitorview m with (nolock) on s.MonitorId = m.Id +join managedtype mt with (nolock) on m.TargetMonitoringClassId = mt.ManagedTypeId +where m.IsUnitMonitor = 1 +AND sce.TimeGenerated > dateadd(dd,-7,getutcdate()) +group by m.DisplayName, m.Name,mt.typename +order by NumStateChanges desc \ No newline at end of file diff --git a/SQL Queries/OperationsManager/State_MonitorsMostCritical.sql b/SQL Queries/OperationsManager/State_MonitorsMostCritical.sql new file mode 100644 index 0000000..2aeae91 --- /dev/null +++ b/SQL Queries/OperationsManager/State_MonitorsMostCritical.sql @@ -0,0 +1,10 @@ +SELECT + count(*) as 'MonitorCount', +mv.DisplayName AS 'MonitorDisplayName', +mv.Name AS 'MonitorName' +FROM State s +JOIN MonitorView mv ON mv.Id = s.MonitorId +WHERE s.HealthState = 3 +AND mv.IsUnitMonitor = 1 +GROUP BY mv.Name,mv.DisplayName +ORDER by count(*) DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/State_MonitorsMostWarning.sql b/SQL Queries/OperationsManager/State_MonitorsMostWarning.sql new file mode 100644 index 0000000..11e764b --- /dev/null +++ b/SQL Queries/OperationsManager/State_MonitorsMostWarning.sql @@ -0,0 +1,10 @@ +SELECT + count(*) as 'MonitorCount', +mv.DisplayName AS 'MonitorDisplayName', +mv.Name AS 'MonitorName' +FROM State s +JOIN MonitorView mv ON mv.Id = s.MonitorId +WHERE s.HealthState = 2 +AND mv.IsUnitMonitor = 1 +GROUP BY mv.Name,mv.DisplayName +ORDER by count(*) DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/State_OldStale.sql b/SQL Queries/OperationsManager/State_OldStale.sql new file mode 100644 index 0000000..a4d6357 --- /dev/null +++ b/SQL Queries/OperationsManager/State_OldStale.sql @@ -0,0 +1,9 @@ +declare @statedaystokeep INT +SELECT @statedaystokeep = DaysToKeep from PartitionAndGroomingSettings WHERE ObjectName = 'StateChangeEvent' +SELECT COUNT(*) as 'Total StateChanges', +count(CASE WHEN sce.TimeGenerated > dateadd(dd,-@statedaystokeep,getutcdate()) THEN sce.TimeGenerated ELSE NULL END) as 'within grooming retention', +count(CASE WHEN sce.TimeGenerated < dateadd(dd,-@statedaystokeep,getutcdate()) THEN sce.TimeGenerated ELSE NULL END) as '> grooming retention', +count(CASE WHEN sce.TimeGenerated < dateadd(dd,-30,getutcdate()) THEN sce.TimeGenerated ELSE NULL END) as '> 30 days', +count(CASE WHEN sce.TimeGenerated < dateadd(dd,-90,getutcdate()) THEN sce.TimeGenerated ELSE NULL END) as '> 90 days', +count(CASE WHEN sce.TimeGenerated < dateadd(dd,-365,getutcdate()) THEN sce.TimeGenerated ELSE NULL END) as '> 365 days' +from StateChangeEvent sce \ No newline at end of file diff --git a/SQL Queries/OperationsManager/State_UnhealthyMonitors.sql b/SQL Queries/OperationsManager/State_UnhealthyMonitors.sql new file mode 100644 index 0000000..8d25329 --- /dev/null +++ b/SQL Queries/OperationsManager/State_UnhealthyMonitors.sql @@ -0,0 +1,14 @@ +SELECT + count(*) as 'UnhealthyMonitorInstances', +mv.DisplayName AS 'MonitorDisplayName', +mv.Name AS 'MonitorName', +MonitorState = CASE + WHEN s.HealthState = 3 THEN 'Critical' + WHEN s.HealthState = 2 THEN 'Warning' + END +FROM State s +JOIN MonitorView mv ON mv.Id = s.MonitorId +WHERE s.HealthState IN (2,3) +AND mv.IsUnitMonitor = 1 +GROUP BY mv.Name,mv.DisplayName,s.HealthState +ORDER by count(*) DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Sync_History_Delta.sql b/SQL Queries/OperationsManager/Sync_History_Delta.sql new file mode 100644 index 0000000..dc51e5a --- /dev/null +++ b/SQL Queries/OperationsManager/Sync_History_Delta.sql @@ -0,0 +1,5 @@ +Select WorkItemName, b.WorkItemStateName, ServerName, StartedDateTimeUtc, CompletedDateTimeUtc, DurationSeconds, ERRORMESSAGE +from cs.WorkItem a , cs.WorkItemState b +where a.WorkItemStateId= b.WorkItemStateId +and WorkItemName like '%delta%' +ORDER BY StartedDateTimeUtc DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/Sync_History_Snapshot.sql b/SQL Queries/OperationsManager/Sync_History_Snapshot.sql new file mode 100644 index 0000000..dd79257 --- /dev/null +++ b/SQL Queries/OperationsManager/Sync_History_Snapshot.sql @@ -0,0 +1,5 @@ +Select WorkItemName, b.WorkItemStateName, ServerName, StartedDateTimeUtc, CompletedDateTimeUtc, DurationSeconds, ERRORMESSAGE +from cs.WorkItem a , cs.WorkItemState b +where a.WorkItemStateId= b.WorkItemStateId +and WorkItemName like '%Snapshot%' +ORDER by StartedDateTimeUtc DESC \ No newline at end of file diff --git a/SQL Queries/OperationsManager/UNIX_Agents.sql b/SQL Queries/OperationsManager/UNIX_Agents.sql new file mode 100644 index 0000000..d9f0a8c --- /dev/null +++ b/SQL Queries/OperationsManager/UNIX_Agents.sql @@ -0,0 +1,30 @@ +declare @AgentVersionCol as nvarchar(max) +declare @ArchitectureCol as nvarchar(max) +declare @IPAddressCol as nvarchar(max) +declare @query as nvarchar(max) +SELECT @AgentVersionCol=COLUMN_NAME FROM INFORMATION_SCHEMA.Columns where TABLE_NAME = 'MT_Microsoft$Unix$Computer' +and COLUMN_NAME Like 'AgentVersion%' +SELECT @ArchitectureCol=COLUMN_NAME FROM INFORMATION_SCHEMA.Columns where TABLE_NAME = 'MT_Microsoft$Unix$Computer' +and COLUMN_NAME Like 'Architecture%' +SELECT @IPAddressCol=COLUMN_NAME FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = 'MT_Microsoft$Unix$Computer' +AND COLUMN_NAME Like 'IPAddress%' +set @query = 'select bme2.DisplayName as ''Agent'', ' + @AgentVersionCol + ' as ''Build'' , +' + @ArchitectureCol + ' as ''Architecture'', ' + @IPAddressCol + ' as ''IPAddress'', bme.Displayname as ''ResourcePool'' +from dbo.Relationship r with (nolock) +join dbo.RelationshipType rt with (nolock) +on r.RelationshipTypeId = rt.RelationshipTypeId +join dbo.BasemanagedEntity bme with (nolock) +on bme.basemanagedentityid = r.SourceEntityId +join dbo.BasemanagedEntity bme2 with (nolock) +on r.TargetEntityId = bme2.BaseManagedEntityId +join MT_Microsoft$Unix$Computer mtvc +on bme2.BaseManagedEntityId = mtvc.BaseManagedEntityId +where rt.RelationshipTypeName = ''Microsoft.SystemCenter.ManagementActionPointManagesEntity '' +and bme.IsDeleted = 0 +and r.IsDeleted = 0 +and bme2.basemanagedtypeid in (SELECT DerivedTypeId +FROM DerivedManagedTypes with (nolock) +WHERE BaseTypeId = (select managedtypeid +from managedtype where typename = ''Microsoft.Unix.Computer'') +and DerivedIsAbstract = 0)' +exec(@query) \ No newline at end of file diff --git a/SQL Queries/OperationsManager/URL_PerWatcher.sql b/SQL Queries/OperationsManager/URL_PerWatcher.sql new file mode 100644 index 0000000..b35a1a7 --- /dev/null +++ b/SQL Queries/OperationsManager/URL_PerWatcher.sql @@ -0,0 +1,9 @@ +SELECT +SourceObjectDisplayName as 'WatcherName', + count(*) as 'NumberOfURLs', + h.IsAgent, + h.IsManagementServer +FROM RelationshipGenericView r +JOIN MT_HealthService h with(NOLOCK) on r.SourceObjectDisplayName=h.DisplayName +WHERE r.RelationshipId like 'A98C9038-6E2A-9394-3B07-9C8380A8956D' and TargetObjectFullName like 'Microsoft.SystemCenter.WebApplicationTest.WebTest:%' +GROUP BY r.SourceObjectDisplayName, h.IsAgent,h.IsManagementServer order by count(*) desc \ No newline at end of file diff --git a/SQL Queries/OperationsManager/UserRoles.sql b/SQL Queries/OperationsManager/UserRoles.sql new file mode 100644 index 0000000..55aa4e5 --- /dev/null +++ b/SQL Queries/OperationsManager/UserRoles.sql @@ -0,0 +1,5 @@ +SELECT + UserRoleName, + IsSystem +from + userrole \ No newline at end of file