How to change the color of the node in map topology view

If the specific node is down, then i want to change the colour in opennms map topology.

Assume 4 Nodes are connected in topology.
A->B->C->D, B->D, A->C. If the node B is down then the connection between B->D, B->C should come in REd color.

Initially all the nodes are connected with the black link in Opennms map topology.

Sam,

You can create your topology view using graphml and create an edge status provider using groovy script.

Use a graphml template similar to: opennms-demo/topology.xml at 994db89f1aeee9e5433fdbcde55da97148c469b4 ยท opennms-forge/opennms-demo ยท GitHub

I am attaching a sample groovy script for your perusal.

import org.opennms.netmgt.model.OnmsSeverity
import org.opennms.features.topology.plugins.topo.graphml.status.GraphMLEdgeStatus
import java.util.logging.Logger
import org.opennms.netmgt.model.OnmsSnmpInterface
import org.opennms.netmgt.model.OnmsNode
import java.util.List
import java.text.DecimalFormat
import java.text.DecimalFormatSymbols

Logger logger = Logger.getLogger("GroovyLog")
logger.info ("Edge Status: "+System.currentTimeMillis())

assert edge != null
logger.info("edge: "+edge);
logger.info("EdgeClass: "+edge.getTooltipText());
//edge.setTooltipText("HELLOOOOO");

//assert alarmSummary != null
//logger.info("alarmSummary: "+alarmSummary);
assert measurements != null;
logger.info("measurements: "+measurements);

assert sourceNode != null
//assert sourceNode.label == "node1"
logger.info("sourceNode: "+sourceNode);
logger.info("Source DOWN: "+sourceNode.isDown());

//List<OnmsNode> visitedNodes = null;

long end = System.currentTimeMillis();
long start = end - (15 * 60 * 1000);
double threshold = 75.0;

String edge_tooltip = "["+sourceNode.label;

boolean edge_color_flag = false;

DecimalFormat df = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
df.setMaximumFractionDigits(6);

for(OnmsSnmpInterface iface:sourceNode.getSnmpInterfaces()){
	logger.info("source iface: "+iface);
	String snmpifname = iface.getIfName();
	logger.info("source snmpifname: "+snmpifname);	
	if(snmpifname.startsWith("Port")){
		String snmpphyaddr = iface.getPhysAddr();
		//List<Double> bandwidth = measurements.computeUtilization(sourceNode, snmpifname);
		String resource = "nodeSource["+sourceNode.getForeignSource()+":"+sourceNode.getForeignId()+"].interfaceSnmp["+snmpifname+"-"+snmpphyaddr+"]";
		logger.info("source resource: "+resource);
		//List<Double> bandwidth = measurements.computeUtilization(resource, start, end, 300000, "AVERAGE");
		double ifHCInOctets = measurements.getLastValue(resource, "ifHCInOctets", "AVERAGE");
		logger.info("source ifHCInOctets: "+ifHCInOctets);
		double ifHCOutOctets = measurements.getLastValue(resource, "ifHCOutOctets", "AVERAGE");
		logger.info("source ifHCOutOctets: "+ifHCOutOctets);
	
		Long snmpifspeed = iface.getIfSpeed();
		logger.info("source snmpifspeed: "+snmpifspeed);

		if(!"NaN".equals(snmpifspeed.toString()) && !String.valueOf(ifHCInOctets).equals("NaN") && !String.valueOf(ifHCOutOctets).equals("NaN")){
			
			//double ifInPercent = (8 * ifHCInOctets / 1000000) / 100 * 100;
			double ifInPercent = (8 * ifHCInOctets / snmpifspeed) / 100 * 100;
			//double ifOutPercent = (8 * ifHCOutOctets / 1000000) / 100 * 100;
			double ifOutPercent = (8 * ifHCOutOctets / snmpifspeed) / 100 * 100;
			edge_tooltip = edge_tooltip+" "+snmpifname+"("+snmpifspeed/1000000000+"gb): In-"+df.format(ifInPercent)+"% Out-"+df.format(ifOutPercent)+"% ";

			if(Double.valueOf(df.format(ifInPercent)).doubleValue() > threshold || Double.valueOf(df.format(ifOutPercent)).doubleValue() > threshold){
				logger.info("source ifInPercent: "+df.format(ifInPercent)+" - ifOutPercent: "+df.format(ifOutPercent));
				edge_color_flag = true;
			}
			logger.info("source edge_color_flag: "+edge_color_flag);
		}
	}	
}

edge_tooltip = edge_tooltip+"] "

assert nodeDao != null;
logger.info("nodeDao: "+nodeDao);

//assert resourceDao != null;
//logger.info("resourceDao: "+resourceDao);

//assert ipInterfaceDao != null;
//logger.info("ipInterfaceDao: "+ipInterfaceDao);

assert snmpInterfaceDao != null;
logger.info("snmpInterfaceDao: "+snmpInterfaceDao);

logger.info("measurements: "+measurements);

edge.setTooltipText(edge_tooltip);

//return new GraphMLEdgeStatus() \
//    .severity(OnmsSeverity.NORMAL) \
//    .style([ 'stroke-dasharray' : '5,5', 'stroke' : 'red', 'stroke-width' : '8' ])
    //.style(["stroke": "pink"])

GraphMLEdgeStatus status = new GraphMLEdgeStatus();
status.severity(OnmsSeverity.NORMAL);
//status.style([ 'stroke-dasharray' : '5,5', 'stroke' : 'red', 'stroke-width' : '8' ]);

if(edge_color_flag){
	status.style([ 'stroke-dasharray' : '5,5', 'stroke' : 'red', 'stroke-width' : '8' ]);
}

return status

sudhakar