Показаны сообщения с ярлыком MSSQL. Показать все сообщения
Показаны сообщения с ярлыком MSSQL. Показать все сообщения

2012/08/09

Check on Nagios the latest files in folder with NSClient++ 0.3.9

CURRENT CONFIGURATION: Linux OpenSuSe, Nagios 3.2.3, NRPE; Windows 2003R2 x64 server, NSClient++ 0.3.9.330 2011-09-02
OBJECTIVE: Monitor MSSQL backup, IIS logs replication with Nagios. Check FOLDER with files (MSSQL backup, IIS logs, S3 logs, etc.). Send WARNING if files are older than some hours.
SOLUTION:
NRPE has to work on Nagios server and on Windows client computer with NSClient++.
Nagios server command.cfg file:
define command{
  command_name    check_nrpe_files_written
  command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c CheckFiles -a "path=$ARG1$" "pattern=$ARG2$" "filter=written gt -$ARG3$" truncate=4096 "master-syntax=files: %total%" max-dir-depth=$ARG4$ MinWarn=0
}

define command{
  command_name    check_nrpe_files_creation
  command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c CheckFiles -a "path=$ARG1$" "pattern=$ARG2$" "filter=creation gt -$ARG3$" truncate=4096 "master-syntax=files: %total%" max-dir-depth=$ARG4$ MinWarn=0
}

Nagios server somename.cfg file examples:


define service{
...
  check_command           check_nrpe_files_creation!F:\\Backup\\SERVER01\\mssql\\backup\\default\\full!*.bkz!30h!0
  normal_check_interval   720
}
define service{
...
  check_command           check_nrpe_files_creation!F:\\Backup\\SERVER06\\ServiceDesk\\backup!*.data!30h!0
  normal_check_interval   720
}
define service{
...
  check_command           check_nrpe_files_creation!F:\\backup\\SERVER01!*-exchange_1_storage_group.bkf!8d!0
  normal_check_interval   1440
}
define service{
...
  check_command           check_nrpe_files_written!D:\\Logs\\IISLogs!*WEB01*.log!6h!4
  normal_check_interval   180
}
define service{
...
  check_command           check_nrpe_files_written!D:\\Replica\\UploadCopy\\s3!LastReplication.log!30h!0
  normal_check_interval   720
}

NSClient++ NSC.ini file:

[modules]
NRPEListener.dll
[NRPE]
allow_arguments=1
allow_nasty_meta_chars=1
Big thanks to NSClient++ author for program and excellent support.

2010/03/09

MSSQL 2005 procedure a file move rename

CURRENT CONFIGURATION: MSSQL server 2005

OBJECTIVE: Move or rename a file from MSSQL

SOLUTION:
I wrote SQL procedure. You can change destination database to whatever you want.
USE master
GO

-- set required options
EXEC sp_configure 'show advanced options',1
RECONFIGURE
GO
EXEC sp_configure 'Ole Automation Procedures',1
RECONFIGURE
GO

USE [sysman]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[dba_file_move_rename]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[dba_file_move_rename]
GO

CREATE PROCEDURE [dbo].[dba_file_move_rename]
    @OldFilePath    nvarchar(512),
    @NewFilePath    nvarchar(512),
    @send_email_proc  nvarchar(256),
    @log int = 2
AS
-- *****************************************************************************
-- Author:  Vadim Zenin http://vadimszenins.blogspot.com
-- Version:    1.00
-- Date:      10/12/2009 18:37:34
-- Procedure for file move or rename
--
-- Usage:
-- In batch file: sqlcmd -E -dsysman -Q"EXEC sysman..dba_file_move_rename 'C:\temp\oldfile.txt', 'C:\temp\newile.txt', 'send_email', 1" >>%LOGFILE%
--
-- Parametrs:
-- @OldFilePath example: 'C:\temp\oldfile.txt'
-- @NewFilePath example: 'C:\temp\newile.txt'
-- @send_email_proc example: 'send_email'
-- @log (0 - none, 1 - minimum, 2 - standard(default), 4 - debug) optinal
--
-- Tested platform:
-- MS SQL 2005
--
-- Version 1.00 revision:
--
--
-- This code is made available as is, without warranty of any kind. The entire
-- risk of the use or the results from the use of this code remains with the user.
-- *****************************************************************************

DECLARE
    @procname        nvarchar(256),
    @fso            int,
    @hr              int,
    @sqlcmd            nvarchar(600),
    @email_subj        nvarchar(255),
    @email_body        nvarchar(3000)

