Wednesday, 6 March 2019

MerakiBeats


Installing GO

Download and Install Go Language

  • Update your system using the following command.
### Debian 9 / Ubuntu 16.04 / 14.04 ###

# apt-get update

### CentOS / RHEL / Fedora ###

# yum -y update

  • Install wget package
### Debian 9 / Ubuntu 16.04 / 14.04 ###

# apt-get install wget

### CentOS / RHEL / Fedora ###

# yum -y install wget
  • Download the Go language binary package 
# wget https://storage.googleapis.com/golang/go1.9.2.linux-amd64.tar.gz
  • Extract the archive and move it to /usr/local
# tar -zxvf  go1.9.2.linux-amd64.tar.gz -C /usr/local/
  • Setup Go Environment variables
    • temporary
export PATH=$PATH:/usr/local/go/bin
    • permanent
place the above command in /etc/profile or $HOME/.profile file for persistent across sessions
  • install gcc (this is generally required)
yum install gcc
  • Verify Go Installation
# go version
go version go1.9.2 linux/amd64

# go env

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/work"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

Build the binary for merakibeat

To clone merakibeat from the git repository, run the following commands


mkdir -p ${GOPATH}/src/github.com/CiscoDevNet/merakibeat

git clone https://github.com/CiscoDevNet/merakibeat.git ${GOPATH}/src/wwwin-github.cisco.com/DevNet/merakibeat
  • Build
To build the binary for merakibeat run the command below. This will generate a binary in the same directory with the name merakibeat.

make
  • Run
To run merakibeat with debugging output enabled, run

