Script Policy

This policy lets you use Groovy scripts to modify provisioned node data. These scripts have to be placed in the ${OPENNMS_HOME}/etc/script-policies directory. An example would be to change the node’s primary interface or location. The script will be invoked for each matching node.

The following example shows the source code for setting the 192.168.100.0/24 interface to PRIMARY, while all remaining interfaces are set to SECONDARY. Furthermore, the node’s location is set to Minneapolis.

import org.opennms.netmgt.model.OnmsIpInterface;
import org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation;
import org.opennms.netmgt.model.PrimaryType;

for(OnmsIpInterface iface : node.getIpInterfaces()) {
    if (iface.getIpAddressAsString().matches("^192\\.168\\.100\\..*")) {
        LOG.warn(iface.getIpAddressAsString() + " set to PRIMARY")
        iface.setIsSnmpPrimary(PrimaryType.PRIMARY)
    } else {
        LOG.warn(iface.getIpAddressAsString() + " set to SECONDARY")
        iface.setIsSnmpPrimary(PrimaryType.SECONDARY)
    }
}

node.setLocation(new OnmsMonitoringLocation("Minneapolis", ""));

return node;