Cisco Cisco Security Manager 4.7 Guía Del Usuario
Cisco Security Manager 4.7 API Specification (Version 2.0)
OL- 32164-01
Page 227
9.4 Executing show access-list on a firewall device
The following simple sample program implemented in java demonstrates a REST client using the CSM API to
execute a show access-list command on a firewall device. Use the following client.properties as input (change the
deviceIP to match the IP of a valid device in the server’s inventory) :
execute a show access-list command on a firewall device. Use the following client.properties as input (change the
deviceIP to match the IP of a valid device in the server’s inventory) :
USER=admin
PASSWORD=admin
HOST=localhost
XML_REQUEST=<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
<csm:execDeviceReadOnlyCLICmdsRequest xmlns:csm=\"csm\">\
<protVersion>1.0</protVersion>\
<reqId>123</reqId>\
<deviceReadOnlyCLICmd>\
<deviceIP>192.168.1.1</deviceIP>\
<cmd>show</cmd>\
<argument>access-list</argument>\
</deviceReadOnlyCLICmd>\
</csm:execDeviceReadOnlyCLICmdsRequest>
# Set LOGIN_REQUIRED to true if the URI supplied
# requires login to be done as a prerequisite.
LOGIN_REQUIRED=true
URI=https://localhost/nbi/utilservice/execDeviceReadOnlyCLICmds
PASSWORD=admin
HOST=localhost
XML_REQUEST=<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
<csm:execDeviceReadOnlyCLICmdsRequest xmlns:csm=\"csm\">\
<protVersion>1.0</protVersion>\
<reqId>123</reqId>\
<deviceReadOnlyCLICmd>\
<deviceIP>192.168.1.1</deviceIP>\
<cmd>show</cmd>\
<argument>access-list</argument>\
</deviceReadOnlyCLICmd>\
</csm:execDeviceReadOnlyCLICmdsRequest>
# Set LOGIN_REQUIRED to true if the URI supplied
# requires login to be done as a prerequisite.
LOGIN_REQUIRED=true
URI=https://localhost/nbi/utilservice/execDeviceReadOnlyCLICmds
After compiling, use the following command to run the program:
Command Prompt> java RestClient <path_to_client.properties> [<uri>]
Class
RestClient.java
/**
* Sample program to execute a show access
-
list command on a firewall
*/
import
java.io.ByteArrayInputStream;
import
java.io.IOException;
import
java.net.URI;
import
java.security.KeyManagementException;
import
java.security.NoSuchAlgorithmException;
import
java.security.SecureRandom;
import
java.security.cert.X509Certificate;
import
javax.net.ssl.SSLContext;
import
javax.net.ssl.TrustManager;
import
javax.net.ssl.X509TrustManager;
import
javax.xml.parsers.DocumentBuilder;
import
javax.xml.parsers.DocumentBuilderFactory;
import
org.apache.http.HttpEntity;
import
org.apache.http.HttpResponse;
import
org.apache.http.HttpStatus;
import
org.apache.http.StatusLine;
import
org.apache.http.client.ClientProtocolException;
import
org.apache.http.client.CookieStore;
import
org.apache.http.client.methods.HttpPost;
import
org.apache.http.conn.ClientConnectionManager;
import
org.apache.http.conn.scheme.Scheme;
import
org.apache.http.conn.scheme.SchemeRegistry;