./merakibeat -c merakibeat.yml -e -d "*"



    Friday, 17 June 2016

    Contrail Analytics Application Programming Interfaces (API) -UVE


    Contrail Analytics collects information from the various components of the system, and provides the visibility into flows, logs and UVEs that is needed to operate this system. This information is provided via a REST API, which can be used to build management and analytics applications and dashboards. The Contrail UI uses this REST API as well.


    To get information about a UVE, you must have the UVE type and the UVE key. In Contrail, UVEs are identified by type, such as virtual network, virtual machine, vRouter, and so on. A system-wide unique key is associated with each UVE. The key type could be different, based on the UVE type

    First we need to get the correct UVE key like below:


    Then after selecting the required UVE key(vRouter in the below example) we can get the required information:


    Selecting the particular vRouter we can get the detailed information:
    http://172.16.5.93:8081/analytics/uves/vrouter/vm-hyper3?flat




    Thursday, 16 June 2016

    installing VMwareTools

    First download the VMwareTools file from the below location:


    https://my.vmware.com/group/vmware/details?productId=529&downloadGroup=VMTOOLS1006

    Now follow these steps after copying the VMWareTools file to  /tmp directory

    tar -xvzf VMwareTools-xxxxxx.tar.gz

    cd vmware-tools-distrib/

    ./vmware-install.pl


    at this point just follow the instructions till you get this message



    Enjoy,
    
    --the VMware team

    Sunday, 5 June 2016

    updating python script to SSH with and without Enable password for Cisco devices

    python script to SSH with and without Enable password for Cisco devices
    i have tried this on Cisco IOS, IOS-XE and NX-OS and works for me.

    Without enable password requirement to print 'Show hostname' and 'Show version'(you can change that to whatever CLI you need to print.

    import paramiko

    def sshCall(host,port,user,passw):
      dssh = paramiko.SSHClient()
      dssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
      dssh.connect(hostname=host,port=port,username=user,password=passw)
      dssh.exec_command('term len 0')
      stdin, stdout, stderr = dssh.exec_command('show hostname')
      bc=stdout.read()
      print bc
      # b=bc.strip('\n')
      stdin, stdout, stderr = dssh.exec_command('show version')
      a= stdout.read()
      print a
      f = open('/output.txt', 'a')

      f.write(bc)

      f.write(a)
      f.close()
      dssh.close()

    sshCall('1.1.1.1',22,"username","password”)

    With enable password

    import paramiko
    import time

    def sshCall(host,port,user,passw):
      dssh = paramiko.SSHClient()
      dssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
      dssh.connect(hostname=host,port=port, username=user,password=passw)
      shell = dssh.invoke_shell()
      time.sleep(1)
      shell.send('enable\n')
      shell.send('FixStream123!\n')
      time.sleep(1)
      shell.send('term len 0\n')

      shell.send('show version\n')
      time.sleep(2)
      resp = shell.recv(9999)
      print resp
      dssh.close()

    sshCall('1.1.1.1',22,"usr","pwd")

    Saturday, 4 June 2016

    Juniper Contrail Python API


    You can download the Contrail python API Bindings from here

    https://github.com/Juniper/contrail-python-api

    Install instructions

    git clone https://github.com/Juniper/contrail-python-api
    cd contrail-python-api
    python setup.py install

    So the basic example explains how to connect using the Client Method and list Virtual_Networks


    import pycontrail.client as client
    conn = client.Client(url='http://10.84.34.141:8082',
            auth_params={'type':'keystone',
            'auth_url':'http://10.84.34.141:5000/v2.0',
            'username':'admin',
            'password':'secret',
            'tenant_name':'admin'})

    conn.virtual_networks_list()

    I am going to explain how to collect Data that will make some sense, although a lot of python enthusiasts will figure it out but if this is any help id be happy
    reason why i wanted to share this script is that i had taken time to write the loops to get all the dict data within lists etc. 

    I printed all the output in JSON format as final output

    from pycontrail import client
    import jsonpickle

    import jsonpickle
    conn = client.Client(
            url='http://1.1.1.1:8082',auth_params={'type':'keystone','auth_url':'http://2.2.2.2:5000/v2.0','username':'admin','password':'password','tenant_name':'admin'})

    route_instance_uuid_list=[]
    bb = conn.routing_instances_list()
    for each_route_instance in bb['routing-instances']:
        route_instance_uuid_list.append(each_route_instance['uuid'])


    route_instance_detail_list=[]
    for each_route_instance in route_instance_uuid_list:
        vn_detail_dict={'name':None,'route_instance':[],'route_target':[]}
        aa= conn.routing_instance_read(id=each_route_instance)
        vn_detail_dict['name'] =aa.name
        # print aa.name


        #route_instance
        try:
            route_instance=[]


            for each_routing in aa.routing_instance_refs:
                route_instance_dict={}
                route_instance_dict['route_instance']= dict(zip(range(0,len(each_routing['to'])), each_routing['to']))
                route_instance.append(route_instance_dict)
        except:
            pass
        vn_detail_dict['route_instance']=route_instance
        #route_instance

        #route_targets
        try:
            route_target=[]

            for each_routetarget in aa.route_target_refs:
                route_target_dict={}
                route_target_dict['route_target']= dict(zip(range(0,len(each_routetarget['to'])), each_routetarget['to']))
                route_target.append(route_target_dict)
        except:
            pass
        vn_detail_dict['route_target']=route_target
        #route_targets

        route_instance_detail_list.append(vn_detail_dict)



    vn_instance_uuid_list=[]
    vn=conn.virtual_networks_list()
    for each_vn in vn['virtual-networks']:
        vn_instance_uuid_list.append(each_vn['uuid'])








    vn_instance_detail_list=[]
    for each_vn_instance in vn_instance_uuid_list:

        vn_instance_detail_dict={}
        gg=conn.virtual_network_read(id=each_vn_instance)
        vn_instance_detail_dict['virtual_network_network_id']= gg.virtual_network_network_id
        vn_instance_detail_dict['uuid']= gg.uuid
        vn_instance_detail_dict['name']= gg.name
        vn_instance_detail_dict['parent_name']= gg.parent_name
        vn_instance_detail_dict['parent_uuid']= gg.parent_uuid
        try:
            vn_instance_detail_dict['forwarding_mode']= gg.virtual_network_properties.forwarding_mode

            for each_ipam in gg.network_ipam_refs:
                ipam_subnet_list=[]
                for each_ipam_subnet in each_ipam['attr'].ipam_subnets:
                    ipam_subnet_dict={}
                    ipam_subnet_dict['default_gateway']= each_ipam_subnet.default_gateway
                    ipam_subnet_dict['dns_server_address']= each_ipam_subnet.dns_server_address
                    ipam_subnet_dict['subnet_uuid']= each_ipam_subnet.subnet_uuid
                    ipam_subnet_dict['subnet_name'] =each_ipam_subnet.subnet_name
                    ipam_subnet_dict['ip_prefix_len']= each_ipam_subnet.subnet.ip_prefix_len
                    ipam_subnet_dict['ip_prefix']= each_ipam_subnet.subnet.ip_prefix
                    ipam_subnet_list.append(ipam_subnet_dict)
                    allocation_pool_list=[]
                    for each_allocation_pool in  each_ipam_subnet.allocation_pools:
                        allocation_pool_dict={}
                        allocation_pool_dict['start'] =each_allocation_pool.start
                        allocation_pool_dict['end']= each_allocation_pool.end
                        allocation_pool_list.append(allocation_pool_dict)
                    ipam_subnet_dict['allocation_pool']=allocation_pool_list

            vn_instance_detail_dict['ipam']=ipam_subnet_list

            network_policy_list=[]
            for each_network_policy in gg.network_policy_refs:
                network_policy_dict={}
                network_policy_dict['uuid']= each_network_policy['uuid']
                network_policy_dict['network_policy'] =dict(zip(range(0,len(each_network_policy['to'])), each_network_policy['to']))
                network_policy_list.append(network_policy_dict)
                vn_instance_detail_dict['network_policy']=network_policy_list

        except:
            pass
        vn_instance_detail_list.append(vn_instance_detail_dict)



    np_uuid_list=[]
    np_list = conn.network_policys_list()
    for each_np in np_list['network-policys']:
        np_uuid_list.append(each_np['uuid'])


    each_np_detail_list=[]
    for each_np_uuid in np_uuid_list:
        each_np_detail_dict={'policy':[]}
        nppp = conn.network_policy_read(id=each_np_uuid)
        each_np_detail_dict['uuid']= nppp.uuid
        each_np_detail_dict['name']=  nppp.name
        each_np_detail_dict['parent_name']=  nppp.parent_name
        try:
            each_policy_list=[]
            for each_policy_entry in nppp.network_policy_entries.policy_rule:
                each_policy_dict={'dst_addresses':[],'src_addresses':[]}
                each_policy_dict['protocol']= each_policy_entry.protocol
                each_policy_dict['ethertype']= each_policy_entry.ethertype
                each_policy_dict['direction']= each_policy_entry.direction
                each_policy_dict['rule_uuid']= each_policy_entry.rule_uuid
                each_policy_dict['simple_action']=  each_policy_entry.action_list.simple_action
                each_policy_dict['gateway_name']=  each_policy_entry.action_list.gateway_name

                dst_address_list=[]
                for each_dst_address in each_policy_entry.dst_addresses:
                    dst_address_dict={}
                    dst_address_dict['network_policy']= each_dst_address.network_policy
                    dst_address_dict['security_group']= each_dst_address.security_group
                    dst_address_dict['subnet']= each_dst_address.subnet
                    dst_address_dict['virtual_network']= each_dst_address.virtual_network
                    dst_address_list.append(dst_address_dict)

                each_policy_dict['dst_addresses']=dst_address_list
                src_address_list=[]
                for each_src_address in each_policy_entry.src_addresses:
                    src_address_dict={}
                    src_address_dict['network_policy']= each_src_address.network_policy
                    src_address_dict['security_group']=  each_src_address.security_group
                    src_address_dict['subnet']=  each_src_address.subnet
                    src_address_dict['virtual_network']=  each_src_address.virtual_network
                    src_address_list.append(src_address_dict)
                each_policy_dict['src_addresses']=src_address_list
                each_policy_list.append(each_policy_dict)
            each_np_detail_dict['policy']=each_policy_list

        except:
            pass
        each_np_detail_list.append(each_np_detail_dict)



    final_output = {
        'virtual_network_instance':vn_instance_detail_list,
        'route_instance':route_instance_detail_list,
        'network_policy':each_np_detail_list
    }

    print jsonpickle.pickler.encode(final_output)

        

    Thursday, 11 February 2016

    mapping dataStores NAA identifier from a host like VMware to NetApp LUN serial number

    what is LUN NAA

    A LUN Network Address Authority (NAA) number is a globally unique identifier for a LUN. The NAA number can be used to determine a LUN's serial number and vice-versa.

    Method

    Data ONTAP operating in 7-Mode or clustered Data ONTAP 8.3 or later include a LUN command to obtain the LUN serial number in the hexadecimal format:
    lun serial -x /vol/test/lun
    Serial (hex)#: 0x486e542d4f5a2f47694d684b
    Take the example of a LUN with the following NAA number:

    naa.60a98000486e542d4f5a2f47694d684b

    Remove the NAA string and the first 8 characters. In this example, naa.60a98000 (this is one of the NetApp vendor identifiers).
    The remaining value (486e542d4f5a2f47694d684b) is the hexadecimal string which, when converted from HEX to ASCII, will be the LUN serial number. There are many Web-based tools to convert HEX to ASCII and vice-versa if you are using a version of Data ONTAP that does not have the lun serial -x command available.
    486e542d4f5a2f47694d684b in HEX converts to an ASCII value of HnT-OZ/GiMhK

    You can use either the output of the command lun show –v, or review the 'LUN CONFIGURATION' section of a storage system’s autosupport output to determine which is the LUN, based on the LUN serial number in the ASCII format.
    The following is an example of the output of the lun show –v command:

    Filer1> lun show -v /vol/test/lun
    /vol/test/lun  5g (5368709120)(r/w, online, mapped)
    Serial#: HnT-OZ/GiMhK
    Share: none
    Space Reservation: disabled
    Multiprotocol Type: vmware
    Maps: test=0


    after taking the serial number convert the string value to Hex value using any online tool 


    append the NAA prefix based on the table below:

    so the result is naa.60a98000486e542d4f5a2f47694d684b

    Note the LUN serial number above (HnT-0Z/GiMhK). The LUN with naa.60a98000486e542d4f5a2f47694d684b is /vol/test/lun.

    NAA prefixes:
    Clustered Data ONTAP and Data ONTAP 7-Mode   naa.60a98000
    Clustered Data ONTAP                                           naa.600a0980
    E-Series                                                                   naa.60080e50

    Monday, 15 September 2014

    UCS deep dive

    just a visual of the UCS B-series deep dive
    this is what how i look at a low level of a B-series blade server.


    Wednesday, 13 August 2014

    Nexus FabricPath on nexus7k and nexus5k with fabricpath authentication

    This is a config template for fabricpath configuration with fabricpath isis md5 Authentication


    so i have configured the dual links in LACP port channeling and enabled fabricPath on the port-channel with authentication (md5 authentication with key-string as "fabmd5" )

    Outputs/verifications after the config are down

    Topology

    7k-4:

    feature lacp
    feature-set fabricpath
    !
    vlan 100,200
      mode fabricpath
    fabricpath switch-id 4
    !
    key chain chain-name
      key 0
        key-string 7 fabmd5
    !
    interface Ethernet2/23
      switchport mode fabricpath
      channel-group 2324 mode active
      no shutdown
    !
    interface Ethernet2/24
      switchport mode fabricpath
      channel-group 2324 mode active
      no shutdown
    !
    interface Ethernet2/25
      switchport mode fabricpath
      channel-group 2526 mode active
      no shutdown
    !
    interface Ethernet2/26
      switchport mode fabricpath
      channel-group 2526 mode active
      no shutdown
    !
    interface port-channel2324
      switchport
      switchport mode fabricpath
      fabricpath isis authentication-type md5
      fabricpath isis authentication key-chain chain-name
    !
    interface port-channel2526
      switchport
      switchport mode fabricpath
      fabricpath isis authentication-type md5
      fabricpath isis authentication key-chain chain-name
    !

    7k-3:

    feature lacp
    feature-set fabricpath
    !
    vlan 100,200
      mode fabricpath
    fabricpath switch-id 3
    !
    key chain chain-name
      key 0
        key-string 7 fabmd5
    !
    interface Ethernet2/9
      switchport mode fabricpath
      channel-group 910 mode active
      no shutdown
    !
    interface Ethernet2/10
      switchport mode fabricpath
      channel-group 910 mode active
      no shutdown
    !
    interface Ethernet2/11
      switchport mode fabricpath
      channel-group 1112 mode active
      no shutdown
    !
    interface Ethernet2/12
      switchport mode fabricpath
      channel-group 1112 mode active
      no shutdown
    !
    interface port-channel910
      switchport
      switchport mode fabricpath
      fabricpath isis authentication-type md5
      fabricpath isis authentication key-chain chain-name
    !
    interface port-channel1112
      switchport
      switchport mode fabricpath
      fabricpath isis authentication-type md5
      fabricpath isis authentication key-chain chain-name
    !

    5k-1:

    install feature-set fabricpath
    feature-set fabricpath
    feature lacp
    fabricpath switch-id 1
    !
    vlan 100,200
      mode fabricpath
    !
    key chain chain-name
      key 0
        key-string 7 fabmd5
    !
    interface Ethernet1/5
      switchport mode fabricpath
      channel-group 2526 mode active
    !
    interface Ethernet1/6
      switchport mode fabricpath
      channel-group 2526 mode active
    !
    interface Ethernet1/10
      switchport mode fabricpath
      channel-group 910 mode active
    !
    interface Ethernet1/11
      switchport mode fabricpath
      channel-group 910 mode active
    !
    interface port-channel910
      switchport mode fabricpath
      fabricpath isis authentication-type md5
      fabricpath isis authentication key-chain chain-name
    !
    interface port-channel2526
      switchport mode fabricpath
      fabricpath isis authentication-type md5
      fabricpath isis authentication key-chain chain-name
    !

    5K-2:

    install feature-set fabricpath
    feature-set fabricpath
    feature lacp
    !
    fabricpath switch-id 2
    !
    vlan 100,200
      mode fabricpath
    !
    key chain chain-name
      key 0
        key-string 7 fabmd5
    !
    interface Ethernet1/5
      switchport mode fabricpath
      channel-group 1112 mode active

    interface Ethernet1/6
      switchport mode fabricpath
      channel-group 1112 mode active

    interface Ethernet1/10
      switchport mode fabricpath
      channel-group 2324 mode active

    interface Ethernet1/11
      switchport mode fabricpath
      channel-group 2324 mode active
    !
    interface port-channel1112
      switchport mode fabricpath
      fabricpath isis authentication-type md5
      fabricpath isis authentication key-chain chain-name
    !
    interface port-channel2324
      switchport mode fabricpath
      fabricpath isis authentication-type md5
      fabricpath isis authentication key-chain chain-name
    !


    OUTPUTS/Verifications

    5K2# show port-channel summary 
    Flags:  D - Down        P - Up in port-channel (members)
            I - Individual  H - Hot-standby (LACP only)
            s - Suspended   r - Module-removed
            S - Switched    R - Routed
            U - Up (port-channel)
            M - Not in use. Min-links not met
    --------------------------------------------------------------------------------
    Group Port-       Type     Protocol  Member Ports
          Channel
    --------------------------------------------------------------------------------
    1112  Po1112(SU)  Eth      LACP      Eth1/5(P)    Eth1/6(P)    
    2324  Po2324(SU)  Eth      LACP      Eth1/10(P)   Eth1/11(P)   

    5K2# show fabricpath isis adjacency 
    Fabricpath IS-IS domain: default Fabricpath IS-IS adjacency database:
    System ID       SNPA            Level  State  Hold Time  Interface
    c067.xxxxxx  N/A             1      UP     00:00:22   port-channel1112
    c067.xxx.xxx  N/A             1      UP     00:00:22   port-channel2324

    5K2# show fabricpath isis interface port-channel 2324
    Fabricpath IS-IS domain: default 
    Interface: port-channel2324
      Status: protocol-up/link-up/admin-up
      Index: 0x0002, Local Circuit ID: 0x01, Circuit Type: L1
      Authentication type MD5
      Authentication keychain is chain-name
      Authentication check specified
      Extended Local Circuit ID: 0x16000913, P2P Circuit ID: 0000.0000.0000.00
      Retx interval: 5, Retx throttle interval: 66 ms
      LSP interval: 33 ms, MTU: 1500
      P2P Adjs: 1, AdjsUp: 1, Priority 64
      Hello Interval: 10, Multi: 3, Next IIH: 00:00:03
      Level   Adjs   AdjsUp  Metric   CSNP  Next CSNP  Last LSP ID
      1          1        1      20     60  00:01:03   ffff.ffff.ffff.ff-ff
      Topologies enabled:
        Topology Metric  MetricConfig Forwarding
        0        20      no           UP        


    Tuesday, 12 August 2014

    python script to ssh and telnet and take input from Excel sheet

    So this is a super cool script that i am going to share .

    functions of the script

    1. python script takes input from excel sheet cells for 
    • IP address
    • username 
    • password
    • transport type(ssh/telnet)
    • enable password
    2. python script runs the functions defined and captures output of your choice and stores it in a file with the hostname/IP address of the router

    assuming you have pre-installed the packages as shown in the previous script

    import paramiko
    import sys
    import os
    import xlrd
    import unidecode
    import telnetlib
    import time

    def sshCall(data1,data2,data3):
    dssh = paramiko.SSHClient()
    dssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    dssh.connect(data1.encode('ascii'),port=22, username=data2.encode('ascii'), password=data3.encode('ascii'))  
    dssh.exec_command('term len 0')
    stdin, stdout, stderr = dssh.exec_command('show hostname')
    bc=stdout.read()
    b=bc.strip('\n')
    stdin, stdout, stderr = dssh.exec_command('sh ver')
    a= stdout.read()
    print bc
    f = open(b, 'a')
    f.write(a)
    f.close()
    dssh.close()
    def telNetCall(data1,data2,data3,data5):
    hostlist= [ (data1),] 
    for host in hostlist:
    print data1
    user  = (data2)
    password = (data3)
    ena = (data5)
    telnet  = telnetlib.Telnet(host) 
    telnet.read_until('Username: ', 3)
    telnet.write(user.encode('ascii') + '\r')
    telnet.read_until('Password: ', 3)
    telnet.write(password.encode('ascii') + '\r')
    telnet.write('enable' + '\r\n')
    telnet.write(ena.encode('ascii') + '\r\n')
    telnet.write('term len 0' + '\r\n')
    telnet.write("show version"+ "\r\n")
    telnet.write('exit' + '\r')
    a=telnet.read_all()
    f = open(host, 'w')
    f.write(str(a))


    os.chdir("C:/myscript/")
    workbook = xlrd.open_workbook('Book1.xls')
    worksheet = workbook.sheet_by_name('Sheet1') 


    for x in range(1,4):
    data1 = (worksheet.cell(x,0).value).decode('ascii')
    data2 = (worksheet.cell(x,1).value).decode('ascii')
    data3 = (worksheet.cell(x,2).value).decode('ascii')
    data4 = (worksheet.cell(x,3).value).decode('ascii')
    data5 = (worksheet.cell(x,4).value).decode('ascii')
    if data4 == 'telnet':
    telNetCall(data1,data2,data3,data5)
    else:
    sshCall(data1,data2,data3)