use of org.netxms.client.objects.AbstractObject in project netxms by netxms.
the class IdMatchingDialog method mapNode.
/**
* Map node
*
* @param data
*/
private void mapNode(ObjectIdMatchingData data) {
Set<Integer> classFilter;
switch(data.objectClass) {
case AbstractObject.OBJECT_NODE:
case AbstractObject.OBJECT_CLUSTER:
classFilter = ObjectSelectionDialog.createNodeSelectionFilter(false);
showFilterToolTip = true;
break;
case AbstractObject.OBJECT_CONTAINER:
classFilter = ObjectSelectionDialog.createContainerSelectionFilter();
showFilterToolTip = false;
break;
case AbstractObject.OBJECT_ZONE:
classFilter = ObjectSelectionDialog.createZoneSelectionFilter();
showFilterToolTip = true;
break;
case AbstractObject.OBJECT_DASHBOARD:
classFilter = new HashSet<Integer>(2);
classFilter.add(AbstractObject.OBJECT_DASHBOARD);
classFilter.add(AbstractObject.OBJECT_DASHBOARDROOT);
break;
default:
classFilter = null;
break;
}
ObjectSelectionDialog dlg = new ObjectSelectionDialog(getShell(), null, classFilter);
dlg.showFilterToolTip(showFilterToolTip);
if (dlg.open() == Window.OK) {
AbstractObject object = dlg.getSelectedObjects().get(0);
if (ImportDashboard.isCompatibleClasses(object.getObjectClass(), data.objectClass)) {
data.dstId = object.getObjectId();
data.dstName = object.getObjectName();
updateDciMapping(data);
viewer.update(data, null);
} else {
MessageDialogHelper.openWarning(getShell(), Messages.get().IdMatchingDialog_Warning, Messages.get().IdMatchingDialog_ClassMismatch);
}
}
}
use of org.netxms.client.objects.AbstractObject in project netxms by netxms.
the class AlarmDetails method refresh.
/**
* Refresh view
*/
private void refresh() {
new ConsoleJob(Messages.get().AlarmDetails_RefreshJobTitle, this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final Alarm alarm = session.getAlarm(alarmId);
final List<AlarmComment> comments = session.getAlarmComments(alarmId);
List<EventInfo> _events = null;
try {
_events = session.getAlarmEvents(alarmId);
} catch (NXCException e) {
if (e.getErrorCode() != RCC.ACCESS_DENIED)
throw e;
}
final List<EventInfo> events = _events;
runInUIThread(new Runnable() {
@Override
public void run() {
updateAlarmDetails(alarm);
for (AlarmCommentsEditor e : editors.values()) e.dispose();
for (AlarmComment n : comments) editors.put(n.getId(), createEditor(n));
if (lastValuesWidget == null) {
AbstractObject object = session.findObjectById(alarm.getSourceObjectId());
if (object != null) {
// $NON-NLS-1$
lastValuesWidget = new LastValuesWidget(AlarmDetails.this, dataArea, SWT.BORDER, object, "AlarmDetails.LastValues", null);
lastValuesWidget.refresh();
}
}
if (events != null) {
eventViewer.setInput(events);
eventViewer.expandAll();
if (labelAccessDenied != null) {
labelAccessDenied.dispose();
labelAccessDenied = null;
}
} else if (labelAccessDenied == null) {
labelAccessDenied = new CLabel(eventViewer.getControl().getParent(), SWT.NONE);
toolkit.adapt(labelAccessDenied);
labelAccessDenied.setImage(StatusDisplayInfo.getStatusImage(Severity.CRITICAL));
labelAccessDenied.setText(Messages.get().AlarmDetails_RelatedEvents_AccessDenied);
labelAccessDenied.moveAbove(null);
labelAccessDenied.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
}
updateLayout();
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().AlarmDetails_RefreshJobError;
}
}.start();
}
use of org.netxms.client.objects.AbstractObject 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.AbstractObject in project netxms by netxms.
the class GrafanaAlarms method getCollection.
/* (non-Javadoc)
* @see org.netxms.websvc.handlers.AbstractHandler#getCollection(java.util.Map)
*/
@Override
public Object getCollection(Map<String, String> query) throws Exception {
if (!getSession().isObjectsSynchronized())
getSession().syncObjects();
if (query.isEmpty()) {
Set<Integer> classFilter = new HashSet<Integer>(5);
classFilter.add(AbstractObject.OBJECT_NODE);
classFilter.add(AbstractObject.OBJECT_MOBILEDEVICE);
classFilter.add(AbstractObject.OBJECT_RACK);
classFilter.add(AbstractObject.OBJECT_CLUSTER);
classFilter.add(AbstractObject.OBJECT_SENSOR);
AbstractObject[] objects = getSession().getTopLevelObjects(classFilter);
Map<Long, String> result = new HashMap<Long, String>();
for (AbstractObject o : objects) result.put(o.getObjectId(), o.getObjectName());
return result;
}
JsonObject root = new JsonObject();
JsonArray columns = new JsonArray();
columns.add(createColumn("Severity", true, true));
columns.add(createColumn("State", true, false));
columns.add(createColumn("Source", true, false));
columns.add(createColumn("Message", true, false));
columns.add(createColumn("Count", true, false));
columns.add(createColumn("Helpdesk ID", true, false));
columns.add(createColumn("Ack/Resolved By", true, false));
columns.add(createColumn("Created", true, false));
columns.add(createColumn("Last Change", true, false));
root.add("columns", columns);
JsonArray rows = new JsonArray();
JsonArray r = new JsonArray();
DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
AbstractObject object = null;
AbstractUserObject user = null;
JsonParser parser = new JsonParser();
JsonElement element = parser.parse(query.get("targets"));
if (!element.isJsonArray())
return new JsonArray();
JsonArray targets = element.getAsJsonArray();
JsonObject alarmSource;
long sourceId = 0;
Map<Long, Alarm> alarms = getSession().getAlarms();
for (JsonElement e : targets) {
for (Alarm a : alarms.values()) {
if (e.getAsJsonObject().has("alarmSource")) {
alarmSource = e.getAsJsonObject().getAsJsonObject("alarmSource");
if (alarmSource.size() > 0)
sourceId = Long.parseLong(alarmSource.get("id").getAsString());
}
if (sourceId == 0 || a.getSourceObjectId() == sourceId) {
r.add(a.getCurrentSeverity().name());
r.add(STATES[a.getState()]);
object = getSession().findObjectById(a.getSourceObjectId());
if (object == null)
r.add(a.getSourceObjectId());
else
r.add(object.getObjectName());
r.add(a.getMessage());
r.add(a.getRepeatCount());
r.add(a.getHelpdeskReference());
user = getSession().findUserDBObjectById(a.getAckByUser());
if (user == null)
r.add("");
else
r.add(user.getName());
r.add(df.format(a.getCreationTime()));
r.add(df.format(a.getLastChangeTime()));
rows.add(r);
r = new JsonArray();
}
}
}
root.add("rows", rows);
root.addProperty("type", "table");
JsonArray wrapper = new JsonArray();
wrapper.add(root);
return wrapper;
}
use of org.netxms.client.objects.AbstractObject in project netxms by netxms.
the class SummaryTableAdHoc method create.
/* (non-Javadoc)
* @see org.netxms.websvc.handlers.AbstractHandler#create(org.json.JSONObject)
*/
@Override
protected Object create(JSONObject data) throws Exception {
NXCSession session = getSession();
if (!session.isObjectsSynchronized())
session.syncObjects();
String objectFilter = JsonTools.getStringFromJson(data, "baseObject", null);
log.debug("POST adhoc summaryTable: baseObject = " + objectFilter);
JSONArray columnFilter = JsonTools.getJsonArrayFromJson(data, "columns", null);
if (objectFilter == null || objectFilter.isEmpty() || columnFilter == null) {
log.warn("POST adhoc summaryTable: no DciSummaryTableColumn table or no value for BaseObject");
return createErrorResponse(RCC.INVALID_ARGUMENT);
}
long baseObjectId;
try {
baseObjectId = Long.parseLong(objectFilter);
} catch (NumberFormatException ex) {
AbstractObject obj = session.findObjectByName(objectFilter);
if (obj != null)
baseObjectId = obj.getObjectId();
else
baseObjectId = 0;
}
List<DciSummaryTableColumn> columns = new ArrayList<DciSummaryTableColumn>();
for (int i = 0; i < columnFilter.length(); i++) {
JSONObject obj = columnFilter.getJSONObject(i);
columns.add(new DciSummaryTableColumn(JsonTools.getStringFromJson(obj, "columnName", ""), JsonTools.getStringFromJson(obj, "dciName", ""), JsonTools.getBooleanFromJson(obj, "isRegexp", false) ? DciSummaryTableColumn.REGEXP_MATCH : 0));
}
AggregationFunction agrFunc = JsonTools.getEnumFromJson(data, AggregationFunction.class, "aggregationFunction", null);
Date startDate;
Date endDate;
long date = JsonTools.getLongFromJson(data, "startDate", -1);
startDate = date > 0 ? new Date(date * 1000) : null;
date = JsonTools.getLongFromJson(data, "endDate", -1);
endDate = date > 0 ? new Date(date * 1000) : null;
// end date
boolean multiInstance = JsonTools.getBooleanFromJson(data, "multiInstance", true);
Table table = session.queryAdHocDciSummaryTable(baseObjectId, columns, agrFunc, startDate, endDate, multiInstance);
// create json
JSONObject root = new JSONObject();
JSONArray columnList = new JSONArray();
JSONArray rowList = new JSONArray();
String[] names = table.getColumnDisplayNames();
for (int i = 0; i < names.length; i++) columnList.put(names[i]);
root.put("columns", columnList);
TableRow[] rows = table.getAllRows();
for (int i = 0; i < rows.length; i++) {
JSONArray row = new JSONArray();
for (int j = 0; j < rows[i].size(); j++) row.put(rows[i].get(j).getValue());
rowList.put(row);
}
root.put("rows", rowList);
return new ResponseContainer("table", root);
}
Aggregations