Skip to content
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

EDA does not like either slashes or dashes within the condition path #60

Open
burnyd opened this issue Dec 5, 2022 · 7 comments
Open

Comments

@burnyd
Copy link

burnyd commented Dec 5, 2022

Version of ansible-rulebook

ansible-rulebook --version
__version__ = '0.9.4'
fd66d7cb-4b33-4949-b826-11a854ba7dc2

I am trying to develop a new EDA source plugin. I need to key off data coming from a pub/sub bus. Some sample data will look as the following

{"name":"sub1","timestamp":1670273612118710138,"tags":{"interface_name":"Ethernet1","source":"172.20.20.3","subscription-name":"sub1"},"values":{"/interfaces/interface/state/admin-status":"UP"}}

The very last portion is what I need to key off of the values key

"values":{"/interfaces/interface/state/admin-status":"UP"}

The condition portion of the rule-book looks as follows.

rules:
    - name: check down interface
      condition: event.values./interfaces/interface/state/admin-status == "DOWN"

Resulting in the following error.

self._session_id = self._api.createRuleset(self.serialized_ruleset)

I have tried dotted notation, brackets and also vars all within the same error message. Either I can key off of this value or if there is a way to be able to check to see if the word DOWN is within that array would work as well. But generally speaking it does not like slashes or dashes.

@mkanoor
Copy link
Contributor

mkanoor commented Dec 5, 2022

@burnyd In the source plugin are you getting array data? Currently we don't support array in conditions. In the source plugin you should be able to morph the data the way you want to check in the rules.

@burnyd
Copy link
Author

burnyd commented Dec 5, 2022

@burnyd In the source plugin are you getting array data? Currently we don't support array in conditions. In the source plugin you should be able to morph the data the way you want to check in the rules.

Yes, I am getting a python dictionary for the data referenced within the issue. So the output pushed into the python async queue would look like this.

{"name":"sub1","timestamp":1670273612118710138,"tags":{"interface_name":"Ethernet1","source":"172.20.20.3","subscription-name":"sub1"},"values":{"/interfaces/interface/state/admin-status":"UP"}}

If I can understand what you are saying is I need to edit the source plugin so I am only returning the value of a string of "UP" and that the return value cannot be an array?

@mkanoor
Copy link
Contributor

mkanoor commented Dec 5, 2022

@burnyd I was thinking you would have multiple interfaces in that case you would have to use indexing e.g. interface[0], interface[1] that is currently not supported. In your example it looks like the key has embedded slashes and that might be throwing it off. I will look into it

@burnyd
Copy link
Author

burnyd commented Dec 5, 2022

Okay please let me know. Otherwise, It looks I have to replace strings with "/" or "-" with underscores.

@mkanoor
Copy link
Contributor

mkanoor commented Dec 6, 2022

@burnyd The identifiers used for keys needs to follow the rules for Ansible variable names and it can only contain
letters, numbers, and underscores

https://docs.ansible.com/ansible/2.5/user_guide/playbooks_variables.html#what-makes-a-valid-variable-name

I think in your case you would have to convert the / to underscore

@burnyd
Copy link
Author

burnyd commented Dec 6, 2022

When you say convert the / to underscore you are referring to the actual source EDA plugin? So have that use python string replace for "/" to "" and within the condition where I am keying use "" ? Just want to make sure I am clear on this.

@benthomasson
Copy link
Contributor

benthomasson commented Dec 6, 2022

You can use event filters for this: https://github.com/benthomasson/ci-cd-demo/blob/main/event_filters/dashes_to_underscores.py

See how to use them here: https://github.com/benthomasson/ci-cd-demo/blob/main/github-ci-cd-rules.yml

    - name: azure_service_bus
      ansible.eda.azure_service_bus:
        conn_str: "{{connection_str}}"
        queue_name: "{{queue_name}}"
      filters:
        - json_filter:
            include_keys: ['clone_url']
            exclude_keys: ['*_url', '_links', 'base', 'sender', 'owner', 'user']
        - dashes_to_underscores:```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants