Code Monkey home page Code Monkey logo

merlin_unchained's Introduction

Merlin: Network Magic

A Django implementation of Merlin

Merlin

Powered by

pyATS

pyATS

Build using

Django

REST API provided by

Django REST Framework

Scheduling coordinated by

Celery

And

Celery

Featuring presentation enhancements with

Datatables

And Mind Maps by

Markmap

Metrics by

Prometheus

Featuring Advanced Search and more with

Elastic

Containerized with

Docker

Presented with

Heimdall

Merlin Installation Guide

Install Docker Engine and Docker Compose (already included on macOS and Windows)

First make sure you have Docker Compose https://docs.docker.com/compose/install/

From your terminal

git clone https://github.com/automateyournetwork/merlin_unchained.git &&
cd merlin_unchained/merlin/merlin

Note: If you will be accessing Merlin from a different PC, edit ALLOWED_HOSTS in the settings.py file before building the container.

docker-compose build merlin_unchained &&
docker-compose up -d merlin_unchained

To gracefull shutdown Merlin:

$ docker-compose down --volumes

Merlin User Guide

DevNet Sandbox Integration - https://www.youtube.com/watch?v=VBAqD9SiHxg

Considerations for current Alpha build

  • Please note - these instructions are currently to install all of the required packages, clone the repository, and start a pre-packaged database and server.

  • In the near future this project will move to a Docker container in hopes of eliminating these manual steps

  • In the interest of agility and accessibility and due to demand I've decided to make a working README for the project in it's current Alpha state so others can start to use the tool

  • The project has ** only ** been tested against a single device and has not taken scale into consideration at this point yet - once I scale out and confirm 1+n devices work this bullet point will be removed

Homepage

Simply Visit http://localhost:80 to navigate the world of Merlin

Homepage

Log In - Admin Panel

You should now be able to visit http://localhost:8000/admin

Admin URL

Where you will be presented with a login

Admin Log In

Default Username and Password:

admin

admin

You can change this default password as well as add your own users and groups via the admin panel

Tables

Each pyATS function - learn config, parse show ip interface brief, learn platform, etc - are all mapped to indivudal database tables

As an administrator you can perform Create Read Update Delete (CRUD) operations directly from the administrator panel

Tables

Default Dataset

This utility is currently being built using the Cisco DevNet Sandbox - Nexus 9000

Sandbox

I have included a single record set per table for demonstration from the Cisco DevNet Sandbox - Nexus 9000

In order to be YAML FREE we convert a traiditonal "testbed.yaml" file into a database Model and Table

Traditional pyATS solutions typically would include a file like

testbed_DevNet_Nexus9k_Sandbox.yaml

That would look like this:

devices:
    sbx-n9kv:
      alias: 'DevNet_Sandbox_Nexus9k'
      type: Nexus 9000
      os: 'nxos'
      platform: n9k
      credentials:
        default:
          username: admin
          password: Cisco123
      connections:        
        cli:
          protocol: ssh
          ip: 10.10.20.58
          port: 22
          arguments:
            connection_timeout: 360

Merlin has transformed this into a database table via a Django Model which allows us to be YAML FREE!

Default Testbed Device

Nexus 9000 as a Database

Again, this alpha has been tested on a Nexus 9000, should you choose to try this on your own (hopefully) LAB equipment

  • Delete this device from the database

Delete Device

  • Add a new device

Add Device

Populate the following fields:

  • Hostname - (required) The actual hostname of the device
  • Alias - (required) A friendly name for the device
  • Type - (optional) Platform type friendly name (ie - Nexus 9000)
  • OS - (required) Either 'nxos', 'ios', or 'iosxe'
  • Platform (required) Plese check pyATS documentation but Platforms include:
    • n9k, n7k, n5k, cat4500, cat3850, cat9300
  • Username - (required) A valid username
  • Password - (required) A valid password
  • Protocol - (required) Typically 'ssh'; could be 'telnet'
  • IP - (required) A valid IP address (ie - 10.10.20.58)
  • Port - (required) Typically '22'
  • Connection Timeout - (optional) Typically 360 seconds

Again, you can populate multiple devices and mix operating systems, but in this Alpha scale (1+n devices) and non-NXOS platforms (IOS, IOS-XE), have NOT been tested, will NOT be supported, but will eventually become part of Merlin. Your mileage may vary.

Bulk Import

Using this format


Hostname,Alias,Device_type,OS,Platform,Username,Password,Protocol,IP Address,Port,Connection Timeout

You can visit http://localhost:8000/DeviceImport/ and bulk-upload your devices into Merlin

Bulk Upload

Please refer to the bulk_import_template.csv file in this repository

Scheduling Merlin

In the Admin Panel, using the Django Celery Beat package, you can setup periodic scheduled hands-free Merlin.

Celery Scheduling

Celery Task

Celery Schedule

Scheduling Notes

  • It is recommended to use the Scheduler in the Admin panel, however, to manually start a 5 minute full state capture run the 2 following lines at the CLI:
