use of org.opennms.features.namecutter.NameCutter in project opennms by OpenNMS.
the class JsmiMibParser method getPrefabGraphs.
/* (non-Javadoc)
* @see org.opennms.features.vaadin.mibcompiler.api.MibParser#getPrefabGraphs()
*/
@Override
public List<PrefabGraph> getPrefabGraphs() {
if (module == null) {
return null;
}
final String color = System.getProperty("org.opennms.snmp.mib-compiler.default-graph-template.color", "#00ccff");
List<PrefabGraph> graphs = new ArrayList<PrefabGraph>();
LOG.info("Generating graph templates for {}", module.getId());
NameCutter cutter = new NameCutter();
try {
for (SmiVariable v : module.getVariables()) {
String groupName = getGroupName(v);
String resourceType = getResourceType(v);
if (resourceType == null)
resourceType = "nodeSnmp";
String typeName = getMetricType(v.getType().getPrimitiveType());
if (v.getId().contains("Index")) {
// Treat SNMP Indexes as strings.
typeName = "string";
}
int order = 1;
if (typeName != null && !typeName.toLowerCase().contains("string")) {
String name = groupName + '.' + v.getId();
String title = getMibName() + "::" + groupName + "::" + v.getId();
// RRDtool/JRobin DS size restriction.
String alias = cutter.trimByCamelCase(v.getId(), 19);
String descr = v.getDescription().replaceAll("[\n\r]", "").replaceAll("\\s+", " ");
StringBuffer sb = new StringBuffer();
sb.append("--title=\"").append(title).append("\" \\\n");
sb.append(" DEF:var={rrd1}:").append(alias).append(":AVERAGE \\\n");
sb.append(" LINE1:var").append(color).append(":\"").append(v.getId()).append("\" \\\n");
sb.append(" GPRINT:var:AVERAGE:\"Avg\\\\: %8.2lf %s\" \\\n");
sb.append(" GPRINT:var:MIN:\"Min\\\\: %8.2lf %s\" \\\n");
sb.append(" GPRINT:var:MAX:\"Max\\\\: %8.2lf %s\\\\n\"");
sb.append("\n\n");
PrefabGraph graph = new PrefabGraph(name, title, new String[] { alias }, sb.toString(), new String[0], new String[0], order++, new String[] { resourceType }, descr, null, null, new String[0]);
graphs.add(graph);
}
}
} catch (Throwable e) {
String errors = e.getMessage();
if (errors == null || errors.trim().equals(""))
errors = "An unknown error accured when generating graph templates from the MIB " + module.getId();
LOG.error("Graph templates parsing error: {}", errors, e);
errorHandler.addError(errors);
return null;
}
return graphs;
}
use of org.opennms.features.namecutter.NameCutter in project opennms by OpenNMS.
the class JsmiMibParser method getDataCollection.
/* (non-Javadoc)
* @see org.opennms.features.vaadin.mibcompiler.api.MibParser#getDataCollection()
*/
@Override
public DatacollectionGroup getDataCollection() {
if (module == null) {
return null;
}
LOG.info("Generating data collection configuration for {}", module.getId());
DatacollectionGroup dcGroup = new DatacollectionGroup();
dcGroup.setName(module.getId());
NameCutter cutter = new NameCutter();
try {
for (SmiVariable v : module.getVariables()) {
String groupName = getGroupName(v);
String resourceType = getResourceType(v);
Group group = getGroup(dcGroup, groupName, resourceType);
// FIXME what if it is not a primitive type, like in ENTITY-SENSOR-MIB ?
String typeName = getMetricType(v.getType().getPrimitiveType());
if (typeName != null) {
// RRDtool/JRobin DS size restriction.
String alias = cutter.trimByCamelCase(v.getId(), 19);
MibObj mibObj = new MibObj();
mibObj.setOid('.' + v.getOidStr());
mibObj.setInstance(resourceType == null ? "0" : resourceType);
mibObj.setAlias(alias);
mibObj.setType(typeName);
group.addMibObj(mibObj);
if (typeName.equals("string") && resourceType != null) {
for (ResourceType rs : dcGroup.getResourceTypes()) {
if (rs.getName().equals(resourceType) && rs.getResourceLabel().equals("${index}")) {
rs.setResourceLabel("${" + v.getId() + "} (${index})");
}
}
}
}
}
} catch (Throwable e) {
String errors = e.getMessage();
if (errors == null || errors.trim().equals(""))
errors = "An unknown error accured when generating data collection objects from the MIB " + module.getId();
LOG.error("Data Collection parsing error: {}", errors, e);
errorHandler.addError(errors);
return null;
}
return dcGroup;
}
Aggregations