Retrieving all Endpoints from ANC Policies BY MAC
We retrieve the ANC policy by the desired MAC Address.
Code Step-Through
The Public class ANCGETEndpointByMAC calls the MAC string.
The private static void get method calls SampleConfigObject string name and ip address and mac address. The Sample config object contains the pxGrid connection parameters such as the ISE pxGrid name hostname, identity filename keystore (.jks) filename and the truststore keystore (.jks)filename and we receive the new pxGrid control object. The pxGrid control configuration contains the pxGrid client account, service lookup, and access secret obtained from the ISE pxGrid node
Under //pxGrid ServiceLookup for session service, a service lookup is performed for the ISE node publishing the com.cisco.ise.config.anc service. If there were more the (1) ISE node in the pxGrid, randomization would be performed to find the availble node. This of this is as load balancing to evenly distribute the load.
Under //User first service, we get WebSockets URL from "restBaseUrl" + "/getEndpointByMacAddress
Under //pxGrid AccessSecret for the node, we obtain the secret from the ISE pxGrid node and we make the mac address request
SampleHelper.postObjectAndPrint obtains the ISE pxGrid node, access secret, WebSocket URL, and trust information from the Client Manager.
Main parses the SampleObject Parameters
Under //Account Activate we obtain the pxGridcontrol and wait 60 seconds for the pxGrid client account to be activated, the pxGrid controller version is received, we obtain the MAC address from the ANC policy
JAVA Sample Code
package com.cisco.pxgrid.samples.ise;
import java.io.IOException;
import org.apache.commons.cli.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.cisco.pxgrid.samples.ise.model.AccountState;
import com.cisco.pxgrid.samples.ise.model.Service;
/**
* Demonstrates how to retrieve endpoints by MAC from ANC Policy
*/
public class ANCGetEndpointByMac {
private static Logger logger = LoggerFactory.getLogger(ANCGetEndpointByMac.class);
private static class ByMacRequest {
private String mac;
public String getMac() {
return mac;
}
public void setMac(String mac) {
this.mac = mac;
}
}
private static void get(SampleConfiguration config, String mac) throws IOException {
PxgridControl pxgrid = new PxgridControl(config);
// pxGrid ServiceLookup for session service
Service[] services = pxgrid.serviceLookup("com.cisco.ise.config.anc");
if (services == null || services.length == 0) {
System.out.println("Service unavailabe");
return;
}
// Use first service
Service service = services[0];
String url = service.getProperties().get("restBaseUrl") + "/getEndpointByMacAddress";
logger.info("url={}", url);
// pxGrid AccessSecret for the node
String secret = pxgrid.getAccessSecret(service.getNodeName());
ByMacRequest request = new ByMacRequest();
request.setMac(mac);
SampleHelper.postObjectAndPrint(url, config.getNodeName(), secret, config.getSSLContext().getSocketFactory(), request);
}
public static void main(String [] args) throws Exception {
// Parse arguments
SampleConfiguration config = new SampleConfiguration();
try {
config.parse(args);
} catch (ParseException e) {
config.printHelp("ANCGetEndpointByMAC");
System.exit(1);
}
// AccountActivate
PxgridControl pxgrid = new PxgridControl(config);
while (pxgrid.accountActivate() != AccountState.ENABLED)
Thread.sleep(60000);
logger.info("pxGrid controller version={}", pxgrid.getControllerVersion());
String mac = SampleHelper.prompt("Get endpoint by mac: ");
get(config, mac);
}
}
Sample Output
hostname = ise24fc3.lab10.com
nodename = mac11
password = (not specified)
description = (not specified)
keystorefilename = /Applications/master_rest_samples/sw1.jks
keystorepassword = Cisco123
truststorefilename = /Applications/master_rest_samples/sw1root.jks
truststorepassword = Cisco123
--------------------
22:56:12.010 [main] INFO com.cisco.pxgrid.samples.ise.PxgridControl - AccountActivate request={}
22:56:12.168 [main] INFO com.cisco.pxgrid.samples.ise.PxgridControl - AccountActivate response={"accountState":"ENABLED","version":"2.0.0.13"}
22:56:12.168 [main] INFO com.cisco.pxgrid.samples.ise.ANCGetEndpointByMac - pxGrid controller version=2.0.0.13
Get endpoint by mac:
00:0E:C6:8F:B4:9B
22:57:13.719 [main] INFO com.cisco.pxgrid.samples.ise.PxgridControl - ServiceLookup request={"name":"com.cisco.ise.config.anc"}
22:57:13.745 [main] INFO com.cisco.pxgrid.samples.ise.PxgridControl - ServiceLookup response={"services":[{"name":"com.cisco.ise.config.anc","nodeName":"ise-admin-ise24fc3","properties":{"wsPubsubService":"com.cisco.ise.pubsub","restBaseUrl":"https://ise24fc3.lab10.com:8910/pxgrid/ise/config/anc","statusTopic":"/topic/com.cisco.ise.config.anc.status"}}]}
22:57:13.745 [main] INFO com.cisco.pxgrid.samples.ise.ANCGetEndpointByMac - url=https://ise24fc3.lab10.com:8910/pxgrid/ise/config/anc/getEndpointByMacAddress
22:57:13.759 [main] INFO com.cisco.pxgrid.samples.ise.PxgridControl - AccessSecret request={"peerNodeName":"ise-admin-ise24fc3"}
22:57:13.774 [main] INFO com.cisco.pxgrid.samples.ise.PxgridControl - AccessSecret response={"secret":"Nwl9dttaLJ4b3hf7"}
22:57:13.811 [main] INFO com.cisco.pxgrid.samples.ise.SampleHelper - postData={"mac":"00:0E:C6:8F:B4:9B"}
22:57:13.844 [main] INFO com.cisco.pxgrid.samples.ise.SampleHelper - Response status=200
Content: {"policyName":"ANC_QUARANTINE_EXAMPLE","macAddress":"00:0E:C6:8F:B4:9B"}
What we see in ISE