(merlin)$ celery -A merlin beat -l info --logfile=celery.beat.log --detach  

(merlin)$ celery -A merlin worker -l info --logfile=celery.log --detach
  • To stop manually scheduled period tasks:
(merlin)$ pkill -f "celery worker"  

(merlin)$ kill -9 $(ps aux | grep celery | grep -v grep | awk '{print $2}' | tr '\n'  ' ') > /dev/null 2>&1

pyATS Command Coverage

As of this build the following pyATS functions have been transformed into Merlin:

  • Learn ACL

  • Learn ARP

  • Learn ARP Statistics

  • Learn BGP Instances

  • Learn BGP Routes

  • Learn BGP Tables

  • Learn Config

  • Learn Interface

  • Learn Platform

  • Learn Platform Slots

  • Learn Platform Virtual Devices

  • Learn VLAN

  • Learn VRF

  • Show Inventory

  • Show IP Interface Brief

  • Show Version

On-Demand Centre

Merlin allows users to capture either the full network state or individual functions using the On-Demand Centre.

On-Demand Centre

Users can press the button will capture the requested records for all devices in the database

On-Demand All Devices

Users can also filter the scope of the pyATS job at a group level using Device Type, Operating System or Username; or at an individual device level using Hostname, Alias, or IP Address

On-Demand Filter

While the pyATS job collects and transforms the network state a spinner will be displayed in the Status field

On-Demand Spinner

Search Engine

The Merlin Search Engine allows users to keyword search against the database.

Merlin Search

Search All Records will search both Network State and Network Configuration tables. Using this search will return the 'full' JSON of a running-config if the search hits against the Learn Configuration table.

Merlin All Records

This search omits Learn Config and only searches the "State" of the network

Merlin All Records Config Example

This search only looks up Learn Config and, different from the All Records Search, will break down any hits in a Configuration to each individual key, value pair found.

Using the same "vty" example:

Merlin Config Records

Merlin Config Results Example

Network State Change Centre

The Merlin Network State Change Centre can detect changes in the network state or configuration by gathering the latest state from the network and comparing it against the previous latest record set in the database.

Much like the On-Demand Centre users can press a button to compare against all devices in the database or they can use keyword filtering at a group or host level to scope the network state capture against specific devices.

Merlin Network State Change Centre

No Changes Detected

If Merlin does not detect any changes in network state or configuration it will tell you!

No Changes

Additions Found

If Merlin detects additions - that is to say, state or configuration found in the network but not found in the database - you will be notified of these additions

CLI Changes

Changes Found Additions 01

Changes Found Additions 02

Changes Found Additions 03

Removals Found

If Merlin detects removals - that is to say, state or configuration not found in the network but found in the database - you will be notified of these removals

Changes Found Removals 01

Changes Found Removals 01

REST API

Merlin contains a fully functional, stand-alone REST API !

Merlin API

Merlin API Panel

As you can see - each pyATS function has it's own dedicated REST API

http://localhost:8000/API/LearnConfig/

Merlin Config API

cURL, Postman, Python

Provided Merlin is running you can automate and program against the REST API !

Without ever even launching your browser you can use other tools to access the REST API

cURL

curl http://localhost:8000/API/LearnConfig/

Merlin API - cURL

Postman

Popular API tools like Postman can also be used!

Merlin API - Postman

Python

Pythonically you can use the requests library

$ source merlin/bin/activate 
(merlin)$ python
# import requests
>>> Import requests

# GET Learn Config Tables

>>> learn_config = requests.get("http://localhost:8000/API/LearnConfig")

# Validate response
>>> config
<Response [200]>

# Dump content of API to screen
>>> config.content

Merlin API - Python

Triggering Automation with the API

It should be noted that all of the pyATS automation behind "the buttons" and filters can be triggered with REST API GET requests against the appropriate URL / API

For example if you want to repopulate the entire database with fresh network state and configuration you could do a GET against

http://localhost:8000/OnDemand/GetAll/get_all_all_result/

Merlin API - Trigger Automation

Merlin API - Sending

Once the pyATS job completes Postman will return the following success confirming the database has been refreshed with new network state.

Merlin API - Sending

Business Ready Document Centre

At the heart of Merlin is the ability to provide network state and configuration information in Business Ready Documents - Spreadsheets !

Either download All Records or only the Latest Records with the click of a button!

Merlin CSV

All Records

Merlin All CSV

Latest Records

Merlin Latest CSV

These CSV files will be in your default browser Download location and can be opened with Excel, VS Code with Excel Preview, or any CSV-viewer

Latest Records

Often users may want only the latest records - the so-called "current" state - of the database and ideally the network state and running-configuration

Users can visit any /Latest/{{ any function }} to get the Latest records.

Merlin Latest

For example

http://localhost:8000/Latest/LearnConfig/

Merlin Latest

Natural HTML Filtering

Merlin URLs provide natural filtering for users

Each function - for example http://localhost:8000/LearnConfig/ can be followed by the following natural filters against the database records

All

All records in a specific database table

