Search in sources :

Example 1 with GenericObject

use of org.netxms.client.objects.GenericObject in project netxms by netxms.

the class NXCSession method createObjectFromMessage.

/**
 * Create object from message
 *
 * @param msg Source NXCP message
 * @return NetXMS object
 */
private AbstractObject createObjectFromMessage(NXCPMessage msg) {
    final int objectClass = msg.getFieldAsInt32(NXCPCodes.VID_OBJECT_CLASS);
    AbstractObject object = createCustomObjectFromMessage(objectClass, msg);
    if (object != null)
        return object;
    switch(objectClass) {
        case AbstractObject.OBJECT_ACCESSPOINT:
            object = new AccessPoint(msg, this);
            break;
        case AbstractObject.OBJECT_AGENTPOLICY:
            object = new AgentPolicy(msg, this);
            break;
        case AbstractObject.OBJECT_AGENTPOLICY_CONFIG:
            object = new AgentPolicyConfig(msg, this);
            break;
        case AbstractObject.OBJECT_AGENTPOLICY_LOGPARSER:
            object = new AgentPolicyLogParser(msg, this);
            break;
        case AbstractObject.OBJECT_BUSINESSSERVICE:
            object = new BusinessService(msg, this);
            break;
        case AbstractObject.OBJECT_BUSINESSSERVICEROOT:
            object = new BusinessServiceRoot(msg, this);
            break;
        case AbstractObject.OBJECT_CHASSIS:
            object = new Chassis(msg, this);
            break;
        case AbstractObject.OBJECT_CLUSTER:
            object = new Cluster(msg, this);
            break;
        case AbstractObject.OBJECT_CONDITION:
            object = new Condition(msg, this);
            break;
        case AbstractObject.OBJECT_CONTAINER:
            object = new Container(msg, this);
            break;
        case AbstractObject.OBJECT_DASHBOARDGROUP:
            object = new DashboardGroup(msg, this);
            break;
        case AbstractObject.OBJECT_DASHBOARD:
            object = new Dashboard(msg, this);
            break;
        case AbstractObject.OBJECT_DASHBOARDROOT:
            object = new DashboardRoot(msg, this);
            break;
        case AbstractObject.OBJECT_INTERFACE:
            object = new Interface(msg, this);
            break;
        case AbstractObject.OBJECT_MOBILEDEVICE:
            object = new MobileDevice(msg, this);
            break;
        case AbstractObject.OBJECT_NETWORK:
            object = new EntireNetwork(msg, this);
            break;
        case AbstractObject.OBJECT_NETWORKMAP:
            object = new NetworkMap(msg, this);
            break;
        case AbstractObject.OBJECT_NETWORKMAPGROUP:
            object = new NetworkMapGroup(msg, this);
            break;
        case AbstractObject.OBJECT_NETWORKMAPROOT:
            object = new NetworkMapRoot(msg, this);
            break;
        case AbstractObject.OBJECT_NETWORKSERVICE:
            object = new NetworkService(msg, this);
            break;
        case AbstractObject.OBJECT_NODE:
            object = new Node(msg, this);
            break;
        case AbstractObject.OBJECT_NODELINK:
            object = new NodeLink(msg, this);
            break;
        case AbstractObject.OBJECT_POLICYGROUP:
            object = new PolicyGroup(msg, this);
            break;
        case AbstractObject.OBJECT_POLICYROOT:
            object = new PolicyRoot(msg, this);
            break;
        case AbstractObject.OBJECT_RACK:
            object = new Rack(msg, this);
            break;
        case AbstractObject.OBJECT_SENSOR:
            object = new Sensor(msg, this);
            break;
        case AbstractObject.OBJECT_SERVICEROOT:
            object = new ServiceRoot(msg, this);
            break;
        case AbstractObject.OBJECT_SLMCHECK:
            object = new ServiceCheck(msg, this);
            break;
        case AbstractObject.OBJECT_SUBNET:
            object = new Subnet(msg, this);
            break;
        case AbstractObject.OBJECT_TEMPLATE:
            object = new Template(msg, this);
            break;
        case AbstractObject.OBJECT_TEMPLATEGROUP:
            object = new TemplateGroup(msg, this);
            break;
        case AbstractObject.OBJECT_TEMPLATEROOT:
            object = new TemplateRoot(msg, this);
            break;
        case AbstractObject.OBJECT_VPNCONNECTOR:
            object = new VPNConnector(msg, this);
            break;
        case AbstractObject.OBJECT_ZONE:
            object = new Zone(msg, this);
            break;
        default:
            object = new GenericObject(msg, this);
            break;
    }
    return object;
}
Also used : Chassis(org.netxms.client.objects.Chassis) DashboardGroup(org.netxms.client.objects.DashboardGroup) ServiceCheck(org.netxms.client.objects.ServiceCheck) TemplateRoot(org.netxms.client.objects.TemplateRoot) DashboardRoot(org.netxms.client.objects.DashboardRoot) AbstractNode(org.netxms.client.objects.AbstractNode) Node(org.netxms.client.objects.Node) NetworkMapGroup(org.netxms.client.objects.NetworkMapGroup) Dashboard(org.netxms.client.objects.Dashboard) AgentPolicyConfig(org.netxms.client.objects.AgentPolicyConfig) Template(org.netxms.client.objects.Template) Rack(org.netxms.client.objects.Rack) BusinessServiceRoot(org.netxms.client.objects.BusinessServiceRoot) Container(org.netxms.client.objects.Container) MobileDevice(org.netxms.client.objects.MobileDevice) TemplateGroup(org.netxms.client.objects.TemplateGroup) PolicyRoot(org.netxms.client.objects.PolicyRoot) Condition(org.netxms.client.objects.Condition) PolicyGroup(org.netxms.client.objects.PolicyGroup) Zone(org.netxms.client.objects.Zone) AccessPoint(org.netxms.client.objects.AccessPoint) VPNConnector(org.netxms.client.objects.VPNConnector) Cluster(org.netxms.client.objects.Cluster) NetworkMapRoot(org.netxms.client.objects.NetworkMapRoot) EntireNetwork(org.netxms.client.objects.EntireNetwork) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint) ServiceRoot(org.netxms.client.objects.ServiceRoot) BusinessServiceRoot(org.netxms.client.objects.BusinessServiceRoot) BusinessService(org.netxms.client.objects.BusinessService) AgentPolicy(org.netxms.client.objects.AgentPolicy) AbstractObject(org.netxms.client.objects.AbstractObject) GenericObject(org.netxms.client.objects.GenericObject) AgentPolicyLogParser(org.netxms.client.objects.AgentPolicyLogParser) NetworkService(org.netxms.client.objects.NetworkService) NodeLink(org.netxms.client.objects.NodeLink) Subnet(org.netxms.client.objects.Subnet) Interface(org.netxms.client.objects.Interface) NetworkMap(org.netxms.client.objects.NetworkMap) Sensor(org.netxms.client.objects.Sensor)

