Upgraded from Opsview Community Edition to Core – trouble with check_vmware.pl?

So you’ve been upgrading your Opsview installation from Community to Core?

If you’re using the ‘check_vmware.pl’ script to monitor your vCenter or ESXi, you might experience some errors from the related service checks, as they no longer can connect to the host. Instead you get something like this:

“UNKNOWN: Login to VirtualCentre server failed: Server version unavailable at ‘https://x.x.x.x:443/sdk/vimService.wsdl’ at /usr/local/share/perl/……”

When upgrading Opsview, some of the Perl libraries are also upgraded, and the new version does some certificate checking. The VMware self-signed certificate causes an error, which makes the script fail.

The solution is to disable the certificate check by adding this at the top of the ‘check_vmware.pl’ script:

$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;

Udgivet i Opsview Monitoring | Tagget , , , , | Kommentarer lukket til Upgraded from Opsview Community Edition to Core – trouble with check_vmware.pl?

How to create a temporary table in SQL Server

When you are creating SQL scripts you will sometimes need to create a temporary file. This can be done in 2 different ways in SQL Server.

— The scope of this temporary table is only the SPID that created the Table.
CREATE TABLE #TableTemp
(
  tableName varchar(40),
  rowCount int
)

— This temporary table can be used by every SPID in the SQL Instance,
— until it is dropped or the server is restarted
CREATE TABLE ##TableTemp
(
  tableName varchar(40),
  rowCount int
)

Udgivet i SQL Server - scripts | Tagget , | Kommentarer lukket til How to create a temporary table in SQL Server

Track down escalation locks


-- You can use sys.dm_db_index_operational_stats to
-- track how many attempts were made to escalate
-- to table locks (index_lock_promotion_attempt_count),
-- as well as how many times escalations actually
-- succeeded (index_lock_promotion_count).
-- The following query shows the top 5 objects with the
-- highest number of escalations:

SELECT TOP 5
OBJECT_NAME(object_id, database_id) object_nm,
index_id,
partition_number,
index_lock_promotion_attempt_count,
index_lock_promotion_count
FROM
sys.dm_db_index_operational_stats(db_id(), NULL, NULL, NULL)
ORDER BY
index_lock_promotion_count DESC

Udgivet i SQL Server - scripts | Tagget , , | Kommentarer lukket til Track down escalation locks

How to move a Logfile to another location

— If you need to move a logfile onto another harddrive, you can do it this way.

USE master
GO

— If this command just keeps running, then it properly is because there is connection against the database

ALTER DATABASE <Databasename> SET SINGLE_USER
GO

SP_DETACH_DB ‘<Databasename>’
GO

— Now you can move the log file to the new location.
/*XP_CMDSHELL ‘COPY <source location\filename> <destination location\filename>*/

SP_ATTACH_DB ‘<Databasename>’, ‘<Data filename>’, ‘Log filename’
GO

Udgivet i SQL Server - scripts | Kommentarer lukket til How to move a Logfile to another location

Enabling the SharePoint 2010 Developer Dashboard

 

Although this tool is mainly designed to assist developers in creating fast code, it can also be a useful tool for the administrators by providing performance and trace information when troubleshooting slow loading/rendering pages.

It can be enabled using either Powershell, stsadm – or you can download a nice configuration feature for use with the Central Administration.

The Powershell approach:

Launch the “SharePoint 2010 Management Shell” and enter the following:

$DevDashboardSettings = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings;
$DevDashboardSettings.DisplayLevel = 'OnDemand';
$DevDashboardSettings.RequiredPermissions = 'EmptyMask';
$DevDashboardSettings.TraceEnabled = $true;
$DevDashboardSettings.Update();

The DisplayLevel  value can be ‘On’, ‘Off’ or ‘OnDemand’.The suggested RequiredPermissions ‘EmptyMask’ value activates the Dashboard for all (including anonymous) users.

Or you can use stsadm:

stsadm -o setproperty -pn developer-dashboard -pv [on|off|ondemand]

An even easier way is to download Wictor Wiléns configuration feature and deploy it to the Central Administration:

Download the .wsp file from here: http://www.wictorwilen.se/Post/SharePoint-2010-Developer-Dashboard-configuration-feature.aspx

Install the feature to your farm using Powershell:

Add-SPSolution -Literalpath <fullpath\filename.wsp>

Deploy and activate the feature on your farm, and go to Central Administration -> General Application Settings -> Developer Settings

All set! 😉

Udgivet i SharePoint 2010 Tips & Tricks | Tagget , , | Kommentarer lukket til Enabling the SharePoint 2010 Developer Dashboard

Showing the number of packages read and written in the last 30 sec.


-- A script showing the number of reads/write for the last 30 sek.
-- Made by SeoSoft ApS
-- E-mail: SEO@SeoSoft.dk

SELECT c.session_id, c.num_reads, c.num_writes, c.net_packet_size, c.client_net_address, st.text
INTO #CONNECTIONS
FROM sys.dm_exec_connections AS c
CROSS APPLY (SELECT * FROM sys.dm_exec_sql_text(c.most_recent_sql_handle))
AS st

