pxGrid 2.0 Sample Code

pxGrid 2.0 provides samples in java, python, golang. The sample source codes are more complete in java. The recommendation would be to download the java code, become familiar with the code and then code in your desired programming language. Before download the sample code, ensure that you have generated certificates for your application Generating Certificates

JAVA Code Download

Below is an example of downloading the JAVA sample source code and importing into Eclipse.

You can also copy and modify the sample code to thier respective services, to complete the list of Java Code

  1. Open browser to https://github.com/cisco-pxgrid/pxgrid-rest-ws

  1. Download the zipped file and save locally

  1. Unzip the file You should see:

  1. Select File->Import->Maven->Existing Maven Projects

  1. Select Next->enter root directory where the POM file is located Note: The POM.xml file will be enabled

  2. Highlight the snapshot.jar file

  1. Select Finish

  2. You should see the imported jar file and the following samples: Note: If you do not see the scripts, select Run->Run As->Maven Clean

Session Subscribe Code Example

SessionSubscribe Coding Example This is a common example of subscribing to the session directory service and receiving incoming session notifications in real-time

  1. Under com.cisco.pxgrid.samples.ise->SessionSubscribe, Right-Click on “mainStringID:void->Run As->Run Configurations You will see

  2. Select (x) Arguments, and enter the following:

Note: The keystorefile name, keystorepassword, truststore filename and truststore password are from the earlier step in generating certificates.

-a ise24fc3.lab10.com -u mac03 -k /Applications/master_rest_samples/session1.jks -p Cisco123 -t /Applications/master_rest_samples/rootsession.jks -q Cisco123
where the argument usage is:
usage: SessionSubscribe
 -a,--hostname <arg>             Host name (multiple accepted)
 -d,--description <arg>          Description (optional)
 -k,--keystorefilename <arg>     Keystore .jks filename (not required if
                                 password is specified)
 -p,--keystorepassword <arg>     Keystore password (not required if
                                 password is specified)
 -q,--truststorepassword <arg>   Truststore password
 -t,--truststorefilename <arg>   Truststore .jks filename
 -u,--nodename <arg>             Node name
 -w,--password <arg>             Password (not required if keystore is
                                 specified)                              
  1. Select Apply

  2. Select Run

  3. If you have active user authenticated sessions coming in, you will see the following:

----- config ------
 hostname = ise24fc3.lab10.com
 nodename = mac03
 password = (not specified)
 description = (not specified)
 keystorefilename = /Applications/master_rest_samples/session1.jks
 keystorepassword = Cisco123
 truststorefilename = /Applications/master_rest_samples/rootsession.jks
 truststorepassword = Cisco123
--------------------
22:29:27.354 [main] INFO com.cisco.pxgrid.samples.ise.PxgridControl - AccountActivate request={}
22:29:32.701 [main] INFO com.cisco.pxgrid.samples.ise.PxgridControl - AccountActivate response={"accountState":"ENABLED","version":"2.0.0.13"}
22:29:32.701 [main] INFO com.cisco.pxgrid.samples.ise.SessionSubscribe - pxGrid controller version=2.0.0.13
22:29:32.703 [main] INFO com.cisco.pxgrid.samples.ise.PxgridControl - ServiceLookup request={"name":"com.cisco.ise.session"}
22:29:32.722 [main] INFO com.cisco.pxgrid.samples.ise.PxgridControl - ServiceLookup response={"services":[{"name":"com.cisco.ise.session","nodeName":"ise-mnt-ise24fc3","properties":{"sessionTopic":"/topic/com.cisco.ise.session","groupTopic":"/topic/com.cisco.ise.session.group","wsPubsubService":"com.cisco.ise.pubsub","restBaseURL":"https://ise24fc3.lab10.com:8910/pxgrid/mnt/sd","restBaseUrl":"https://ise24fc3.lab10.com:8910/pxgrid/mnt/sd"}}]}
22:29:32.722 [main] INFO com.cisco.pxgrid.samples.ise.SessionSubscribe - wsPubsubServiceName=com.cisco.ise.pubsub sessionTopic=/topic/com.cisco.ise.session
22:29:32.722 [main] INFO com.cisco.pxgrid.samples.ise.PxgridControl - ServiceLookup request={"name":"com.cisco.ise.pubsub"}
22:29:32.733 [main] INFO com.cisco.pxgrid.samples.ise.PxgridControl - ServiceLookup response={"services":[{"name":"com.cisco.ise.pubsub","nodeName":"ise-pubsub-ise24fc3","properties":{"wsUrl":"wss://ise24fc3.lab10.com:8910/pxgrid/ise/pubsub"}}]}
22:29:32.733 [main] INFO com.cisco.pxgrid.samples.ise.SessionSubscribe - wsUrl=wss://ise24fc3.lab10.com:8910/pxgrid/ise/pubsub
22:29:32.735 [main] INFO com.cisco.pxgrid.samples.ise.PxgridControl - AccessSecret request={"peerNodeName":"ise-pubsub-ise24fc3"}
22:29:32.895 [main] INFO com.cisco.pxgrid.samples.ise.PxgridControl - AccessSecret response={"secret":"36QiBjNQdWnR6lPf"}
22:29:34.805 [Grizzly(1)] INFO com.cisco.pxgrid.samples.ise.StompPubsubClientEndpoint - WS onOpen
22:29:34.833 [main] INFO com.cisco.pxgrid.samples.ise.StompPubsubClientEndpoint - STOMP CONNECT host=ise24fc3.lab10.com
22:29:34.840 [main] INFO com.cisco.pxgrid.samples.ise.StompPubsubClientEndpoint - STOMP SUBSCRIBE topic=/topic/com.cisco.ise.session
22:29:34.842 [Grizzly(2)] INFO com.cisco.pxgrid.samples.ise.StompPubsubClientEndpoint - STOMP CONNECTED version=1.2
press <enter> to disconnect...
22:31:57.678 [Grizzly(1)] INFO com.cisco.pxgrid.samples.ise.SessionSubscribe - Content={"sessions":[{"timestamp":"2018-04-16T02:31:53.599Z","state":"STARTED","userName":"jeppich","callingStationId":"10:DD:B1:C9:3C:39","calledStationId":"50:3D:E5:C4:05:8C","auditSessionId":"0A0000010000002D02D9EFBF","ipAddresses":["192.168.1.136"],"macAddress":"10:DD:B1:C9:3C:39","nasIpAddress":"192.168.1.3","nasPortId":"GigabitEthernet1/0/12","nasPortType":"Ethernet","endpointProfile":"Apple-Device","endpointOperatingSystem":"Apple Mac OS X 10.7.0 (Lion) - 10.10 (Yosemite) or iOS 4.1 - 8.3 (Darwin 10.0.0 - 14.5.0)","adNormalizedUser":"jeppich","adUserDomainName":"lab10.com","adUserNetBiosName":"LAB10","adUserResolvedIdentities":"jeppich@lab10.com","adUserResolvedDns":"CN\u003dJohn Eppich,CN\u003dUsers,DC\u003dlab10,DC\u003dcom","providers":["None"],"endpointCheckResult":"none","identitySourcePortStart":0,"identitySourcePortEnd":0,"identitySourcePortFirst":0,"isMachineAuthentication":"false","serviceType":"Framed","networkDeviceProfileName":"Cisco","radiusFlowType":"Wired802_1x","ssid":"50-3D-E5-C4-05-8C","mdmRegistered":false,"mdmCompliant":false,"mdmDiskEncrypted":false,"mdmJailBroken":false,"mdmPinLocked":false}]}