Interfaces Management on Cisco IOS

Overview

In this tutorial you will learn how to create a Microservice to manage the interfaces of a Cisco IOS router.

Although this example is based on Cisco ISR CLI it can be adapted to other type of devices with CLI-based management.

Getting the sources

The source of this tutorial are available on GitHub at https://github.com/openmsa/Workflows-Microservices/tree/master/MICROSERVICES/CISCO

Configuration sample

Here is an example of the configuration that we want to import into our object:


MSA358#sho ip interface
GigabitEthernet1 is administratively down, line protocol is down
  Internet protocol processing disabled
GigabitEthernet2 is up, line protocol is up
  Internet address is 10.30.19.12/23
  Broadcast address is 255.255.255.255
  Address determined by setup command
  MTU is 1500 bytes
  Helper address is not set
  Directed broadcast forwarding is disabled
  Outgoing Common access list is not set
  Outgoing access list is not set
  Inbound Common access list is not set

IMPORT Method

Configuration Parser

Image

Details of the parser

  • Object indentifier extractor
 @(?<object_id>\S+) is administratively \S+, line protocol is (?<status>\S+)@
 @(?<object_id>\S+) is \S+, line protocol is (?<status>\S+)@
  • Objects variable extractor
 @\s+Internet address is (?<address>\S+)/(?<_cidr>\S+)@

it is also possible to extract additional parameters such as MTU, byte in/out, packets in/out

 @\s+(?<packets_in>\S+) packets input, (?<bytes_in>\S+) bytes@
 @\s+(?<packets_out>\S+) packets output, (?<bytes_out>\S+) bytes@
 @\s+MTU (?<MTU>\S+) bytes, BW (?<BW>\S+) Kbit/sec@
  • Ignore line parsers
 @^\s@

Post Import

This parser extracts the CIDR number of the subnet, but in the case where we want to display the mask in the form 255.X.X.X then we need to use a post-import operation to create a new variable 'mask':

{if !empty($params._cidr)}
{get_mask_from_len len=$params._cidr var="_mask"}
 {assign_object_variable var="mask" value=$_mask}
{/if}

VARIABLES

Image

UPDATE

A simple implementation can be used here:

interface {$params.object_id}
{if empty($params.address)}
 no ip address
 shut
{else}
 ip address {$params.address} {$params.mask}
 no shut
{/if}

Result in the Microservice Console


Image

Display the Interface Status with Colors

This is useful to enhance the visual aspect of your objects and ease the monitoring of your interface.

Colourization is done with a POST-IMPORT that assigns the special variable '''_color''':

{if  $params.status == down }
      {assign_object_variable var="_color" value=red}
{/if}
{if  $params.status == up }
      {assign_object_variable var="_color" value=green}
{/if}

Image