WAITFOR DELAY '00:00:30'

UPDATE #CONNECTIONS
SET
num_reads = (SELECT num_reads FROM sys.dm_exec_connections WHERE session_id = #CONNECTIONS.session_id) - num_reads,
num_writes = (SELECT num_writes FROM sys.dm_exec_connections WHERE session_id = #CONNECTIONS.session_id) - num_writes

SELECT TOP 50 * FROM #CONNECTIONS ORDER BY num_reads desc

DROP TABLE #CONNECTIONS

Udgivet i SQL Server - scripts | Kommentarer lukket til Showing the number of packages read and written in the last 30 sec.

Create XML file for showing SQL Security settings


-- This script is making an XML file showing all security setting at a SQL Server
-- specifying which users are member of which Server/Database roles
-- Perhaps I am modifying the script to show which objects user defined roles is holding
-- Created by SeoSoft ApS - Søren Eggert Lundsteen Olsen
-- Version 1.1.0
-- Now possible to write members of Domain Groups
DECLARE @Sql NVARCHAR(MAX) SET @Sql = ''
DECLARE @RoleName sysname SET @RoleName =''
DECLARE @IsNTGroup int SET @IsNTGroup = 0
DECLARE @UserType sysname SET @UserType =''
DECLARE @UserName sysname SET @UserName =''
DECLARE @DatabaseName sysname SET @DatabaseName =''
DECLARE @Empty INT SET @Empty = 0
DECLARE @vi INT
DECLARE @account_name sysname SET @account_name = ''
DECLARE @GroupMembers TABLE
(
[account_name] sysname,
[type] sysname,
[privilege] sysname,
[mapped_login_name] sysname,
[permission_path] sysname
)

DECLARE curGroupMembers CURSOR LOCAL FOR
SELECT [account_name]
FROM @GroupMembers

DECLARE curRoles CURSOR LOCAL FOR
SELECT [name] AS RoleName
FROM [master].[sys].[server_principals]
WHERE type = 'R'

DECLARE curDatabaseRoles CURSOR LOCAL FOR
SELECT [name]
FROM [sys].[database_principals]
WHERE type = 'R'

DECLARE curUsers CURSOR LOCAL FOR
SELECT [name], [TYPE]
FROM [master].[sys].[server_principals]
WHERE [TYPE] IN ('U', 'G')

DECLARE curDatabases CURSOR LOCAL FOR
SELECT [name]
FROM [master].[sys].[databases]

DECLARE curDatabaseUsers CURSOR LOCAL FOR
SELECT [name] AS UserName, [isntgroup] AS IsNTGroup
FROM [sys].[sysUsers]
WHERE [isLogin] = 1

SET NOCOUNT ON

OPEN curRoles
FETCH NEXT FROM curRoles INTO @RoleName

IF @@FETCH_STATUS = 0
BEGIN
PRINT ''
PRINT ''
SET @Empty = 1
END

WHILE @@FETCH_STATUS = 0
BEGIN
PRINT ' '
PRINT ' SERVER'
PRINT ' SERVER ROLE'
PRINT ' ' + @RoleName + ''

OPEN curUsers
FETCH NEXT FROM curUsers INTO @UserName, @UserType

WHILE @@FETCH_STATUS = 0
BEGIN
IF @UserType = 'U'
BEGIN
SET @Sql = ' SELECT @RoleMember = IS_SRVROLEMEMBER(''' + @RoleName + ''',''' + @UserName + ''');'

BEGIN TRY
EXEC SP_EXECUTESQL
@Query = @Sql
, @Params = N'@RoleMember INT OUTPUT'
, @RoleMember = @vi OUTPUT
IF @vi > 0
BEGIN
PRINT ' ' + @UserName + ''
END
END TRY
BEGIN CATCH
PRINT ' IS_SRVROLEMEMBER FAILED' + @UserName + ''
END CATCH
END
ELSE
BEGIN
SET @Sql = ' SELECT @RoleMember = IS_ROLEMEMBER(''' + @RoleName + ''',''' + @UserName + ''');'

BEGIN TRY
EXEC SP_EXECUTESQL
@Query = @Sql
, @Params = N'@RoleMember INT OUTPUT'
, @RoleMember = @vi OUTPUT
END TRY
BEGIN CATCH
PRINT ' IS_ROLEMEMBER FAILED' + @RoleName + ':' + @UserName + ''
SET @vi = 0
END CATCH
IF @vi > 0
BEGIN

DELETE FROM @GroupMembers

BEGIN TRY
INSERT INTO @GroupMembers
EXEC MASTER.sys.xp_logininfo
@acctname= @UserName,
@option='members'
END TRY
BEGIN CATCH
PRINT ' xp_logininfo FAILED' + @UserName + ''
END CATCH
OPEN curGroupMembers
FETCH curGroupMembers INTO @account_name
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT ' ' + @account_name + '' + @UserName + ''

FETCH curGroupMembers INTO @account_name
END
CLOSE curGroupMembers
END
END
FETCH NEXT FROM curUsers INTO @UserName, @UserType
END

CLOSE curUsers

FETCH NEXT FROM curRoles INTO @RoleName
PRINT ' '
END

OPEN curDatabases
FETCH NEXT FROM curDatabases INTO @DatabaseName

WHILE @@FETCH_STATUS = 0
BEGIN
Set @Sql = 'USE ' + QUOTENAME(@DatabaseName);
EXEC SP_EXECUTESQL @Sql

OPEN curDatabaseRoles
FETCH NEXT FROM curDatabaseRoles INTO @RoleName

WHILE @@FETCH_STATUS = 0
BEGIN
PRINT ' '
PRINT ' ' + @DatabaseName + ''
PRINT ' DATABASE ROLE'
PRINT ' ' + @RoleName + ''

OPEN curDatabaseUsers
FETCH NEXT FROM curDatabaseUsers INTO @UserName, @IsNTGroup

WHILE @@FETCH_STATUS = 0
BEGIN
IF @IsNTGroup = 0
BEGIN
SET @Sql = ' SELECT @RoleMember = IS_ROLEMEMBER(''' + @RoleName + ''',''' + @UserName + ''');'
BEGIN TRY
EXEC SP_EXECUTESQL
@Query = @Sql
, @Params = N'@RoleMember INT OUTPUT'
, @RoleMember = @vi OUTPUT
IF @vi = 1
BEGIN
PRINT ' ' + @UserName + ''
END
END TRY
BEGIN CATCH
PRINT ' IS_ROLEMEMBER FAILED' + @UserName + ''
END CATCH
END
ELSE
BEGIN
SET @Sql = ' SELECT @RoleMember = IS_ROLEMEMBER(''' + @RoleName + ''',''' + @UserName + ''');'

BEGIN TRY
EXEC SP_EXECUTESQL
@Query = @Sql
, @Params = N'@RoleMember INT OUTPUT'
, @RoleMember = @vi OUTPUT
END TRY
BEGIN CATCH
PRINT ' IS_ROLEMEMBER FAILED' + @RoleName + ':' + @UserName + ''
SET @vi = 0
END CATCH
IF @vi > 0
BEGIN

DELETE FROM @GroupMembers

BEGIN TRY
INSERT INTO @GroupMembers
EXEC MASTER.sys.xp_logininfo
@acctname= @UserName,
@option='members'
END TRY
BEGIN CATCH
PRINT ' xp_logininfo FAILED' + @UserName + ''
END CATCH

OPEN curGroupMembers
FETCH curGroupMembers INTO @account_name
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT ' ' + @account_name + '' + @UserName + ''

FETCH curGroupMembers INTO @account_name
END
CLOSE curGroupMembers
END

END
FETCH NEXT FROM curDatabaseUsers INTO @UserName, @IsNTGroup
END
CLOSE curDatabaseUsers
FETCH NEXT FROM curDatabaseRoles INTO @RoleName
PRINT ' '
END

CLOSE curDatabaseRoles

FETCH NEXT FROM curDatabases INTO @DatabaseName
END

DEALLOCATE curDatabaseUsers
DEALLOCATE curDatabaseRoles

CLOSE curDatabases
DEALLOCATE curDatabases

IF @Empty = 1
BEGIN
PRINT ''
END

DEALLOCATE curUsers

CLOSE curRoles
DEALLOCATE curRoles
DEALLOCATE curGroupMembers

Udgivet i SQL Server - scripts | Kommentarer lukket til Create XML file for showing SQL Security settings

Drop Column statistics

Are you facing suddenly poor performance, try to recreate Columns statistics. SQL Server are using these statistics to decide which execution-plan would be the best.

You always have to run this script when you are upgrading your SQL server from one version to another.


DECLARE ALLNAME CURSOR FOR
Select
t.name FROM sys.stats
INNER JOIN sys.tables t
ON
sys.stats.object_id= t.object_id
WHERE
sys.stats.auto_created <> 0

DECLARE AllStats CURSOR FOR
Select
sys.stats.name FROM sys.stats
INNER JOIN sys.tables t
ON
sys.stats.object_id= t.object_id
WHERE
sys.stats.auto_created <> 0

DECLARE @StatName NVARCHAR(512)
DECLARE @Name NVARCHAR(512)

OPEN AllStats
OPEN ALLNAME

FETCH next FROM AllStats INTO @StatName
FETCH next FROM AllNAME INTO @Name

WHILE @@FETCH_STATUS= 0
BEGIN
EXEC ('drop statistics '+ @Name+'.'+ @StatName)
Print ('drop statistics '+ @Name+'.'+ @StatName)
FETCH NEXT FROM AllStats INTO @StatName
FETCH NEXT FROM AllNAME INTO @Name
END
CLOSE AllStats
CLOSE ALLNAME
DEALLOCATE ALLNAME
DEALLOCATE AllStats
GO

Udgivet i SQL Server - scripts | Tagget , , | Kommentarer lukket til Drop Column statistics