use of org.netxms.client.objects.AbstractNode in project netxms by netxms.
the class NXCSession method findNodesByHostname.
/**
* Find all nodes that contain the primary hostname
*
* @param zoneId zone ID
* @param hostname Hostname to find
* @return List of nodes found
* @throws IOException if socket or file I/O error occurs
* @throws NXCException if NetXMS server returns an error or operation was timed out
*/
public List<AbstractNode> findNodesByHostname(int zoneId, String hostname) throws IOException, NXCException {
final NXCPMessage msg = newMessage(NXCPCodes.CMD_FIND_HOSTNAME_LOCATION);
msg.setFieldInt32(NXCPCodes.VID_ZONE_UIN, zoneId);
msg.setField(NXCPCodes.VID_HOSTNAME, hostname);
sendMessage(msg);
final NXCPMessage response = waitForRCC(msg.getMessageId());
int count = response.getFieldAsInt32(NXCPCodes.VID_NUM_ELEMENTS);
long base = NXCPCodes.VID_ELEMENT_LIST_BASE;
List<AbstractNode> nodes = new ArrayList<AbstractNode>();
for (int i = 0; i < count; i++) {
nodes.add((AbstractNode) findObjectById(response.getFieldAsInt32(base++)));
}
return nodes;
}
use of org.netxms.client.objects.AbstractNode in project netxms by netxms.
the class TakeScreenshot method selectionChanged.
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
*/
@Override
public void selectionChanged(IAction action, ISelection selection) {
if ((selection instanceof IStructuredSelection) && (((IStructuredSelection) selection).size() == 1)) {
Object obj = ((IStructuredSelection) selection).getFirstElement();
if ((obj instanceof AbstractNode) && ((AbstractNode) obj).hasAgent()) {
action.setEnabled(true);
node = ((AbstractObject) obj);
} else {
action.setEnabled(false);
node = null;
}
} else {
action.setEnabled(false);
node = null;
}
}
use of org.netxms.client.objects.AbstractNode in project netxms by netxms.
the class ObjectStatusRadialWidget method paint.
public void paint(GC gc) {
gc.setAdvanced(true);
if (!gc.getAdvanced()) {
gc.drawText("Advanced graphics not supported", 30, 30, true);
return;
}
objectMap.clear();
leafObjectCount = calculateMaxLVLAndObjCount(rootObject, 1);
leafObjectSize = 360 / (float) leafObjectCount;
Rectangle rect = getClientArea();
rect.width--;
rect.height--;
gc.setAntialias(SWT.ON);
gc.setTextAntialias(SWT.ON);
gc.setForeground(SharedColors.getColor(SharedColors.TEXT_NORMAL, getDisplay()));
gc.setLineWidth(1);
// calculate values
int rectSide = Math.min(rect.width, rect.height);
diameter = rectSide / (maxLvl + 1);
centerX = rect.x + (rectSide / 2);
centerY = rect.y + (rectSide / 2);
// draw objects
drawParts(gc, rootObject, 2, 0);
// draw general oval with
// draw white oval
gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
gc.setAlpha(255);
gc.fillOval(centerX - diameter / 2 - 3, centerY - diameter / 2 - 3, diameter + 6, diameter + 6);
gc.setBackground(StatusDisplayInfo.getStatusColor(rootObject.getStatus()));
gc.setAlpha(255);
gc.fillOval(centerX - diameter / 2, centerY - diameter / 2, diameter, diameter);
final String text = (rootObject instanceof AbstractNode) ? // $NON-NLS-1$
(rootObject.getObjectName() + "\n" + ((AbstractNode) rootObject).getPrimaryIP().getHostAddress()) : rootObject.getObjectName();
gc.setClipping(rect);
int h = gc.textExtent(text, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER).y;
int l = gc.textExtent(text, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER).x;
gc.setForeground(ColorConverter.selectTextColorByBackgroundColor(StatusDisplayInfo.getStatusColor(rootObject.getStatus()), cCache));
gc.drawText(text, rect.x + (rectSide / 2) - l / 2, rect.y + (rectSide / 2) - h / 2, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
objectMap.add(new ObjectPosition(0, 360, 1, rootObject));
}
use of org.netxms.client.objects.AbstractNode in project netxms by netxms.
the class CreateInterfraceDci method run.
/**
* @see IActionDelegate#run(IAction)
*/
public void run(IAction action) {
final CreateInterfaceDciDialog dlg = new CreateInterfaceDciDialog(shell, (objects.size() == 1) ? objects.get(0) : null);
if (dlg.open() == Window.OK) {
final List<Interface> ifaces = new ArrayList<Interface>(objects);
// Get set of nodes
final Set<AbstractNode> nodes = new HashSet<AbstractNode>();
for (Interface iface : ifaces) {
AbstractNode node = iface.getParentNode();
if (node != null) {
nodes.add(node);
}
}
// Check what nodes requires DCI list lock
final Map<Long, Boolean> lockRequired = new HashMap<Long, Boolean>(nodes.size());
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
for (AbstractNode n : nodes) {
IViewReference ref = page.findViewReference(DataCollectionEditor.ID, Long.toString(n.getObjectId()));
lockRequired.put(n.getObjectId(), !((ref != null) && (ref.getView(false) != null)));
}
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().CreateInterfraceDci_JobTitle, viewPart, Activator.PLUGIN_ID, null) {
@Override
protected String getErrorMessage() {
return Messages.get().CreateInterfraceDci_JobError;
}
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
InterfaceDciInfo[] dciInfo = dlg.getDciInfo();
monitor.beginTask(Messages.get(getDisplay()).CreateInterfraceDci_TaskName, ifaces.size() * dciInfo.length);
for (int i = 0; i < ifaces.size(); i++) {
for (int j = 0; j < dciInfo.length; j++) {
if (dciInfo[j].enabled) {
createInterfaceDci(session, ifaces.get(i), j, dciInfo[j], dlg.getPollingInterval(), dlg.getRetentionTime(), ifaces.size() > 1, lockRequired);
}
monitor.worked(1);
}
}
monitor.done();
}
}.start();
}
}
use of org.netxms.client.objects.AbstractNode in project netxms by netxms.
the class CreateInterfraceDci method createInterfaceDci.
/**
* @param iface
* @param dciType
* @param dciInfo
* @throws Exception
*/
private static void createInterfaceDci(NXCSession session, Interface iface, int dciType, InterfaceDciInfo dciInfo, int pollingInterval, int retentionTime, boolean updateDescription, Map<Long, Boolean> lockRequired) throws Exception {
AbstractNode node = iface.getParentNode();
if (node == null)
throw new NXCException(RCC.INTERNAL_ERROR);
DataCollectionConfiguration dcc;
if (lockRequired.get(node.getObjectId())) {
dcc = session.openDataCollectionConfiguration(node.getObjectId());
} else {
dcc = new DataCollectionConfiguration(session, node.getObjectId());
}
final DataCollectionItem dci = (DataCollectionItem) dcc.findItem(dcc.createItem(null), DataCollectionItem.class);
dci.setPollingInterval(pollingInterval);
dci.setRetentionTime(retentionTime);
if (node.hasAgent()) {
dci.setOrigin(DataCollectionItem.AGENT);
if (node.isAgentIfXCountersSupported())
dci.setDataType(((dciType != IFDCI_IN_ERRORS) && (dciType != IFDCI_OUT_ERRORS)) ? DataType.COUNTER64 : DataType.COUNTER32);
else
dci.setDataType(DataType.COUNTER32);
} else {
dci.setOrigin(DataCollectionItem.SNMP);
if (node.isIfXTableSupported())
dci.setDataType(((dciType != IFDCI_IN_ERRORS) && (dciType != IFDCI_OUT_ERRORS)) ? DataType.COUNTER64 : DataType.COUNTER32);
else
dci.setDataType(DataType.COUNTER32);
}
dci.setStatus(DataCollectionItem.ACTIVE);
// $NON-NLS-1$
dci.setDescription(updateDescription ? dciInfo.description.replaceAll("@@ifName@@", iface.getObjectName()) : dciInfo.description);
dci.setDeltaCalculation(dciInfo.delta ? DataCollectionItem.DELTA_AVERAGE_PER_SECOND : DataCollectionItem.DELTA_NONE);
if (dci.getOrigin() == DataCollectionItem.AGENT) {
switch(dciType) {
case IFDCI_IN_BYTES:
case IFDCI_IN_BITS:
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
dci.setName((node.isAgentIfXCountersSupported() ? "Net.Interface.BytesIn64(" : "Net.Interface.BytesIn(") + iface.getIfIndex() + ")");
break;
case IFDCI_OUT_BYTES:
case IFDCI_OUT_BITS:
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
dci.setName((node.isAgentIfXCountersSupported() ? "Net.Interface.BytesOut64(" : "Net.Interface.BytesOut(") + iface.getIfIndex() + ")");
break;
case IFDCI_IN_PACKETS:
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
dci.setName((node.isAgentIfXCountersSupported() ? "Net.Interface.PacketsIn64(" : "Net.Interface.PacketsIn(") + iface.getIfIndex() + ")");
break;
case IFDCI_OUT_PACKETS:
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
dci.setName((node.isAgentIfXCountersSupported() ? "Net.Interface.PacketsOut64(" : "Net.Interface.PacketsOut(") + iface.getIfIndex() + ")");
break;
case IFDCI_IN_ERRORS:
// $NON-NLS-1$ //$NON-NLS-2$
dci.setName("Net.Interface.InErrors(" + iface.getIfIndex() + ")");
break;
case IFDCI_OUT_ERRORS:
// $NON-NLS-1$ //$NON-NLS-2$
dci.setName("Net.Interface.OutErrors(" + iface.getIfIndex() + ")");
break;
}
} else {
switch(dciType) {
case IFDCI_IN_BYTES:
case IFDCI_IN_BITS:
// $NON-NLS-1$ //$NON-NLS-2$
dci.setName((node.isIfXTableSupported() ? ".1.3.6.1.2.1.31.1.1.1.6" : ".1.3.6.1.2.1.2.2.1.10") + getInterfaceInstance(iface));
break;
case IFDCI_OUT_BYTES:
case IFDCI_OUT_BITS:
// $NON-NLS-1$ //$NON-NLS-2$
dci.setName((node.isIfXTableSupported() ? ".1.3.6.1.2.1.31.1.1.1.10" : ".1.3.6.1.2.1.2.2.1.16") + getInterfaceInstance(iface));
break;
case IFDCI_IN_PACKETS:
// $NON-NLS-1$ //$NON-NLS-2$
dci.setName((node.isIfXTableSupported() ? ".1.3.6.1.2.1.31.1.1.1.7" : ".1.3.6.1.2.1.2.2.1.11") + getInterfaceInstance(iface));
break;
case IFDCI_OUT_PACKETS:
// $NON-NLS-1$ //$NON-NLS-2$
dci.setName((node.isIfXTableSupported() ? ".1.3.6.1.2.1.31.1.1.1.11" : ".1.3.6.1.2.1.2.2.1.17") + getInterfaceInstance(iface));
break;
case IFDCI_IN_ERRORS:
// $NON-NLS-1$
dci.setName(".1.3.6.1.2.1.2.2.1.14" + getInterfaceInstance(iface));
break;
case IFDCI_OUT_ERRORS:
// $NON-NLS-1$
dci.setName(".1.3.6.1.2.1.2.2.1.20" + getInterfaceInstance(iface));
break;
}
}
if ((dciType == IFDCI_IN_BITS) || (dciType == IFDCI_OUT_BITS)) {
// $NON-NLS-1$
dci.setTransformationScript("return $1 * 8;");
}
dcc.modifyObject(dci);
if (lockRequired.get(node.getObjectId())) {
dcc.close();
}
}
Aggregations