http://localhost:8000/LearnConfig/All

Year

All records in a specific database table by year

http://localhost:8000/LearnConfig/2021/

Month

All records in a specific database table by year and month

http://localhost:8000/LearnConfig/2021/09

Day

All records in a specific database table by year and month and day

http://localhost:8000/LearnConfig/2021/09/27

Device Hostname

All records in a specific database table by hostname

http://localhost:8000/LearnConfig/Hostname/sbx-n9kv

Device Operating System

All records in a specific database table by operating system (so far "nxos")

http://localhost:8000/LearnConfig/OS/nxos

Device Type

All records in a specific database table by device type (ie Nexus_9000)

http://localhost:8000/LearnConfig/Type/Nexus_9000

Device Alias

All records in a specific database table by device Alias

http://localhost:8000/LearnConfig/Alias/DevNet_Sandbox_Nexus9k

Username

All records in a specific database table by configured username

http://localhost:8000/LearnConfig/Username/admin

IP

All records in a specific database table by IP Address

http://localhost:8000/LearnConfig/IP/10.10.20.58

Port

All records in a specific database table by port

http://localhost:8000/LearnConfig/Port/22

How to Reach Me

Please contact me on Twitter - https://twitter.com/john_capobianco

merlin_unchained's People

Contributors

automateyournetwork avatar dannywade avatar johncapobianco avatar kedharnathgoud avatar obrigg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

merlin_unchained's Issues

Docker image problems

Hi John,

I get many errors when I want to run Docker image.
Adding extra lines to the dockerfile fixed the issues for me.

  1. Problem;
    Hashes of expected file:
    • Checksum-FileSize:7626752 [weak]
    • SHA256:b7dd6cc0630334321ff822cf2fc69df1263d81548e808c46f7a77af66f54c19e
    • SHA1:f90289555ba000250b4f3b06c2d4fa70eae4da72 [weak]
    • MD5Sum:bf3fd40405388c5da311c791f93dfa9e [weak]
      Hashes of received file:
    • SHA256:34032bc756f67b5257c6a16fe9fb1ec14a9ee72890c7739b6b257fba11e90112
    • SHA1:686718a66a3d2e583580a574b324ba7d03be5a0c [weak]
    • MD5Sum:c35c6eed0e0dfd9830b431f245eb1c5a [weak]
    • Checksum-FileSize:6054390 [weak]

Solution:
Add this lines;
ENV DJANGO_SUPERUSER_PASSWORD=admin

#********************************************************
RUN touch /etc/apt/apt.conf.d/99fixbadproxy
&& echo "Acquire::http::Pipeline-Depth 0;" >> /etc/apt/apt.conf.d/99fixbadproxy
&& echo "Acquire::http::No-Cache true;" >> /etc/apt/apt.conf.d/99fixbadproxy
&& echo "Acquire::BrokenProxy true;" >> /etc/apt/apt.conf.d/99fixbadproxy
&& apt-get update -o Acquire::CompressionTypes::Order::=gz
&& apt-get clean
&& rm -rf /var/lib/apt/lists/*
&& apt-get update -y
#********************************************************

RUN echo "==> Upgrading apk and installing system utilities ...."
&& apt -y update \

  1. Problem:

Step 23/31 : RUN echo "==> Adding Network JSON Graph..." && npm install netjsongraph.js --save
---> Running in 5bd891ca66c6
==> Adding Network JSON Graph...
npm ERR! Tracker "idealTree" already exists

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-05-04T18_56_19_156Z-debug-0.log
ERROR: Service 'merlin_unchained' failed to build: The command '/bin/sh -c echo "==> Adding Network JSON Graph..." && npm install netjsongraph.js --save' returned a non-zero code: 1
root@ayg02lab01:/home/sahip/merlin_unchained/merlin/merlin#

  1. Solution:
    Solution provated in :
    https://stackoverflow.com/questions/57534295/npm-err-tracker-idealtree-already-exists-while-creating-the-docker-image-for

RUN echo "==> Adding Twilio..."
&& pip install twilio

#************************************************************
COPY /merlin/merlin/static/ ./
COPY /merlin/merlin/static/ /merlin/merlin/static/
#***********************************************************
RUN echo "==> Adding Network JSON Graph..."
&& npm install netjsongraph.js --save


Now everything perfectly running;

Digest: sha256:df538ffaef03a079cf38dfcba8b67c47e8943f542b67adba91c2ef2720323654
Status: Downloaded newer image for grafana/grafana:latest
Creating elasticsearch ... done
Creating heimdall ... done
Creating merlin_unchained_prometheus_1 ... done
Creating merlin_unchained_db_1 ... done
Creating merlin_unchained_redis_1 ... done
Creating dejavu ... done
Creating kibana ... done
Creating elasticvue ... done
Creating grafana ... done
Creating pgadmin4_container ... done
Creating merlin_unchained_merlin_celery_beat00_1 ... done
Creating merlin_unchained_flower_1 ... done
Creating merlin_unchained_merlin_unchained_1 ... done

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.