JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Solaris WBEM Developer's Guide
search filter icon
search icon

Document Information

Preface

1.  Overview of Solaris Web-Based Enterprise Management

2.  Using the CIM Object Manager

3.  Using the Sample Programs

4.  Writing a Client Program

Client API Overview

Sequence of a Client Application

Opening and Closing a Client Connection

About Name Spaces

Opening a Client Connection

Closing a Client Connection

Performing Basic Client Operations

Creating an Instance

Deleting an Instance

Getting and Setting Instances

Getting and Setting Properties

Enumerating Objects

Enumerating Objects

Creating Associations

About the Association Methods

Passing a Class to the Association Methods

Passing Instances to the Association Methods

Using Optional Arguments With the Association Methods

Calling Methods

Retrieving Class Definitions

Handling Exceptions

Creating a Name Space

Deleting a Name Space

Creating a Base Class

Deleting a Class

Setting Access Control

Solaris_UserAcl Class

To Set Access Control for a User

Solaris_NamespaceAcl Class

To Set Access Control for a Name Space

Working With Qualifiers and Qualifier Types

Getting and Setting CIM Qualifiers

Batching Client Requests

Handling CIM Events

About Indications

About Subscriptions

To Create a Subscription

Adding a CIM Listener

Creating an Event Filter

To Create an Event Filter

Creating an Event Handler

Binding an Event Filter to an Event Handler

Reading and Writing Log Messages

About Log Files

5.  Writing WBEM Queries

6.  Writing a Provider Program

7.  Creating JavaBeans Components Using the MOF Compiler

8.  Administering Security

9.  Troubleshooting

A.  Solaris Platform Schema

Index

Reading and Writing Log Messages

The Solaris platform MOF files include logging classes. Clients can create and read log records using these classes to record errors, warnings, and informational messages. For example, a log message can indicate one of the following conditions:

The underlying providers for the logging classes can forward logging requests to the syslog daemon, the default logging system in the Solaris OS. See thesyslogd(1M) man page for more information.

About Log Files

WBEM log messages are stored in individual log files in the /var/sadm/wbem/log directory. Properties that you manipulate with the singleton instance of the Solaris_LogServiceProperties class:

The format of each log entry is defined by the Solaris_LogEntry class, which is a subclass of CIM_LogRecord. You can find Solaris_LogEntry in Solaris_Device.mof, and CIM_LogRecord in CIM_Device26.mof.

A log message includes the following elements:

Table 4-8 Log Message Elements

Element
Description
Category
Type of message – application, system, or security
Severity
Severity of the condition – warning or error
Application
Name of the application or the provider that is writing the log message
User
Name of the user who was using the application when the log message was generated
Client Machine
Name and IP address of the system that the user was on when the log message was generated
Server Machine
Name of the system on which the incident that generated the log message occurred
Summary Message
Descriptive summary of the incident
Detailed Message
Detailed description of the incident
Data
Contextual information that provides a better understanding of the incident
SyslogFlag
Boolean flag that specifies whether to send the message to syslogd(1M)

The following examples show how to create a log and how to display the contents of a log.

Example 4-25 Creating an Instance of Solaris_LogEntry

This example creates an instance of Solaris_LogEntry and sets the instance.

public class CreateLog {
    public static void main(String args[]) throws CIMException {

        // Display usage statement if insufficient command line
        // arguments are passed.
        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 = "";

        // Query user for number of records that need to be created.
        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);
        }

        // Over-arching try-catch block
        try {
            CIMNameSpace cns = new CIMNameSpace(args[0]);
            UserPrincipal up = new UserPrincipal(args[1]);
            PasswordCredential pc = new PasswordCredential(args[2]);

            // Set up the transport protocol - set by default to 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;


                // Prompt user for relevant info needed to create the
                // log record.

                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());

                // Create as many instances of the record as requested.
                for (int i = 0; i < num_recs; i++) {
                        cc.createInstance(logreccop, ci);
                }
        } catch (Exception e) {
            System.out.println("Exception: "+e);
                e.printStackTrace();
        }

        // close session.
        if (cc != null) {
            cc.close();
        }
    }
}

Example 4-26 Displaying a List of Log Records

This example displays a list of log records.

 public class ReadLog {
    public static void main(String args[]) throws CIMException {

        String protocol = CIMClient.CIM_RMI;

        // Display usage statement if insufficient command line
        // arguments are passed.
        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();

        // Over-arching try-catch block
        try {
            CIMNameSpace cns = new CIMNameSpace(args[0]);
            UserPrincipal up = new UserPrincipal(args[1]);
            PasswordCredential pc = new PasswordCredential(args[2]);

            // Set up the transport protocol - set by default to 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");

            // Enumerate the list of instances of class Solaris_LogEntry
            Enumeration e = cc.enumerateInstances(cop, true, false,
                                                false, false, null);

            // iterate over the list and print out each property.
            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();
        }

        // close session.
        if (cc != null) {
            cc.close();
        }
    }
}