Thanks everyone for your helpful responses! As promised, here's the code
that will allow you to update the status, ticket ID, and acknowledgement
of an alarm from an external source.

It doesn't have very elegant error handling, but it's extremely simple.
Feel free to expand it's capabilities as you please, I just ask that
updates either get put on the Spectrum Wiki or emailed to me or the list
so that the group can share in any enhancements.

Let me know if you have any questions.
-- 
Brett Davis, CCNA, GSEC
IT Network and Security Operations
Purdue University
YONG 605
Phone (765) 49-62304
[email protected]
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package alarmconnector;

/**
 *
 * @author wbdavis
 */
import com.aprisma.spectrum.core.idl.*;
import com.aprisma.spectrum.core.util.*;
import com.aprisma.spectrum.core.idl.CsCAttribute.*;
import com.aprisma.spectrum.core.idl.CsCError.*;
import com.aprisma.spectrum.core.idl.CsCException.*;
import com.aprisma.util.corba.*;
import com.aprisma.spectrum.core.idl.CsCAlarmDomainPackage.*;
import com.aprisma.spectrum.core.idl.CsCModelDomainPackage.*;
import com.aprisma.spectrum.core.idl.CsCModelTypePackage.*;
import java.util.*;
import java.nio.*;
import java.io.*;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        String domainName = "";
        String action = "";
        String alarmID = "";
        if (args.length < 3)
        {
            System.out.println("Usage: AlarmConnector [spectroServer] [alarmID] 
[action [argument]]");
            System.out.println("Actions: ");
            System.out.println("set_ticket_id [ticket id]");
            System.out.println("update_status [status]");
            System.out.println("acknowledge");
            System.exit(0);
        }
        else
        {
            domainName = args[0];
            try
            {
                alarmID = args[1];
            }
            catch (Throwable e)
            {
                e.printStackTrace();
            }
            action = args[2];
        }

        try
        {
            CORBAHelper helper = CORBAHelper.getHelperImpl();
            Properties props = new Properties();
            props.setProperty ( "user.name", "spectrum" );
            //System.out.println("Connecting to SpectroSERVER...");
            if (helper.init(null, props))
            {
                //System.out.println("Connected: Instantiating Model Domains 
and Alarm Domain");
                CsCModelDomain md = (CsCModelDomain) 
helper.getObjectImplementation(CsCModelDomain.class, domainName);
                CsCAlarmDomain ad = md.getAlarmDomain();
                byte[] alarmIDBytes = new byte[16];
                alarmIDBytes = CsCorbaUniqueIDHelper.parse(alarmID, 
alarmIDBytes);
                byte[][] alarms = new byte[][]{alarmIDBytes};

                if (action.equalsIgnoreCase("set_ticket_id"))
                {
                    try
                    {
                        String ticketID = args[3];
                        CsCValue val = new CsCValue();
                        val.textString(ticketID);
                        CsCAttrValue attrVal = new 
CsCAttrValue(CsCorbaAlarmHelper.TROUBLE_TICKET_ID, val, CsCError_e.SUCCESS);

                        CsCAttrValue[] attrValArray = new CsCAttrValue[1];
                        attrValArray[0] = attrVal;
                        CsCAttrValList writeValList = new 
CsCAttrValList(attrValArray, CsCError_e.SUCCESS);

                        try {
                            ad.writeAttrValListOfAlarms(alarms, writeValList);
                        } catch (Throwable e) {
                            System.out.println(e);
                        }
                    }
                    catch (Throwable e)
                    {
                        e.printStackTrace();
                    }
                }
                else if (action.equalsIgnoreCase("update_status"))
                {
                    try
                    {
                        String status = args[3];
                        CsCValue val = new CsCValue();
                        val.textString(status);
                        CsCAttrValue attrVal = new 
CsCAttrValue(CsCorbaAlarmHelper.ALARM_STATUS, val, CsCError_e.SUCCESS);

                        CsCAttrValue[] attrValArray = new CsCAttrValue[1];
                        attrValArray[0] = attrVal;
                        CsCAttrValList writeValList = new 
CsCAttrValList(attrValArray, CsCError_e.SUCCESS);

                        try {
                            ad.writeAttrValListOfAlarms(alarms, writeValList);
                        } catch (Throwable e) {
                            System.out.println(e);
                        }
                    }
                    catch (Throwable e)
                    {
                        e.printStackTrace();
                    }
                }
                else if (action.equalsIgnoreCase("acknowledge"))
                {
                    try
                    {
                        CsCValue val = new CsCValue();
                        val.boolValue(true);
                        CsCAttrValue attrVal = new 
CsCAttrValue(CsCorbaAlarmHelper.ACKNOWLEDGED, val, CsCError_e.SUCCESS);

                        CsCAttrValue[] attrValArray = new CsCAttrValue[1];
                        attrValArray[0] = attrVal;
                        CsCAttrValList writeValList = new 
CsCAttrValList(attrValArray, CsCError_e.SUCCESS);

                        try {
                            ad.writeAttrValListOfAlarms(alarms, writeValList);
                        } catch (Throwable e) {
                            System.out.println(e);
                        }
                    }
                    catch (Throwable e)
                    {
                        e.printStackTrace();
                    }
                }
                //System.out.println("Alarm updated. Exiting...");
            }
        }
        catch (Throwable e)
        {
            e.printStackTrace();
        }
    }
}

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to