Send netdisco-users mailing list submissions to
        netdisco-users@lists.sourceforge.net

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.sourceforge.net/lists/listinfo/netdisco-users
or, via email, send a message with subject or body 'help' to
        netdisco-users-requ...@lists.sourceforge.net

You can reach the person managing the list at
        netdisco-users-ow...@lists.sourceforge.net

When replying, please edit your Subject line so it is more specific
than "Re: Contents of netdisco-users digest..."
Today's Topics:

   1. Re: pulling out Inventory via Python for automation?
      (Michael Butash)
--- Begin Message ---
I put this together as a different inventory view I was looking for, look
at the SELECT sql query, you'll see where you pull data out of what
tables.  Add this to your deploy.yml and you can see what you get from your
query, then call the data directly using the query via python dbi call to
the db to get what you need.

I finally just dropped into a psql shell and poked around until I figured
out the tables and what data went where.  Some notes below for non-native
sql speakers to do some initial exploration.

## add to $netdisco-install-directory/environments/deploy.yml
reports:
  - tag: device-show-all-inventory
    label: 'Custom - Device Show All Inventory'
    category: Device
    columns:
    - { name: Device_Name}
    - { ip: IP}
    - { dns: FQDN}
    - { vendor: Vendor}
    - { os: Operating_System}
    - { model: Model}
    - { os_ver: OS_Version}
    - { serial: Serial_Number}
    - { last_discover: Last_Discovery}
    query: |
      SELECT name AS name, ip AS ip, dns AS dns, vendor AS vendor, os AS
os, os_ver AS os_ver, model AS model, serial AS serial, last_discover AS
last_discover
        FROM device
      ORDER BY name

## note query select from above, drop full query into sql below to test

## you can download the report directly as csv then even using the tag name
http://netmon-1:5000/ajax/content/report/device-show-all-inventory?

## jump into postgres account for god mode
root@netmon-1:~# su postgres

## launch the psql client for postgres
postgres@netmon-1:~$ psql
psql (12.7 (Ubuntu 12.7-0ubuntu0.20.04.1))
Type "help" for help.

## switch to netdisco db
postgres=# \c netdisco
You are now connected to database "netdisco" as user "postgres".

## describe tables, each contain device relations to each other.
netdisco=# \dt
                   List of relations
 Schema |            Name            | Type  |  Owner
--------+----------------------------+-------+----------
 public | admin                      | table | netdisco
 public | community                  | table | netdisco
 public | dbix_class_schema_versions | table | netdisco
 public | device                     | table | netdisco
 public | device_ip                  | table | netdisco
 public | device_module              | table | netdisco
 public | device_port                | table | netdisco
 public | device_port_log            | table | netdisco
 public | device_port_power          | table | netdisco
 public | device_port_properties     | table | netdisco
 public | device_port_ssid           | table | netdisco
 public | device_port_vlan           | table | netdisco
 public | device_port_wireless       | table | netdisco
 public | device_power               | table | netdisco
 public | device_skip                | table | netdisco
 public | device_vlan                | table | netdisco
 public | log                        | table | netdisco
 public | netmap_positions           | table | netdisco
 public | node                       | table | netdisco
 public | node_ip                    | table | netdisco
 public | node_monitor               | table | netdisco
 public | node_nbt                   | table | netdisco
 public | node_wireless              | table | netdisco
 public | oui                        | table | netdisco
 public | process                    | table | netdisco
 public | sessions                   | table | netdisco
 public | statistics                 | table | netdisco
 public | subnets                    | table | netdisco
 public | topology                   | table | netdisco
 public | user_log                   | table | netdisco
 public | users                      | table | netdisco
(31 rows)

## look at all data in any table to see format for each row of device.
This looks at "device" table.
netdisco=# select * from device;

## test query above
netdisco=# SELECT name AS name, ip AS ip, dns AS dns, vendor AS vendor, os
AS os, os_ver AS os_ver, model AS model, serial AS serial, last_discover AS
last_discover FROM device ORDER BY name

