Skip to content

Plugins are not applied to custom directive #300

Open
@WalkerD243

Description

@WalkerD243

Deployment Type

Docker

Version

v2.0.4

Steps to Reproduce

  1. Create directives.yaml:
    juniper-bgp-route:
    name: BGP Route Custom
    plugins:
    - "/etc/hyperglass/plugins/transform_plugin.py"
    rules:
    - condition: 0.0.0.0/0
    commands: show route protocol bgp table inet.0 {target} detail | display json
    - condition: ::/0
    commands: show route protocol bgp table inet6.0 {target} detail | display json
    field:
    description: 'IPv4 or IPv6 Address'
    validation: '[0-9a-f.:/]+'
    juniper-received-from-peer:
    name: Received from Peer
    plugins:
    - /etc/hyperglass/custom_plugins/transform_plugin.py
    rules:
    - condition: ''
    commands: show route receive-protocol bgp {target}

    field:
    description: 'Your IPv4 or IPv6 BGP Peer Address'
    validation: '[0-9a-f.:/]+'

  2. Create plugin based on https://hyperglass.dev/plugins
    from ipaddress import ip_network
    from hyperglass.plugins import InputPlugin

class TransformCIDR(InputPlugin):
def transform(self, query):
(target := query.query_target)
target_network = ip_network(target)
if target_network.version == 4:
return f"{target_network.network_address!s} {target_network.netmask!s}"
return target

  1. put the transform_plugin.py in /etc/hyperglass/plugins and /etc/hyperglass/custom_plugins folder

  2. check that the container can see the plugins:
    docker container exec hyperglass-hyperglass-1 cat /etc/hyperglass/plugins/transform_plugin.py
    docker container exec hyperglass-hyperglass-1 cat /etc/hyperglass/custom_plugins/transform_plugin.py

  3. enable debug mode like in https://hyperglass.dev/installation/environment-variables

  4. enter the hyperglass site and enter "192.0.2.0/24" in the query as in https://hyperglass.dev/plugins example

  5. observe the live output from the container and look at the line:
    hyperglass-1 | [DEBUG] 20241030 14:26:43 |129 | queries → Constructed query {'type': 'juniper-bgp-route', 'target': ['192.0.2.0/24'], 'constructed_query': ['show route protocol bgp table inet.0 192.0.2.0/24 detail | display json']}

  6. look at the result in the webinterface, as it should transform 192.0.2.0/24 to 192.0.2.0 255.255.255.0 and the query is executed on a juniper device it should return a syntax error at the 255.255.255.0

Expected Behavior

I would expect that the constructed_query line form step 7. above would be:
hyperglass-1 | [DEBUG] 20241030 14:26:43 |129 | queries → Constructed query {'type': 'juniper-bgp-route', 'target': ['192.0.2.0/24'], 'constructed_query': ['show route protocol bgp table inet.0 192.0.2.0 255.255.255.0 detail | display json']}

and the result in the webinterface should return a syntax error at the 255.255.255.0 as it is executed on a juniper device in my case

Observed Behavior

I get the line:
hyperglass-1 | [DEBUG] 20241030 14:26:43 |129 | queries → Constructed query {'type': 'juniper-bgp-route', 'target': ['192.0.2.0/24'], 'constructed_query': ['show route protocol bgp table inet.0 192.0.2.0 255.255.255.0 detail | display json']}

and a normal result in the webinterface as if the query wasn't changed by the plugin

For me it seems like the plugin is not applied at all, even if change the last line in the plugin config to "return 'test'" the query is still successfull. I tried different folders in /etc/hyperglass and giving 777 full rights to the folder and files inside.

The same thing happens with the output plugins, please have a look. this is ssuch a great platform!

Configuration

web:
    logo:
        light: /etc/hyperglass/a.svg
        dark: /etc/hyperglass/a.svg
        favicon: /etc/hyperglass/a.svg
        width: 40%
        height: null
    text:
        title: Looking Glass
        subtitle: provided by hyperglass
        title_mode: all

Devices

devices:
  - name: Oldenburg Test
    address: 
    credential:
      username: 
      password: 
    platform: juniper
    directives:
      - builtins: false
      - juniper-bgp-route
      - juniper-received-from-peer
    attrs:
      source4: 
      source6:

Logs

hyperglass-1  | [INFO] 20241030 14:26:30 |1762 | callHandlers → 80.228.255.62:52285 - "GET / HTTP/1.1" 200 {}
hyperglass-1  | [INFO] 20241030 14:26:31 |1762 | callHandlers → 80.228.255.62:52285 - "GET /_next/static/chunks/webpack-790cb4468e180930.js HTTP/1.1" 200 {}
hyperglass-1  | [INFO] 20241030 14:26:31 |1762 | callHandlers → 80.228.255.62:52286 - "GET /_next/static/nz0t2HFziAXTmh8bM1vdX/_buildManifest.js HTTP/1.1" 200 {}
hyperglass-1  | [INFO] 20241030 14:26:31 |1762 | callHandlers → 80.228.255.62:52287 - "GET /_next/static/nz0t2HFziAXTmh8bM1vdX/_ssgManifest.js HTTP/1.1" 200 {}
hyperglass-1  | [INFO] 20241030 14:26:31 |1762 | callHandlers → 80.228.255.62:52287 - "GET /_next/static/chunks/915.4213c6fa1c4191ba.js HTTP/1.1" 200 {}
hyperglass-1  | [DEBUG] 20241030 14:26:43 |111 | membership → Checking target membership {'target': '192.0.2.0/24', 'network': '0.0.0.0/0'}
hyperglass-1  | [DEBUG] 20241030 14:26:43 |116 | membership → Target membership verified {'target': '192.0.2.0/24', 'network': '0.0.0.0/0'}
hyperglass-1  | [DEBUG] 20241030 14:26:43 |123 | in_range → Target is in range {'target': '192.0.2.0/24', 'range': '0-32'}
hyperglass-1  | [DEBUG] 20241030 14:26:43 |107 | validate_query_target → Validation passed {'query': Query(query_location='oldenburg_test', query_target=['192.0.2.0/24'], query_type='juniper-bgp-route')}
hyperglass-1  | [INFO] 20241030 14:26:43 |79 | query → Starting query execution {'query': Query(query_location='oldenburg_test', query_target=['192.0.2.0/24'], query_type='juniper-bgp-route')}
hyperglass-1  | [DEBUG] 20241030 14:26:43 |97 | query → Cache miss {'query': Query(query_location='oldenburg_test', query_target=['192.0.2.0/24'], query_type='juniper-bgp-route'), 'cache_key': 'hyperglass.query.bd2cab8688de5e3c1830c75380ace8f313a2ef493f56a31e6afefc6840e5135f'}
hyperglass-1  | [DEBUG] 20241030 14:26:43 |51 | execute →  {'query': Query(query_location='oldenburg_test', query_target=['192.0.2.0/24'], query_type='juniper-bgp-route'), 'device': 'oldenburg_test'}
hyperglass-1  | [DEBUG] 20241030 14:26:43 |46 | __init__ → Constructing query {'type': 'juniper-bgp-route', 'target': ['192.0.2.0/24']}
hyperglass-1  | [DEBUG] 20241030 14:26:43 |129 | queries → Constructed query {'type': 'juniper-bgp-route', 'target': ['192.0.2.0/24'], 'constructed_query': ['show route protocol bgp table inet.0 192.0.2.0/24 detail | display json']}
hyperglass-1  | [DEBUG] 20241030 14:26:43 |51 | collect → Connecting to device {'device': 'Oldenburg Test', 'address': 'None:None', 'proxy': None}
hyperglass-1  | [DEBUG] 20241030 14:26:52 |115 | query → Runtime: 8.6084 seconds {'query': Query(query_location='oldenburg_test', query_target=['192.0.2.0/24'], query_type='juniper-bgp-route')}
hyperglass-1  | [DEBUG] 20241030 14:26:52 |134 | query → Response cached {'query': Query(query_location='oldenburg_test', query_target=['192.0.2.0/24'], query_type='juniper-bgp-route'), 'cache_timeout': 120}
hyperglass-1  | [INFO] 20241030 14:26:52 |146 | query → Execution completed {'query': Query(query_location='oldenburg_test', query_target=['192.0.2.0/24'], query_type='juniper-bgp-route')}
hyperglass-1  | [INFO] 20241030 14:26:52 |1762 | callHandlers → 80.228.255.62:52292 - "POST /api/query HTTP/1.1" 201 {}
hyperglass-1  | [WARNING] 20241030 14:29:21 |1762 | callHandlers → Invalid HTTP request received. {}
hyperglass-1  | [INFO] 20241030 14:29:32 |1762 | callHandlers → 152.32.245.93:58616 - "GET / HTTP/1.1" 200 {}
hyperglass-1  | [INFO] 20241030 14:29:37 |1762 | callHandlers → 152.32.245.93:47778 - "GET /images/favicons/favicon-196x196.png HTTP/1.1" 200 {}
hyperglass-1  | [INFO] 20241030 14:29:38 |1762 | callHandlers → 152.32.245.93:47786 - "GET /robots.txt HTTP/1.1" 200 {}
hyperglass-1  | [INFO] 20241030 14:29:38 |1762 | callHandlers → 152.32.245.93:47798 - "GET /sitemap.xml HTTP/1.1" 404 {}
hyperglass-1  | [INFO] 20241030 14:29:38 |1762 | callHandlers → 152.32.245.93:47826 - "GET /_next/static/chunks/polyfills-c67a75d1b6f99dc8.js HTTP/1.1" 200 {}
hyperglass-1  | [INFO] 20241030 14:29:38 |1762 | callHandlers → 152.32.245.93:47824 - "GET /_next/static/nz0t2HFziAXTmh8bM1vdX/_buildManifest.js HTTP/1.1" 200 {}
hyperglass-1  | [INFO] 20241030 14:29:38 |1762 | callHandlers → 152.32.245.93:47802 - "GET /_next/static/chunks/webpack-790cb4468e180930.js HTTP/1.1" 200 {}
hyperglass-1  | [INFO] 20241030 14:29:38 |1762 | callHandlers → 152.32.245.93:47816 - "GET /_next/static/chunks/pages/_app-e5cf2d2230ac6396.js HTTP/1.1" 200 {}
hyperglass-1  | [INFO] 20241030 14:29:38 |1762 | callHandlers → 152.32.245.93:47840 - "GET /_next/static/chunks/pages/index-a1a889711ef3362f.js HTTP/1.1" 200 {}
hyperglass-1  | [INFO] 20241030 14:29:39 |1762 | callHandlers → 152.32.245.93:47866 - "GET /_next/static/chunks/main-113d9e0de0ebdeca.js HTTP/1.1" 200 {}
hyperglass-1  | [INFO] 20241030 14:29:39 |1762 | callHandlers → 152.32.245.93:47850 - "GET /_next/static/chunks/framework-f856061fb4a8c9e6.js HTTP/1.1" 200 {}
hyperglass-1  | [INFO] 20241030 14:29:39 |1762 | callHandlers → 152.32.245.93:47878 - "GET /_next/static/nz0t2HFziAXTmh8bM1vdX/_ssgManifest.js HTTP/1.1" 200 {}
hyperglass-1  | [INFO] 20241030 14:29:40 |1762 | callHandlers → 152.32.245.93:47892 - "GET /config.json HTTP/1.1" 404 {}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions