cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

377
Views
0
Helpful
3
Replies
Highlighted

need a CSV file ot txt --> with interface name , ip address and hostname - how to get ?

Hallo

 

the Goal is a list like :

Firewall Name1      Interface name1          ip-address1    

                             Interface Name 2         ip-address2

 

Firewall Name2      Interface name1          ip-address1    

                             Interface Name 2         ip-address2

.

.

Question :

Where are the config files saved in the CSM structure ?

Idea: copy them to a unix System and select it via perl script

 

CSM Export Feature has no Output with needed Information ?

Idea : using CSM Export , but no Interface and IP will be exported

 

We have device expert for compliance checks

Idea : write a regex to get my Information , but no way . Anybody else is using the device exprt and can help ?

 

sincerley Alfred

 

 

3 REPLIES 3
Highlighted
Cisco Employee

If you have CSM REST API

If you have CSM REST API enabled, you can use 'getGroupList' method to get the information you are looking for in the single output and then parse through it to get it in any format you like.

 

Thanks,

Chetan

Highlighted

Hi ChetanAPI is enable and

Hi Chetan

API is enable and how can I use it ?

Do I need a license ?

May I have an example script e.g. ?

 

thanks ,

Alfred

Highlighted
Cisco Employee

Hi Alfred,

Hi Alfred,

CSM 4.7 onwards includes a demo license. If not, you need a license to use API. Simplest way to test it using 'Advanced REST Client' extension in chrome. 

These are relevant snippets from the Python script I use for working with CSM API.

 

import re
import csv
import logging
import datetime
from httplib2 import Http
from bs4 import BeautifulSoup

headers = {'Content-Type': 'application/xml'}
connection = Http(disable_ssl_certificate_validation=True)
csm = {}
csm['reqid'] = '123'

####### MAIN STARTS HERE #######
def main():
  # Log all the messages
  logging.basicConfig(
    filename='C:/Users/Chetan/Documents/CSM/nb api/output.txt',
    level=logging.DEBUG,
    format='%(asctime)s-%(levelname)s: %(message)s',
    datefmt='%m/%d/%Y %I:%M:%S %p')
  
  # Login to CSM
  response_login = api_login('10.1.1.10', 'csmuser', 'password')
  if response_login[0]:
    logging.debug('Successful Login!')
  else :
    logging.debug('Login FAILED')
    print_response(response_login)

  # Verify Service Info - can use as heartbeat
  response_srvInfo = getServiceInfo()
  if response_srvInfo[0]:
    logging.debug(
      'Service Info: ' + response_srvInfo[1].servicedesc.string)
  else :
    logging.debug('getServiceInfo FAILED')
    print_response(response_srvInfo)

  ######### ADD SCRIPT HERE ##########
  response_getGroupList = getGroupList()
  if response_getGroupList[0]:
    logging.debug(
      'Service Info: ' + response_getGroupList[1].prettify() )
  else :
    logging.debug('getGroupList FAILED')
    print_response(response_getGroupList)

  
  response_logout = api_logout()    # Logout CSM API session
  logging.debug('Logout response: ' + str(response_login[0]))

####### MAIN ENDS HERE #######

def make_tuple(response):
  """Returns a tuple of usable objects from the HTTP server response.
  USAGE: 
  tuple_resp = make_tuple(response)
  tuple_resp[0]: TRUE for successful server response
  tuple_resp[1]: BeatifulSoup object for XML payload
  """
  tuple_resp = (response[0]['status'] == '200', BeautifulSoup(response[1]))
  return tuple_resp

def print_response(response):
  """Print XML response data returned by CSM API in BeautifulSoup
  format. Note that BeautifulSoup module converts all XML tags to
  lower case.
  """
  logging.debug(response[1].prettify())

def api_login(csmanager, csm_user='csmuser', csm_pass='password', reqid='123'):
  """CSM API CLIENT AUTHENTICATION
  
  csmanager: CSM Server IP address or hostname
  csm_user: username
  csm_pass: password
  reqid (optional): CSM API request ID. Default is '123'
  
  After successful login, cookies are updated in the HTTP header for
  further communication.
  """
  csm['host'] = csmanager    # CSM Server IP address or hostname
  csm['reqid'] = reqid       # CSM API request ID
  url = 'https://' + csm['host'] + '/nbi/login'
  body = '<?xml version="1.0" encoding="UTF-8"?>' 
  body += '<ns1:loginRequest xmlns:ns1="csm">' 
  body += '<protVersion>1.0</protVersion><reqId>'+ csm['reqid'] +'</reqId>'
  body += '<username>' + csm_user + '</username>'
  body += '<password>' + csm_pass + '</password>'
  body += '<heartbeatRequested>false</heartbeatRequested>'
  body += '</ns1:loginRequest>'
  response = connection.request(url, "POST", body, headers)
  if response[0]['status'] == '200':
    # Update the HTTP header with cookies received from the server.
    headers['Cookie'] = response[0]['set-cookie']
  return make_tuple(response)

def api_logout():
  """Log out of current CSM API session. Old cookies are removed from
  the HTTP header.
  """
  url = 'https://' + csm['host'] + '/nbi/logout'
  body =  '<?xml version="1.0" encoding="UTF-8"?>' 
  body += '<ns1:logoutRequest xmlns:ns1="csm">'
  body += '<protVersion>1.0</protVersion><reqId>'+ csm['reqid'] +'</reqId>'
  body += '</ns1:logoutRequest>'
  response = connection.request(url, "POST", body, headers)
  headers.pop('Cookie')    # Remove the cookie from HTTP header
  return make_tuple(response)

### GET-SERVICE-INFO
def getServiceInfo():
  url = 'https://' + csm['host'] + '/nbi/configservice/GetServiceInfo'
  body =  '<?xml version="1.0" encoding="UTF-8"?>'
  body += '<ns1:getServiceInfoRequest xmlns:ns1="csm">'
  body += '<protVersion>1.0</protVersion><reqId>'+ csm['reqid'] +'</reqId>'
  body += '</ns1:getServiceInfoRequest>'
  response = connection.request(url, "POST", body, headers)
  return make_tuple(response)

### GET GROUP LIST
# The GetGroupList method returns the list of devices groups.
def getGroupList():
  url = 'https://' + csm['host'] + '/nbi/configservice/getGroupList'
  body =  '<?xml version="1.0" encoding="UTF-8"?>'
  body += '<ns1:groupListRequest xmlns:ns1="csm">'
  body += '<protVersion>1.0</protVersion><reqId>'+ csm['reqid'] +'</reqId>'
  body += '<includeEmptyGroups>false</includeEmptyGroups>'
  body += '</ns1:groupListRequest>'
  response = connection.request(url, "POST", body, headers)
  return make_tuple(response)

# Standard boilerplate to call main() function.
if __name__ == '__main__':
  main()

 

Hope this helps!

Chetan