-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugins are not applied to custom directive #300
Comments
I have walked through the code and find out two possiblitiy location that might cause this bug.
Therefore, the current solution is to
|
Thank you very much for your time. And put the plugins into the plugins directory but have the same results. And the live output from the container doesnt show PLUGIN_DIR... should that be there or will a print in that function not work? |
It seems that with docker, the code is actually run at
if you have done correclty, it should print something out. |
Thanks for the suggestion ! I changed the volumes as above and got the error:
when starting the container. I changed and it works as expected, printing the output directly into the container output on the cli. With that I could troubleshoot a bit and found a potential solution:
and got the following result from the container:
To fix that problem I have following two solutions: 1: Swap lines 324-328 from
to
2: Transform the strings in plugins.iterdir() to Path Objects and insert a .name. in the comparison of f and p:
But with approach 2. you have to also add With these changes applied I am now getting:
What do you think about it, maybe theres a better solution. |
Well, since I am not the author/maintainer of this project. I think that we should leave the answer to him; however he is disappeared from the Internet currently. Still, love to see that you have solve the problem. matching_plugins = (
f
for f in plugin_dir.iterdir()
if f.name.split(".")[0] in (p.name.split(".")[0] for Path(p) in plugins)
) I think solution 2 with a slightly change might be a better solution, since it have the least change to the original code. matching_plugins = []
for f in plugin_dir.iterdir():
for p in plugins:
if f.name.split(".")[0] == p.split(".")[0]:
matching_plugins.append(f) Not tested yet, but I think this is your original intention? |
Thanks for your help ! Definitely the cleaner approach but the Path(p) throws errors on my instance. I kept
for further testing and discovered that my transform_input.py plugin is registered and executed. The line I created a Output plugin juniper-bgp-route.py:
which gets registered in the container start but not executed after the query ( yes i bound that in another command in the directives.yaml). For further troubleshooting I did in /opt/hyperglass/hyperglass/plugins/_manager.py:
and did the query as before and now got the output: hyperglass-1 | [DEBUG] 20241108 07:26:43 |51 | collect → Connecting to device {'device': 'Oldenburg Test', 'address': 'None:None', 'proxy': None} so it looks like there's no platform set for the plugin and therefore the plugin fails the check in directives = ( based on the builtin plugins i added the marked line to my plugin juniper-bgp-route.py:
Now the output plugin works as expected and the query output is Plugin Test Successfull... You mentioned that the creator is currently not responding on this project therefore I'm thinking about forking my changes, so that others with the same problems have a solution until the creator fixes these problems in this original repository . With that in mind I would also remove the platform check in the /opt/hyperglass/hyperglass/plugins/_manager.py from
to
|
I am also thinking of forking one and fix other issues. Perhaps create a hyperglass 2 or something. Do U mind inviting U to create a PR after the new hyperglass is created? |
Sure would be glad, after all your help. |
Deployment Type
Docker
Version
v2.0.4
Steps to Reproduce
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.:/]+'
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
put the transform_plugin.py in /etc/hyperglass/plugins and /etc/hyperglass/custom_plugins folder
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
enable debug mode like in https://hyperglass.dev/installation/environment-variables
enter the hyperglass site and enter "192.0.2.0/24" in the query as in https://hyperglass.dev/plugins example
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']}
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
Devices
Logs
The text was updated successfully, but these errors were encountered: