dev
  • Contents
      • NAV documentation
        • Getting help
        • First steps
        • Digging deeper
      • Overview
        • What it is
        • What NAV does
        • A brief history of NAV
      • Installing NAV
        • Installing a pre-packaged version of NAV
        • Installing NAV from source code
      • Getting started with NAV
        • Minimal configuration
        • Starting NAV
        • Logging in to the web interface
        • Seeding your database
        • Further reading
      • Getting organized
        • Organizing your seed data
        • Organizing your collected data
      • Howtos
        • Command line utilities provided in NAV
        • Installing NAV from source code
        • Install from source on Debian
        • Installing Graphite for use with NAV on Debian
        • Integrating Graphite with NAV
        • Migrating RRD data to Graphite (from NAV 3 to NAV 4)
        • Troubleshooting topology problems in NAV
        • Robustifying e-mail
        • Migrating data from one NAV installation to another
        • Authenticating with the apache plugin mod_auth_openidc and Feide
        • Controlling log output from NAV
        • The NAV API
        • NAV API Parameters
      • FAQ
        • Is vendor X / device Y supported?
        • Why are there gaps in my graphs?
        • Why does NAV list my device’s uplink as N/A?
        • Why doesn’t device X show as down in the status page when I know it’s down?
        • A device is down, I see it on the status page, my profile should cover the event, but I am not alerted. Why?
        • Why is my Cisco switch’ syslog full of SNMP-3-AUTHFAIL messages for requests from my NAV server?
        • I added a new IP Device using SeedDB, but nothing happens. Why?
        • How do I make NAV send SMS alerts?
        • How long are ARP and CAM records kept in the database?
      • Reference material
        • Management profiles
        • Arnold
        • Cabling and Patch
        • Event Engine
        • Event Templates
        • Event- and alert type hierarchy
        • Geomap
        • IPAM - IP Address Management
        • ipdevpoll
        • External authentication (LDAP, REMOTE_USER)
        • MailIn
        • navstats
        • PortAdmin
        • Radius
        • Setting up FreeRADIUS to log to NAV
        • smsd
        • snmptrapd
        • Backend processes in NAV
      • Network Administration Visualized release notes
        • NAV 5.8
        • NAV 5.7
        • NAV 5.6
        • NAV 5.5
        • NAV 5.4
        • NAV 5.3
        • NAV 5.2
        • NAV 5.1
        • NAV 5.0
        • NAV 4.9
        • NAV 4.8
        • NAV 4.7
        • NAV 4.6
        • NAV 4.5
        • NAV 4.4
        • NAV 4.3
        • NAV 4.2
        • NAV 4.1
        • NAV 4.0
        • NAV 3.15
        • NAV 3.14
        • NAV 3.13
        • NAV 3.12
        • NAV 3.11
        • NAV 3.10
        • NAV 3.9
        • NAV 3.8
      • Glossary
      • Hacking NAV
        • Hacker’s guide to NAV
        • Hacking with PyCharm
        • Using NAV with Docker for development
        • Javascript hacking
        • Checklist for releasing a new NAV version
        • Writing a new servicemon plugin
        • Adding support for a new environment probe device to NAV
        • The NAV API
        • Extending NAV locally
        • How to customize parts of NAV’s web interface
        • NAVbar search providers
        • Establishing SNMP tunnels using socat/SSH
  • Page
      • NAVbar search providers
        • A simple implementation example
        • The SearchProvider base class
        • The SearchResult namedtuple
  • « How to custom...
  • Establishing ... »
  • NAVbar search providers
    • A simple implementation example
    • The SearchProvider base class
    • The SearchResult namedtuple
Source

NAVbar search providers¶

NAV’s search bar (the one seen at the top of every NAV web page) provides a pluggable architecture for search implementations. Any class that implements the interface of nav.web.info.searchproviders.SearchProvider can be used as a provider of search results for the NAVbar.

The list of SearchProvider implementations that are used to respond to NAVbar search is configured in NAV’s Django settings. The default list, as of NAV 4.8, looks like this:

# Classes that implement a search engine for the web navbar
SEARCHPROVIDERS = [
    'nav.web.info.searchproviders.RoomSearchProvider',
    'nav.web.info.searchproviders.LocationSearchProvider',
    'nav.web.info.searchproviders.NetboxSearchProvider',
    'nav.web.info.searchproviders.InterfaceSearchProvider',
    'nav.web.info.searchproviders.VlanSearchProvider',
    'nav.web.info.searchproviders.PrefixSearchProvider',
    'nav.web.info.searchproviders.DevicegroupSearchProvider',
    'nav.web.info.searchproviders.UnrecognizedNeighborSearchProvider',
]

If you want to hook in your own SearchProvider, local to your installation, you can do this by manipulating this list in your local_settings.py file.

A simple implementation example¶

This is the current implementation of the Room search provider; it will do a substring search among room IDs, and then return search results which link back to each matched room’s details page.

class RoomSearchProvider(SearchProvider):
    """Searchprovider for rooms"""
    name = "Rooms"
    headers = [
        ('Roomid', 'id'),
        ('Description', 'description')
    ]
    link = 'Roomid'

    def fetch_results(self):
        results = Room.objects.filter(id__icontains=self.query).order_by("id")
        for result in results:
            self.results.append(SearchResult(
                reverse('room-info', kwargs={'roomid': result.id}),
                result)
            )

The actual work of the implementation is accomplished within the fetch_results() method, which must return a list of nav.web.info.searchproviders.SearchResult namedtuples.

The headers class attribute defines how to extract columnar information from the returned SearchResult’s instance objects. In this case, the search result tab for Rooms will contain two columns: One captioned Roomid, where the cell values come from the Room objects’ id attribute, and one captioned Description, where the cell values come from the Room objects’ description attributes.

The SearchProvider base class¶

class nav.web.info.searchproviders.SearchProvider(query='')¶

Search provider interface.

To implement this interface, all that is needed is to inherit from this class, set some class attributes and override the fetch_results() method. The query, as entered by the end-user will be available in the self.query variable.

__init__(query='')¶
Parameters

query – The search query string, as entered by the user.

fetch_results()¶

Fetches and returns results based on self.query.

Returns

A list of nav.web.info.searchproviders.SearchResult instances.

headers = (('Column title', 'result instance attribute name'),)¶

Defines the result table columns; what the column titles should be, and which attribute from the SearchResult.inst object to extract the values for this column from.

link = 'id'¶

The title of the result column to put hyperlinks in

name = 'SearchProvider'¶

Used as the caption of results from this provider

The SearchResult namedtuple¶

A SearchResult namedtuple consist of the href and inst attributes. href is a URL used as a hyperlink on the search result line. inst is normally some kind of instance object, typically a Django model, which represent the search result itself.

class nav.web.info.searchproviders.SearchResult(href, inst)¶
property href¶

Alias for field number 0

property inst¶

Alias for field number 1

Back to top

© Copyright 2012-2023 Uninett AS, 2022-2023 Sikt.
Created using Sphinx 4.4.0.