private void init() throws CollectException { try { // // Get a runspace if there are any in the pool, or create a new one, and load the // Get-SystemMetrics // Powershell module code. // IRunspace runspace = null; IWindowsSession.View view = session.getNativeView(); for (IRunspace rs : session.getRunspacePool().enumerate()) { if (rs.getView() == view) { runspace = rs; break; } } if (runspace == null) { runspace = session.getRunspacePool().spawn(view); } runspace.loadAssembly(getClass().getResourceAsStream("Systemmetric.dll")); runspace.loadModule(getClass().getResourceAsStream("Systemmetric.psm1")); // // Run the Get-SystemMetrics module and parse the output // metrics = new HashMap<String, SystemmetricItem>(); for (String line : runspace.invoke("Get-SystemMetrics").split("\n")) { int ptr = line.indexOf(":"); String key = null, val = null; if (ptr > 0) { key = line.substring(0, ptr).trim(); val = line.substring(ptr + 1).trim(); try { EntityItemSystemMetricIndexType index = Factories.sc.windows.createEntityItemSystemMetricIndexType(); index.setDatatype(SimpleDatatypeEnumeration.STRING.value()); index.setValue(key); EntityItemIntType value = Factories.sc.core.createEntityItemIntType(); value.setDatatype(SimpleDatatypeEnumeration.INT.value()); value.setValue(new Integer(val).toString()); SystemmetricItem item = Factories.sc.windows.createSystemmetricItem(); item.setIndex(index); item.setValue(value); metrics.put(key, item); } catch (IllegalArgumentException e) { session.getLogger().warn(JOVALMsg.ERROR_WIN_SYSTEMMETRIC_VALUE, e.getMessage(), key); } } } } catch (Exception e) { session.getLogger().warn(JOVALMsg.getMessage(JOVALMsg.ERROR_EXCEPTION), e); error = new CollectException(e.getMessage(), FlagEnumeration.ERROR); throw error; } }
private Collection<PatchItem> getItems(String base) { Collection<PatchItem> items = new ArrayList<PatchItem>(); Collection<RevisionEntry> entries = revisions.get(base); if (entries != null) { for (RevisionEntry entry : entries) { PatchItem item = Factories.sc.solaris.createPatchItem(); EntityItemIntType baseType = Factories.sc.core.createEntityItemIntType(); baseType.setValue(entry.patch.getBaseString()); baseType.setDatatype(SimpleDatatypeEnumeration.INT.value()); item.setBase(baseType); EntityItemIntType versionType = Factories.sc.core.createEntityItemIntType(); versionType.setValue(entry.patch.getVersionString()); versionType.setDatatype(SimpleDatatypeEnumeration.INT.value()); item.setPatchVersion(versionType); items.add(item); } } return items; }
protected Collection<FileItem> getItems( ObjectType obj, Collection<IFile> files, IRequestContext rc) throws CollectException { FileObject fObj = (FileObject) obj; Collection<FileItem> items = new ArrayList<FileItem>(); for (IFile f : files) { try { FileItem item = (FileItem) getBaseItem(obj, f); if (item != null) { EntityItemIntType aTimeType = Factories.sc.core.createEntityItemIntType(); Date temp = f.getAccessTime(); if (temp == null) { aTimeType.setStatus(StatusEnumeration.NOT_COLLECTED); } else { aTimeType.setValue(Timestamp.toWindowsTimestamp(temp.getTime())); aTimeType.setDatatype(SimpleDatatypeEnumeration.INT.value()); } item.setATime(aTimeType); EntityItemIntType cTimeType = Factories.sc.core.createEntityItemIntType(); temp = f.getCreateTime(); if (temp == null) { cTimeType.setStatus(StatusEnumeration.NOT_COLLECTED); } else { cTimeType.setValue(Timestamp.toWindowsTimestamp(temp.getTime())); cTimeType.setDatatype(SimpleDatatypeEnumeration.INT.value()); } item.setCTime(cTimeType); EntityItemIntType mTimeType = Factories.sc.core.createEntityItemIntType(); temp = f.getLastModified(); if (temp == null) { mTimeType.setStatus(StatusEnumeration.NOT_COLLECTED); } else { mTimeType.setValue(Timestamp.toWindowsTimestamp(temp.getTime())); mTimeType.setDatatype(SimpleDatatypeEnumeration.INT.value()); } item.setMTime(mTimeType); EntityItemIntType sizeType = Factories.sc.core.createEntityItemIntType(); if (f.isFile()) { sizeType.setValue(new Long(f.length()).toString()); sizeType.setDatatype(SimpleDatatypeEnumeration.INT.value()); } else { sizeType.setStatus(StatusEnumeration.DOES_NOT_EXIST); } item.setSize(sizeType); addExtendedInfo(fObj, f.getExtended(), item); addHeaderInfo(fObj, f, item); items.add(item); } } catch (IOException e) { session.getLogger().warn(Message.ERROR_IO, f.getPath(), e.getMessage()); MessageType msg = Factories.common.createMessageType(); msg.setLevel(MessageLevelEnumeration.ERROR); msg.setValue(e.getMessage()); rc.addMessage(msg); } } return items; }
private XinetdItem makeItem(Service service) { XinetdItem item = Factories.sc.unix.createXinetdItem(); EntityItemStringType serviceName = Factories.sc.core.createEntityItemStringType(); serviceName.setValue(service.getName()); item.setServiceName(serviceName); EntityItemBoolType disabled = Factories.sc.core.createEntityItemBoolType(); disabled.setDatatype(SimpleDatatypeEnumeration.BOOLEAN.value()); try { disabled.setValue(service.getString(Property.DISABLE).equals("yes") ? "1" : "0"); } catch (NoSuchElementException e) { disabled.setStatus(StatusEnumeration.DOES_NOT_EXIST); } item.setDisabled(disabled); try { for (String flag : service.get(Property.FLAGS)) { EntityItemStringType value = Factories.sc.core.createEntityItemStringType(); value.setValue(flag); item.getFlags().add(value); } } catch (NoSuchElementException e) { } try { for (String deny : service.get(Property.NO_ACCESS)) { EntityItemStringType value = Factories.sc.core.createEntityItemStringType(); value.setValue(deny); item.getNoAccess().add(value); } } catch (NoSuchElementException e) { } try { for (String allow : service.get(Property.ONLY_FROM)) { EntityItemIPAddressStringType value = Factories.sc.core.createEntityItemIPAddressStringType(); value.setValue(allow); item.getOnlyFrom().add(value); } } catch (NoSuchElementException e) { } EntityItemIntType port = Factories.sc.core.createEntityItemIntType(); port.setDatatype(SimpleDatatypeEnumeration.INT.value()); try { port.setValue(service.getString(Property.PORT)); } catch (NoSuchElementException e) { port.setStatus(StatusEnumeration.DOES_NOT_EXIST); } item.setPort(port); EntityItemStringType protocol = Factories.sc.core.createEntityItemStringType(); try { protocol.setValue(service.getString(Property.PROTOCOL)); } catch (NoSuchElementException e) { protocol.setStatus(StatusEnumeration.DOES_NOT_EXIST); } item.setProtocol(protocol); EntityItemStringType server = Factories.sc.core.createEntityItemStringType(); try { server.setValue(service.getString(Property.SERVER)); } catch (NoSuchElementException e) { server.setStatus(StatusEnumeration.DOES_NOT_EXIST); } item.setServer(server); EntityItemStringType serverArguments = Factories.sc.core.createEntityItemStringType(); try { serverArguments.setValue(service.getString(Property.SERVER_ARGUMENTS)); } catch (NoSuchElementException e) { serverArguments.setStatus(StatusEnumeration.DOES_NOT_EXIST); } item.setServerArguments(serverArguments); EntityItemStringType socketType = Factories.sc.core.createEntityItemStringType(); try { socketType.setValue(service.getString(Property.SOCKET_TYPE)); } catch (NoSuchElementException e) { socketType.setStatus(StatusEnumeration.DOES_NOT_EXIST); } item.setSocketType(socketType); EntityItemXinetdTypeStatusType type = Factories.sc.unix.createEntityItemXinetdTypeStatusType(); try { type.setValue(service.getString(Property.TYPE)); } catch (NoSuchElementException e) { type.setStatus(StatusEnumeration.DOES_NOT_EXIST); } item.setType(type); EntityItemStringType user = Factories.sc.core.createEntityItemStringType(); try { user.setValue(service.getString(Property.USER)); } catch (NoSuchElementException e) { user.setStatus(StatusEnumeration.DOES_NOT_EXIST); } item.setUser(user); EntityItemBoolType wait = Factories.sc.core.createEntityItemBoolType(); wait.setDatatype(SimpleDatatypeEnumeration.BOOLEAN.value()); try { wait.setValue(service.getString(Property.WAIT).equals("wait") ? "1" : "0"); } catch (NoSuchElementException e) { wait.setStatus(StatusEnumeration.DOES_NOT_EXIST); } item.setWait(wait); item.setStatus(StatusEnumeration.EXISTS); return item; }