-- Get current stored procedure name
SELECT @procname = OBJECT_NAME(@@PROCID)
IF @log > 1
begin
    PRINT RTRIM(CAST(GETDATE() AS NVARCHAR(30))) + ' ' + @procname + ' procedure has started';
    PRINT N'The Database Engine instance ' + RTRIM(@@SERVERNAME) + N' is running SQL Server build '
    + RTRIM(CAST(SERVERPROPERTY(N'ProductVersion ') AS NVARCHAR(128)));
end
IF @log > 2
BEGIN
  PRINT 'Parametr 1: ' + @OldFilePath;
  PRINT 'Parametr 2: ' + @NewFilePath;
  PRINT 'Parametr 3: ' + @send_email_proc;
  PRINT 'Parametr 4: ' + RTRIM(@log);
END

-- Check requrements
If not exists (Select * from dbo.sysobjects where xtype='p' and name=@send_email_proc)
BEGIN
    SELECT @email_body = N'!? Stored procedure sysman..' + @send_email_proc + ' does not exist'
    IF @log >= 0
    PRINT @email_body
    RAISERROR (@email_body,16,1) with log
END

--------------------------------------------------------------------------------
-- Main procedure
--------------------------------------------------------------------------------

SET @hr = 0

-- Creating File System Object
EXEC @hr=sp_OACreate 'Scripting.FileSystemObject',@fso OUT
IF @hr <> 0
BEGIN
    EXEC sp_OAGetErrorInfo @fso
    SELECT    @email_subj = N' Error creating File System Object.'+ @procname
  SELECT    @email_body = 'Error creating File System Object. Procedure name: ' + @procname
  IF @log >= 0
  BEGIN
      PRINT N' Sending failure email notification with subject: '
      PRINT @email_subj
    END
    SELECT @sqlcmd = '[sysman]..[' + @send_email_proc + ']'
    IF @log > 2
    PRINT    '- Command: ' + @sqlcmd;
  EXEC @sqlcmd @email_subject = @email_subj,@email_msg = @email_body
  RAISERROR (@email_body,16,1) with log
END

EXECUTE @hr=sp_OAMethod @fso, 'MoveFile', null, @OldFilePath, @NewFilePath
IF @hr <> 0
BEGIN
    EXEC sp_OAGetErrorInfo @fso
    SELECT    @email_subj = N' Error moving or renaming File.' + @procname
  SELECT    @email_body = ' Error moving or renaming File from ' + @OldFilePath +
      ' to ' + @NewFilePath + ' Procedure name: ' + @procname
  IF @log >= 0
  BEGIN
      Print N' Sending failure email notification with subject: '
      Print @email_subj
  END
    SELECT @sqlcmd = '[sysman]..[' + @send_email_proc + ']'
    IF @log > 2
    PRINT    '- Command: ' + @sqlcmd;
  EXEC @sqlcmd @email_subject = @email_subj,@email_msg = @email_body
  RAISERROR (@email_body,16,1) with log
END
else
begin
    IF @log > 0
      Print N'Moving or renaming File from ' + @OldFilePath + ' to ' + @NewFilePath + ' by procedure ' + @procname
end

-- Destroying File System Object
EXEC @hr=sp_OADestroy @fso
IF @hr <> 0 EXEC sp_OAGetErrorInfo @fso

IF @log > 1
    PRINT RTRIM(CAST(GETDATE() AS NVARCHAR(30))) + ' ' + @procname + ' procedure has finished';
Download md5: 60853e73c93a656f7f373809ce3f997b

2010/01/26

MSSQL 2005 procedure to write information to text file

CURRENT CONFIGURATION: MSSQL server 2005

OBJECTIVE: Write line to text, log file from MSSQL server in middle of backup operation to be able to confirm successful result from windows batch script or whatever.

SOLUTION:
I wrote SQL procedure. You can change destination database to whatever you want.
USE master
GO

-- set required options
EXEC sp_configure 'show advanced options',1
RECONFIGURE
GO
EXEC sp_configure 'Ole Automation Procedures',1
RECONFIGURE
GO

USE [sysman]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[dba_write_to_file]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[dba_write_to_file]
GO

CREATE PROCEDURE [dbo].[dba_write_to_file]
    @file_name varchar(1000),
    @string varchar(1000),
    @send_email_proc  nvarchar(256),
    @log int = 2