Saw this the other day to learn some quickie sql to assemble your own
queries, I learned a bit more roundabout.  https://sqlbolt.com/

-mb


On Mon, Jul 19, 2021 at 12:26 PM Joseph Bernard <j...@clemson.edu> wrote:

> I did find this:
>
>
>
> https://github.com/adambaumeister/netdisco_ansible_inventory
>
>
>
> Which also uses the Psycopg library.  I’ll look into Swagger-UI as well.
>
>
>
>
>
> Thanks,
>
> Joseph B.
>
>
>
>
>
> *From: *Jimmy Taylor <jimmytay...@boisestate.edu>
> *Date: *Monday, July 19, 2021 at 3:19 PM
> *To: *"netdisco-users@lists.sourceforge.net" <
> netdisco-users@lists.sourceforge.net>
> *Subject: *Re: [Netdisco] pulling out Inventory via Python for automation?
>
>
>
> I have done this in the past with Netmiko using the Psycopg library.
>
>
>
> https://www.psycopg.org/docs/index.html
>
>
>
> Like Michael was noting, the key is to get your Psql queries so you can
> get the data back in a dictionary that you can work with. I used PgAdmin to
> refine my queries:
>
>
>
> https://www.pgadmin.org/
>
>
>
> Some example queries I've done (use at your own risk):
>
>
>
> https://gist.github.com/consentfactory/3990cfc6c1b75eb65fcfe1fdccf013ff
>
>
>
> All this said, Netdisco has since implemented the Swagger-UI, which I
> might prefer to use at times.
>
>
>
> On Mon, Jul 19, 2021 at 11:56 AM Michael Butash <mich...@butash.net>
> wrote:
>
> I too am curious about this.
>
>
>
> I have been working on creating a few custom reports in ND for my own
> purposes, and learning where to find data across its sql tables (as well as
> learning sql queries) is probably the main thing, still automation data is
> my end goal too.  ND is a wealth of information to reuse if you can get all
> the bits formatted and exported into expected sql columns/rows if nothing
> else.
>
>
>
> I am not a dev or sql dba, but lots of googling plus examples previously
> posted got me some decent custom report output beyond what ND does.
> Probably just need to dip directly into pgsql with a dbi to get what you
> want, and work off that, at least my plan.
>
>
>
> Biggest issue I'm having is trying to figure out how to combine/recognize
> things like relations between port channels + physical ports, and just
> figuring out what is an uplink with lack of cdp/lldp vs. endpoint ports,
> that sometimes ala vm hosts have many macs learned as well.  These are just
> challenges with any automation in general around making sense of snmp data
> between vendors I suppose, and why devops is so hard with networking, at
> least for my non-developer self.
>
>
>
> There is the API as well, but not sure how better it might be to work with
> that vs. raw sql queries for your needs.
>
>
>
> HTH!
>
>
>
> -mb
>
>
>
>
>
> On Mon, Jul 19, 2021 at 8:25 AM Joseph Bernard <j...@clemson.edu> wrote:
>
> Has anyone done or found Python code that can pull out switch information
> from Netidsco for use with things like Nornir, Netmiko, or NAPALM?  Just
> wanted to check so I don’t reinvent the wheel.
>
>
>
> Thanks,
>
> Joseph Bernard
>
> _______________________________________________
> Netdisco mailing list
> netdisco-users@lists.sourceforge.net
> https://sourceforge.net/p/netdisco/mailman/netdisco-users/
>
> _______________________________________________
> Netdisco mailing list
> netdisco-users@lists.sourceforge.net
> https://sourceforge.net/p/netdisco/mailman/netdisco-users/
>
>
>
>
> --
>
> *Jimmy Taylor*
>
> *Network Engineer*
>
> Office of Information Technology
>
> Boise State University
> _______________________________________________
> Netdisco mailing list
> netdisco-users@lists.sourceforge.net
> https://sourceforge.net/p/netdisco/mailman/netdisco-users/

--- End Message ---
_______________________________________________
Netdisco mailing list - Digest Mode
netdisco-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/netdisco-users

Reply via email to