use of org.netxms.client.NXCSession in project netxms by netxms.
the class FindNodeByPrimaryHostname method run.
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
@Override
public void run(IAction action) {
final EnterPrimaryHostnameDlg dlg = new EnterPrimaryHostnameDlg(window.getShell());
if (dlg.open() != Window.OK)
return;
final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob("Searching for hostname" + dlg.getHostname() + "in the network", null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final List<AbstractNode> nodes = session.findNodesByHostname((int) dlg.getZoneId(), dlg.getHostname());
runInUIThread(new Runnable() {
@Override
public void run() {
if (nodes != null && !nodes.isEmpty()) {
StringBuilder sb = new StringBuilder();
sb.append("The following nodes matching the criteria have been found: ");
for (int i = 0; i < nodes.size(); i++) {
sb.append("\n" + nodes.get(i).getPrimaryName());
}
MessageDialogHelper.openInformation(shell, "Result", sb.toString());
} else
MessageDialogHelper.openInformation(shell, "Result", "No nodes found!");
}
});
}
@Override
protected String getErrorMessage() {
return "Search for hostname" + dlg.getHostname() + "failed.";
}
}.start();
}
use of org.netxms.client.NXCSession in project netxms by netxms.
the class NetxmsConnector method executeAction.
private boolean executeAction(ConnectorAction action) {
List<String> servers = settingsManager.getServers();
String login = settingsManager.getLogin();
String password = settingsManager.getPassword();
boolean success = false;
boolean alarmNotFound = false;
for (String server : servers) {
ConnectionDetails connectionDetails = new ConnectionDetails(server).parse();
String connAddress = connectionDetails.getAddress();
int connPort = connectionDetails.getPort();
NXCSession session = new NXCSession(connAddress, connPort, true);
session.setIgnoreProtocolVersion(true);
try {
session.connect();
session.login(login, password);
log.debug("Connected to " + server);
// do stuff
success = true;
action.execute(session);
log.debug("Action executed on " + server);
} catch (IOException e) {
log.error("Connection failed", e);
} catch (NXCException e) {
if (e.getErrorCode() != RCC.INVALID_ALARM_ID) {
log.error("Connection failed", e);
} else {
alarmNotFound = true;
}
}
}
return success || alarmNotFound;
}
use of org.netxms.client.NXCSession in project netxms by netxms.
the class ExportDashboard method run.
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
@Override
public void run(IAction action) {
if (dashboard == null)
return;
final Set<Long> objects = new HashSet<Long>();
final Map<Long, Long> items = new HashMap<Long, Long>();
// $NON-NLS-1$
final StringBuilder xml = new StringBuilder("<dashboard>\n\t<name>");
xml.append(dashboard.getObjectName());
// $NON-NLS-1$
xml.append("</name>\n\t<columns>");
xml.append(dashboard.getNumColumns());
// $NON-NLS-1$
xml.append("</columns>\n\t<options>");
xml.append(dashboard.getOptions());
// $NON-NLS-1$
xml.append("</options>\n\t<elements>\n");
for (DashboardElement e : dashboard.getElements()) {
// $NON-NLS-1$
xml.append("\t\t<dashboardElement>\n\t\t\t<type>");
xml.append(e.getType());
// $NON-NLS-1$
xml.append("</type>\n");
xml.append(e.getLayout());
xml.append('\n');
xml.append(e.getData());
// $NON-NLS-1$
xml.append("\n\t\t</dashboardElement>\n");
DashboardElementConfig config = (DashboardElementConfig) Platform.getAdapterManager().getAdapter(e, DashboardElementConfig.class);
if (config != null) {
objects.addAll(config.getObjects());
items.putAll(config.getDataCollectionItems());
}
}
// $NON-NLS-1$
xml.append("\t</elements>\n");
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().ExportDashboard_JobTitle, wbPart, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
// Add object ID mapping
// $NON-NLS-1$
xml.append("\t<objectMap>\n");
for (Long id : objects) {
AbstractObject o = session.findObjectById(id);
if (o != null) {
// $NON-NLS-1$
xml.append("\t\t<object id=\"");
xml.append(id);
// $NON-NLS-1$
xml.append("\" class=\"");
xml.append(o.getObjectClass());
// $NON-NLS-1$
xml.append("\">");
xml.append(o.getObjectName());
// $NON-NLS-1$
xml.append("</object>\n");
}
}
// $NON-NLS-1$
xml.append("\t</objectMap>\n\t<dciMap>\n");
// Add DCI ID mapping
long[] nodeList = new long[items.size()];
long[] dciList = new long[items.size()];
int pos = 0;
for (Entry<Long, Long> dci : items.entrySet()) {
dciList[pos] = dci.getKey();
nodeList[pos] = dci.getValue();
pos++;
}
String[] names = session.dciIdsToNames(nodeList, dciList);
for (int i = 0; i < names.length; i++) {
// $NON-NLS-1$
xml.append("\t\t<dci id=\"");
xml.append(dciList[i]);
// $NON-NLS-1$
xml.append("\" node=\"");
xml.append(nodeList[i]);
// $NON-NLS-1$
xml.append("\">");
xml.append(names[i]);
// $NON-NLS-1$
xml.append("</dci>\n");
}
// $NON-NLS-1$
xml.append("\t</dciMap>\n</dashboard>\n");
// $NON-NLS-1$
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(dashboard.getObjectName() + ".xml"), "UTF-8");
try {
out.write(xml.toString());
} finally {
out.close();
final File dashboardFile = new File(dashboard.getObjectName() + ".xml");
if (dashboardFile.length() > 0) {
DownloadServiceHandler.addDownload(dashboardFile.getName(), dashboardFile.getName(), dashboardFile, "application/octet-stream");
runInUIThread(new Runnable() {
@Override
public void run() {
DownloadServiceHandler.startDownload(dashboardFile.getName());
}
});
}
}
}
@Override
protected String getErrorMessage() {
return Messages.get().ExportDashboard_ErrorText;
}
}.start();
}
use of org.netxms.client.NXCSession in project netxms by netxms.
the class DCISummaryTableSortColumnSelectionDialog method createDialogArea.
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite dialogArea = (Composite) super.createDialogArea(parent);
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob("Get summary table configuration by id", null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
sourceSummaryTable = session.getDciSummaryTable(summaryTableId);
runInUIThread(new Runnable() {
@Override
public void run() {
refresh();
}
});
}
@Override
protected String getErrorMessage() {
return "Unable to get summary table configuration";
}
}.start();
GridLayout layout = new GridLayout();
dialogArea.setLayout(layout);
selector = new DCISummaryTableColumnSelector(dialogArea, SWT.NONE, AbstractSelector.SHOW_CLEAR_BUTTON, sortingColumn, null, sourceSummaryTable);
selector.setLabel("Filter column name");
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.horizontalSpan = 520;
selector.setLayoutData(gd);
descSorting = new Button(dialogArea, SWT.CHECK);
gd = new GridData();
// gd.horizontalAlignment = SWT.FILL;
// gd.grabExcessHorizontalSpace = true;
descSorting.setText("Use descending sorting");
descSorting.setLayoutData(gd);
descSorting.setSelection(isDescSorting);
return dialogArea;
}
use of org.netxms.client.NXCSession in project netxms by netxms.
the class IdMatchingDialog method updateDciMapping.
/**
* Update mapping for all DCIs of given node after node mapping change
*
* @param objData
*/
private void updateDciMapping(final ObjectIdMatchingData objData) {
if (objData.dcis.size() == 0)
return;
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().IdMatchingDialog_JobTitle, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final DciValue[] dciValues = session.getLastValues(objData.dstId);
runInUIThread(new Runnable() {
@Override
public void run() {
for (DciIdMatchingData d : objData.dcis) {
d.dstNodeId = objData.dstId;
d.dstDciId = 0;
d.dstName = null;
for (DciValue v : dciValues) {
if (v.getDescription().equalsIgnoreCase(d.srcName)) {
d.dstDciId = v.getId();
d.dstName = v.getDescription();
break;
}
}
}
viewer.refresh(true);
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().IdMatchingDialog_JobErrorText;
}
}.start();
}
Aggregations