Shark Inventory Report

Overview

From time to time, I have to correlate our inventory with our asset records.  This is a basic script that will read from a varialbe list(SHARKLIST) and print out the name/ip, version, serial number, and licenses of all sharks you want to "inventory".

 

Customizations

You will need to populate the SHARKLIST variable with either the hostname or IPaddresses of your vsharks/sharks.   When running the script you will need to feed it a username with -u and password -p options.

 

The script

 

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <codecell>

import pycurl, argparse, cStringIO, json, pprint, re, sys

parser = argparse.ArgumentParser(description='Parameter options')
parser.add_argument('-u','--username',help="username",required=True)
parser.add_argument('-p','--password',help="password",required=True)
rargs = parser.parse_args()

METHODE = 'https://'
URL1 = '/api/shark/4.0/system/version_info'
URL2 = '/api/shark/4.0/settings/licenses'
SHARKLIST = ['x.x.x.x','hostname']

def getUserData(URL):
        c = pycurl.Curl()
        c.setopt(pycurl.URL, METHODE+SHARK+URL)
        c.setopt(pycurl.SSL_VERIFYPEER, 0)
        c.setopt(pycurl.SSL_VERIFYHOST, 0)
        c.setopt(pycurl.SSL_VERIFYHOST, 0)
        c.setopt(pycurl.HTTPHEADER, ['Accept: application/json'])
        c.setopt(pycurl.VERBOSE, 0)
        c.setopt(pycurl.USERPWD, rargs.username+':'+rargs.password)
        c.setopt(pycurl.WRITEFUNCTION, b1.write)
        c.perform()

for SHARK in SHARKLIST:
    b1 = cStringIO.StringIO()
    contents = getUserData(URL1)
    serial = re.findall("serial_number\": \"([^\"]+)\"",b1.getvalue())
    version = re.findall("shark_version\": \"([^\"]+)\"",b1.getvalue())

    b1 = cStringIO.StringIO()
    contents = getUserData(URL2)
    licensekeys = re.findall("key\": \"([^\"]+)",b1.getvalue())
    featurename = re.findall("feature_name\": \"([^\"]+)",b1.getvalue())
    lic = [None]*(len(featurename)+len(licensekeys))
    lic[::2] = featurename
    lic[1::2] = licensekeys
    print "%s ; %s ; %s; %s;" %(SHARK,serial[0],version[0],lic)