3 Syslogプロパティの設定
3.3 Rules / Filters / Actions (ルール/フィルター/アクション)
3.3.16 Action - Run Script (アクション – スクリプト実行)
3.3.16.3 スクリプト関数
スクリプト実行後に何をするかを設定します。0 はルールの次のアクションを続けます。1 〜 99はルール内でスキップするアク ション数です(1=次の1アクションをスキップ、3=次の3アクションをスキップ)。100 は次のルールへのジャンプです。1000 は すべてのルールをスキップしメッセージ処理を終了します。値が指定されていないときは 0 とみなされます。
タイプ: 整数 (0-32767) 範囲: 0 から 1000
指示: 0=スキップしない, 1-99=スキップするアクション数, 100=次のルールまでスキップ, 1000=メッセージ処理終了 Fields.SecondsSinceMidnight
詳細: 深夜0時からの経過時間(秒)
タイプ: ロング (0-20億) 範囲: 0 〜 86400
Fields.SecondsSinceStartup
詳細: プログラム起動からの経過時間(秒)
タイプ: ロング (0-20億)
使用例:
Filename = "C:\Program files\Syslogd\Logs\TestLog.txt"
' Use the date and time from the current message With Fields
MsgDate = .VarDate & " " & .VarTime
MsgText = "This is a test message from the scripting action"
Data = MsgDate & vbtab & .ConvertPriorityToText(.VarPriority) & vbtab & _ .VarPeerAddress & vbtab & MsgText
Call .ActionLogToFile(Filename, Data) End with
Fields.ActionPlaySound(SoundFilename As String, RepeatCount as Long)
機能: 音を鳴らす、あるいは指定したwavファイルを実行。X 回もしくはキャンセルされるまで繰り返す。
入力パラメータ: サウンドファイル名文字列, ロング値で繰り返し回数 結果: なし
サウンドファイル名が空白の場合はシステムビープ音を鳴らす。
RepeatCount オプション:
0 = キャンセルされるまで繰り返し(メイン表示ウィンドウで点滅するベルを押してキャンセルします) 1 〜 100 = 繰り返し数
繰り返し数が1以上の時、5秒間隔でサウンドまたはビープ音が鳴ります。
使用例:
' Play the squeak sound 5 times
Call Fields.ActionPlaySound("C:\Program Files\Syslogd\Sounds\Squeak.wav", 5) ' Play the squeak sound until cancelled
Call Fields.ActionPlaySound("C:\Program Files\Syslogd\Sounds\Squeak.wav", 0) ' Play the system beep sound 10 times
Call Fields.ActionPlaySound("", 10)
' Play the system beep sound until cancelled Call Fields.ActionPlaySound("", 0)
Fields.ActionSendEmail(MailTo, MailFrom, MailSubject, MailMessage , [MailImportance] , [MailPriority] , [MailSensitivity] )
機能: 指定のアドレスにEメールを送信 結果:なし
E-mail Delivery Options(Importance、Priority、Sensitivity)の指定は任意です。
Eメール送信オプション
以下のパラメータを使用してEメールメッセージに Importance(重要度)、Priority(プライオリティ)、Sensitivity(種類)のフラグ を設定できます。Eメール受信者には適宜これらのレベルが付けられたメッセージが届きます。
MailImportance: 0 - Unspecified (デフォルト) 1 - High
2 - Normal 3 - Low
MailPriority: 0 - Unspecified (デフォルト) 1 - Normal
2 - Urgent 3 - Non-Urgent
MailSensitivity: 0 - Unspecified (デフォルト) 1 - Personal
2 - Private 3 - Confidential
複数のアドレスにメッセージを送信する場合は各アドレスをカンマで区切ります。
例
MailTo = "[email protected],[email protected],[email protected]"
使用例: Eメール送信オプションをデフォルト値で [email protected] にEメール送信 MailTo = "[email protected]"
MailFrom = "[email protected]"
MailSubject = "This is a test of the scripting action"
MailMessage = "This is a test mail message" & vbCrLf & "Multiple lines."
Call Fields.ActionSendEmail(MailTo, MailFrom, MailSubject, MailMessage)
使用例:Eメール送信オプションを Importance = High、Priority = Urgent、Sensitivity = Confidential で [email protected] にEメール送信
MailTo = "[email protected]"
MailFrom = "[email protected]"
MailSubject = "This is a test of the scripting action"
MailMessage = "This is a test mail message" & vbCrLf & "Multiple lines."
MailImportance = 1 MailPriority = 2 MailSensitivity = 3
Call Fields.ActionSendEmail(MailTo, MailFrom, MailSubject, MailMessage, MailImportance, MailPriority, MailSensitivity)
Fields.ActionLogToFile(Filename, Data, [RotateLogFile] , [RotationType] , [NumLogFiles] , [Amount] , [Unit])
機能: 指定のログファイルの終わりにデータを追加 結果: なし
メッセージログをファイルに独自のフォーマットで記録します。
ファイル名に AutoSplit 値が使えます。
ファイル名に現在の時刻を含めるには %TimeHH を使います。
例: Filename = "C:\Program files\Syslogd\Logs\TestLog%TimeHH.txt"
使用例:
Filename = "C:\Program files\Syslogd\Logs\TestLog.txt"
MsgPriority = "Local7.Info"
MsgHostAddress = Fields.VarPeerAddress
' Use the date and time from the current message MsgDate = Fields.VarDate & " " & Fields.VarTime
MsgText = "This is a test message from the scripting action"
Data = MsgDate & vbtab & MsgPriority & vbtab & MsgHostAddress & vbtab & MsgText Call Fields.ActionLogToFile(Filename, Data)
注:この例では Other fields の Read 権限が有効になっていなければなりません。VarDate とVarTime 変数がスクリプトを読 むことができるようにするためです。
ログファイルローテーション:
Kiwi Syslog Daemon のログファイルローテーション機能についての詳細は関連項目を参照してください。
パラメータ RotateLogFile, RotationType, NumLogFiles, Amount および Unit の指定は任意ですが、ローテートされるログ ファイルに記録する場合は必須です。
RotateLogFile: 0 = ローテートしない 1 = ローテートする
RotationType: 0 = ログファイルサイズが Amount や Unit の指定値を超えた場合にローテートする 1 = ログファイルの経過時間が Amount や Unit の指定値を超えた場合にローテートする NumLogFiles: ローテーションで使用するログファイルの数
Amount: For RotationType=0 : Amount はファイルサイズ For RotationType=1 : Amount はファイルの経過時間
Unit For RotationType=0 : ファイルサイズを示す単位。Amout の単位としてバイト、キロバイト、メガバイト・・・
のどれが適用されるかを指定 0 = バイト 1 = キロバイト 2 = メガバイト
3 = ギガバイト
For RotationType=1: ファイルの経過時間を示す単位。Amount の単位として分、日、週…のどれが適用され るかを指定
0 = 分
1 = 時
2 = 日
3 = 曜日
4 = 週
5 = 月
6 = 四半期
7= 年
使用例:
Filename = "C:\Program files\Syslogd\Logs\TestLog.txt"
MsgPriority = "Local7.Info"
MsgHostAddress = Fields.VarPeerAddress
' Use the date and time from the current message MsgDate = Fields.VarDate & " " & Fields.VarTime
MsgText = "This is a test message from the scripting action"
Data = MsgDate & vbtab & MsgPriority & vbtab & MsgHostAddress & vbtab & MsgText RotateLogFile = 1 'Rotate this log
RotationType = 0 'Using File size rotation - NumLogFiles = 4 'Use up to 4 log files
Amount = 1000 'Each log file no more than 1000 Unit = 0 'bytes in length
Call Fields.ActionLogToFile(Filename, Data, RotateLogFile, RotationType, NumLogFiles, Amount, Unit)
使用例 (2):
Filename = "C:\Program files\Syslogd\Logs\TestLog.txt"
MsgPriority = "Local7.Info"
MsgHostAddress = Fields.VarPeerAddress
' Use the date and time from the current message MsgDate = Fields.VarDate & " " & Fields.VarTime
MsgText = "This is a test message from the scripting action"
Data = MsgDate & vbtab & MsgPriority & vbtab & MsgHostAddress & vbtab & MsgText RotateLogFile = 1 'Rotate this log
RotationType = 1 'Using File age rotation - NumLogFiles = 12 'Use up to 12 log files Amount = 1 'Each log file no more than 1 Unit = 5 'month old
Call Fields.ActionLogToFile(Filename, Data, RotateLogFile, RotationType, NumLogFiles, Amount, Unit)
Fields.ActionSendSyslog(Hostname, Message, Port, Protocol) 機能:syslogメッセージをホスト名の Protocol で指定したポートに送信 結果:なし
Hostname: リモートホストのホスト名またはIPアドレス
Message: プライオリティタグとsyslogメッセージ文を含むテキスト Port: 1 〜 65535の整数 (514 が標準syslogポート)
Protocol: 0 または 1 (0=UDP, 1=TCP)
他のホストにUDPまたはTCPでsyslogメッセージを送信する関数です。
使用例:
Hostname = "10.0.0.1" ' Remote syslog host Priority = 191 ' Local7.Debug
Port = 514 ' Use the standard syslog port Protocol = 0 ' 0=UDP, 1=TCP
' Construct the syslog message by adding <PRI> value to the front of the text Message = "<" + Cstr(Priority) + ">" + "This is an example of a syslog message"
Call Fields.ActionSendSyslog(Hostname, Message, Port, Protocol)
Fields.ActionSpoofSyslog(AdapterAddress, SrcAddress, DstAddress, DstPort, Message) 機能: 見せかけのSyslogメッセージ(UDPのみ)を DstAddress の DstPort ポート宛に送信
結果: なし
AdapterAddress: メッセージ送信元のネットワークアダプタのIPまたはMACアドレス(例:IPアドレス 192.168.0.1、MACアド レス 00:50:56:C0:00:08)
SrcAddress: メッセージ送信元のホスト名またはIPアドレス(メッセージは現物でも見せかけでも構わない)
DstAddress: リモートホスト(受信用)のホスト名またはIPアドレス DstPort: 1 〜 65535の整数 (514 が標準syslogポート)
Message: プライオリティタグとsyslogメッセージ文を含むテキスト 他のホストにUDPでsyslogメッセージを送信する関数です。
使用例:
AdapterAddress = "192.168.1.100" ' Adapter Address (Can be IP Address- ie "192.168.0.1", or MAC address - ie. "00:50:56:C0:00:08")
SrcAddress = "192.10.10.1" ' Source of message DstAddress = "10.0.0.1" ' Destination of message DstPort = 514 ' Use the standard syslog port
Priority = 191 ' Local7.Debug
' Construct the syslog message by adding <PRI> value to the front of the text Message = "<" + Cstr(Priority) + ">" + "This is an example of a syslog message"
Call Fields.ActionSpoofSyslog(AdapterAddress, SrcAddress, DstAddress, DstPort, Message) 重要:
Kiwi Syslog Daemonでこのネットワークパケットのスプーフィング機能をサポートするのは次のプラットフォームの みです。
Windows 2000/XP/2003 (Window 95/98/Me/Vista はサポート対象外)。また、WinPcap バージョン3.0以上がイン ストールされていなければなりません。WinPcap (Windows Packet Capture library)はhttp://www.winpcap.org/か らダウンロードできます。
Fields.ActionLogToFileWithCache(Filename, Data, [RotateLogFile] , [RotationType] , [NumLogFiles], [Amount] , [Unit])
機能: 指定のログファイルにデータを書きます。キャッシュは100メッセージまたは5秒ごとにクリアされます。キャッシュの設定 はレジストリで行います。この関数は書き込みキャッシュを使うこと以外は ActionLogToFile と同じです。毎秒10メッセージ以 上を受信する場合は書き込みキャッシュ関数を使ってください。
結果: なし
メッセージログをファイルに独自のフォーマットで記録します。
ファイル名に AutoSplit 値が使えます。
ファイル名に現在の時刻を含めるには %TimeHH を使います。
例:Filename = "C:\Program files\Syslogd\Logs\TestLog%TimeHH.txt"
使用例:
Filename = "C:\Program files\Syslogd\Logs\TestLog.txt"
MsgPriority = "Local7.Info"
MsgHostAddress = Fields.VarPeerAddress
' Use the date and time from the current message MsgDate = Fields.VarDate & " " & Fields.VarTime
MsgText = "This is a test message from the scripting action"
Data = MsgDate & vbtab & MsgPriority & vbtab & MsgHostAddress & vbtab & MsgText Call Fields.ActionLogToFileWithCache(Filename, Data)
注:この例では Other fields の Read 権限が有効になっていなければなりません。VarDate とVarTime 変数がスクリプトを読 むことができるようにするためです。
ログファイルローテーション:
Kiwi Syslog Daemon のログファイルローテーション機能についての詳細は関連項目を参照してください。
パラメータ RotateLogFile, RotationType, NumLogFiles, Amount および Unit の指定は任意ですが、ローテートされるログ ファイルに記録する場合は必須です。
RotateLogFile: 0 = ローテートしない 1 = ローテートする
RotationType: 0 = ログファイルサイズが Amount や Unit の指定値を超えた場合にローテートする 1 = ログファイルの経過時間が Amount や Unit の指定値を超えた場合にローテートする NumLogFiles: ローテーションで使用するログファイルの数
Amount: For RotationType=0 : Amount はファイルサイズ For RotationType=1 : Amount はファイルの経過時間
Unit For RotationType=0 : ファイルサイズを示す単位。Amout の単位としてバイト、キロバイト、メガバイト・・・
のどれが適用されるかを指定 0 = バイト 1 = キロバイト 2 = メガバイト
3 = ギガバイト
For RotationType=1: ファイルの経過時間を示す単位。Amount の単位として分、日、週…のどれが適用され
るかを指定
0 = 分
1 = 時
2 = 日
3 = 曜日
4 = 週
5 = 月
6 = 四半期
7= 年
使用例:
Filename = "C:\Program files\Syslogd\Logs\TestLog.txt"
MsgPriority = "Local7.Info"
MsgHostAddress = Fields.VarPeerAddress
' Use the date and time from the current message MsgDate = Fields.VarDate & " " & Fields.VarTime
MsgText = "This is a test message from the scripting action"
Data = MsgDate & vbtab & MsgPriority & vbtab & MsgHostAddress & vbtab & MsgText RotateLogFile = 1 'Rotate this log
RotationType = 0 'Using File size rotation - NumLogFiles = 4 'Use up to 4 log files
Amount = 1000 'Each log file no more than 1000 Unit = 0 'bytes in length
Call Fields.ActionLogToFileWithCache(Filename, Data, RotateLogFile, RotationType, NumLogFiles, Amount, Unit)
使用例 (2):
Filename = "C:\Program files\Syslogd\Logs\TestLog.txt"
MsgPriority = "Local7.Info"
MsgHostAddress = Fields.VarPeerAddress
' Use the date and time from the current message MsgDate = Fields.VarDate & " " & Fields.VarTime
MsgText = "This is a test message from the scripting action"
Data = MsgDate & vbtab & MsgPriority & vbtab & MsgHostAddress & vbtab & MsgText RotateLogFile = 1 'Rotate this log
RotationType = 1 'Using File age rotation - NumLogFiles = 12 'Use up to 12 log files Amount = 1 'Each log file no more than 1 Unit = 5 'month old
Call Fields.ActionLogToFileWithCache(Filename, Data, RotateLogFile, RotationType, NumLogFiles, Amount, Unit)
Fields.ActionDeleteFile(Filename) 機能:指定ファイルを削除
結果:なし
ログファイルを削除し完全なスタート状態にします。
ワイルドカードを使用できませんので、完全なファイル名を指定する必要があります。確認メッセージが表示されないため、慎重 に使用してください。
使用例:
Filename = "C:\Program files\Syslogd\Logs\TestLog.txt"
Call Fields.ActionDeleteFile(Filename)
Fields.ActionDisplay(DisplayNumber, TabDelimitedMessage) 機能:指定したバーチャルディスプレイ番号にメッセージを表示
結果:なし
画面に独自フォーマットのメッセージを表示するための関数です。
TabDelimitedMessage には5個のタブ区切りフィールドを指定します。各フィールドの内容は何でもかまいません。標準の表示
フィールド: 日付 [TAB] 時刻 [TAB] プライオリティ [TAB] ホスト名 [TAB] メッセージ 使用例:
With Fields
MsgPriority = ConvertPriorityToText(.VarPriority) MsgHostAddress = .VarPeerAddress
' Use the date and time from the current message MsgDate = .VarDate & " " & .VarTime
MsgText = "This is a test message from the scripting action"
Display = MsgDate & vbtab & MsgTime & vbtab & MsgPriority & vbtab &_
MsgHostAddress & vbtab & MsgText Call .ActionDisplay(0, Display)
End with
Fields.ActionLogToODBC(DSNString, TableName, InsertStatement, Timeout) 機能:DSNString とTableNameで指定したデータベースに InsertStatement を渡す。
Timeout はデータベース接続を待つ時間(秒)です。
結果:成功ではブランク。その他の場合は文字列。
この関数はメッセージをデータベースに独自フォーマットで記録するためのものです。データベース接続はプログラム内で開かれ ます。データを送信するたびに接続の生成と切断を行うことによるオーバーヘッドを防ぐためです。データベースへの送信データ がなくなり、タイムアウト時間が過ぎると接続が遮断されます。次にデータ送信されるときに再接続されます。
使用例:
"KiwiSyslog" というSystem DSNが生成されており、MS Access データベースをポイントするコードです。書き込むデータベー スタイプによりSQL挿入文の構文は若干異なります。以下の例は MS Access 97 および2000で実証済みです。
必要なフィールドすべてが設定された "Syslogd" というテーブルが作成済みであることを前提とします。
MyDSN = "DSN=KiwiSyslog;"
MyTable = "Syslogd"
MyFields = "MsgDate,MsgTime,MsgPriority,MsgHostname,MsgText"
' MS Access DB SQL INSERT command example:
' INSERT INTO Syslogd (MsgDate,MsgTime,MsgPriority,MsgHostname,MsgText) ' VALUES ('2004-08-08','13:26:26','Local7.Debug','host.company.com',
' 'This is a test message from Kiwi Syslog Daemon') With Fields
' Construct the insert statement
SQLcmd = "INSERT INTO " & MyTable & " (" & MyFields & ") VALUES (" & _ Quote(.VarDate) & "," & Quote(.VarTime) & "," & _
Quote(.ConvertPriorityToText(.VarPriority)) & "," & _
Quote(.VarPeerAddress) & "," & Quote(.VarCleanMessageText) & ")"
' Log the data to database using DSN, Table, SQLcmd and Timeout of 30 seconds .VarCustom01 = .ActionLogToODBC(MyDSN, MyTable, SQLcmd, 30)
' VarCustom01 now holds the return value from the function.