WBEM ログメッセージは、/var/sadm/wbem/log ディレクトリ内の個々のログファイルに格納されます。Solaris_LogServiceProperties クラスの singleton インスタンスでは、次のプロパティを操作できます。
ログファイル名
ログファイルが格納されているディレクトリ
ログファイルのサイズの制限
格納できるログファイル数
メッセージを syslogd(1M) に転送するかどうか
各ログエントリの形式は、CIM_LogRecord のサブクラスである Solaris_LogEntry クラスによって定義されます。Solaris_LogEntry は Solaris_Device.mof 内に、CIM_LogRecord は CIM_Device26.mof 内に存在します。
ログメッセージには、次の要素が含まれます。
表 4–8 ログメッセージの要素|
要素 |
説明 |
|---|---|
|
Category |
メッセージの種類 – アプリケーション、システム、またはセキュリティ |
|
Severity |
状況の重大性 – 警告またはエラー |
|
Application |
ログメッセージを書き込んだアプリケーション (またはプロバイダ) の名前 |
|
User |
ログメッセージの生成時にアプリケーションを使用していたユーザー名 |
|
Client Machine |
ログメッセージの生成時にユーザーが使用していたシステム名および IP アドレス |
|
Server Machine |
ログメッセージの原因となったイベントが発生したシステム名 |
|
Summary Message |
イベントの概要説明 |
|
Detailed Message |
イベントの詳細説明 |
|
Data |
イベントをより把握するための状況説明 |
|
SyslogFlag |
メッセージを syslogd(1M) に送信するかどうかを指定するブール値のフラグ |
次の例では、ログを作成し、その内容を表示します。
このプログラム例では、Solaris_LogEntry のインスタンスを作成し、そのインスタンスを設定します。
public class CreateLog {
public static void main(String args[]) throws CIMException {
// 渡されたコマンド行引数が不足している場合は、
// 使用法を表示する
if (args.length < 3) {
System.out.println("Usage: CreateLog host username password
" + "[rmi|http]");
System.exit(1);
}
String protocol = CIMClient.CIM_RMI;
CIMClient cc = null;
CIMObjectPath cop = null;
BufferedReader d = new BufferedReader(new InputStreamReader
(System.in));
String input_line = "";
// 作成するレコード数をユーザーに問い合わせる
System.out.print("How many log records do you want to write? ");
int num_recs = 0;
try {
num_recs = Integer.parseInt(d.readLine());
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
// try-catch ブロックのオーバーアーチ
try {
CIMNameSpace cns = new CIMNameSpace(args[0]);
UserPrincipal up = new UserPrincipal(args[1]);
PasswordCredential pc = new PasswordCredential(args[2]);
// トランスポートプロトコルをデフォルトの RMI に設定する
if (args.length == 4 && args[3].equalsIgnoreCase("http")) {
protocol = CIMClient.CIM_XML;
}
cc = new CIMClient(cns, up, pc, protocol);
Vector keys = new Vector();
CIMProperty logsvcKey = null;
// ログ記録の作成に必要な関連情報の
// 入力をユーザーに求める
System.out.println("Please enter the record Category: ");
System.out.println("\t(0)application, (1)security,
(2)system");
logsvcKey = new CIMProperty("category");
input_line = d.readLine();
logsvcKey.setValue(new CIMValue(Integer.valueOf
(input_line)));
keys.addElement(logsvcKey);
System.out.println("Please enter the record Severity:");
System.out.println("\t(0)Informational, (1)Warning,
(2)Error");
logsvcKey = new CIMProperty("severity");
input_line = d.readLine();
logsvcKey.setValue(new CIMValue(Integer.valueOf
(input_line)));
keys.addElement(logsvcKey);
logsvcKey = new CIMProperty("Source");
System.out.println("Please enter Application Name:");
logsvcKey.setValue(new CIMValue(d.readLine()));
keys.addElement(logsvcKey);
logsvcKey = new CIMProperty("SummaryMessage");
System.out.println("Please enter a summary message:");
logsvcKey.setValue(new CIMValue(d.readLine()));
keys.addElement(logsvcKey);
logsvcKey = new CIMProperty("DetailedMessage");
System.out.println("Please enter a detailed message:");
logsvcKey.setValue(new CIMValue(d.readLine()));
keys.addElement(logsvcKey);
logsvcKey = new CIMProperty("RecordData");
logsvcKey.setValue(
new CIMValue("0xfe 0x45 0xae 0xda random data"));
keys.addElement(logsvcKey);
logsvcKey = new CIMProperty("SyslogFlag");
logsvcKey.setValue(new CIMValue(new Boolean(true)));
keys.addElement(logsvcKey);
CIMObjectPath logreccop =
new CIMObjectPath("Solaris_LogEntry", keys);
CIMClass logClass = cc.getClass(logreccop);
CIMInstance ci = logClass.newInstance();
ci.setClassName("Solaris_LogEntry");
ci.setProperties(keys);
// System.out.println(ci.toString());
// 要求された数のレコードインスタンスを作成する
for (int i = 0; i < num_recs; i++) {
cc.createInstance(logreccop, ci);
}
} catch (Exception e) {
System.out.println("Exception: "+e);
e.printStackTrace();
}
// セッションの終了
if (cc != null) {
cc.close();
}
}
}
このプログラム例では、ログ記録のリストを表示します。
public class ReadLog {
public static void main(String args[]) throws CIMException {
String protocol = CIMClient.CIM_RMI;
// 渡されたコマンド行引数が不足している場合、
// 使用法を表示する
if (args.length < 3) {
System.out.println("Usage: ReadLog host username password " +
"[rmi|http]");
System.exit(1);
}
CIMClient cc = null;
CIMObjectPath cop = null;
CIMObjectPath serviceObjPath = null;
Vector inVec = new Vector();
Vector outVec = new Vector();
// try-catch ブロックのオーバーアーチ
try {
CIMNameSpace cns = new CIMNameSpace(args[0]);
UserPrincipal up = new UserPrincipal(args[1]);
PasswordCredential pc = new PasswordCredential(args[2]);
// トランスポートプロトコルをデフォルトの RMI に設定する
if (args.length == 4 && args[3].equalsIgnoreCase("http")) {
protocol = CIMClient.CIM_XML;
}
cc = new CIMClient(cns, up, pc, protocol);
cop = new CIMObjectPath("Solaris_LogEntry");
// Solaris_LogEntry クラスのインスタンスリストを列挙する
Enumeration e = cc.enumerateInstances(cop, true, false,
false, false, null);
// リストを繰り返し処理して、各プロパティを出力する
for (; e.hasMoreElements(); ) {
System.out.println("---------------------------------");
CIMInstance ci = (CIMInstance)e.nextElement();
System.out.println("Log filename : " +
((String)ci.getProperty("LogName").getValue().
getValue()));
int categ =
(((Integer)ci.getProperty("Category").getValue().getValue()).
intValue());
if (categ == 0)
System.out.println("Category : Application Log");
else if (categ == 1)
System.out.println("Category : Security Log");
else if (categ == 2)
System.out.println("Category : System Log");
int severity =
(((Integer)ci.getProperty("Severity").getValue().getValue()).
intValue());
if (severity == 0)
System.out.println("Severity : Informational");
else if (severity == 1)
System.out.println("Severity : Warning Log!");
else if (severity == 2)
System.out.println("Severity : Error!!");
System.out.println("Log Record written by :" +
((String)ci.getProperty("Source").getValue().getValue()));
System.out.println("User : " +
((String)ci.getProperty("UserName").getValue().getValue()));
System.out.println("Client Machine : " +
((String)ci.getProperty("ClientMachineName").getValue().getValue()));
System.out.println("Server Machine : " +
((String)ci.getProperty("ServerMachineName").getValue().getValue()));
System.out.println("Summary Message : " +
((String)ci.getProperty("SummaryMessage").getValue().getValue()));
System.out.println("Detailed Message : " +
((String)ci.getProperty("DetailedMessage").getValue().getValue()));
System.out.println("Additional data : " +
((String)ci.getProperty("RecordData").getValue().getValue()));
boolean syslogflag =
((Boolean)ci.getProperty("SyslogFlag").getValue().getValue()).
booleanValue();
if (syslogflag == true) {
System.out.println("Record was written to syslog");
} else {
System.out.println("Record was not written to syslog");
}
System.out.println("---------------------------------");
}
} catch (Exception e) {
System.out.println("Exception: "+e);
e.printStackTrace();
}
// セッションを閉じる
if (cc != null) {
cc.close();
}
}
}