AS
-- *****************************************************************************
-- Author:  Vadim Zenin http://vadimszenins.blogspot.com
-- Version:    1.00
-- Date:      10/12/2009 19:25:02
-- Procedure to write string to file
--
-- Usage:
-- In batch file: sqlcmd -E -dsysman -Q"EXEC sysman..dba_write_to_file 'C:\temp\testfile.txt', 'my test string', 'send_email', 1" >>%LOGFILE%
--
-- Parametrs:
-- @file_name example: 'C:\temp\testfile.txt'
-- @string example: 'my test string'
-- @send_email_proc example: 'send_email'
-- @log (0 - none, 1 - minimum, 2 - standard(default), 4 - debug) optinal
--
-- Tested platform:
-- MS SQL 2005
--
-- Version 1.00 revision:
--
--
-- This code is made available as is, without warranty of any kind. The entire
-- risk of the use or the results from the use of this code remains with the user.
-- *****************************************************************************
DECLARE
    @procname        nvarchar(256),
    @fso            int,
    @hr              int,
    @sqlcmd            nvarchar(600),
    @email_subj        nvarchar(255),
    @email_body        nvarchar(3000),
    @FileID         int

-- Get current stored procedure name
SELECT @procname = OBJECT_NAME(@@PROCID)
IF @log > 1
begin
    PRINT RTRIM(CAST(GETDATE() AS NVARCHAR(30))) + ' ' + @procname + ' procedure has started';
    PRINT N'The Database Engine instance ' + RTRIM(@@SERVERNAME) + N' is running SQL Server build '
    + RTRIM(CAST(SERVERPROPERTY(N'ProductVersion ') AS NVARCHAR(128)));
end
IF @log > 2
BEGIN
  PRINT 'Parametr 1: ' + @file_name;
  PRINT 'Parametr 2: ' + @string;
  PRINT 'Parametr 3: ' + @send_email_proc;
  PRINT 'Parametr 4: ' + RTRIM(@log);
END

-- Check requrements
If not exists (Select * from dbo.sysobjects where xtype='p' and name=@send_email_proc)
BEGIN
    SELECT @email_body = N'!? Stored procedure sysman..' + @send_email_proc + ' does not exist'
    IF @log >= 0
    PRINT @email_body
    RAISERROR (@email_body,16,1) with log
END

--------------------------------------------------------------------------------
-- Main procedure
--------------------------------------------------------------------------------

SET @hr = 0

-- Creating File System Object
EXEC @hr=sp_OACreate 'Scripting.FileSystemObject',@fso OUT
IF @hr <> 0
BEGIN
    EXEC sp_OAGetErrorInfo @fso
    SELECT    @email_subj = N' Error creating File System Object.' + @procname
  SELECT    @email_body = 'Error creating File System Object. Procedure name: ' + @procname
  IF @log >= 0
  BEGIN
      PRINT N' Sending failure email notification with subject: '
      PRINT @email_subj
    END
    SELECT @sqlcmd = '[sysman]..[' + @send_email_proc + ']'
    IF @log > 2
    PRINT    '- Command: ' + @sqlcmd;
  EXEC @sqlcmd @email_subject = @email_subj,@email_msg = @email_body
  RAISERROR (@email_body,16,1) with log
END

-- Opening a file
EXEC @hr = sp_OAMethod @fso, 'OpenTextFile', @FileID OUT,@file_name, 8, 1 -- Append if required (8)
--execute @hr = sp_OAMethod @fso, 'OpenTextFile', @FileID OUT,@file_name,  1
IF @hr <> 0
BEGIN
    EXEC sp_OAGetErrorInfo @fso
    SELECT    @email_subj = N' Error opening file.' + @procname
  SELECT    @email_body = 'Error opening file' + @file_name + ' . Procedure name: ' + @procname
  IF @log >= 0
  BEGIN
      PRINT N' Sending failure email notification with subject: '
      PRINT @email_subj
    END
    SELECT @sqlcmd = '[sysman]..[' + @send_email_proc + ']'
    IF @log > 2
    PRINT    '- Command: ' + @sqlcmd;
  EXEC @sqlcmd @email_subject = @email_subj,@email_msg = @email_body
  RAISERROR (@email_body,16,1) with log
END

-- Writing Text to File
EXEC @hr = sp_OAMethod @FileID, 'WriteLine', Null, @string
IF @hr <> 0
BEGIN
    EXEC sp_OAGetErrorInfo @fso
    SELECT    @email_subj = N' Error writing to file.' + @procname
  SELECT    @email_body = 'Error writing to file' + @file_name + ' . Procedure name: ' + @procname
  IF @log >= 0
  BEGIN
      PRINT N' Sending failure email notification with subject: '
      PRINT @email_subj
    END
    SELECT @sqlcmd = '[sysman]..[' + @send_email_proc + ']'
    IF @log > 2
    PRINT    '- Command: ' + @sqlcmd;
  EXEC @sqlcmd @email_subject = @email_subj,@email_msg = @email_body
  RAISERROR (@email_body,16,1) with log
END
else
begin
    IF @log > 0
      Print N'Writing to file ' + @file_name + ' by procedure ' + @procname
end

EXECUTE @hr = sp_OADestroy @FileID
IF @hr <> 0 EXEC sp_OAGetErrorInfo @fso

-- Destroying File System Object
EXEC @hr=sp_OADestroy @fso
IF @hr <> 0 EXEC sp_OAGetErrorInfo @fso

IF @log > 1
    PRINT RTRIM(CAST(GETDATE() AS NVARCHAR(30))) + ' ' + @procname + ' procedure has finished';
Download md5: 221c4765d32b91ae264e6e9d20c64d90

2008/10/01

WSUS 3 SP1 and remote MS SQL Database with nonstandard IP port

CURRENT CONFIGURATION: Windows 2003 R2 x64 SP2, WSUS 3.0 SP1 and remote MS SQL 2005 server with non standard IP port.

OBJECTIVE: Connect to WSUS administration console.

ISSUE: WSUS administration console responds: Cannot connect to 'yourWSUSserverName'. SQL server may not be running on the server. Please verify that SQL Server is running and configured correctly on the server.
Application Event ID: 7032
The WSUS administration console was unable to connect to the WSUS Server via the remote API.
Verify that the Update Services service, IIS and SQL are running on the server. If the problem persists, try restarting IIS, SQL, and the Update Services Service.
The WSUS administration console has encountered an unexpected error. This may be a transient error; try restarting the administration console. If this error persists,
Try removing the persisted preferences for the console by deleting the wsus file under %appdata%\Microsoft\MMC\.


SOLUTION:
Just in case delete the files under %appdata%\Microsoft\MMC\
Check YourSqlServerName in registry "HKLM\SOFTWARE\Microsoft\Update Services\Server\Setup\SqlServerName"
Try connect to SQL server with command:
sqlcmd -S YourSqlServerName,IPport -E -d SUSDB
If you connected successful change value of registry "HKLM\SOFTWARE\Microsoft\Update Services\Server\Setup\SqlServerName" to YourSqlServerName,IPport
Restart WsusService
Try open the
WSUS administration console.

Links: Troubleshooting database issues
TAGS: wsus, MSSQL, SQL server, WSUS remote database

2008/09/29

Check on Nagios the latest files in folder with NSClient++

CURRENT CONFIGURATION: Linux OpenSuSe, Nagios 3.0.1, NRPE; Windows 2003 x64 server, NSClient++ 0.3.5.1

OBJECTIVE: Monitor SQL backup with Nagios. Check FOLDER with SQL backup files. Send WARNING if ALL files *.bak are older than 24 hours.

SOLUTION:
NRPE has to work on Nagios server and on Windows client computer with NSClient++.
Nagios server command.cfg file:

define command{
command_name check_nrpe_file_new
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c CheckFile2 -a file="$ARG1$" filter=in filter+creation=\<"$ARG2$" syntax="%filename% was created %creation%" MinWarn=0 #MinCrit=0 }

define command{
command_name check_nrpe_file_mod
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c CheckFile2 -a file="$ARG1$" filter=in filter+written=\<"$ARG2$" syntax="%filename% was modified %write%" MinWarn=0 }


Nagios server somename.cfg file:

define service{
...
check_command check_nrpe_file_new!X:\\FOLDER\\TX\\*.trn!35m
normal_check_interval 60
}

define service{
...
check_command check_nrpe_file_mod!X:\\FOLDER\\*.bak!30h
normal_check_interval 60
}


NSClient++ NSC.ini file:

[modules]
NRPEListener.dll
[NRPE]
allow_arguments=1
allow_nasty_meta_chars=1


Big thanks to NSClient++ author for program and excellent support.
P.S. I use
NSClient++ 0.3.6.316 (10/09/2009). For NSClient++ 0.3.9.330 2011-09-02 please read article Check on Nagios the latest files in folder with NSClient++ 0.3.9

TAGS: Nagios, Windows server, file age