Example 2 with GenericObject

use of org.netxms.client.objects.GenericObject in project netxms by netxms.

the class ObjectFinder method doSearch.

/**
 * Do object search
 *
 * @param searchString search string
 * @param classFilter
 * @param zoneFilter
 * @param addrEnd
 * @param addrStart
 */
private void doSearch(final String searchString, final int mode, final List<Integer> classFilter, final List<Long> zoneFilter, final InetAddress addrStart, final InetAddress addrEnd) {
    final NXCSession session = ConsoleSharedData.getSession();
    new ConsoleJob("Find objects", this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final Pattern regexp = (mode == SEARCH_MODE_REGEXP) ? Pattern.compile(searchString, Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.UNICODE_CASE) : null;
            final List<AbstractObject> objects = session.filterObjects(new ObjectFilter() {

                @Override
                public boolean filter(AbstractObject object) {
                    if (session.isZoningEnabled() && session.getAllZones().size() != zoneFilter.size()) {
                        if (object instanceof ZoneMember) {
                            ZoneMember node = (ZoneMember) object;
                            if (!zoneFilter.contains(node.getZoneId()))
                                return false;
                        }
                        if (object instanceof Sensor) {
                            AbstractNode proxy = session.findObjectById(((Sensor) object).getProxyId(), AbstractNode.class);
                            if (proxy != null && zoneFilter.contains(proxy.getZoneId()))
                                return false;
                        } else if (object instanceof Interface) {
                            AbstractNode parent = ((Interface) object).getParentNode();
                            if (parent != null && !zoneFilter.contains(parent.getZoneId()))
                                return false;
                        } else if (object instanceof NetworkService) {
                            AbstractNode parent = ((NetworkService) object).getParentNode();
                            if (parent != null && !zoneFilter.contains(parent.getZoneId()))
                                return false;
                        } else if (object instanceof VPNConnector) {
                            AbstractNode parent = ((VPNConnector) object).getParentNode();
                            if (parent != null && !zoneFilter.contains(parent.getZoneId()))
                                return false;
                        } else if (object instanceof AccessPoint) {
                            AbstractNode parent = ((AccessPoint) object).getParentNode();
                            if (parent != null && !zoneFilter.contains(parent.getZoneId()))
                                return false;
                        } else if (object instanceof GenericObject && !zoneFilter.isEmpty()) {
                            AbstractObject[] children = ((GenericObject) object).getChildsAsArray();
                            boolean match = false;
                            for (AbstractObject o : children) {
                                if (o instanceof ZoneMember && zoneFilter.contains(((ZoneMember) o).getZoneId()))
                                    match = true;
                            }
                            if (!match)
                                return false;
                        }
                    }
                    if (!classFilter.contains(object.getObjectClass()))
                        return false;
                    if ((addrStart != null) && (addrEnd != null)) {
                        if (!checkAddrRange(addrStart, addrEnd, object))
                            return false;
                    }
                    if (searchString.isEmpty())
                        return true;
                    for (String s : object.getStrings()) {
                        switch(mode) {
                            case SEARCH_MODE_NORMAL:
                                if (s.toLowerCase().contains(searchString))
                                    return true;
                                break;
                            case SEARCH_MODE_PATTERN:
                                if (Glob.match(searchString, s.toLowerCase()))
                                    return true;
                                break;
                            case SEARCH_MODE_REGEXP:
                                if (regexp.matcher(s).find())
                                    return true;
                                break;
                        }
                    }
                    return false;
                }
            });
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    results.setInput(objects);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return "Object search failure";
        }
    }.start();
}
Also used : Pattern(java.util.regex.Pattern) NXCSession(org.netxms.client.NXCSession) AbstractNode(org.netxms.client.objects.AbstractNode) AccessPoint(org.netxms.client.objects.AccessPoint) VPNConnector(org.netxms.client.objects.VPNConnector) ObjectFilter(org.netxms.client.ObjectFilter) PartInitException(org.eclipse.ui.PartInitException) UnknownHostException(java.net.UnknownHostException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractObject(org.netxms.client.objects.AbstractObject) GenericObject(org.netxms.client.objects.GenericObject) NetworkService(org.netxms.client.objects.NetworkService) List(java.util.List) ArrayList(java.util.ArrayList) ZoneMember(org.netxms.client.objects.ZoneMember) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) Interface(org.netxms.client.objects.Interface) Sensor(org.netxms.client.objects.Sensor)

Aggregations

AbstractNode (org.netxms.client.objects.AbstractNode)2 AbstractObject (org.netxms.client.objects.AbstractObject)2 AccessPoint (org.netxms.client.objects.AccessPoint)2 GenericObject (org.netxms.client.objects.GenericObject)2 Interface (org.netxms.client.objects.Interface)2 NetworkService (org.netxms.client.objects.NetworkService)2 Sensor (org.netxms.client.objects.Sensor)2 VPNConnector (org.netxms.client.objects.VPNConnector)2 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Pattern (java.util.regex.Pattern)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 PartInitException (org.eclipse.ui.PartInitException)1 NXCSession (org.netxms.client.NXCSession)1 ObjectFilter (org.netxms.client.ObjectFilter)1 AgentPolicy (org.netxms.client.objects.AgentPolicy)1 AgentPolicyConfig (org.netxms.client.objects.AgentPolicyConfig)1 AgentPolicyLogParser (org.netxms.client.objects.AgentPolicyLogParser)1 BusinessService (org.netxms.client.objects.BusinessService)1