Forum Discussion

MarkPateman's avatar
MarkPateman
Icon for Nimbostratus rankNimbostratus
Sep 28, 2020

List Virtual Servers with state

Sounds simple but find no simple answer.

Run a script against and F5 to list the VS and state, up/down/available/disabled,... ?

 

Looked at the Rest API and F5-SDK. Even ansible but that has such poor output, too messy.

 

Maybe the answer is diving into pools and stats. If so, amazed such basic information is not easier to obtain.

 

Idea to to log the states, with datetime stamp, then if still 'down' after 1 month disable, then if no complaints, strip the config. Have far too many dead VS entries. Have many F5 and some contain hundreds of VS.

 

Maybe I missed the answer ?

 

Outline of script ...

 

node = ManagementRoot('node1','admin','password')

virts = node.tm.ltm.virtuals.get_collection()

for virt in virts:

baseDict = virt.raw

  print(baseDict['name'], baseDict.get('disable','False'), baseDict['status'])

 

 

 

2 Replies

  • Hi

     

    You should be able to get the VIP status from /mgmt/tm/ltm/virtual/stats

  • Cheers.

     

    Lot more messy, but works.

     

    If anyone else wants basic outline of the code ...

     

    f5nodename='an_f5_target'

    node = f5cli.F5(f5nodename,'asimpleaccount','asimplepassword')

    r = node.invoke('ltm/virtual/stats')

    counters = dict()

    counters['vips'] = 0

    if r.status_code == 200:

      fh = open(timeStamped(fmt='%Y%m%d') + '.' + f5nodename + '.dat','w+')

      rtnData = r.json()['entries']

      for vs in rtnData:

        counters['vips'] += 1

        enableState = rtnData[vs]['nestedStats']['entries'].get('status.enabledState',{"description":'N/A'})['description']

        availableState = rtnData[vs]['nestedStats']['entries'].get('status.availabilityState',{"description":'N/A'})['description']

        reasonState = rtnData[vs]['nestedStats']['entries'].get('status.statusReason',{"description":'N/A'})['description']

        output = "\t".join([vs.replace('/stats/',''), enableState, availableState, reasonState])

        print(output)

        if availableState != 'available':

          fh.write(output + "\n")

        if availableState not in counters:

          counters[availableState] = 1

        else:

          counters[availableState] += 1

      fh.close()

    print('---------------------')

    for counter, value in counters.items():

      print(f"{counter} = {value}")

    print('---------------------')

     

    f5cli.F5 is my own super simple class to store the node and credentials and then invoke python 'requests' call.

     

    prints some counters to screen and records all the none online entries in a file with reverse date and f5 name, for now.