Sun Microsystems, Inc.
spacerspacer
spacer www.sun.com docs.sun.com |
spacer
black dot
 
 
Chapter 3, Writing a Client Program Handling CIM Events Creating an Event Filter To Create an Event Filter   Previous   Contents   Next 
   
 

CIMClass cimfilter = cc.getClass(new CIMObjectPath
                                ("CIM_IndicationFilter"), true);
CIMInstance ci = cimfilter.newInstance();
//Assuming that the test_a class exists in the namespace
String filterString = "select * from CIM_InstCreation where sourceInstance 
                       isa test_a"

ci.setProperty("query", new CIMValue(filterString));
CIMObjectPath filter = cc.createInstance(newCIMObjectPath(), ci);


Creating an Event Handler

An event handler is an instance of a CIM_IndicationHandler class. You set the properties in an instance of the CIM_IndicationHandler class to uniquely name the handler and identify the UID of its owner. The CIM Event MOF defines a CIM_IndicationHandlerCIMXML class for describing the destination for indications to be delivered to client applications using the HTTP protocol. The Solaris Event MOF extends the CIM_IndicationHandler class by creating the Solaris_JAVAXRMIDelivery class to handle delivery of indications of CIM events to client applications using the RMI protocol. RMI clients must instantiate the Solaris_JAVAXRMIDelivery class to set up an RMI delivery location.

Table 3-7 CIM_IndicationHandler Properties

Property

Description

Required/Optional

SystemCreationClassName

The name of the system on which the creation class for the handler resides or to which it applies.

Optional. Completed by the CIM Object Manager. 

SystemName

The name of the system on which the handler resides or to which it applies.

Optional. The default value for this key property is the name of the system on which the CIM Object Manager is running.

CreationClassName

The class or subclass used to create the handler.

Optional. The CIM Object Manager assigns the appropriate class name as the default for this key property.

Name

The unique name of the handler.

Optional. The client application must assign a unique name.

Owner

The name of the entity that created or maintains this handler. The provider can check this value to determine whether or not to authorize a handler to receive an indication.

Optional. The default value is the Solaris user name of the user creating the instance.


Example 3-23 Creating an Event Handler

// Create an instance of the Solaris_JAVAXRMIDelivery class or get
// the appropriate instance of the handler.
CIMInstance ci = cc.getIndicationHandler(null);

//Create a new instance (delivery) from
//the rmidelivery instance.
CIMObjectPath delivery = cc.createInstance(new CIMObjectPath(), ci);


Binding an Event Filter to an Event Handler

You bind an event filter to an event handler by creating an instance of the CIM_IndicationSubscription class. When you create an indication of this class, indications for the events specified by the event filter are delivered.

The following example creates a subscription (filterdelivery) and defines the filter property to the filter object path created in "To Create an Event Filter", and defines the handler property to the delivery object path created in Example 3-23.


Example 3-24 Binding an Event Filter to an Event Handler

CIMClass filterdelivery = cc.getClass(new 
        CIMObjectPath("CIM_IndicationSubscription"), 
        true, true, true, null);
ci = filterdelivery.newInstance():

//Create a property called filter that refers to the filter instance.
ci.setProperty("filter", new CIMValue(filter));

//Create a property called handler that refers to the delivery instance.
ci.setProperty("handler", new CIMValue(delivery));

CIMObjectPath indsub = cc.createInstance(new CIMObjectPath(), ci);


Reading and Writing Log Messages

The Solaris MOFs 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 when a system cannot access a serial port, when a system successfully mounts a file system, or when the number of processes that are running on a system exceeds the allowed number.

The underlying providers for the logging classes can forward logging requests to the syslog daemon, the default logging system in the Solaris operating environment. See syslogd(1M).

About Log Files

WBEM log messages are stored in individual log files in the /var/sadm/wbem/log directory. The names of the log files, the directory in which the log files are stored, the log file size limit, the number of log files to store, and whether to forward messages to syslogd(1M) are 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_Device1.0.mof, and CIM_LogRecord in CIM_Device26.mof.

A log message includes the following elements:

Table 3-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 or not to send the message to syslogd(1M)


Example 3-25 Creating an Instance of Solaris_LogEntry

This example creates an instance of Solaris_LogEntryand 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 3-26 Displaying a List of Log Records

 
 
 
  Previous   Contents   Next