7. より理解を深めるためにおすすめ(私もこれで勉強しました)■SQL Server 2008 自習書シリーズ http://technet.microsoft.com/ja-jp/sqlserver/dd610200.aspx■SQL Server バーチャルラボ http://technet.microsoft.com/ja-jp/virtuallabs/cc879114.aspx
8.
9. ログ管理システムのイメージ 【取り込み】 ・イベントログをデータベースに蓄積 ・定期的に取り込みタスクを実行 ・サーバーが増えても柔軟に対応可能 【統計資料】 ・期間を指定してレポートを作成 ・レポートの体裁は事前に定義できる ・レポートはブラウザから表示できる イベントログ SSIS SQL DB SSRS SSAS
10. ITPROを支える3つの機能 必要最小限のSQL文の知識と、若干のコーディング力が求められる SSIS:SQL Server Integration Service データ移入作業の可視化 ・外部ファイル、データベースからの取り込み ・データ変換 SSRS:SQL Server Reporting Service 資料作成の単純化 ・レポートテンプレートの作成、表示、印刷 ・パラメタ化による動的なレポートの生成 SSAS:SQL Server Analysis Service ・多次元データベースによる分析(OLAP) ・データマイニング
14. イベントログを取得するスクリプト例 strComputer = “.” Set objService= GetObject(“winmgmts:“ & strComputer & “ootimv2”) Set objEvtSet = objService.ExecQuery_ ("Select * From Win32_NTLogEvent Where Logfile='System'") For Each e In objEvtSet wscript.echoe.ComputerName & "," & e.EventCode Next
15. Logfile 属性について 使用可能なLogfile属性は、以下のコマンドで調査できる C:amp;gt; wmicnteventlog list brief FileSizeLogfileName Name NumberOfRecords 6361088 Application C:indowsystem32inevtogspplication.evtx 8022 69632 HardwareEvents C:indowsystem32inevtogsardwareEvents.evtx 0 69632 Internet Explorer C:indowsystem32inevtogsnternet Explorer.evtx 0 69632 Key Management Service C:indowsystem32inevtogsey Management Service.evtx 0 69632 Media Center C:indowsystem32inevtogsedia Center.evtx 0 1052672 OAlerts C:indowsystem32inevtogsAlerts.evtx 254 69632 ODiag C:indowsystem32inevtogsDiag.evtx 0 69632 Operations Manager C:indowsystem32inevtogsperations Manager.evtx 120 69632 OSession C:indowsystem32inevtogsSession.evtx 4 30740480 Security C:indowsystem32inevtogsecurity.evtx 40359 8458240 System C:indowsystem32inevtogsystem.evtx 20623 1118208 Windows PowerShell C:indowsystem32inevtogsindows PowerShell.evtx
51. 処理6:Insert 文を生成 SQL文を生成するにあたり、各値をSQLServerに取り込み可能な形式に整形する User::Category User::User 変数の値がNullかどうかをチェックしてから取り出す Scriptタスク Dim strCategory As String = "" If Not IsDBNull(Dts.Variables("User::Category").Value) Then strCategory= Dts.Variables("User::Category").Value.ToString End If Dim strMessage As String = "" If Not IsDBNull(Dts.Variables("User::Message").Value) Then strMessage = Dts.Variables("User::Message").Value.ToString strMessage = Replace(strMessage, "'", "-") End If Messageにはシングルクオーテーションが含まれているので置き換え
52. Scriptタスク Dim strTimeGenerated As String = "19000101 00:00:00" If Not IsDBNull(Dts.Variables("User::TimeGenerated").Value) Then strTimeGenerated = Dts.Variables("User::TimeGenerated").Value.ToString strTimeGenerated= Mid(strTimeGenerated, 1, 8) & " " & _ Mid(strTimeGenerated, 9, 2) & ":" & _ Mid(strTimeGenerated, 11, 2) & ":" & _ Mid(strTimeGenerated, 13, 2) End If Dim strSQL As String = "INSERT INTO [EventLog].[dbo].[EventLogData_" & strLogfile & "] ([Category]" & _ ",[CategoryString]" & _ ",[ComputerName]" & _ " VALUES('" & strCategory & "'," & _ "'" & strCategoryString & "'," & _ "'" & strComputerName & "'," & _ Dts.Variables("User::InsertSQL").Value = strSQL DateTime列に取り込めるように整形 SQL文を生成 User::InsertSQL
53. 処理7:Insert Into を実行 User::InsertSQL SQLタスク SQLStatement dbo.Eventlog_<LogfileName> ') User::InsertSQL Value INSERT INTO [EventLog].[dbo].[EventLogData_Application] ([Category],[CategoryString],[ComputerName],[Data],[EventCode],[EventIdentifier],[EventType],[InsertionStrings],[LogFile],[Message],[RecordNumber],[SourceName],[TimeGenerated],[TimeWritten],[Type],[User]) VALUES('0','','TF-SQL01-01.t6303.contoso.co.jp','','12290','1073819650','3','System.String[]','Application','Package "Package" has been cancelled.',3205,'SQLISPackage100','20090923 03:23:31','20090923 03:23:31','情報','T6303dministrator') 接続マネージャ